Build Rustic-Sql #7
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. 构造符合 Shell 规范的变量名 (aarch64-linux-android -> AARCH64_LINUX_ANDROID) | |
| # 这样可以绕过 "not a valid identifier" 的错误 | |
| 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 "Building for: ${{ matrix.rust_target }}" | |
| echo "Using Clang: $CLANG_BIN" | |
| # 3. 注入环境变量 | |
| # CC_<target> 和 AR_<target> 是 cc-rs 识别的标准格式 | |
| export "CC_$TARGET_UPPER=$CLANG_BIN" | |
| export "AR_$TARGET_UPPER=$AR_BIN" | |
| # Cargo 寻找链接器的标准格式 | |
| 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 |