Build Rustic-Sql #5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Build Rustic for Android | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| rustic_version: | |
| description: 'Rustic 版本号 (例如: 0.10.3)' | |
| required: true | |
| default: '0.10.3' | |
| jobs: | |
| build-android: | |
| name: build-android (${{ matrix.arch }}) | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| - arch: arm64 | |
| rust_target: aarch64-linux-android | |
| ndk_target: aarch64-linux-android | |
| - arch: armv7 | |
| rust_target: armv7-linux-androideabi | |
| ndk_target: armv7a-linux-androideabi | |
| steps: | |
| - name: Checkout Rustic | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: rustic-rs/rustic | |
| ref: v${{ github.event.inputs.rustic_version }} | |
| - name: Install Rust Toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.rust_target }} | |
| - name: Build Binary | |
| env: | |
| ANDROID_API: 24 | |
| run: | | |
| set -euo pipefail | |
| # 1. 定位 NDK 工具链路径 | |
| NDK_DIR="${ANDROID_NDK_LATEST_HOME}" | |
| TOOLCHAIN="$NDK_DIR/toolchains/llvm/prebuilt/linux-x86_64" | |
| # 2. 准备变量 | |
| TARGET_UPPER=$(echo ${{ matrix.rust_target }} | tr '[:lower:]' '[:upper:]' | tr '-' '_') | |
| CLANG_BIN="$TOOLCHAIN/bin/${{ matrix.ndk_target }}${ANDROID_API}-clang" | |
| AR_BIN="$TOOLCHAIN/bin/llvm-ar" | |
| echo "Using Clang: $CLANG_BIN" | |
| echo "Using AR: $AR_BIN" | |
| # 3. 注入环境变量 (覆盖所有可能的编译器查找方式) | |
| # 修复 ring 库找不到编译器的问题 | |
| export "CC_${{ matrix.rust_target }}=$CLANG_BIN" | |
| export "CC_$TARGET_UPPER=$CLANG_BIN" | |
| export "AR_${{ matrix.rust_target }}=$AR_BIN" | |
| export "AR_$TARGET_UPPER=$AR_BIN" | |
| export "CARGO_TARGET_${TARGET_UPPER}_LINKER=$CLANG_BIN" | |
| # 额外增加通用变量作为保底 | |
| export CC="$CLANG_BIN" | |
| export AR="$AR_BIN" | |
| # 4. 执行编译 | |
| # 使用 --locked 确保依赖版本与原始项目一致 | |
| cargo build --release --target ${{ matrix.rust_target }} --bin rustic | |
| # 5. 裁剪体积 | |
| echo "Stripping binary..." | |
| "$TOOLCHAIN/bin/llvm-strip" target/${{ matrix.rust_target }}/release/rustic | |
| - name: Upload Artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: rustic-v${{ github.event.inputs.rustic_version }}-${{ matrix.arch }}-android | |
| path: target/${{ matrix.rust_target }}/release/rustic |