Skip to content

Commit

Permalink
query-engine-c-abi: CI build for RN binaries
Browse files Browse the repository at this point in the history
Adds GH Actions pipeline for building iOS & Andorid query engine
for `prisma-react-native`. Pipeline is triggered by engineer, similar to
Windows and Mac builds.

See prisma/engineer#120
Example of succesfull run: https://buildkite.com/prisma/release-prisma-engines/builds/3721#018f1a4f-95c9-4cdd-b551-94e53d4e1978

Contributes to prisma/team-orm#1106
  • Loading branch information
SevInf committed Apr 26, 2024
1 parent 744b41c commit 0bfcd91
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 62 deletions.
101 changes: 101 additions & 0 deletions .github/workflows/build-engines-react-native.yml
@@ -0,0 +1,101 @@
name: Build Engines for React native
on:
workflow_dispatch:
inputs:
commit:
description: "Commit on the given branch to build"
required: false

jobs:
build-ios:
# Do not change `name`, prisma-engines Buildkite build job depends on this name ending with the commit
name: "iOS build on branch ${{ github.event.ref }} for commit ${{ github.event.inputs.commit }}"
runs-on: macos-13

steps:
- name: Output link to real commit
run: echo ${{ github.repository }}/commit/${{ github.event.inputs.commit }}

- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.commit }}

- uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-apple-ios,aarch64-apple-ios,aarch64-apple-ios-sim

- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-ios-cargo-${{ hashFiles('**/Cargo.lock') }}

- run: |
cd query-engine/query-engine-c-abi
make ios
- uses: actions/upload-artifact@v4
with:
name: ios
path: |
${{ github.workspace }}/query-engine/query-engine-c-abi/ios/*
build-android:
# Do not change `name`, prisma-engines Buildkite build job depends on this name ending with the commit
name: "Android build on branch ${{ github.event.ref }} for commit ${{ github.event.inputs.commit }}"
runs-on: ubuntu-latest

steps:
- name: Output link to real commit
run: echo ${{ github.repository }}/commit/${{ github.event.inputs.commit }}

- name: Checkout # TODO: commit
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.commit }}
- uses: dtolnay/rust-toolchain@stable
with:
targets: aarch64-linux-android,armv7-linux-androideabi,x86_64-linux-android,i686-linux-android

- uses: nttld/setup-ndk@v1
with:
ndk-version: r26d

- uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-android-cargo-${{ hashFiles('**/Cargo.lock') }}

