|
| 1 | +name: Build release binaries |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - build-binaries |
| 7 | + release: |
| 8 | + types: ['created'] |
| 9 | + |
| 10 | +jobs: |
| 11 | + build-binaries: |
| 12 | + name: Build binaries for ${{matrix.target}} |
| 13 | + runs-on: ${{matrix.runner}} |
| 14 | + strategy: |
| 15 | + fail-fast: false |
| 16 | + matrix: |
| 17 | + include: |
| 18 | + - target: aarch64-unknown-linux-gnu |
| 19 | + runner: ubuntu-latest |
| 20 | + - target: x86_64-unknown-linux-gnu |
| 21 | + runner: ubuntu-latest |
| 22 | + - target: aarch64-apple-darwin |
| 23 | + runner: macos-14 |
| 24 | + - target: x86_64-apple-darwin |
| 25 | + runner: macos-13 |
| 26 | + - target: x86_64-pc-windows-msvc |
| 27 | + runner: windows-latest |
| 28 | + |
| 29 | + steps: |
| 30 | + - name: Checkout |
| 31 | + uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Install system deps (aarch64-unknown-linux-gnu) |
| 34 | + if: ${{matrix.target == 'aarch64-unknown-linux-gnu'}} |
| 35 | + run: | |
| 36 | + sudo apt-get update |
| 37 | + sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu libc6-dev-arm64-cross |
| 38 | +
|
| 39 | + - name: Install Rust toolchain |
| 40 | + uses: dtolnay/rust-toolchain@stable |
| 41 | + with: |
| 42 | + components: llvm-tools-preview |
| 43 | + target: ${{matrix.target}} |
| 44 | + |
| 45 | + - name: Install pnpm |
| 46 | + run: | |
| 47 | + corepack enable |
| 48 | + corepack prepare pnpm@latest --activate |
| 49 | +
|
| 50 | + - name: Install Node.js |
| 51 | + uses: actions/setup-node@v4 |
| 52 | + with: |
| 53 | + node-version: 18 |
| 54 | + cache: pnpm |
| 55 | + |
| 56 | + - name: Cache Rust dependencies |
| 57 | + uses: Swatinem/rust-cache@v2 |
| 58 | + with: |
| 59 | + shared-key: ${{matrix.target}} |
| 60 | + |
| 61 | + - name: Install Node.js dependencies |
| 62 | + env: |
| 63 | + SKIP_RUST_BUILD: 1 |
| 64 | + run: pnpm install |
| 65 | + |
| 66 | + - name: Build library for aarch64-unknown-linux-gnu |
| 67 | + if: ${{matrix.target == 'aarch64-unknown-linux-gnu'}} |
| 68 | + env: |
| 69 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: aarch64-linux-gnu-gcc |
| 70 | + CC_aarch64_unknown_linux_gnu: aarch64-linux-gnu-gcc |
| 71 | + CXX_aarch64_unknown_linux_gnu: aarch64-linux-gnu-g++ |
| 72 | + run: | |
| 73 | + mkdir -p generated/${{matrix.target}} |
| 74 | + pnpm run build:rust --target=${{matrix.target}} |
| 75 | +
|
| 76 | + - name: Build library |
| 77 | + id: build-library |
| 78 | + if: ${{!contains(fromJSON('["aarch64-unknown-linux-gnu"]'), matrix.target)}} |
| 79 | + run: | |
| 80 | + mkdir -p generated/${{matrix.target}} |
| 81 | + pnpm run build:rust --target=${{matrix.target}} |
| 82 | +
|
| 83 | + - name: Package artifact |
| 84 | + id: package-artifact |
| 85 | + # This needs to be set so that this works on a Windows runner |
| 86 | + shell: bash |
| 87 | + env: |
| 88 | + ARCHIVE_FILENAME: c2pa-node_${{matrix.target}}-${{ github.event.release.tag_name || 'dev' }}.zip |
| 89 | + run: | |
| 90 | + cd generated |
| 91 | + 7z a -tzip "${{ env.ARCHIVE_FILENAME }}" c2pa.node |
| 92 | + echo "archive=${{ env.ARCHIVE_FILENAME }}" >> "$GITHUB_OUTPUT" |
| 93 | +
|
| 94 | + - name: Upload artifact (development only) |
| 95 | + id: upload-artifact |
| 96 | + uses: actions/upload-artifact@v4 |
| 97 | + if: ${{ github.event.release.upload_url == '' }} |
| 98 | + with: |
| 99 | + name: ${{ steps.package-artifact.outputs.archive }} |
| 100 | + path: generated/${{ steps.package-artifact.outputs.archive }} |
| 101 | + retention-days: 3 |
| 102 | + |
| 103 | + - name: Upload release asset |
| 104 | + id: upload-release-asset |
| 105 | + uses: actions/upload-release-asset@v1 |
| 106 | + if: ${{ github.event.release.upload_url != '' }} |
| 107 | + env: |
| 108 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 109 | + with: |
| 110 | + upload_url: ${{ github.event.release.upload_url }} |
| 111 | + asset_path: generated/${{ steps.package-artifact.outputs.archive }} |
| 112 | + asset_name: ${{ steps.package-artifact.outputs.archive }} |
| 113 | + asset_content_type: application/zip |
0 commit comments