diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1d4dd75..ee9d584 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -4,12 +4,12 @@ on: push: branches: [ "main" ] tags: - - 'v*' # 当推送版本标签时触发,如 v1.0.0 + - 'v*' pull_request: branches: [ "main" ] permissions: - contents: write # 这给予了创建 release 的权限 + contents: write packages: write pull-requests: write @@ -24,22 +24,24 @@ jobs: matrix: include: # Linux x86_64 构建 - - target: x86_64-unknown-linux-gnu + - target: x86_64-linux-gnu os: ubuntu-latest # Linux ARM64 构建 - - target: aarch64-unknown-linux-gnu + - target: aarch64-linux-gnu os: ubuntu-latest + cross: true # Linux ARM v7 构建 - - target: armv7-unknown-linux-gnueabihf + - target: armv7-linux-gnueabihf os: ubuntu-latest + cross: true # macOS Intel 构建 - target: x86_64-apple-darwin os: macos-latest - # macOS ARM (M1/M2) 构建 + # macOS ARM 构建 - target: aarch64-apple-darwin os: macos-latest @@ -52,21 +54,25 @@ jobs: steps: - uses: actions/checkout@v3 + # 使用 cross 工具来处理交叉编译 + - name: Install cross + if: matrix.cross + run: cargo install cross + - name: Install Rust uses: dtolnay/rust-toolchain@stable with: targets: ${{ matrix.target }} - # 为 Linux ARM 目标安装必要的依赖 - - name: Install ARM dependencies - if: contains(matrix.target, 'arm') - run: | - sudo apt-get update - sudo apt-get install -y gcc-arm-linux-gnueabihf gcc-aarch64-linux-gnu - + # 根据是否需要交叉编译选择不同的构建命令 - name: Build Binary run: | - cargo build --verbose --release --target ${{ matrix.target }} + if [ "${{ matrix.cross }}" = "true" ]; then + cross build --verbose --release --target ${{ matrix.target }} + else + cargo build --verbose --release --target ${{ matrix.target }} + fi + shell: bash # 创建发布包 - name: Package Binary