Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

query-engine-c-abi: CI build for RN binaries #4838

Merged
merged 3 commits into from Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .buildkite/engineer
Expand Up @@ -54,7 +54,7 @@ fi
# Check if the system has engineer installed, if not, use a local copy.
if ! type "engineer" &> /dev/null; then
# Setup Prisma engine build & test tool (engineer).
curl --fail -sSL "https://prisma-engineer.s3-eu-west-1.amazonaws.com/1.66/latest/$OS/engineer.gz" --output engineer.gz
curl --fail -sSL "https://prisma-engineer.s3-eu-west-1.amazonaws.com/1.67/latest/$OS/engineer.gz" --output engineer.gz
gzip -d engineer.gz
chmod +x engineer

Expand Down
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
SevInf marked this conversation as resolved.
Show resolved Hide resolved
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.