Skip to content

Commit

Permalink
Merge pull request zingolabs#694 from juanky201271/dev_ci_docker_problem
Browse files Browse the repository at this point in the history
CI - Trying with docker install manually
  • Loading branch information
juanky201271 authored Sep 12, 2024
2 parents 6ced4d1 + ec7794e commit 8e441e9
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 63 deletions.
77 changes: 58 additions & 19 deletions .github/workflows/android-build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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') }}
Expand All @@ -32,21 +33,33 @@ 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 }}
key: native-android-uniffi-${{ env.ARCH }}-${{ env.CACHE-KEY }}
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
Expand All @@ -70,9 +83,28 @@ jobs:
if cat rust/lib/Cargo.toml | grep "^zingolib" | grep -q "branch"; then exit 1; fi
cd rust
cargo update -p zingolib --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: |
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 }}
57 changes: 31 additions & 26 deletions .github/workflows/android-integration-test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,33 @@ 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
brew install [email protected]
brew install colima
brew install --formula docker
colima start
Expand Down Expand Up @@ -190,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:
Expand Down
19 changes: 9 additions & 10 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 6 additions & 1 deletion rust/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions rust/buildphases/exportbuiltartifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
3 changes: 0 additions & 3 deletions scripts/emulate_app.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 0 additions & 1 deletion scripts/emulator_install_apk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ source ./scripts/emulator_read_target.sh

echo -e "\nCleaning & Building APKs..."
cd android
./gradlew clean
./gradlew assembleDebug -PsplitApk=true
cd ..

Expand Down
3 changes: 0 additions & 3 deletions scripts/integration_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 8e441e9

Please sign in to comment.