Skip to content

Commit

Permalink
fix: fix build android with cargo-ndk, use cache in ci
Browse files Browse the repository at this point in the history
  • Loading branch information
vivianjeng committed Feb 26, 2024
1 parent 6c038cb commit 5cf3020
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 4 deletions.
73 changes: 70 additions & 3 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,35 @@ jobs:
test-ios:
runs-on: macos-latest
steps:
# TODO: We should be able to cache this
- uses: actions/checkout@v3
- name: Cache toml
uses: actions/cache@v4
id: toml-macos-restore
with:
path: /Users/runner/.cargo/bin/toml
key: ${{ runner.os }}-toml-0.2.3 # version of toml-cli 0.2.3
- name: Cache circom
uses: actions/cache@v4
id: circom-macos-restore
with:
path: /Users/runner/.cargo/bin/circom
key: ${{ runner.os }}-circom-2.1.8 # version of circom 2.1.8
- name: Install circom
if: steps.circom-macos-restore.outputs.cache-hit != 'true'
run: |
sudo wget -O /Users/runner/.cargo/bin/circom https://github.com/iden3/circom/releases/download/v2.1.8/circom-macos-amd64
sudo chmod +x /Users/runner/.cargo/bin/circom
- uses: actions/checkout@v3
- name: Get uniffi-version
if: steps.toml-macos-restore.outputs.cache-hit == 'true'
id: extract-version
run: UNIFFI_VERSION=$(toml get mopro-ffi/Cargo.toml dependencies.uniffi.version -r)
- name: Cache uniffi-bindgen
uses: actions/cache@v4
if: steps.toml-macos-restore.outputs.cache-hit == 'true'
id: uniffi-bindgen-macos-restore
with:
path: /Users/runner/.cargo/bin/uniffi-bindgen
key: ${{ runner.os }}-uniffi-bindgen-${{ steps.extract-version.outputs.UNIFFI_VERSION }}
- name: Prepare CI for iOS
run: ./scripts/prepare_ci.sh
- name: Build for iOS
Expand All @@ -35,15 +58,49 @@ jobs:
run: |
cd mopro-ios/MoproKit/Example
xcodebuild test -scheme MoproKit-Example -workspace MoproKit.xcworkspace -destination "platform=iOS Simulator,OS=16.2,name=iPhone 14 Pro"
- name: Get uniffi-version
if: steps.uniffi-bindgen-macos-restore.outputs.cache-hit != 'true'
id: post-extract-version
run: UNIFFI_VERSION=$(toml get mopro-ffi/Cargo.toml dependencies.uniffi.version -r)
- name: Save uniffi-bindgen cache
if: steps.uniffi-bindgen-macos-restore.outputs.cache-hit != 'true'
uses: actions/cache@v4
with:
path: /Users/runner/.cargo/bin/uniffi-bindgen
key: ${{ runner.os }}-uniffi-bindgen-${{ steps.post-extract-version.outputs.UNIFFI_VERSION }}

test-android:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Restore toml
uses: actions/cache@v4
id: toml-linux-restore
with:
path: /home/runner/.cargo/bin/toml
key: ${{ runner.os }}-toml-0.2.3 # version of toml-cli 0.2.3
- name: Restore circom
uses: actions/cache@v4
id: circom-linux-restore
with:
path: /usr/bin/circom
key: ${{ runner.os }}-circom-2.1.8
- name: Install circom
if: steps.circom-linux-restore.outputs.cache-hit != 'true'
run: |
sudo wget -O /usr/bin/circom https://github.com/iden3/circom/releases/download/v2.1.8/circom-linux-amd64
sudo chmod +x /usr/bin/circom
- uses: actions/checkout@v3
- name: Get uniffi-version
id: extract-version
if: steps.toml-linux-restore.outputs.cache-hit == 'true'
run: UNIFFI_VERSION=$(toml get mopro-ffi/Cargo.toml dependencies.uniffi.version -r)
- name: Restore uniffi-bindgen
uses: actions/cache@v4
if: steps.toml-linux-restore.outputs.cache-hit == 'true'
id: uniffi-bindgen-linux-restore
with:
path: /home/runner/.cargo/bin/uniffi-bindgen
key: ${{ runner.os }}-uniffi-bindgen-${{ steps.extract-version.outputs.UNIFFI_VERSION }}
- name: Prepare CI for Core and FFI
run: ./scripts/prepare_ci.sh
- name: Build for Android
Expand All @@ -56,3 +113,13 @@ jobs:
cd mopro-ffi/
curl -L https://repo1.maven.org/maven2/net/java/dev/jna/jna/5.13.0/jna-5.13.0.jar -o target/jna-5.13.0.jar
CLASSPATH=target/jna-5.13.0.jar cargo test -- --nocapture
- name: Get uniffi-version
if: steps.uniffi-bindgen-linux-restore.outputs.cache-hit != 'true'
id: post-extract-version
run: UNIFFI_VERSION=$(toml get mopro-ffi/Cargo.toml dependencies.uniffi.version -r)
- name: Save uniffi-bindgen
uses: actions/cache@v4
if: steps.uniffi-bindgen-linux-restore.outputs.cache-hit != 'true'
with:
path: /home/runner/.cargo/bin/uniffi-bindgen
key: ${{ runner.os }}-uniffi-bindgen-${{ steps.post-extract-version.outputs.UNIFFI_VERSION }}
5 changes: 4 additions & 1 deletion scripts/build_android.sh
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,15 @@ PROJECT_DIR=$(pwd)

cd ${PROJECT_DIR}/mopro-ffi

print_action "[android] Install cargo-ndk"
cargo install cargo-ndk

# Print appropriate message based on device type
print_action "Using $ARCHITECTURE libmopro_ffi.a ($LIB_DIR) static library..."
print_warning "This only works on $FOLDER devices!"

print_action "[android] Build target in $BUILD_MODE mode"
cargo build --lib ${COMMAND} --target ${ARCHITECTURE}
cargo ndk -t ${ARCHITECTURE} build --lib ${COMMAND}

print_action "[android] Copy files in mopro-android/Example/jniLibs/"
for binary in target/*/*/libmopro_ffi.so; do file $binary; done
Expand Down

0 comments on commit 5cf3020

Please sign in to comment.