From b4b88df1fb0c0cc4333ae6761e5e7c760483b6ca Mon Sep 17 00:00:00 2001 From: b-ma Date: Mon, 23 Dec 2024 19:16:16 +0100 Subject: [PATCH 01/28] first pass --- .cargo/config.toml | 25 ------------------------- .github/workflows/build.yml | 6 +++--- .gitignore | 2 ++ Cargo.toml | 4 ++++ 4 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 .cargo/config.toml diff --git a/.cargo/config.toml b/.cargo/config.toml deleted file mode 100644 index f09aa672..00000000 --- a/.cargo/config.toml +++ /dev/null @@ -1,25 +0,0 @@ -[target.arm-unknown-linux-gnueabihf] -linker = "arm-linux-gnueabihf-gcc" -rustflags = [ - "-L", - "/usr/lib/arm-linux-gnueabihf", - "-L", - "/usr/arm-linux-gnueabihf/lib", -] - -[target.aarch64-unknown-linux-gnu] -linker = "aarch64-linux-gnu-gcc" - -[target.x86_64-unknown-linux-gnu] -linker = "x86_64-linux-gnu-gcc" - - -[target.x86_64-unknown-linux-musl] -rustflags = [ - "-C", - "target-feature=-crt-static", -] - -[target.aarch64-unknown-linux-musl] -linker = "aarch64-linux-musl-gcc" -rustflags = ["-C", "target-feature=-crt-static"] diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dca454da..89699641 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -5,8 +5,8 @@ env: MACOSX_DEPLOYMENT_TARGET: '10.13' on: create: - tags: - - v* + tags: + - v* pull_request: null workflow_dispatch: @@ -38,7 +38,7 @@ jobs: build: needs: checks - if: "!contains(github.event.head_commit.message, 'skip ci')" + if: !contains(github.event.head_commit.message, 'skip ci') strategy: fail-fast: false matrix: diff --git a/.gitignore b/.gitignore index 0e35d7bd..d1041132 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,8 @@ NOTES.md /generator/src .DS_Store +_* + # Working files TODOS.md NOTES.md diff --git a/Cargo.toml b/Cargo.toml index 48875267..03909780 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,8 +23,12 @@ mimalloc = {version = "0.1"} [build-dependencies] napi-build = "1" +[profile.dev] +opt-level = 3 + [profile.release] lto = true +strip = true [features] jack = ["web-audio-api/cpal-jack"] From ccd58dab6fc8eaa376881105f42ffe6550819780 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 09:25:37 +0100 Subject: [PATCH 02/28] notes --- load-native.cjs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/load-native.cjs b/load-native.cjs index 9a1031d0..ef8c6325 100644 --- a/load-native.cjs +++ b/load-native.cjs @@ -44,8 +44,12 @@ switch (platform) { throw new Error(`Unsupported architecture on macOS: ${arch}`); } break; + // case 'freebsd': x64 only case 'linux': switch (arch) { + // @todo + // - support riscv64 arch + // - support musl C lib case 'x64': try { nativeBinding = require('./node-web-audio-api.linux-x64-gnu.node'); From e4852542062456f7a9b8500eb3badbadb8360aae Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 09:28:01 +0100 Subject: [PATCH 03/28] ci: extract checks from build workflow --- .github/workflows/check.yaml | 64 ++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 .github/workflows/check.yaml diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 00000000..6991b481 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,64 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow + +name: build + +# read-only repo token, no access to secrets +permissions: + contents: read + +# no access to secrets +on: + push: + branches: [main] + pull_request: + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + verify-build: + runs-on: ubuntu-latest + + steps: + - name: Install ALSA and Jack dependencies + run: | + sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-jackd2-dev + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: clippy, rustfmt + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: lts + + - name: Check out repository + uses: actions/checkout@v4 + + - name: Generate Cargo.lock + run: cargo generate-lockfile + + # restore cargo cache from previous runs + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + # The cache should not be shared between different workflows and jobs. + shared-key: ${{ github.workflow }}-${{ github.job }} + + # check it builds + - name: Build + run: npm run build + + # run checks and tests + - name: Clippy + run: cargo clippy --all-features -- -D warnings + - name: Fmt + run: cargo fmt -- --check --color always + - name: Lint + run: npm run lint + - name: Test + run: npm run test + From 6598c15edb5f3cd91f7e3720a6311124062df93c Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 09:38:31 +0100 Subject: [PATCH 04/28] ci: test in branch --- .github/workflows/build.yml | 142 ----------------------------------- .github/workflows/check.yaml | 4 +- 2 files changed, 2 insertions(+), 144 deletions(-) delete mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml deleted file mode 100644 index 89699641..00000000 --- a/.github/workflows/build.yml +++ /dev/null @@ -1,142 +0,0 @@ -name: build -env: - DEBUG: napi:* - APP_NAME: node-web-audio-api - MACOSX_DEPLOYMENT_TARGET: '10.13' -on: - create: - tags: - - v* - pull_request: null - workflow_dispatch: - -jobs: - checks: - runs-on: ubuntu-latest - steps: - - name: Install Rust toolchain - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - components: clippy - - - name: Install ALSA and Jack dependencies - run: | - sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-jackd2-dev - - - name: Check out repository - uses: actions/checkout@v4 - - - name: Generate Cargo.lock - run: cargo generate-lockfile - - - name: Clippy - run: cargo clippy --all-features -- -D warnings - - # - name: Lint - # run: npm run lint - - build: - needs: checks - if: !contains(github.event.head_commit.message, 'skip ci') - strategy: - fail-fast: false - matrix: - settings: - # --------------------------------------------------------- - # MAC - # --------------------------------------------------------- - - # Intel x86_64 - - host: macos-latest - target: x86_64-apple-darwin - architecture: x64 - build: | - npm run build -- --target x86_64-apple-darwin - strip -x *.node - - # ARM64 - - host: macos-latest - target: aarch64-apple-darwin - architecture: x64 - build: | - npm run build -- --target aarch64-apple-darwin - strip -x *.node - - # --------------------------------------------------------- - # WINDOWS - # --------------------------------------------------------- - - # Intel x86_64 - - host: windows-latest - target: x86_64-pc-windows-msvc - architecture: x64 - build: npm run build - - # ARM64 - - host: windows-latest - target: aarch64-pc-windows-msvc - architecture: x64 - build: npm run build -- --target aarch64-pc-windows-msvc - - # --------------------------------------------------------- - # Linux requires libasound2-dev which is a mess to do remotely - # in particular for RPi, do it locally and workaround... - # --------------------------------------------------------- - - name: stable - ${{ matrix.settings.target }} - node@22.1 - runs-on: ${{ matrix.settings.host }} - steps: - - uses: actions/checkout@v4 - - name: Setup node - uses: actions/setup-node@v4 - with: - node-version: 22.1 - check-latest: true - architecture: ${{ matrix.settings.architecture }} - - - name: Setup Rust toolchain - uses: dtolnay/rust-toolchain@stable - with: - toolchain: stable - targets: ${{ matrix.settings.target }} - - - name: Generate Cargo.lock - run: cargo generate-lockfile - - - name: Cache cargo - uses: actions/cache@v4 - with: - path: | - ~/.cargo/registry/index/ - ~/.cargo/registry/cache/ - ~/.cargo/git/db/ - .cargo-cache - target/ - key: ${{ matrix.settings.target }}-cargo-${{ matrix.settings.host }} - - - name: Pull latest image - run: ${{ matrix.settings.docker }} - env: - DOCKER_REGISTRY_URL: ghcr.io - if: ${{ matrix.settings.docker }} - - - name: Setup toolchain - run: ${{ matrix.settings.setup }} - if: ${{ matrix.settings.setup }} - shell: bash - - - name: Install dependencies - run: npm install - - - name: Build - run: ${{ matrix.settings.build }} - shell: bash - - - name: Upload artifact - uses: actions/upload-artifact@v4 - with: - name: bindings-${{ matrix.settings.target }} - path: ${{ env.APP_NAME }}.*.node - if-no-files-found: error - diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 6991b481..c4bfabdd 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -1,6 +1,6 @@ # yaml-language-server: $schema=https://json.schemastore.org/github-workflow -name: build +name: checks # read-only repo token, no access to secrets permissions: @@ -9,7 +9,7 @@ permissions: # no access to secrets on: push: - branches: [main] + branches: [main, chore/refactor-ci] pull_request: workflow_dispatch: From d5f8481c711ba2a210136131b90a190e52c72771 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 09:39:54 +0100 Subject: [PATCH 05/28] ci: fix node version --- .github/workflows/check.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index c4bfabdd..5d6b26f2 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -33,7 +33,7 @@ jobs: - name: Setup node uses: actions/setup-node@v4 with: - node-version: lts + node-version: 22 - name: Check out repository uses: actions/checkout@v4 From 6d6afbefa822f59c30c56ac9c54b4ec2592cc43a Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 09:42:53 +0100 Subject: [PATCH 06/28] ci: install deps + harmonize naming --- .github/workflows/check.yaml | 64 ------------------------------------ 1 file changed, 64 deletions(-) delete mode 100644 .github/workflows/check.yaml diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml deleted file mode 100644 index 5d6b26f2..00000000 --- a/.github/workflows/check.yaml +++ /dev/null @@ -1,64 +0,0 @@ -# yaml-language-server: $schema=https://json.schemastore.org/github-workflow - -name: checks - -# read-only repo token, no access to secrets -permissions: - contents: read - -# no access to secrets -on: - push: - branches: [main, chore/refactor-ci] - pull_request: - workflow_dispatch: - -env: - CARGO_TERM_COLOR: always - -jobs: - verify-build: - runs-on: ubuntu-latest - - steps: - - name: Install ALSA and Jack dependencies - run: | - sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-jackd2-dev - - - name: Setup Rust toolchain - uses: dtolnay/rust-toolchain@stable - with: - components: clippy, rustfmt - - - name: Setup node - uses: actions/setup-node@v4 - with: - node-version: 22 - - - name: Check out repository - uses: actions/checkout@v4 - - - name: Generate Cargo.lock - run: cargo generate-lockfile - - # restore cargo cache from previous runs - - name: Rust Cache - uses: Swatinem/rust-cache@v2 - with: - # The cache should not be shared between different workflows and jobs. - shared-key: ${{ github.workflow }}-${{ github.job }} - - # check it builds - - name: Build - run: npm run build - - # run checks and tests - - name: Clippy - run: cargo clippy --all-features -- -D warnings - - name: Fmt - run: cargo fmt -- --check --color always - - name: Lint - run: npm run lint - - name: Test - run: npm run test - From 6be1d773ad618090fe566b08d4aa17ea2e9bde97 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 09:43:37 +0100 Subject: [PATCH 07/28] ci: install deps + harmonize naming --- .github/workflows/verify-build.yaml | 67 +++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 .github/workflows/verify-build.yaml diff --git a/.github/workflows/verify-build.yaml b/.github/workflows/verify-build.yaml new file mode 100644 index 00000000..40831dcc --- /dev/null +++ b/.github/workflows/verify-build.yaml @@ -0,0 +1,67 @@ +# yaml-language-server: $schema=https://json.schemastore.org/github-workflow + +name: verify-build + +# read-only repo token, no access to secrets +permissions: + contents: read + +# no access to secrets +on: + push: + branches: [main, chore/refactor-ci] + pull_request: + workflow_dispatch: + +env: + CARGO_TERM_COLOR: always + +jobs: + verify-build: + runs-on: ubuntu-latest + + steps: + - name: Install ALSA and Jack dependencies + run: | + sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-jackd2-dev + + - name: Setup Rust toolchain + uses: dtolnay/rust-toolchain@stable + with: + components: clippy, rustfmt + + - name: Setup node + uses: actions/setup-node@v4 + with: + node-version: 22 + + - name: Check out repository + uses: actions/checkout@v4 + + - name: Generate Cargo.lock + run: cargo generate-lockfile + + # restore cargo cache from previous runs + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + # The cache should not be shared between different workflows and jobs. + shared-key: ${{ github.workflow }}-${{ github.job }} + + - name: Install Deps + run: npm install + + # check it builds + - name: Build + run: npm run build + + # run checks and tests + - name: Clippy + run: cargo clippy --all-features -- -D warnings + - name: Fmt + run: cargo fmt -- --check --color always + - name: Lint + run: npm run lint + - name: Test + run: npm run test + From 012b31f71ade77d219b5745cfb4becf94c037539 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 09:48:43 +0100 Subject: [PATCH 08/28] ci: check if we can run the tests on macos-latest --- .github/workflows/verify-build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/verify-build.yaml b/.github/workflows/verify-build.yaml index 40831dcc..65fb4dc9 100644 --- a/.github/workflows/verify-build.yaml +++ b/.github/workflows/verify-build.yaml @@ -18,7 +18,7 @@ env: jobs: verify-build: - runs-on: ubuntu-latest + runs-on: macos-latest steps: - name: Install ALSA and Jack dependencies From a62d6f09a17f7c3a58b31c3d8e7d757b54f270de Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 09:49:26 +0100 Subject: [PATCH 09/28] ci: check if we can run the tests on macos-latest --- .github/workflows/verify-build.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/verify-build.yaml b/.github/workflows/verify-build.yaml index 65fb4dc9..9b059b38 100644 --- a/.github/workflows/verify-build.yaml +++ b/.github/workflows/verify-build.yaml @@ -21,9 +21,9 @@ jobs: runs-on: macos-latest steps: - - name: Install ALSA and Jack dependencies - run: | - sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-jackd2-dev + # - name: Install ALSA and Jack dependencies + # run: | + # sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-jackd2-dev - name: Setup Rust toolchain uses: dtolnay/rust-toolchain@stable From 8309c7ef5379dfafc9ef14571e54fde732205903 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 09:58:21 +0100 Subject: [PATCH 10/28] ci: avoid checking jack feature on macos runner --- .github/workflows/verify-build.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/verify-build.yaml b/.github/workflows/verify-build.yaml index 9b059b38..069592a2 100644 --- a/.github/workflows/verify-build.yaml +++ b/.github/workflows/verify-build.yaml @@ -57,7 +57,8 @@ jobs: # run checks and tests - name: Clippy - run: cargo clippy --all-features -- -D warnings + # run: cargo clippy --all-features -- -D warnings + run: cargo clippy --all-targets -- -D warnings - name: Fmt run: cargo fmt -- --check --color always - name: Lint From 8136cec9681bfaf6574905982aa98792382b9522 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 10:13:47 +0100 Subject: [PATCH 11/28] ci: do not try to access mic in ci tests --- .github/workflows/verify-build.yaml | 2 +- package.json | 1 + tests/getUserMedia.spec.mjs | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/.github/workflows/verify-build.yaml b/.github/workflows/verify-build.yaml index 069592a2..e3669967 100644 --- a/.github/workflows/verify-build.yaml +++ b/.github/workflows/verify-build.yaml @@ -64,5 +64,5 @@ jobs: - name: Lint run: npm run lint - name: Test - run: npm run test + run: npm run test:ci diff --git a/package.json b/package.json index c0375949..f28edc29 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,7 @@ "preversion": "yarn install && npm run generate", "postversion": "cargo bump $npm_package_version && git commit -am \"v$npm_package_version\" && node .scripts/check-changelog.mjs", "test": "mocha tests/*.spec.mjs", + "test:ci": "mocha tests/*.spec.mjs -- --ci", "test:only": "mocha", "wpt": "npm run build && node ./.scripts/wpt-harness.mjs", "wpt:only": "node ./.scripts/wpt-harness.mjs" diff --git a/tests/getUserMedia.spec.mjs b/tests/getUserMedia.spec.mjs index 97a0faa2..1a6f2d2f 100644 --- a/tests/getUserMedia.spec.mjs +++ b/tests/getUserMedia.spec.mjs @@ -3,6 +3,8 @@ import { sleep } from '@ircam/sc-utils'; import { mediaDevices, AudioContext, MediaStreamAudioSourceNode } from '../index.mjs'; +const CI = process.argv.includes('--ci'); + describe('# mediaDevices.getUserMedia(options)', () => { it('should fail if no argument given', async () => { let failed = false; @@ -48,6 +50,12 @@ describe('# mediaDevices.getUserMedia(options)', () => { }); it('should not fail if options.audio = true', async () => { + // accessing microphone in CI make the process stuck + if (CI) { + console.log('Run in CI, aborting...'); + return; + } + let failed = false; const audioContext = new AudioContext(); @@ -67,6 +75,12 @@ describe('# mediaDevices.getUserMedia(options)', () => { }); it('should work with MediaStreamAudioSourceNode [1 factory] (make some noise)', async () => { + // accessing microphone in CI make the process stuck + if (CI) { + console.log('Run in CI, aborting...'); + return; + } + let failed = false; const audioContext = new AudioContext(); @@ -89,6 +103,12 @@ describe('# mediaDevices.getUserMedia(options)', () => { }); it('should work with MediaStreamAudioSourceNode [2 ctor] (make some noise)', async () => { + // accessing microphone in CI make the process stuck + if (CI) { + console.log('Run in CI, aborting...'); + return; + } + let failed = false; const audioContext = new AudioContext(); From 3d4c1598c03a4f2e5c836ac833a87e12e8119439 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 11:19:19 +0100 Subject: [PATCH 12/28] 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 00000000..6d29d030 --- /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 e3669967..68229db8 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 03909780..18064dbc 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" +] From 3ea6e8f0d400b85636db28f7c1498690dd381b29 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 11:20:24 +0100 Subject: [PATCH 13/28] ci: allow test in branch --- .github/workflows/matrix-build.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index 6d29d030..5c7f067f 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -7,6 +7,7 @@ env: on: push: + branches: [chore/refactor-ci] tags: - '*' workflow_dispatch: From 0f7d1319874fde9470297cca6567daaf172e52e8 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 11:21:07 +0100 Subject: [PATCH 14/28] ci: allow test in branch --- .github/workflows/verify-build.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/verify-build.yaml b/.github/workflows/verify-build.yaml index 68229db8..634a7502 100644 --- a/.github/workflows/verify-build.yaml +++ b/.github/workflows/verify-build.yaml @@ -11,8 +11,9 @@ permissions: # no access to secrets on: - push: - branches: [main, chore/refactor-ci] + # @todo - to remove - prevents running while testing + # push: + # branches: [main, chore/refactor-ci] pull_request: workflow_dispatch: workflow_call: From ff041a38f90ff86cab611434dd8c7b595f428f55 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 11:22:44 +0100 Subject: [PATCH 15/28] ci: install deps and fmt --- .github/workflows/matrix-build.yaml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index 5c7f067f..ce0be8a1 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -51,6 +51,8 @@ jobs: - name: Setup Rust toolchain uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt # only install cross (via cargo-binstall) if we need it - name: Install Cross @@ -63,7 +65,10 @@ jobs: - name: Generate Cargo.lock run: cargo generate-lockfile - - name: Generate files from IDL + - name: Install Deps + run: npm install + + - name: Re-generate files from IDL run: npm run generate - name: Build Binary From 5cc53593f8961c800c5497e233ccc32486f70910 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 11:32:42 +0100 Subject: [PATCH 16/28] ci: some fix --- .github/workflows/matrix-build.yaml | 16 +++++++++------- .github/workflows/verify-build.yaml | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index ce0be8a1..8ef012b2 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -2,6 +2,7 @@ name: matrix-build env: DEBUG: napi:* PROJECT_NAME: node-web-audio-api + CARGO_BUILD_NAME: libnode_web_audio_api MACOSX_DEPLOYMENT_TARGET: '10.13' CARGO_TERM_COLOR: always @@ -33,10 +34,10 @@ jobs: target: x86_64-pc-windows-msvc command: cargo - - name: linux-arm64-gnu - runner: ubuntu-latest - target: aarch64-unknown-linux-gnu - command: cross + # - name: linux-arm64-gnu + # runner: ubuntu-latest + # target: aarch64-unknown-linux-gnu + # command: cross name: build - ${{ matrix.name }} steps: @@ -72,11 +73,12 @@ jobs: run: npm run generate - name: Build Binary + shell: bash run: | if [[ "${{ matrix.runner }}" == "ubuntu-latest" ]]; then - ${{ matrix.command }} build --verbose --locked --features jack --release --target ${{ matrix.target }} + ${{ matrix.command }} build --locked --features jack --release --target ${{ matrix.target }} else - ${{ matrix.command }} build --verbose --locked --release --target ${{ matrix.target }} + ${{ matrix.command }} build --locked --release --target ${{ matrix.target }} fi - name: Rename Binary @@ -92,7 +94,7 @@ jobs: fi # The built binary output location - BIN_OUTPUT="target/${{ matrix.target }}/release/lib${PROJECT_NAME}${BIN_SUFFIX}" + BIN_OUTPUT="target/${{ matrix.target }}/release/lib${CARGO_BUILD_NAME}${BIN_SUFFIX}" # Define a better name for the final binary BIN_RELEASE="${PROJECT_NAME}.${{ matrix.name }}.node" diff --git a/.github/workflows/verify-build.yaml b/.github/workflows/verify-build.yaml index 634a7502..b82ffada 100644 --- a/.github/workflows/verify-build.yaml +++ b/.github/workflows/verify-build.yaml @@ -14,7 +14,7 @@ on: # @todo - to remove - prevents running while testing # push: # branches: [main, chore/refactor-ci] - pull_request: + # pull_request: workflow_dispatch: workflow_call: From da57f8ca4b86bfeb19b6fd4afa602b70206c7704 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 11:34:59 +0100 Subject: [PATCH 17/28] ci: some fix --- .github/workflows/matrix-build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index 8ef012b2..d6952629 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -94,7 +94,7 @@ jobs: fi # The built binary output location - BIN_OUTPUT="target/${{ matrix.target }}/release/lib${CARGO_BUILD_NAME}${BIN_SUFFIX}" + BIN_OUTPUT="target/${{ matrix.target }}/release/${CARGO_BUILD_NAME}${BIN_SUFFIX}" # Define a better name for the final binary BIN_RELEASE="${PROJECT_NAME}.${{ matrix.name }}.node" From 4fc255b113801047c8c1dade2c2430bacd09fcc1 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 12:11:06 +0100 Subject: [PATCH 18/28] ci: try to find windows build --- .github/workflows/matrix-build.yaml | 10 ++++++---- .scripts/build-retrieve-from-github.mjs | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index d6952629..5278d955 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -24,10 +24,10 @@ jobs: fail-fast: false matrix: include: - - name: darwin-arm64 - runner: macos-latest - target: aarch64-apple-darwin - command: cargo + # - name: darwin-arm64 + # runner: macos-latest + # target: aarch64-apple-darwin + # command: cargo - name: win32-x64-msvc runner: windows-latest @@ -93,6 +93,8 @@ jobs: BIN_SUFFIX=".so" fi + ls -al target/${{ matrix.target }}/release/ + # The built binary output location BIN_OUTPUT="target/${{ matrix.target }}/release/${CARGO_BUILD_NAME}${BIN_SUFFIX}" diff --git a/.scripts/build-retrieve-from-github.mjs b/.scripts/build-retrieve-from-github.mjs index 7add4510..aeab9115 100644 --- a/.scripts/build-retrieve-from-github.mjs +++ b/.scripts/build-retrieve-from-github.mjs @@ -9,8 +9,8 @@ const owner = process.env.REPO_OWNER; const repo = process.env.REPO_NAME; const ghToken = process.env.GITHUB_TOKEN; -const workflowName = 'build'; -const numArtifacts = 4; // 2 Mac, 2 windows +const workflowName = 'matrix-build'; +const numArtifacts = 1; // 2 Mac, 2 windows // need a key for downloading job artifacts const octokit = new Octokit({ auth: ghToken }); From 05d3b68f2f0b9342fefd1b812a274e91eb089e51 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 12:21:29 +0100 Subject: [PATCH 19/28] ci: different build prefix accroding to platform --- .github/workflows/matrix-build.yaml | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index 5278d955..452adb61 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -2,7 +2,7 @@ name: matrix-build env: DEBUG: napi:* PROJECT_NAME: node-web-audio-api - CARGO_BUILD_NAME: libnode_web_audio_api + CARGO_BUILD_NAME: node_web_audio_api MACOSX_DEPLOYMENT_TARGET: '10.13' CARGO_TERM_COLOR: always @@ -24,10 +24,10 @@ jobs: fail-fast: false matrix: include: - # - name: darwin-arm64 - # runner: macos-latest - # target: aarch64-apple-darwin - # command: cargo + - name: darwin-arm64 + runner: macos-latest + target: aarch64-apple-darwin + command: cargo - name: win32-x64-msvc runner: windows-latest @@ -93,10 +93,19 @@ jobs: BIN_SUFFIX=".so" fi + BIN_PREFIX="" + if [[ "${{ matrix.runner }}" == "windows-latest" ]]; then + BIN_PREFIX="" + elif [[ "${{ matrix.runner }}" == "macos-latest" ]]; then + BIN_PREFIX="lib" + elif [[ "${{ matrix.runner }}" == "ubuntu-latest" ]]; then + BIN_PREFIX="lib" + fi + ls -al target/${{ matrix.target }}/release/ # The built binary output location - BIN_OUTPUT="target/${{ matrix.target }}/release/${CARGO_BUILD_NAME}${BIN_SUFFIX}" + BIN_OUTPUT="target/${{ matrix.target }}/release/${BIN_PREFIX}${CARGO_BUILD_NAME}${BIN_SUFFIX}" # Define a better name for the final binary BIN_RELEASE="${PROJECT_NAME}.${{ matrix.name }}.node" From 3028633e0491e4ce3e96828b3599c49423a013a0 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 15:08:39 +0100 Subject: [PATCH 20/28] chore: add pre-build scripts --- .github/workflows/matrix-build.yaml | 25 +++++++++++++------------ .scripts/build-retrieve-from-github.mjs | 2 +- Cargo.toml | 7 ------- 3 files changed, 14 insertions(+), 20 deletions(-) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index 452adb61..bb123f0e 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -24,20 +24,20 @@ jobs: fail-fast: false matrix: include: - - name: darwin-arm64 - runner: macos-latest - target: aarch64-apple-darwin - command: cargo + # - 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: 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: linux-arm64-gnu + runner: ubuntu-latest + target: aarch64-unknown-linux-gnu + command: cross name: build - ${{ matrix.name }} steps: @@ -76,6 +76,7 @@ jobs: shell: bash run: | if [[ "${{ matrix.runner }}" == "ubuntu-latest" ]]; then + echo "Build with Jack feature" ${{ matrix.command }} build --locked --features jack --release --target ${{ matrix.target }} else ${{ matrix.command }} build --locked --release --target ${{ matrix.target }} diff --git a/.scripts/build-retrieve-from-github.mjs b/.scripts/build-retrieve-from-github.mjs index aeab9115..26a870a4 100644 --- a/.scripts/build-retrieve-from-github.mjs +++ b/.scripts/build-retrieve-from-github.mjs @@ -10,7 +10,7 @@ const repo = process.env.REPO_NAME; const ghToken = process.env.GITHUB_TOKEN; const workflowName = 'matrix-build'; -const numArtifacts = 1; // 2 Mac, 2 windows +const numArtifacts = 2; // 2 Mac, 2 windows // need a key for downloading job artifacts const octokit = new Octokit({ auth: ghToken }); diff --git a/Cargo.toml b/Cargo.toml index 18064dbc..03909780 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,10 +32,3 @@ 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" -] From c0a6d0262cdf628c155c0a55778d867108ce43c6 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 15:20:11 +0100 Subject: [PATCH 21/28] chore: add Cross.toml --- Cross.toml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Cross.toml diff --git a/Cross.toml b/Cross.toml new file mode 100644 index 00000000..0ff6e3c7 --- /dev/null +++ b/Cross.toml @@ -0,0 +1,5 @@ +[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" +] From a1dda6d0d241ede237c506334facac5ab1f631f3 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 15:59:40 +0100 Subject: [PATCH 22/28] ci: add linux-arm-gnueabihf target --- .github/workflows/matrix-build.yaml | 33 +++++++++++++------------ .scripts/build-retrieve-from-github.mjs | 2 +- Cross.toml | 6 +++++ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index bb123f0e..8571f6df 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -24,21 +24,26 @@ jobs: fail-fast: false matrix: include: - # - name: darwin-arm64 - # runner: macos-latest - # target: aarch64-apple-darwin - # command: cargo + - 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: 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: linux-arm-gnueabihf + runner: ubuntu-latest + target: arm-unknown-linux-gnueabihf + command: cross + name: build - ${{ matrix.name }} steps: - name: Check out repository @@ -85,22 +90,18 @@ jobs: - name: Rename Binary shell: bash run: | + BIN_PREFIX="" 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 - BIN_PREFIX="" if [[ "${{ matrix.runner }}" == "windows-latest" ]]; then BIN_PREFIX="" + BIN_SUFFIX=".dll" elif [[ "${{ matrix.runner }}" == "macos-latest" ]]; then BIN_PREFIX="lib" + BIN_SUFFIX=".dylib" elif [[ "${{ matrix.runner }}" == "ubuntu-latest" ]]; then BIN_PREFIX="lib" + BIN_SUFFIX=".so" fi ls -al target/${{ matrix.target }}/release/ diff --git a/.scripts/build-retrieve-from-github.mjs b/.scripts/build-retrieve-from-github.mjs index 26a870a4..aeab9115 100644 --- a/.scripts/build-retrieve-from-github.mjs +++ b/.scripts/build-retrieve-from-github.mjs @@ -10,7 +10,7 @@ const repo = process.env.REPO_NAME; const ghToken = process.env.GITHUB_TOKEN; const workflowName = 'matrix-build'; -const numArtifacts = 2; // 2 Mac, 2 windows +const numArtifacts = 1; // 2 Mac, 2 windows // need a key for downloading job artifacts const octokit = new Octokit({ auth: ghToken }); diff --git a/Cross.toml b/Cross.toml index 0ff6e3c7..e864b761 100644 --- a/Cross.toml +++ b/Cross.toml @@ -3,3 +3,9 @@ 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" ] + +[target.arm-unknown-linux-gnueabihf] +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" +] From fb59e94e55580739e0412df35cc285bdde1dbbd8 Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 16:13:44 +0100 Subject: [PATCH 23/28] ci: target armv7 instead of arm (v6) --- .github/workflows/matrix-build.yaml | 2 +- Cross.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index 8571f6df..c3d4f460 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -41,7 +41,7 @@ jobs: - name: linux-arm-gnueabihf runner: ubuntu-latest - target: arm-unknown-linux-gnueabihf + target: armv7-unknown-linux-gnueabihf command: cross name: build - ${{ matrix.name }} diff --git a/Cross.toml b/Cross.toml index e864b761..835edd32 100644 --- a/Cross.toml +++ b/Cross.toml @@ -4,7 +4,7 @@ pre-build = [ "apt-get update && apt-get --assume-yes install libasound2-dev:$CROSS_DEB_ARCH libjack-jackd2-dev:$CROSS_DEB_ARCH" ] -[target.arm-unknown-linux-gnueabihf] +[target.armv7-unknown-linux-gnueabihf] 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" From 068c149c24e9bdfedfabc8578972a6fe1a89ab5c Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 17:21:59 +0100 Subject: [PATCH 24/28] ci: back to previous platform builds --- .github/workflows/matrix-build.yaml | 15 +++++++++++++++ Cross.toml | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index c3d4f460..47ab1aba 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -29,6 +29,16 @@ jobs: target: aarch64-apple-darwin command: cargo + - name: darwin-x64 + runner: macos-latest + target: x86_64-apple-darwin + command: cargo + + - name: win32-arm64-msvc + runner: windows-latest + target: aarch64-pc-windows-msvc + command: cargo + - name: win32-x64-msvc runner: windows-latest target: x86_64-pc-windows-msvc @@ -39,6 +49,11 @@ jobs: target: aarch64-unknown-linux-gnu command: cross + - name: linux-x86-gnu + runner: ubuntu-latest + target: x86_64-unknown-linux-gnu + command: cross + - name: linux-arm-gnueabihf runner: ubuntu-latest target: armv7-unknown-linux-gnueabihf diff --git a/Cross.toml b/Cross.toml index 835edd32..c5be2fd3 100644 --- a/Cross.toml +++ b/Cross.toml @@ -9,3 +9,9 @@ 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" ] + +[target.x86_64-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" +] From 9a5a9db13372b2dadd96453c096ceda4405e77be Mon Sep 17 00:00:00 2001 From: b-ma Date: Tue, 24 Dec 2024 17:30:34 +0100 Subject: [PATCH 25/28] fix: always add target with rustup --- .github/workflows/matrix-build.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index 47ab1aba..4b0b492f 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -49,7 +49,7 @@ jobs: target: aarch64-unknown-linux-gnu command: cross - - name: linux-x86-gnu + - name: linux-x64-gnu runner: ubuntu-latest target: x86_64-unknown-linux-gnu command: cross @@ -95,6 +95,8 @@ jobs: - name: Build Binary shell: bash run: | + rustup target add ${{ matrix.target }} + if [[ "${{ matrix.runner }}" == "ubuntu-latest" ]]; then echo "Build with Jack feature" ${{ matrix.command }} build --locked --features jack --release --target ${{ matrix.target }} From 61f7e9bdbbfefec419cc5625437480bfb7cd3c0b Mon Sep 17 00:00:00 2001 From: b-ma Date: Thu, 26 Dec 2024 09:08:25 +0100 Subject: [PATCH 26/28] chore: review local build handling --- .editorconfig | 9 +- .scripts/BUILD_NOTES.md | 42 ------- .scripts/build-linux-arm32-rpi.mjs | 106 ----------------- .scripts/build-linux-arm64-rpi.mjs | 107 ------------------ .scripts/build-linux-gnu-docker.mjs | 23 ---- .../Dockerfile | 34 ------ .scripts/move-artifact.mjs | 45 ++++++++ ...from-github.mjs => retrieve-artifacts.mjs} | 2 +- load-native.cjs | 18 ++- package.json | 17 ++- 10 files changed, 70 insertions(+), 333 deletions(-) delete mode 100644 .scripts/BUILD_NOTES.md delete mode 100644 .scripts/build-linux-arm32-rpi.mjs delete mode 100644 .scripts/build-linux-arm64-rpi.mjs delete mode 100644 .scripts/build-linux-gnu-docker.mjs delete mode 100644 .scripts/docker_x86_64-unknown-linux-gnu/Dockerfile create mode 100644 .scripts/move-artifact.mjs rename .scripts/{build-retrieve-from-github.mjs => retrieve-artifacts.mjs} (98%) diff --git a/.editorconfig b/.editorconfig index 856ace39..ec118333 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,17 +5,14 @@ root = true [*] indent_style = space -indent_size = 4 +indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[*.js] -indent_size = 2 - -[*.mjs] -indent_size = 2 +[*.rs] +indent_size = 4 [*.md] trim_trailing_whitespace = false diff --git a/.scripts/BUILD_NOTES.md b/.scripts/BUILD_NOTES.md deleted file mode 100644 index 17e9c901..00000000 --- a/.scripts/BUILD_NOTES.md +++ /dev/null @@ -1,42 +0,0 @@ -# Prepare RPi build systems - -## Install rust - -[https://www.rust-lang.org/tools/install](https://www.rust-lang.org/tools/install) - -```sh -curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -``` - -### RPI 4 w/ 32 system - -Choose custom installation: - -``` -1) Proceed with installation (default) -2) Customize installation -3) Cancel installation ->2 - -I'm going to ask you the value of each of these installation options. -You may simply press the Enter key to leave unchanged. - -Default host triple? [aarch64-unknown-linux-gnu] -armv7-unknown-linux-gnueabihf -Default toolchain? (stable/beta/nightly/none) [stable] -Profile (which tools and data to install)? (minimal/default/complete) [default] -``` - -## Install dev libs - -```sh -sudo apt-get install -y libjack-jackd2-dev libasound2-dev -``` - - -# Docker image - -``` -cd ./.scripts/docker_x86_64-unknown-linux-gnu/ -docker build -t bbmmaa/build-x86_64 . -``` diff --git a/.scripts/build-linux-arm32-rpi.mjs b/.scripts/build-linux-arm32-rpi.mjs deleted file mode 100644 index 2fb1b9f3..00000000 --- a/.scripts/build-linux-arm32-rpi.mjs +++ /dev/null @@ -1,106 +0,0 @@ -import * as dotenv from 'dotenv'; -import ping from 'ping'; -import { NodeSSH } from 'node-ssh'; -import fs from 'node:fs'; -import path from 'node:path'; -import { execSync } from 'child_process'; - -dotenv.config({ debug: false }); - -const rpiHostname = process.env.RPI_32_HOSTNAME; -const rpiUser = process.env.RPI_32_USER; -const rpiPrivKey = process.env.RPI_32_PRIVKEY; -const rpiCwd = process.env.RPI_32_CWD; -const binaryFilename = 'node-web-audio-api.linux-arm-gnueabihf.node'; - -console.log(`Check ${rpiHostname} is alive`); -const isAlive = await new Promise((resolve, reject) => { - ping.sys.probe(rpiHostname, resolve, { timeout: 5 }); -}); - -if (!isAlive) { - console.log('Cannot connect to host:', rpiHostname); - console.log('aborting...'); - process.exit(1); -} - -const ssh = new NodeSSH(); - -const conn = await ssh.connect({ - host: rpiHostname, - username: rpiUser, - privateKeyPath: rpiPrivKey, -}); - -let res; - -function logResult(res) { - if (res.stderr !== '') { - console.log('[rpi stderr]', res.stderr); - } - - if (res.stdout !== '') { - console.log('[rpi sdtout]', res.stdout); - } -} - -// @note: by default RPi .bashrc exits early if not in interactive more, some -// lines must be commented on the RPi side -// cf. https://github.com/mscdex/ssh2/issues/77 -console.log('> check node'); -res = await conn.execCommand(`which node`); -logResult(res); - -if (res.stdout == '') { - console.log('node not found, exiting...'); - process.exit(1) -} - -console.log('> check cargo'); -res = await conn.execCommand(`which cargo`); -logResult(res); - -if (res.stdout == '') { - console.log('cargo not found, exiting...'); - process.exit(1) -} - -console.log('> pull source on main'); -res = await conn.execCommand(`git pull origin main`, { cwd: rpiCwd }); -logResult(res); - -console.log('> reinstall node_modules'); -res = await conn.execCommand(`rm -Rf node_modules`, { cwd: rpiCwd }); -logResult(res); -res = await conn.execCommand(`npm install`, { cwd: rpiCwd }); -logResult(res); - -console.log('> rustup upgrade'); -res = await conn.execCommand(`rustup upgrade`, { cwd: rpiCwd }); -logResult(res); - -console.log('> cargo update'); -res = await conn.execCommand(`cargo update`, { cwd: rpiCwd }); -logResult(res); - -console.log('> build binary'); -res = await conn.execCommand(`npm run build:jack`, { cwd: rpiCwd }); -logResult(res); - -console.log('> strip symbols'); -res = await conn.execCommand(`arm-linux-gnueabihf-strip ${binaryFilename}`, { cwd: rpiCwd }); -logResult(res); - -console.log('> list files'); -res = await conn.execCommand(`ls -al`, { cwd: rpiCwd }); -logResult(res); - -console.log('> download binary'); -const remoteFile = path.join(rpiCwd, binaryFilename); -res = execSync(`scp ${rpiUser}@${rpiHostname}:${remoteFile} ${process.cwd()}`); -console.log(res.toString()); - -console.log('Done!'); - -conn.dispose(); - diff --git a/.scripts/build-linux-arm64-rpi.mjs b/.scripts/build-linux-arm64-rpi.mjs deleted file mode 100644 index 21cf73a6..00000000 --- a/.scripts/build-linux-arm64-rpi.mjs +++ /dev/null @@ -1,107 +0,0 @@ -import * as dotenv from 'dotenv'; -import ping from 'ping'; -import { NodeSSH } from 'node-ssh'; -import fs from 'node:fs'; -import path from 'node:path'; -import { execSync } from 'child_process'; - -dotenv.config({ debug: false }); - -const rpiHostname = process.env.RPI_64_HOSTNAME; -const rpiUser = process.env.RPI_64_USER; -const rpiPrivKey = process.env.RPI_64_PRIVKEY; -const rpiCwd = process.env.RPI_64_CWD; -const binaryFilename = 'node-web-audio-api.linux-arm64-gnu.node'; - -console.log(`Check ${rpiHostname} is alive`); -const isAlive = await new Promise((resolve, reject) => { - ping.sys.probe(rpiHostname, resolve, { timeout: 5 }); -}); - -if (!isAlive) { - console.log('Cannot connect to host:', rpiHostname); - console.log('aborting...'); - process.exit(1); -} - -const ssh = new NodeSSH(); - -const conn = await ssh.connect({ - host: rpiHostname, - username: rpiUser, - privateKeyPath: rpiPrivKey, -}); - -let res; - -function logResult(res) { - if (res.stderr !== '') { - console.log('[rpi stderr]', res.stderr); - } - - if (res.stdout !== '') { - console.log('[rpi sdtout]', res.stdout); - } -} - -// @note: by default RPi .bashrc exits early if not in interactive more, some -// lines must be commented on the RPi side -// cf. https://github.com/mscdex/ssh2/issues/77 -console.log('> check node'); -res = await conn.execCommand(`which node`); -logResult(res); - -if (res.stdout == '') { - console.log('node not found, exiting...'); - process.exit(1) -} - -console.log('> check cargo'); -res = await conn.execCommand(`which cargo`); -logResult(res); - -if (res.stdout == '') { - console.log('cargo not found, exiting...'); - process.exit(1) -} - -console.log('> pull source on main'); -res = await conn.execCommand(`git pull origin main`, { cwd: rpiCwd }); -logResult(res); - -console.log('> reinstall node_modules'); -res = await conn.execCommand(`rm -Rf node_modules`, { cwd: rpiCwd }); -logResult(res); -res = await conn.execCommand(`npm install`, { cwd: rpiCwd }); -logResult(res); - -console.log('> rustup upgrade'); -res = await conn.execCommand(`rustup upgrade`, { cwd: rpiCwd }); -logResult(res); - -console.log('> cargo update'); -res = await conn.execCommand(`cargo update`, { cwd: rpiCwd }); -logResult(res); - -console.log('> build binary'); -res = await conn.execCommand(`npm run build:jack`, { cwd: rpiCwd }); -logResult(res); - -console.log('> strip symbols'); -res = await conn.execCommand(`aarch64-linux-gnu-strip ${binaryFilename}`, { cwd: rpiCwd }); -logResult(res); - -console.log('> list files'); -res = await conn.execCommand(`ls -al`, { cwd: rpiCwd }); -logResult(res); - -console.log('> download binary'); -const remoteFile = path.join(rpiCwd, binaryFilename); -res = execSync(`scp ${rpiUser}@${rpiHostname}:${remoteFile} ${process.cwd()}`); -console.log(res.toString()); - -console.log('Done!'); - -conn.dispose(); - - diff --git a/.scripts/build-linux-gnu-docker.mjs b/.scripts/build-linux-gnu-docker.mjs deleted file mode 100644 index db3adf8f..00000000 --- a/.scripts/build-linux-gnu-docker.mjs +++ /dev/null @@ -1,23 +0,0 @@ -import { execSync } from 'node:child_process'; - -const cwd = process.cwd(); -console.log(`> executing docker command in dir ${cwd}`); - -// the source code directory is shared with the docker image, -// so every thing is always up to date - -// @todo - rebuild docket image -// cd ./.scripts/docker_x86_64-unknown-linux-gnu/ -// docker build -t bbmmaa/build-x86_64 . - -execSync(`docker run --rm \ - -v ~/.cargo/git:/root/.cargo/git \ - -v ~/.cargo/registry:/root/.cargo/registry \ - -v ${cwd}:/sources \ - -w /sources \ - bbmmaa/build-x86_64 \ - bash -c " - yarn build:jack --target x86_64-unknown-linux-gnu && \ - x86_64-linux-gnu-strip *.linux-x64-gnu.node && \ - ls -al /sources" -`, { stdio: 'inherit' }); diff --git a/.scripts/docker_x86_64-unknown-linux-gnu/Dockerfile b/.scripts/docker_x86_64-unknown-linux-gnu/Dockerfile deleted file mode 100644 index b8303d07..00000000 --- a/.scripts/docker_x86_64-unknown-linux-gnu/Dockerfile +++ /dev/null @@ -1,34 +0,0 @@ -FROM node:20 - -ENV RUSTUP_HOME=/usr/local/rustup \ - CARGO_HOME=/usr/local/cargo \ - PATH=/usr/local/cargo/bin:$PATH \ - CC=clang \ - CXX=clang++ \ - PKG_CONFIG_ALLOW_CROSS=1 \ - RUST_TARGET=x86_64-unknown-linux-gnueabi - -RUN dpkg --add-architecture amd64 && \ - apt-get update && \ - apt-get install -y \ - curl \ - pkg-config \ - libasound2-dev \ - libasound2-dev:amd64 \ - libjack-jackd2-dev \ - libjack-jackd2-dev:amd64 \ - gcc \ - g++ \ - g++-x86-64-linux-gnu \ - libc6-dev \ - libc6-dev:amd64 \ - libc6-dev-amd64-cross \ - ca-certificates \ - qemu-user \ - make \ - file \ - clang \ - && \ - curl https://sh.rustup.rs -sSf | sh -s -- -y - -RUN rustup target add x86_64-unknown-linux-gnu diff --git a/.scripts/move-artifact.mjs b/.scripts/move-artifact.mjs new file mode 100644 index 00000000..4d89b9f3 --- /dev/null +++ b/.scripts/move-artifact.mjs @@ -0,0 +1,45 @@ +import fs from 'node:fs'; +import path from 'node:path'; + +const { platform } = process; +const profile = process.argv.includes('--release') ? 'release' : 'debug'; + +const pkg = fs.readFileSync(path.join('package.json')); +const PROJECT_NAME = JSON.parse(pkg).name; +const CARGO_BUILD_NAME = PROJECT_NAME.replace(/-/g, '_'); + +let buildPrefix = ''; +let buildSuffix = ''; + +switch (platform) { + case 'win32': + buildPrefix = ''; + buildSuffix = '.dll'; + break; + case 'darwin': + buildPrefix = 'lib'; + buildSuffix = '.dylib'; + break; + default: // let's hope all linux like have same prefix and suffix... + buildPrefix = 'lib'; + buildSuffix = '.so'; + break; +} + +const destReleaseFile = `${PROJECT_NAME}.build-release.node`; +const destDebugFile = `${PROJECT_NAME}.build-debug.node`; + +if (fs.existsSync(destReleaseFile)) { + fs.rmSync(destReleaseFile, { force: true }); +} + +if (fs.existsSync(destDebugFile)) { + fs.rmSync(destDebugFile, { force: true }); +} + +let srcFile = path.join('target', profile, `${buildPrefix}${CARGO_BUILD_NAME}${buildSuffix}`); +let destFile = profile === 'release' ? destReleaseFile : destDebugFile; + +console.log(`> move artifact "${srcFile}" to "${destFile}"`); + +fs.copyFileSync(srcFile, destFile); diff --git a/.scripts/build-retrieve-from-github.mjs b/.scripts/retrieve-artifacts.mjs similarity index 98% rename from .scripts/build-retrieve-from-github.mjs rename to .scripts/retrieve-artifacts.mjs index aeab9115..24d1e2f5 100644 --- a/.scripts/build-retrieve-from-github.mjs +++ b/.scripts/retrieve-artifacts.mjs @@ -10,7 +10,7 @@ const repo = process.env.REPO_NAME; const ghToken = process.env.GITHUB_TOKEN; const workflowName = 'matrix-build'; -const numArtifacts = 1; // 2 Mac, 2 windows +const numArtifacts = 7; // 2 Mac, 2 windows, 3 linux // need a key for downloading job artifacts const octokit = new Octokit({ auth: ghToken }); diff --git a/load-native.cjs b/load-native.cjs index ef8c6325..171b8cdb 100644 --- a/load-native.cjs +++ b/load-native.cjs @@ -1,3 +1,4 @@ +const fs = require('node:fs'); const { platform, arch } = process; let nativeBinding = null; @@ -21,7 +22,7 @@ switch (platform) { } break; default: - throw new Error(`Unsupported architecture on Windows: ${arch}`); + loadError = new Error(`Unsupported architecture on Windows: ${arch}`); } break; case 'darwin': @@ -41,7 +42,7 @@ switch (platform) { } break; default: - throw new Error(`Unsupported architecture on macOS: ${arch}`); + loadError = new Error(`Unsupported architecture on macOS: ${arch}`); } break; // case 'freebsd': x64 only @@ -72,11 +73,20 @@ switch (platform) { } break; default: - throw new Error(`Unsupported architecture on Linux: ${arch}`); + loadError = new Error(`Unsupported architecture on Linux: ${arch}`); } break; default: - throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`); + loadError = new Error(`Unsupported OS: ${platform}, architecture: ${arch}`); +} + +// fallback on local builds +if (fs.existsSync('node-web-audio-api.build-release.node')) { + nativeBinding = require('./node-web-audio-api.build-release.node'); +} + +if (fs.existsSync('node-web-audio-api.build-debug.node')) { + nativeBinding = require('./node-web-audio-api.build-debug.node'); } if (!nativeBinding) { diff --git a/package.json b/package.json index f28edc29..837b8f60 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "node-web-audio-api", "version": "0.21.5", "author": "Benjamin Matuszewski", - "description": "Node.js bindings for web-audio-api-rs using napi-rs", + "description": "Web Audio API implementation for Node.js", "exports": { "import": "./index.mjs", "require": "./index.cjs", @@ -21,7 +21,7 @@ "music", "dsp", "rust", - "n-api" + "node-api" ], "engines": { "node": ">= 14" @@ -35,15 +35,14 @@ "access": "public" }, "scripts": { - "artifacts": "napi artifacts", - "build": "npm run generate && napi build --platform --release", - "build:jack": "npm run generate && napi build --platform --features jack --release", - "build:debug": "npm run generate && napi build --platform", - "build:only": "napi build --platform --release", + "build": "npm run generate && cargo build --release && node ./.scripts/move-artifact.mjs --release", + "build:jack": "npm run generate && cargo build --features jack --release && node ./.scripts/move-artifact.mjs --release", + "build:debug":"npm run generate && cargo build && node ./.scripts/move-artifact.mjs", + "build:only": "cargo build --release && node ./.scripts/move-artifact.mjs --release", "check": "cargo fmt && cargo clippy", "generate": "node generator/index.mjs && cargo fmt", "lint": "npx eslint index.cjs index.mjs && npx eslint js/*.js && npx eslint examples/*.mjs", - "preversion": "yarn install && npm run generate", + "preversion": "npm install && npm run generate", "postversion": "cargo bump $npm_package_version && git commit -am \"v$npm_package_version\" && node .scripts/check-changelog.mjs", "test": "mocha tests/*.spec.mjs", "test:ci": "mocha tests/*.spec.mjs -- --ci", @@ -74,8 +73,6 @@ "wpt-runner": "^5.0.0" }, "dependencies": { - "@napi-rs/cli": "^2.14.3", - "@node-rs/helper": "^1.3.3", "caller": "^1.1.0", "node-fetch": "^3.3.2", "webidl-conversions": "^7.0.0" From 64f90f52cf42a2fdac451af7cd0be3a822a7a735 Mon Sep 17 00:00:00 2001 From: b-ma Date: Thu, 26 Dec 2024 09:11:02 +0100 Subject: [PATCH 27/28] cleaning --- js/OfflineAudioContext.js | 1 - 1 file changed, 1 deletion(-) diff --git a/js/OfflineAudioContext.js b/js/OfflineAudioContext.js index 04ea2aec..972025cb 100644 --- a/js/OfflineAudioContext.js +++ b/js/OfflineAudioContext.js @@ -139,7 +139,6 @@ module.exports = function patchOfflineAudioContext(jsExport, nativeBinding) { await this.audioWorklet[kCheckProcessorsCreated](); // keep this to highlight the workaround w/ the oncomplete event - let _nativeAudioBuffer; try { From 719961d1e0820342f685991c8a80bf114c9fb1a4 Mon Sep 17 00:00:00 2001 From: b-ma Date: Mon, 6 Jan 2025 15:27:56 +0100 Subject: [PATCH 28/28] ci: clean testing conditions --- .github/workflows/matrix-build.yaml | 7 +++---- .github/workflows/verify-build.yaml | 14 +++++--------- load-native.cjs | 2 +- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/.github/workflows/matrix-build.yaml b/.github/workflows/matrix-build.yaml index 4b0b492f..2ef06762 100644 --- a/.github/workflows/matrix-build.yaml +++ b/.github/workflows/matrix-build.yaml @@ -8,17 +8,16 @@ env: on: push: - branches: [chore/refactor-ci] tags: - '*' workflow_dispatch: jobs: - # verify-build: - # uses: ./.github/workflows/verify-build.yaml + verify-build: + uses: ./.github/workflows/verify-build.yaml matrix-build: - # needs: verify-build + needs: verify-build runs-on: ${{ matrix.runner }} strategy: fail-fast: false diff --git a/.github/workflows/verify-build.yaml b/.github/workflows/verify-build.yaml index b82ffada..50f782a9 100644 --- a/.github/workflows/verify-build.yaml +++ b/.github/workflows/verify-build.yaml @@ -11,22 +11,18 @@ permissions: # no access to secrets on: - # @todo - to remove - prevents running while testing - # push: - # branches: [main, chore/refactor-ci] - # pull_request: + push: + branches: [main] + pull_request: workflow_dispatch: - workflow_call: + workflow_call: # make the job callable by matrix-build jobs: verify-build: + # run on macos-latest which seems to have a soundcard available runs-on: macos-latest steps: - # - name: Install ALSA and Jack dependencies - # run: | - # sudo apt-get update && sudo apt-get install -y libasound2-dev libjack-jackd2-dev - - name: Setup Rust toolchain uses: dtolnay/rust-toolchain@stable with: diff --git a/load-native.cjs b/load-native.cjs index 171b8cdb..9e1842f6 100644 --- a/load-native.cjs +++ b/load-native.cjs @@ -80,7 +80,7 @@ switch (platform) { loadError = new Error(`Unsupported OS: ${platform}, architecture: ${arch}`); } -// fallback on local builds +// use local build if exists if (fs.existsSync('node-web-audio-api.build-release.node')) { nativeBinding = require('./node-web-audio-api.build-release.node'); }