From ce671e5496d76ae11134dc7d09afb880f78287ee Mon Sep 17 00:00:00 2001 From: JC Date: Mon, 9 Sep 2024 18:16:40 -0600 Subject: [PATCH 1/3] fix: trying with docker install manually --- .../workflows/android-integration-test.yaml | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/.github/workflows/android-integration-test.yaml b/.github/workflows/android-integration-test.yaml index 30b61e4b7..57237fff5 100644 --- a/.github/workflows/android-integration-test.yaml +++ b/.github/workflows/android-integration-test.yaml @@ -100,31 +100,31 @@ jobs: echo "AVD-ARCH=x86" >> $GITHUB_ENV echo "NEXTEST-ABI=arm32" >> $GITHUB_ENV - - name: Setup Docker 1 try - uses: douglascamata/setup-docker-macos-action@v1-alpha - id: dockerTry1 - continue-on-error: true - with: - lima: v0.18.0 - colima: v0.5.6 - - - name: checking outcome 1 - run: echo ${{ steps.dockerTry1.outcome }} - - - name: Setup Docker 2 try - if: steps.dockerTry1.outcome != 'success' - uses: douglascamata/setup-docker-macos-action@v1-alpha - id: dockerTry2 - continue-on-error: true - with: - lima: v0.18.0 - colima: v0.5.6 - - - name: checking outcome 2 - run: echo ${{ steps.dockerTry2.outcome }} + #- name: Setup Docker 1 try + # uses: douglascamata/setup-docker-macos-action@v1-alpha + # id: dockerTry1 + # continue-on-error: true + # with: + # lima: v0.18.0 + # colima: v0.5.6 + + #- name: checking outcome 1 + # run: echo ${{ steps.dockerTry1.outcome }} + + #- name: Setup Docker 2 try + # if: steps.dockerTry1.outcome != 'success' + # uses: douglascamata/setup-docker-macos-action@v1-alpha + # id: dockerTry2 + # continue-on-error: true + # with: + # lima: v0.18.0 + # colima: v0.5.6 + + #- name: checking outcome 2 + # run: echo ${{ steps.dockerTry2.outcome }} - name: Setup Docker Manually - if: steps.dockerTry1.outcome != 'success' && steps.dockerTry2.outcome != 'success' + # if: steps.dockerTry1.outcome != 'success' && steps.dockerTry2.outcome != 'success' run: | brew uninstall colima brew tap colima/releases From 999fb9b1f0d2d05f696f54fa43855862eaa9db75 Mon Sep 17 00:00:00 2001 From: JC Date: Mon, 9 Sep 2024 19:41:06 -0600 Subject: [PATCH 2/3] fix: trying with docker install manually - fix --- .github/workflows/android-integration-test.yaml | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/workflows/android-integration-test.yaml b/.github/workflows/android-integration-test.yaml index 57237fff5..711171c95 100644 --- a/.github/workflows/android-integration-test.yaml +++ b/.github/workflows/android-integration-test.yaml @@ -126,9 +126,7 @@ jobs: - name: Setup Docker Manually # if: steps.dockerTry1.outcome != 'success' && steps.dockerTry2.outcome != 'success' run: | - brew uninstall colima - brew tap colima/releases - brew install colima@0.5.6 + brew install colima brew install --formula docker colima start From e972c38c43452c47e65b363d12a7be49be0fbfbe Mon Sep 17 00:00:00 2001 From: JC Date: Tue, 10 Sep 2024 09:43:56 -0600 Subject: [PATCH 3/3] fix: build kotlin uniffi before running the tests --- .github/workflows/android-build.yaml | 77 ++++++++++++++----- .../workflows/android-integration-test.yaml | 7 ++ android/app/build.gradle | 19 +++-- rust/Dockerfile | 7 +- rust/buildphases/exportbuiltartifacts.sh | 10 +++ scripts/emulate_app.sh | 3 - scripts/emulator_install_apk.sh | 1 - scripts/integration_tests.sh | 3 - 8 files changed, 90 insertions(+), 37 deletions(-) diff --git a/.github/workflows/android-build.yaml b/.github/workflows/android-build.yaml index 7212c2d8c..74972b80f 100644 --- a/.github/workflows/android-build.yaml +++ b/.github/workflows/android-build.yaml @@ -20,7 +20,8 @@ jobs: name: Check build cache runs-on: macos-13 outputs: - android-cache-found: ${{ steps.android-set-cache-found.outputs.android-cache-found }} + native-cache-found: ${{ steps.android-set-cache-found.outputs.android-cache-found }} + kotlin-cache-found: ${{ steps.kotlin-set-cache-found.outputs.kotlin-cache-found }} steps: - name: Set envs for zingolib CI if: ${{ contains(github.repository, 'zingolib') }} @@ -32,7 +33,7 @@ jobs: repository: ${{ env.REPO-OWNER }}/zingo-mobile - name: Check if native rust cache exists - id: android-check-build-cache + id: native-check-build-cache uses: actions/cache/restore@v4 with: path: android/app/src/main/jniLibs/${{ env.ARCH }} @@ -40,13 +41,25 @@ jobs: lookup-only: true - name: Set cache-found - id: android-set-cache-found - run: echo "android-cache-found=${{ steps.android-check-build-cache.outputs.cache-hit }}" >> $GITHUB_OUTPUT + id: native-set-cache-found + run: echo "native-cache-found=${{ steps.native-check-build-cache.outputs.cache-hit }}" >> $GITHUB_OUTPUT + + - name: Check if kotlin uniffi cache exists + id: kotlin-check-build-cache + uses: actions/cache/restore@v4 + with: + path: android/app/build/generated/source/uniffi/debug/java/uniffi/zingo + key: kotlin-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }} + lookup-only: true + + - name: Set cache-found + id: kotlin-set-cache-found + run: echo "kotlin-cache-found=${{ steps.kotlin-check-build-cache.outputs.cache-hit }}" >> $GITHUB_OUTPUT android-build: - name: Build native rust + name: Build native rust & kotlin uniffi needs: android-check-build-cache - if: ${{ needs.android-check-build-cache.outputs.android-cache-found != 'true' }} + if: ${{ needs.android-check-build-cache.outputs.native-cache-found != 'true' || needs.android-check-build-cache.outputs.kotlin-cache-found != 'true' }} runs-on: ubuntu-22.04 container: image: zingodevops/android_builder:009 @@ -70,9 +83,28 @@ jobs: if cat rust/lib/Cargo.toml | grep "^zingolib\|^zingoconfig" | grep -q "branch"; then exit 1; fi cd rust cargo update -p zingolib -p zingoconfig --aggressive - cargo install --version ^3 cargo-ndk - rustup default nightly + - name: Cargo cache + uses: Swatinem/rust-cache@v2 + with: + workspaces: rust + + - name: Cargo default nightly + run: rustup default nightly + + - name: Cargo uniffi kotlin + working-directory: ./rust/lib + run: | + cargo run --release --features=uniffi/cli --bin uniffi-bindgen \ + generate ./src/zingo.udl --language kotlin \ + --out-dir ../../android/app/build/generated/source/uniffi/debug/java + + - name: Upload kotlin uniffi + uses: actions/upload-artifact@v4 + with: + name: kotlin-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }} + path: android/app/build/generated/source/uniffi/debug/java/uniffi/zingo/zingo.kt + - name: Set envs for x86_64 if: ${{ env.ARCH == 'x86_64' }} run: | @@ -102,18 +134,14 @@ jobs: echo "OPENSSL_PATH=armv7" >> $GITHUB_ENV - name: Cargo NDK - run: | - cargo install --version ^3 cargo-ndk - rustup default nightly + run: cargo install --version ^3 cargo-ndk - - name: Cargo cache - uses: Swatinem/rust-cache@v2 - with: - workspaces: rust - - name: Cargo build working-directory: ./rust/lib - run: cargo ndk --target ${{ env.TARGET }} build --release -Z build-std + run: | + cargo ndk \ + --target ${{ env.TARGET }} build \ + --release -Z build-std env: AR: llvm-ar LD: ld @@ -135,7 +163,7 @@ jobs: with: name: native-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }} path: rust/target/${{ env.TARGET }}/release/libuniffi_zingo.so - + cache-native-android-uniffi: name: Cache native rust needs: android-build @@ -155,10 +183,21 @@ jobs: with: name: native-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }} path: android/app/src/main/jniLibs/${{ env.ARCH }} - + - name: Cache native rust uses: actions/cache/save@v4 with: path: android/app/src/main/jniLibs/${{ env.ARCH }} key: native-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }} + - name: Download kotlin uniffi + uses: actions/download-artifact@v4 + with: + name: kotlin-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }} + path: android/app/build/generated/source/uniffi/debug/java/uniffi/zingo + + - name: Cache kotlin uniffi + uses: actions/cache/save@v4 + with: + path: android/app/build/generated/source/uniffi/debug/java/uniffi/zingo + key: kotlin-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }} \ No newline at end of file diff --git a/.github/workflows/android-integration-test.yaml b/.github/workflows/android-integration-test.yaml index 711171c95..02fa4325d 100644 --- a/.github/workflows/android-integration-test.yaml +++ b/.github/workflows/android-integration-test.yaml @@ -188,6 +188,13 @@ jobs: max_attempts: 3 command: ./scripts/integration_tests.sh -a ${{ env.AVD-ARCH }} -s + - name: Kotlin uniffi cache + uses: actions/cache/restore@v4 + with: + path: android/app/build/generated/source/uniffi/debug/java/uniffi/zingo + key: kotlin-android-uniffi-${{ env.ABI }}-${{ env.CACHE-KEY }} + fail-on-cache-miss: true + - name: Download archive uses: actions/download-artifact@v4 with: diff --git a/android/app/build.gradle b/android/app/build.gradle index a8a505615..47718491b 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -203,19 +203,18 @@ android.applicationVariants.configureEach { variant -> } } +// change this to build.sh script android.applicationVariants.configureEach { variant -> - def t = tasks.register("generate${variant.name.capitalize()}UniFFIBindings", Exec) { - workingDir "${rootProject.projectDir}/../rust" - // Runs the bindings generation, note that you must have uniffi-bindgen installed and in your PATH environment variable - commandLine 'cargo', 'run', '--release', '--features=uniffi/cli', '--bin', 'uniffi-bindgen', - 'generate', '../rust/lib/src/zingo.udl', '--language', 'kotlin', - '--out-dir', "${buildDir}/generated/source/uniffi/${variant.name}/java" - } - variant.javaCompileProvider.get().dependsOn(t) + //def t = tasks.register("generate${variant.name.capitalize()}UniFFIBindings", Exec) { + // workingDir "${rootProject.projectDir}/../rust" + // Runs the bindings generation, note that you must have uniffi-bindgen installed and in your PATH environment variable + // commandLine 'cargo', 'run', '--release', '--features=uniffi/cli', '--bin', 'uniffi-bindgen', + // 'generate', '../rust/lib/src/zingo.udl', '--language', 'kotlin', + // '--out-dir', "${buildDir}/generated/source/uniffi/${variant.name}/java" + //} + //variant.javaCompileProvider.get().dependsOn(t) def sourceSet = variant.sourceSets.find { it.name == variant.name } sourceSet.java.srcDir new File(buildDir, "generated/source/uniffi/${variant.name}/java") - // XXX: I've been trying to make this work but I can't, so the compiled bindings will show as "regular sources" in Android Studio. - //idea.module.generatedSourceDirs += file("${buildDir}/generated/source/uniffi/${variant.name}/java/uniffi") } dependencies { diff --git a/rust/Dockerfile b/rust/Dockerfile index 07084a4d2..090d6adee 100644 --- a/rust/Dockerfile +++ b/rust/Dockerfile @@ -10,9 +10,14 @@ COPY Cargo.lock /opt/zingo/rust/Cargo.lock COPY Cargo.toml /opt/zingo/rust/Cargo.toml COPY zingomobile_utils/ /opt/zingo/rust/zingomobile_utils/ -RUN cargo install --version ^3 cargo-ndk RUN rustup default nightly +RUN cargo run --release --features=uniffi/cli --bin uniffi-bindgen \ + generate ./src/zingo.udl --language kotlin \ + --out-dir ./src + +RUN cargo install --version ^3 cargo-ndk + #RUN AR=llvm-ar LD=ld RANLIB=llvm-ranlib CC=aarch64-linux-android24-clang \ # OPENSSL_DIR=/opt/openssl-3.3.1/aarch64 cargo +nightly build -Z build-std \ # --target aarch64-linux-android --release diff --git a/rust/buildphases/exportbuiltartifacts.sh b/rust/buildphases/exportbuiltartifacts.sh index 40b0ace6f..15894a30c 100755 --- a/rust/buildphases/exportbuiltartifacts.sh +++ b/rust/buildphases/exportbuiltartifacts.sh @@ -6,6 +6,9 @@ mkdir -p ../android/app/src/main/jniLibs/armeabi-v7a mkdir -p ../android/app/src/main/jniLibs/x86 mkdir -p ../android/app/src/main/jniLibs/x86_64 +mkdir -p ../android/app/build/generated/source/uniffi/debug/java/uniffi/zingo +mkdir -p ../android/app/build/generated/source/uniffi/release/java/uniffi/zingo + id=$(docker create devlocal/build_android) docker cp \ @@ -21,4 +24,11 @@ docker cp \ $id:/opt/zingo/rust/target/aarch64-linux-android/release/libzingo.so \ ../android/app/src/main/jniLibs/arm64-v8a/libuniffi_zingo.so +docker cp \ + $id:/opt/zingo/rust/lib/src/uniffi/zingo/zingo.kt \ + ../android/app/build/generated/source/uniffi/debug/java/uniffi/zingo/zingo.kt +docker cp \ + $id:/opt/zingo/rust/lib/src/uniffi/zingo/zingo.kt \ + ../android/app/build/generated/source/uniffi/release/java/uniffi/zingo/zingo.kt + docker rm -v $id diff --git a/scripts/emulate_app.sh b/scripts/emulate_app.sh index 6e4926d76..dd76d4791 100755 --- a/scripts/emulate_app.sh +++ b/scripts/emulate_app.sh @@ -235,9 +235,6 @@ else echo -e "\nRunning yarn..." yarn - echo -e "\nCleaning before Building APKs..." - ./gradlew clean - echo -e "\nBuilding APKs..." ./gradlew assembleDebug -PsplitApk=true diff --git a/scripts/emulator_install_apk.sh b/scripts/emulator_install_apk.sh index b1bd9ac46..c9596fe70 100755 --- a/scripts/emulator_install_apk.sh +++ b/scripts/emulator_install_apk.sh @@ -5,7 +5,6 @@ source ./scripts/emulator_read_target.sh echo -e "\nCleaning & Building APKs..." cd android -./gradlew clean ./gradlew assembleDebug -PsplitApk=true cd .. diff --git a/scripts/integration_tests.sh b/scripts/integration_tests.sh index d9837c5b0..e95531da5 100755 --- a/scripts/integration_tests.sh +++ b/scripts/integration_tests.sh @@ -262,9 +262,6 @@ else echo "AVD found: ${avd_name}" fi - echo -e "\nCleaning before Building APKs..." - ./gradlew clean - echo -e "\nBuilding APKs..." ./gradlew assembleDebug assembleAndroidTest -PsplitApk=true