diff --git a/.github/workflows/build-engines-react-native.yml b/.github/workflows/build-engines-react-native.yml new file mode 100644 index 00000000000..4a0a2c40c0a --- /dev/null +++ b/.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 + diff --git a/query-engine/query-engine-c-abi/.gitignore b/query-engine/query-engine-c-abi/.gitignore index 849b6e98617..fa3e1fc2f01 100644 --- a/query-engine/query-engine-c-abi/.gitignore +++ b/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 diff --git a/query-engine/query-engine-c-abi/Makefile b/query-engine/query-engine-c-abi/Makefile index 83e1d506c4e..362c53e54f1 100644 --- a/query-engine/query-engine-c-abi/Makefile +++ b/query-engine/query-engine-c-abi/Makefile @@ -13,25 +13,33 @@ 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 ################# @@ -39,18 +47,15 @@ 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 \ No newline at end of file + xcodebuild -create-xcframework -library $(wildcard ../../target/aarch64-apple-ios/release/$(LIB)) -headers include -library simulator_fat/libquery_engine.a -headers include -output ios/$@ \ No newline at end of file diff --git a/query-engine/query-engine-c-abi/build-android-target.sh b/query-engine/query-engine-c-abi/build-android-target.sh index db9b7d226a9..73af879957d 100755 --- a/query-engine/query-engine-c-abi/build-android-target.sh +++ b/query-engine/query-engine-c-abi/build-android-target.sh @@ -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" \ No newline at end of file +cargo build --release -p query-engine-c-abi --target "$TARGET" --config "target.$TARGET.linker=\"$TOOLS/bin/${NDK_TARGET}${API_VERSION}-clang\"" \ No newline at end of file diff --git a/query-engine/query-engine-c-abi/cargo-config.toml b/query-engine/query-engine-c-abi/cargo-config.toml deleted file mode 100644 index 68151bfbd7b..00000000000 --- a/query-engine/query-engine-c-abi/cargo-config.toml +++ /dev/null @@ -1,14 +0,0 @@ -# template file -# move this to your home directory to allow rust to compile the library for android -# All paths are relative to the user home folder -[target.aarch64-linux-android] -linker = "Library/Android/sdk/ndk/26.0.10792818/toolchains/llvm/prebuilt/darwin-x86_64/bin/aarch64-linux-android21-clang" - -[target.armv7-linux-androideabi] -linker = "Library/Android/sdk/ndk/26.0.10792818/toolchains/llvm/prebuilt/darwin-x86_64/bin/armv7a-linux-androideabi21-clang" - -[target.i686-linux-android] -linker = "Library/Android/sdk/ndk/26.0.10792818/toolchains/llvm/prebuilt/darwin-x86_64/bin/i686-linux-android21-clang" - -[target.x86_64-linux-android] -linker = "Library/Android/sdk/ndk/26.0.10792818/toolchains/llvm/prebuilt/darwin-x86_64/bin/x86_64-linux-android21-clang" diff --git a/query-engine/query-engine-c-abi/copy-android.sh b/query-engine/query-engine-c-abi/copy-android.sh deleted file mode 100755 index 20b1e86b8ec..00000000000 --- a/query-engine/query-engine-c-abi/copy-android.sh +++ /dev/null @@ -1,18 +0,0 @@ -#! /bin/bash - -TARGET_DIR=../../../react-native-prisma - -mkdir -p $TARGET_DIR/android/jniLibs -mkdir -p $TARGET_DIR/android/jniLibs/x86 -mkdir -p $TARGET_DIR/android/jniLibs/x86_64 -mkdir -p $TARGET_DIR/android/jniLibs/arm64-v8a -mkdir -p $TARGET_DIR/android/jniLibs/armeabi-v7a - -cp ../../target/i686-linux-android/release/libquery_engine.a $TARGET_DIR/android/jniLibs/x86/libquery_engine.a -cp ../../target/aarch64-linux-android/release/libquery_engine.a $TARGET_DIR/android/jniLibs/arm64-v8a/libquery_engine.a -cp ../../target/armv7-linux-androideabi/release/libquery_engine.a $TARGET_DIR/android/jniLibs/armeabi-v7a/libquery_engine.a -cp ../../target/x86_64-linux-android/release/libquery_engine.a $TARGET_DIR/android/jniLibs/x86_64/libquery_engine.a - -cp ./include/query_engine.h $TARGET_DIR/cpp/query_engine.h - -# pingme "✅ Android compilation ready" \ No newline at end of file diff --git a/query-engine/query-engine-c-abi/copy-ios.sh b/query-engine/query-engine-c-abi/copy-ios.sh deleted file mode 100755 index 58195b42bb8..00000000000 --- a/query-engine/query-engine-c-abi/copy-ios.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh - -set -ex - -TARGET_DIR=../../../react-native-prisma - -# This one is not actually necessary but XCode picks it up and mixes up versions -cp ./include/query_engine.h $TARGET_DIR/cpp/query_engine.h - -cp -R QueryEngine.xcframework $TARGET_DIR - -# pingme "✅ Prisma iOS Finished" \ No newline at end of file