修复Windows和Android平台的构建问题 1. 为Windows平台修复SQLite链接问题:使用libsqlite3-sys的b… #37
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 and Release | |
| on: | |
| push: | |
| branches: [ "main", "master", "rust_new" ] | |
| tags: [ "v*" ] | |
| pull_request: | |
| branches: [ "main", "master", "rust_new" ] | |
| env: | |
| CARGO_TERM_COLOR: always | |
| PROJECT_NAME: file_classification_cli | |
| jobs: | |
| test-linux: | |
| name: Test on Ubuntu | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install dependencies (Linux) | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libsqlite3-dev | |
| - name: Run tests | |
| run: cargo test --verbose | |
| test-windows: | |
| name: Test on Windows | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install vcpkg | |
| run: | | |
| git clone https://github.com/Microsoft/vcpkg.git | |
| cd vcpkg | |
| .\bootstrap-vcpkg.bat | |
| - name: Install dependencies (Windows) | |
| run: | | |
| cd vcpkg | |
| .\vcpkg install sqlite3:x64-windows sqlite3:x64-windows-static | |
| - name: Setup vcpkg paths for Windows | |
| run: | | |
| echo "VCPKG_ROOT=$env:GITHUB_WORKSPACE\vcpkg" >> $env:GITHUB_ENV | |
| echo "$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows\lib" >> $env:GITHUB_PATH | |
| echo "$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows-static\lib" >> $env:GITHUB_PATH | |
| - name: Run tests | |
| run: cargo test --verbose | |
| test-macos: | |
| name: Test on macOS | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install dependencies (macOS) | |
| run: | | |
| brew install sqlite3 | |
| - name: Run tests | |
| run: cargo test --verbose | |
| build-android: | |
| name: Build Android binary | |
| needs: [test-linux, test-windows, test-macos] | |
| if: always() | |
| runs-on: ubuntu-latest | |
| continue-on-error: true | |
| strategy: | |
| fail-fast: false | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install Android targets | |
| run: | | |
| rustup target add aarch64-linux-android armv7-linux-androideabi x86_64-linux-android i686-linux-android | |
| - name: Install Android NDK | |
| uses: nttld/setup-ndk@v1 | |
| with: | |
| ndk-version: r25b | |
| - name: Setup Android environment | |
| run: | | |
| echo "ANDROID_NDK_HOME=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV | |
| echo "NDK_HOME=$ANDROID_NDK_LATEST_HOME" >> $GITHUB_ENV | |
| - name: Configure cargo for Android | |
| run: | | |
| mkdir -p .cargo | |
| echo '[target.aarch64-linux-android]' > .cargo/config.toml | |
| echo "ar = \"$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar\"" >> .cargo/config.toml | |
| echo "linker = \"$ANDROID_NDK_LATEST_HOME/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang\"" >> .cargo/config.toml | |
| - name: Install SQLite for Android | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libsqlite3-dev | |
| - name: Build for Android | |
| run: | | |
| cargo build --target aarch64-linux-android --release --bin file_classification_cli --verbose | |
| - name: Set Android binary name | |
| run: echo "ANDROID_BINARY_NAME=file_classification_cli" >> $GITHUB_ENV | |
| - name: Upload Android artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-android | |
| path: target/aarch64-linux-android/release/file_classification_cli | |
| build-linux: | |
| name: Build release binary (Linux) | |
| needs: test-linux | |
| if: always() | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install dependencies (Linux) | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y libsqlite3-dev | |
| - name: Build release binary | |
| run: | | |
| cargo build --release --bin file_classification_cli --verbose | |
| - name: Set binary name | |
| run: echo "BINARY_NAME=file_classification_cli" >> $GITHUB_ENV | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-linux | |
| path: target/release/${{ env.BINARY_NAME }} | |
| build-windows: | |
| name: Build release binary (Windows) | |
| needs: test-windows | |
| if: always() | |
| runs-on: windows-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install vcpkg | |
| run: | | |
| git clone https://github.com/Microsoft/vcpkg.git | |
| cd vcpkg | |
| .\bootstrap-vcpkg.bat | |
| - name: Install dependencies (Windows) | |
| run: | | |
| cd vcpkg | |
| .\vcpkg install sqlite3:x64-windows sqlite3:x64-windows-static | |
| - name: Set up vcpkg for Windows | |
| run: | | |
| echo "VCPKG_ROOT=$env:GITHUB_WORKSPACE\vcpkg" >> $env:GITHUB_ENV | |
| echo "$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows\lib" >> $env:GITHUB_PATH | |
| echo "$env:GITHUB_WORKSPACE\vcpkg\installed\x64-windows-static\lib" >> $env:GITHUB_PATH | |
| - name: Build release binary | |
| run: | | |
| cargo build --release --bin file_classification_cli --verbose | |
| - name: Set binary name | |
| run: echo "BINARY_NAME=file_classification_cli.exe" >> $env:GITHUB_ENV | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-windows | |
| path: target/release/${{ env.BINARY_NAME }} | |
| build-macos: | |
| name: Build release binary (macOS) | |
| needs: test-macos | |
| if: always() | |
| runs-on: macos-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install Rust | |
| uses: dtolnay/rust-toolchain@stable | |
| - name: Install dependencies (macOS) | |
| run: | | |
| brew install sqlite3 | |
| - name: Build release binary | |
| run: | | |
| cargo build --release --bin file_classification_cli --verbose | |
| - name: Set binary name | |
| run: echo "BINARY_NAME=file_classification_cli" >> $GITHUB_ENV | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: file_classification_cli-macos | |
| path: target/release/${{ env.BINARY_NAME }} | |
| release: | |
| name: Create GitHub Release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| needs: [test-linux, test-windows, test-macos, build-linux, build-windows, build-macos, build-android] | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Create release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: | | |
| artifacts/file_classification_cli-linux/file_classification_cli | |
| artifacts/file_classification_cli-windows/file_classification_cli.exe | |
| artifacts/file_classification_cli-macos/file_classification_cli | |
| artifacts/file_classification_cli-android/file_classification_cli |