From 3d4c1598c03a4f2e5c836ac833a87e12e8119439 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 11:19:19 +0100 Subject: [PATCH] ci: matrix-build first pass --- .github/workflows/matrix-build.yaml | 103 ++++++++++++++++++++++++++++ .github/workflows/verify-build.yaml | 7 +- Cargo.toml | 7 ++ 3 files changed, 114 insertions(+), 3 deletions(-) create mode 100644 .github/workflows/matrix-build.yaml diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml new file mode 100644 index 0000000..6d29d03 --- /dev/null +++ b/.github/workflows/matrix-build.yaml @@ -0,0 +1,103 @@ +name: matrix-build +env: + DEBUG: napi:* + PROJECT_NAME: node-web-audio-api + MACOSX_DEPLOYMENT_TARGET: '10.13' + CARGO_TERM_COLOR: always + +on: + push: + tags: + - '*' + workflow_dispatch: + +jobs: + # verify-build: + # uses: ./.github/workflows/verify-build.yaml + + matrix-build: + # needs: verify-build + runs-on: ${{ matrix.runner }} + strategy: + fail-fast: false + matrix: + include: + - name: darwin-arm64 + runner: macos-latest + target: aarch64-apple-darwin + command: cargo + + - name: win32-x64-msvc + runner: windows-latest + target: x86_64-pc-windows-msvc + command: cargo + + - name: linux-arm64-gnu + runner: ubuntu-latest + target: aarch64-unknown-linux-gnu + command: cross + + name: build - ${{ matrix.name }} + steps: + - name: Check out repository + uses: actions/checkout@v4 + + # node is only used to generate the files, can use host architecture + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 22 + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@stable + + # only install cross (via cargo-binstall) if we need it + - name: Install Cross + if: matrix.command == 'cross' + shell: bash + run: | + curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash + cargo binstall --no-confirm cross + + - name: Generate Cargo.lock + run: cargo generate-lockfile + + - name: Generate files from IDL + run: npm run generate + + - name: Build Binary + run: | + if [[ "${{ matrix.runner }}" == "ubuntu-latest" ]]; then + ${{ matrix.command }} build --verbose --locked --features jack --release --target ${{ matrix.target }} + else + ${{ matrix.command }} build --verbose --locked --release --target ${{ matrix.target }} + fi + + - name: Rename Binary + shell: bash + run: | + BIN_SUFFIX="" + if [[ "${{ matrix.runner }}" == "windows-latest" ]]; then + BIN_SUFFIX=".dll" + elif [[ "${{ matrix.runner }}" == "macos-latest" ]]; then + BIN_SUFFIX=".dylib" + elif [[ "${{ matrix.runner }}" == "ubuntu-latest" ]]; then + BIN_SUFFIX=".so" + fi + + # The built binary output location + BIN_OUTPUT="target/${{ matrix.target }}/release/lib${PROJECT_NAME}${BIN_SUFFIX}" + + # Define a better name for the final binary + BIN_RELEASE="${PROJECT_NAME}.${{ matrix.name }}.node" + + # Move the built binary where you want it + mv "${BIN_OUTPUT}" "./${BIN_RELEASE}" + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: bindings-${{ matrix.name }} + path: ${{ env.PROJECT_NAME }}.${{ matrix.name }}.node + if-no-files-found: error + diff --git a/.github/workflows/verify-build.yaml b/.github/workflows/verify-build.yaml index e366996..68229db 100644 --- a/.github/workflows/verify-build.yaml +++ b/.github/workflows/verify-build.yaml @@ -1,6 +1,9 @@ # yaml-language-server: $schema=https://json.schemastore.org/github-workflow name: verify-build +env: + MACOSX_DEPLOYMENT_TARGET: '10.13' + CARGO_TERM_COLOR: always # read-only repo token, no access to secrets permissions: @@ -12,9 +15,7 @@ on: branches: [main, chore/refactor-ci] pull_request: workflow_dispatch: - -env: - CARGO_TERM_COLOR: always + workflow_call: jobs: verify-build: diff --git a/Cargo.toml b/Cargo.toml index 0390978..18064db 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,3 +32,10 @@ strip = true [features] jack = ["web-audio-api/cpal-jack"] + + +[target.aarch64-unknown-linux-gnu] +pre-build = [ + "dpkg --add-architecture $CROSS_DEB_ARCH", + "apt-get update && apt-get --assume-yes install libasound2-dev:$CROSS_DEB_ARCH libjack-jackd2-dev:$CROSS_DEB_ARCH" +]