From 79356968928147856d1d68bfcd1d9efee7e3f467 Mon Sep 17 00:00:00 2001 From: skdhg <46562212+skdhg@users.noreply.github.com> Date: Fri, 11 Aug 2023 17:33:07 +0545 Subject: [PATCH] chore: update --- .github/workflows/CI.yml | 264 +++++++++++++++++++-------------------- README.md | 10 +- build.rs | 19 ++- package.json | 4 - 4 files changed, 154 insertions(+), 143 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 06f8aad..416943f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -45,22 +45,22 @@ jobs: set -e && yarn build --target x86_64-unknown-linux-gnu && strip *.node - - host: ubuntu-latest - target: x86_64-unknown-linux-musl - docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine - build: set -e && yarn build && strip *.node + # - host: ubuntu-latest + # target: x86_64-unknown-linux-musl + # docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine + # build: set -e && yarn build && strip *.node - host: macos-latest target: aarch64-apple-darwin build: | yarn build --target aarch64-apple-darwin strip -x *.node - - host: ubuntu-latest - target: aarch64-unknown-linux-gnu - docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64 - build: |- - set -e && - yarn build --target aarch64-unknown-linux-gnu && - aarch64-unknown-linux-gnu-strip *.node + # - host: ubuntu-latest + # target: aarch64-unknown-linux-gnu + # docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64 + # build: |- + # set -e && + # yarn build --target aarch64-unknown-linux-gnu && + # aarch64-unknown-linux-gnu-strip *.node - host: ubuntu-latest target: armv7-unknown-linux-gnueabihf setup: | @@ -74,19 +74,19 @@ jobs: build: | yarn build --target aarch64-linux-android ${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node - - host: ubuntu-latest - target: armv7-linux-androideabi - build: | - yarn build --target armv7-linux-androideabi - ${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node - - host: ubuntu-latest - target: aarch64-unknown-linux-musl - docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine - build: |- - set -e && - rustup target add aarch64-unknown-linux-musl && - yarn build --target aarch64-unknown-linux-musl && - /aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node + # - host: ubuntu-latest + # target: armv7-linux-androideabi + # build: | + # yarn build --target armv7-linux-androideabi + # ${ANDROID_NDK_LATEST_HOME}/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-strip *.node + # - host: ubuntu-latest + # target: aarch64-unknown-linux-musl + # docker: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine + # build: |- + # set -e && + # rustup target add aarch64-unknown-linux-musl && + # yarn build --target aarch64-unknown-linux-musl && + # /aarch64-linux-musl-cross/bin/aarch64-linux-musl-strip *.node - host: windows-latest target: aarch64-pc-windows-msvc build: yarn build --target aarch64-pc-windows-msvc @@ -280,114 +280,114 @@ jobs: shell: bash - name: Test bindings run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-slim yarn test - test-linux-x64-musl-binding: - name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }} - needs: - - build - strategy: - fail-fast: false - matrix: - node: - - '14' - - '16' - - '18' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup node - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node }} - check-latest: true - cache: yarn - - name: Install dependencies - run: | - yarn config set supportedArchitectures.libc "musl" - yarn install - - name: Download artifacts - uses: actions/download-artifact@v3 - with: - name: bindings-x86_64-unknown-linux-musl - path: . - - name: List packages - run: ls -R . - shell: bash - - name: Test bindings - run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn test - test-linux-aarch64-gnu-binding: - name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }} - needs: - - build - strategy: - fail-fast: false - matrix: - node: - - '14' - - '16' - - '18' - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Download artifacts - uses: actions/download-artifact@v3 - with: - name: bindings-aarch64-unknown-linux-gnu - path: . - - name: List packages - run: ls -R . - shell: bash - - name: Install dependencies - run: | - yarn config set supportedArchitectures.cpu "arm64" - yarn config set supportedArchitectures.libc "glibc" - yarn install - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - with: - platforms: arm64 - - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - - name: Setup and run tests - uses: addnab/docker-run-action@v3 - with: - image: node:${{ matrix.node }}-slim - options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build' - run: | - set -e - yarn test - ls -la - test-linux-aarch64-musl-binding: - name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }} - needs: - - build - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Download artifacts - uses: actions/download-artifact@v3 - with: - name: bindings-aarch64-unknown-linux-musl - path: . - - name: List packages - run: ls -R . - shell: bash - - name: Install dependencies - run: | - yarn config set supportedArchitectures.cpu "arm64" - yarn config set supportedArchitectures.libc "musl" - yarn install - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - with: - platforms: arm64 - - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes - - name: Setup and run tests - uses: addnab/docker-run-action@v3 - with: - image: node:lts-alpine - options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build' - run: | - set -e - yarn test + # test-linux-x64-musl-binding: + # name: Test bindings on x86_64-unknown-linux-musl - node@${{ matrix.node }} + # needs: + # - build + # strategy: + # fail-fast: false + # matrix: + # node: + # - '14' + # - '16' + # - '18' + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Setup node + # uses: actions/setup-node@v3 + # with: + # node-version: ${{ matrix.node }} + # check-latest: true + # cache: yarn + # - name: Install dependencies + # run: | + # yarn config set supportedArchitectures.libc "musl" + # yarn install + # - name: Download artifacts + # uses: actions/download-artifact@v3 + # with: + # name: bindings-x86_64-unknown-linux-musl + # path: . + # - name: List packages + # run: ls -R . + # shell: bash + # - name: Test bindings + # run: docker run --rm -v $(pwd):/build -w /build node:${{ matrix.node }}-alpine yarn test + # test-linux-aarch64-gnu-binding: + # name: Test bindings on aarch64-unknown-linux-gnu - node@${{ matrix.node }} + # needs: + # - build + # strategy: + # fail-fast: false + # matrix: + # node: + # - '14' + # - '16' + # - '18' + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Download artifacts + # uses: actions/download-artifact@v3 + # with: + # name: bindings-aarch64-unknown-linux-gnu + # path: . + # - name: List packages + # run: ls -R . + # shell: bash + # - name: Install dependencies + # run: | + # yarn config set supportedArchitectures.cpu "arm64" + # yarn config set supportedArchitectures.libc "glibc" + # yarn install + # - name: Set up QEMU + # uses: docker/setup-qemu-action@v2 + # with: + # platforms: arm64 + # - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + # - name: Setup and run tests + # uses: addnab/docker-run-action@v3 + # with: + # image: node:${{ matrix.node }}-slim + # options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build' + # run: | + # set -e + # yarn test + # ls -la + # test-linux-aarch64-musl-binding: + # name: Test bindings on aarch64-unknown-linux-musl - node@${{ matrix.node }} + # needs: + # - build + # runs-on: ubuntu-latest + # steps: + # - uses: actions/checkout@v3 + # - name: Download artifacts + # uses: actions/download-artifact@v3 + # with: + # name: bindings-aarch64-unknown-linux-musl + # path: . + # - name: List packages + # run: ls -R . + # shell: bash + # - name: Install dependencies + # run: | + # yarn config set supportedArchitectures.cpu "arm64" + # yarn config set supportedArchitectures.libc "musl" + # yarn install + # - name: Set up QEMU + # uses: docker/setup-qemu-action@v2 + # with: + # platforms: arm64 + # - run: docker run --rm --privileged multiarch/qemu-user-static --reset -p yes + # - name: Setup and run tests + # uses: addnab/docker-run-action@v3 + # with: + # image: node:lts-alpine + # options: '--platform linux/arm64 -v ${{ github.workspace }}:/build -w /build' + # run: | + # set -e + # yarn test test-linux-arm-gnueabihf-binding: name: Test bindings on armv7-unknown-linux-gnueabihf - node@${{ matrix.node }} needs: diff --git a/README.md b/README.md index eb83953..a4569d8 100644 --- a/README.md +++ b/README.md @@ -76,16 +76,16 @@ Running "OpusEncoder Benchmark" suite... Progress: 100% mediaplex: - 3 305 ops/s, ±0.15% | 21.18% slower + 3 516 ops/s, ±0.20% | 14.45% slower @discordjs/opus: - 3 174 ops/s, ±0.09% | 24.3% slower + 3 155 ops/s, ±0.35% | 23.24% slower opusscript: - 4 193 ops/s, ±0.16% | fastest + 4 110 ops/s, ±2.18% | fastest opusscript (no wasm): - 260 ops/s, ±0.55% | slowest, 93.8% slower + 256 ops/s, ±0.30% | slowest, 93.77% slower Finished 4 cases! Fastest: opusscript @@ -109,4 +109,4 @@ Progress: 100% Finished 4 cases! Fastest: @discordjs/opus Slowest: opusscript (no wasm) -``` \ No newline at end of file +``` diff --git a/build.rs b/build.rs index f70eacb..77c0650 100644 --- a/build.rs +++ b/build.rs @@ -2,9 +2,9 @@ extern crate napi_build; +use bindgen; use std::path::PathBuf; use std::{env, fmt::Display, path::Path}; -use bindgen; const fn rustc_linking_word(is_static_link: bool) -> &'static str { if is_static_link { @@ -45,7 +45,22 @@ fn build_opus(is_static: bool) { ); println!("cargo:info=Building Opus via CMake."); - let opus_build_dir = cmake::build(opus_path); + + let mut cmake_config = cmake::Config::new(opus_path); + + if let Ok(android_target) = env::var("CARGO_NDK_ANDROID_TARGET") { + cmake_config.define("ANDROID_ABI", android_target); + + if let Ok(toolchain_file) = env::var("CARGO_NDK_CMAKE_TOOLCHAIN_PATH") { + cmake_config.define("CMAKE_TOOLCHAIN_FILE", toolchain_file); + } + } + + if let Ok(value) = env::var("CMAKE_OSX_SYSROOT") { + cmake_config.configure_arg(format!("-DCMAKE_OSX_SYSROOT={value}")); + } + + let opus_build_dir = cmake_config.build(); link_opus(is_static, opus_build_dir.display()) } diff --git a/package.json b/package.json index 4c72dbe..3466da8 100644 --- a/package.json +++ b/package.json @@ -9,14 +9,10 @@ "additional": [ "aarch64-apple-darwin", "aarch64-linux-android", - "aarch64-unknown-linux-gnu", - "aarch64-unknown-linux-musl", "aarch64-pc-windows-msvc", "armv7-unknown-linux-gnueabihf", - "x86_64-unknown-linux-musl", "x86_64-unknown-freebsd", "i686-pc-windows-msvc", - "armv7-linux-androideabi", "universal-apple-darwin" ] }