Build #3
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 | |
| on: | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| name: Build for ${{ matrix.target }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| include: | |
| - target: x86_64-pc-windows-msvc | |
| os: windows-latest | |
| build-ext: .exe | |
| artifact-ext: -x86_64-pc-windows-msvc.exe | |
| - target: x86_64-apple-darwin | |
| os: macos-latest | |
| build-ext: "" | |
| artifact-ext: -x86_64-apple-darwin | |
| - target: aarch64-apple-darwin | |
| os: macos-latest | |
| build-ext: "" | |
| artifact-ext: -aarch64-apple-darwin | |
| - target: x86_64-unknown-linux-gnu | |
| os: ubuntu-22.04 | |
| build-ext: "" | |
| artifact-ext: -x86_64-unknown-linux-gnu | |
| - target: aarch64-unknown-linux-gnu | |
| os: ubuntu-22.04-arm | |
| build-ext: "" | |
| artifact-ext: -aarch64-unknown-linux-gnu | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Set up Rust toolchain | |
| uses: dtolnay/rust-toolchain@stable | |
| with: | |
| targets: ${{ matrix.target }} | |
| - name: Set up Rust cache | |
| uses: swatinem/rust-cache@v2 | |
| with: | |
| key: ${{ matrix.target }} | |
| - name: Get package name from Cargo.toml | |
| run: | | |
| echo "PACKAGE_NAME=$(cargo metadata --no-deps --format-version 1 | jq -r '.packages[0].name')" >> $GITHUB_ENV | |
| - name: Build for target | |
| run: cargo build --release --target ${{ matrix.target }} | |
| - name: Rename binary and output artifact name (Windows) | |
| if: matrix.os == 'windows-latest' | |
| id: rename_win | |
| shell: pwsh | |
| run: | | |
| $PACKAGE_NAME = $env:PACKAGE_NAME | |
| $ARTIFACT_NAME = "$PACKAGE_NAME${{ matrix.artifact-ext }}" | |
| Move-Item "target\${{ matrix.target }}\release\$PACKAGE_NAME${{ matrix.build-ext }}" $ARTIFACT_NAME | |
| echo "artifact_name=$ARTIFACT_NAME" >> $env:GITHUB_OUTPUT | |
| - name: Rename binary and output artifact name (Unix) | |
| if: matrix.os != 'windows-latest' | |
| id: rename_unix | |
| shell: bash | |
| run: | | |
| ARTIFACT_NAME="${PACKAGE_NAME}${{ matrix.artifact-ext }}" | |
| mv "target/${{ matrix.target }}/release/${PACKAGE_NAME}${{ matrix.build-ext }}" "$ARTIFACT_NAME" | |
| echo "artifact_name=$ARTIFACT_NAME" >> $GITHUB_OUTPUT | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ steps.rename_win.outputs.artifact_name || steps.rename_unix.outputs.artifact_name }} | |
| path: ${{ steps.rename_win.outputs.artifact_name || steps.rename_unix.outputs.artifact_name }} | |
| compression-level: 0 |