- run: |
cd query-engine/query-engine-c-abi
make android
- uses: actions/upload-artifact@v4
with:
name: android
path: |
${{ github.workspace }}/query-engine/query-engine-c-abi/android/*
combine-artifacts:
# Do not change `name`, prisma-engines Buildkite build job depends on this name ending with the commit
name: "Combine iOS and Android artifacts on branch ${{ github.event.ref }} for commit ${{ github.event.inputs.commit }}"
runs-on: ubuntu-latest
needs:
- build-ios
- build-android
steps:
- name: Download artifacts
uses: actions/download-artifact@v4

- name: Upload combined artifact
uses: actions/upload-artifact@v4
with:
name: binaries
path: |
${{ github.workspace }}/ios
${{ github.workspace }}/android
3 changes: 2 additions & 1 deletion query-engine/query-engine-c-abi/.gitignore
@@ -1,4 +1,5 @@
QueryEngine.xcframework
ios
android
simulator_fat
# Artifacts of the C ABI engine
*.tar.gz
Expand Down
33 changes: 19 additions & 14 deletions query-engine/query-engine-c-abi/Makefile
Expand Up @@ -13,44 +13,49 @@ ARCHS_ANDROID = aarch64-linux-android armv7-linux-androideabi x86_64-linux-andro
LIB = libquery_engine.a
XCFRAMEWORK = QueryEngine.xcframework

.PHONY: clean ios android $(ARCH_IOS_SIM) $(ARCHS_IOS) $(ARCHS_ANDROID) sim copy-ios nuke
.PHONY: clean ios android $(ARCH_IOS_SIM) $(ARCHS_IOS) $(ARCHS_ANDROID) sim nuke

nuke:
rm -rf ../../target

clean:
rm -rf QueryEngine.xcframework
rm -rf ios
rm -rf android
rm -rf simulator_fat
mkdir simulator_fat
# rm -rf include
# mkdir include

all: nuke ios android

################# ANDROID #################
android: clean $(ARCHS_ANDROID)
./copy-android.sh

$(ARCHS_ANDROID): %:
mkdir -p android/jniLibs
mkdir android/jniLibs/x86
mkdir android/jniLibs/arm64-v8a
mkdir android/jniLibs/armeabi-v7a
mkdir android/jniLibs/x86_64
cp include/query_engine.h android
cp ../../target/i686-linux-android/release/libquery_engine.a android/jniLibs/x86/libquery_engine.a
cp ../../target/aarch64-linux-android/release/libquery_engine.a android/jniLibs/arm64-v8a/libquery_engine.a
cp ../../target/armv7-linux-androideabi/release/libquery_engine.a android/jniLibs/armeabi-v7a/libquery_engine.a
cp ../../target/x86_64-linux-android/release/libquery_engine.a android/jniLibs/x86_64/libquery_engine.a

$(ARCHS_ANDROID): %:
./build-android-target.sh $@

################# iOS #################
ios: clean $(XCFRAMEWORK)

sim: clean
cargo build --target $(ARCH_IOS_SIM)
xcodebuild -create-xcframework -library ../../target/$(ARCH_IOS_SIM)/debug/libquery_engine.a -headers include -output $(XCFRAMEWORK)
./copy-ios.sh
xcodebuild -create-xcframework -library ../../target/$(ARCH_IOS_SIM)/debug/libquery_engine.a -headers include -output ios/$(XCFRAMEWORK)

sim-release: clean
cargo build --target $(ARCH_IOS_SIM) --release
xcodebuild -create-xcframework -library ../../target/$(ARCH_IOS_SIM)/release/libquery_engine.a -headers include -output $(XCFRAMEWORK)
./copy-ios.sh
xcodebuild -create-xcframework -library ../../target/$(ARCH_IOS_SIM)/release/libquery_engine.a -headers include -output ios/$(XCFRAMEWORK)

$(ARCHS_IOS): %:
cargo build --release --target $@
cargo build -p query-engine-c-abi --release --target $@

$(XCFRAMEWORK): $(ARCHS_IOS)
lipo -create $(wildcard ../../target/x86_64-apple-ios/release/$(LIB)) $(wildcard ../../target/aarch64-apple-ios-sim/release/$(LIB)) -output simulator_fat/libquery_engine.a
xcodebuild -create-xcframework -library $(wildcard ../../target/aarch64-apple-ios/release/$(LIB)) -headers include -library simulator_fat/libquery_engine.a -headers include -output $@
./copy-ios.sh
xcodebuild -create-xcframework -library $(wildcard ../../target/aarch64-apple-ios/release/$(LIB)) -headers include -library simulator_fat/libquery_engine.a -headers include -output ios/$@
8 changes: 5 additions & 3 deletions query-engine/query-engine-c-abi/build-android-target.sh
Expand Up @@ -17,18 +17,20 @@ if [ "$TARGET" = "armv7-linux-androideabi" ]; then
fi

API_VERSION="21"
NDK_HOST="darwin-x86_64"
# shellcheck source=/dev/null
source "$ANDROID_NDK_ROOT/build/tools/ndk_bin_common.sh"
echo "Host tag: $HOST_TAG"

if [ -z "$ANDROID_NDK_ROOT" ]; then
echo "ANDROID NDK IS MISSING 🟥"
exit 1
fi

TOOLS="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$NDK_HOST"
TOOLS="$ANDROID_NDK_ROOT/toolchains/llvm/prebuilt/$HOST_TAG"

AR=$TOOLS/bin/llvm-ar \
CC=$TOOLS/bin/${NDK_TARGET}${API_VERSION}-clang \
CXX=$TOOLS/bin/${NDK_TARGET}${API_VERSION}-clang++ \
RANLIB=$TOOLS/bin/llvm-ranlib \
CXXFLAGS="--target=$NDK_TARGET" \
cargo build --release --target "$TARGET"
cargo build --release -p query-engine-c-abi --target "$TARGET" --config "target.$TARGET.linker=\"$TOOLS/bin/${NDK_TARGET}${API_VERSION}-clang\""
14 changes: 0 additions & 14 deletions query-engine/query-engine-c-abi/cargo-config.toml

This file was deleted.

18 changes: 0 additions & 18 deletions query-engine/query-engine-c-abi/copy-android.sh

This file was deleted.

12 changes: 0 additions & 12 deletions query-engine/query-engine-c-abi/copy-ios.sh

This file was deleted.

0 comments on commit 0bfcd91

Please sign in to comment.