From b41ddd7a34980f02671c2abe85c6f94ff8979b5e Mon Sep 17 00:00:00 2001 From: Tuditi <45079109+Tuditi@users.noreply.github.com> Date: Tue, 7 Feb 2023 10:16:35 +0100 Subject: [PATCH] feat: use N-API 6 builds (#1556) * feat: specify NAPI version in binding.gyp * feat: adjust nodejs scripts * feat: update covector to use updated prebuild script * chore: newline * chore: add .md to changes folder * feat: remove node-version from matrix * fix: remove ubuntu-18.04 & set nodejs to 16.x --- .changes/switch-to-napi-6.md | 6 ++ .github/workflows/covector.yml | 66 ++----------------- client/bindings/nodejs/binding.gyp | 8 ++- client/bindings/nodejs/package.json | 12 ++-- .../nodejs/scripts/electron-neon-build.js | 11 ---- .../nodejs/scripts/electron-prebuild.js | 23 ------- .../{node-neon-build.js => neon-build.js} | 0 7 files changed, 24 insertions(+), 102 deletions(-) create mode 100644 .changes/switch-to-napi-6.md delete mode 100644 client/bindings/nodejs/scripts/electron-neon-build.js delete mode 100644 client/bindings/nodejs/scripts/electron-prebuild.js rename client/bindings/nodejs/scripts/{node-neon-build.js => neon-build.js} (100%) diff --git a/.changes/switch-to-napi-6.md b/.changes/switch-to-napi-6.md new file mode 100644 index 000000000..033d25b9a --- /dev/null +++ b/.changes/switch-to-napi-6.md @@ -0,0 +1,6 @@ + +--- +"nodejs-binding": patch +--- + +Move to N-API 6 builds. diff --git a/.github/workflows/covector.yml b/.github/workflows/covector.yml index 6c062d8e8..91a71fb9c 100644 --- a/.github/workflows/covector.yml +++ b/.github/workflows/covector.yml @@ -90,18 +90,7 @@ jobs: # The GitHub hosted Windows 2022 image comes with Visual Studio 2022, but node-gyp # (which is used by neon-sys) sadly fails to recognize it. As a mitigation, we still run the # tests on Windows 2019, until we can figure out a way to fix the problem. - # NOTE: Using Ubuntu 18.04 to provide glibc compatibility. (#588) - os: [ubuntu-18.04, ubuntu-latest, macos-latest, windows-2019] - node-version: ['14.x', '16.x', '18.x'] - exclude: - # GLIBC_2.28 is only available with a newer ubuntu version - - os: ubuntu-18.04 - node-version: '18.x' - # ubuntu-18.04 is needed for for node 14.x and 16.x - - os: ubuntu-latest - node-version: '14.x' - - os: ubuntu-latest - node-version: '16.x' + os: [ubuntu-latest, macos-latest, windows-2019] steps: - name: Checkout the Source Code @@ -113,10 +102,10 @@ jobs: toolchain: stable cache: false - - name: Set up Node.js ${{ matrix.node-version }} + - name: Set up Node.js 16.x uses: actions/setup-node@v2 with: - node-version: ${{ matrix.node-version }} + node-version: '16.x' - name: Install required packages (Ubuntu) if: ${{ startsWith(matrix.os, 'ubuntu') }} @@ -137,54 +126,7 @@ jobs: - name: Build Node.js Prebuilds working-directory: client/bindings/nodejs/ - run: yarn prebuild:node - - - name: Upload Prebuilds to GitHub Release - working-directory: client/bindings/nodejs/ - run: yarn prebuild --upload-all ${{ secrets.GITHUB_TOKEN }} --tag-prefix nodejs-binding-v - - electron-binding-prebuild: - name: Build Prebuilt Binaries for Electron - if: needs.version-or-publish.outputs.successfulPublish == 'true' - needs: version-or-publish - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - # The GitHub hosted Windows 2022 image comes with Visual Studio 2022, but node-gyp - # (which is used by neon-sys) sadly fails to recognize it. As a mitigation, we still run the - # tests on Windows 2019, until we can figure out a way to fix the problem. - # NOTE: Using Ubuntu 18.04 to provide glibc compatibility. (#588) - os: [ubuntu-18.04, macos-latest, windows-2019] - - steps: - - name: Checkout the Source Code - uses: actions/checkout@v3 - - - name: Set Up Stable Rust - uses: ./.github/actions/setup-rust - with: - toolchain: stable - cache: false - - - name: Set up Node.js 14 - uses: actions/setup-node@v2 - with: - node-version: '14' - - - name: Install required packages (Ubuntu) - if: ${{ startsWith(matrix.os, 'ubuntu') }} - run: | - sudo apt-get update - sudo apt-get install libudev-dev libusb-1.0-0-dev - - - name: Run Yarn Install - working-directory: client/bindings/nodejs/ - run: yarn install - - - name: Build Electron Prebuilds - working-directory: client/bindings/nodejs/ - run: yarn prebuild:electron + run: yarn prebuild - name: Upload Prebuilds to GitHub Release working-directory: client/bindings/nodejs/ diff --git a/client/bindings/nodejs/binding.gyp b/client/bindings/nodejs/binding.gyp index 35781bf06..2cb6226f2 100644 --- a/client/bindings/nodejs/binding.gyp +++ b/client/bindings/nodejs/binding.gyp @@ -1,7 +1,11 @@ { "targets": [ { - "target_name": "index" + "target_name": "index", + 'defines': [ + "NAPI_VERSION=<(napi_build_version)", + ], + "win_delay_load_hook": "true", } ] -} \ No newline at end of file +} diff --git a/client/bindings/nodejs/package.json b/client/bindings/nodejs/package.json index 640a0d015..ea56fbfee 100644 --- a/client/bindings/nodejs/package.json +++ b/client/bindings/nodejs/package.json @@ -21,12 +21,11 @@ "lint": "eslint --ignore-path .eslintignore --ext .js,.ts .", "format": "prettier --ignore-path .eslintignore -w {,*/**/}*.{ts,js,json}", "format-check": "prettier --ignore-path .eslintignore -c {,*/**/}*.{ts,js,json}", - "install": "prebuild-install --tag-prefix nodejs-binding-v || npm run rebuild", + "install": "prebuild-install --runtime napi --tag-prefix nodejs-binding-v || npm run rebuild", "build": "npm run build:neon && tsc", "build:neon": "cargo-cp-artifact -nc ./index.node -- cargo build --release --message-format=json-render-diagnostics", - "rebuild": "npm run build:neon && tsc && node scripts/node-neon-build.js --strip && node scripts/strip.js", - "prebuild:node": "prebuild --prepack scripts/node-neon-build.js --strip", - "prebuild:electron": "node scripts/electron-prebuild.js", + "rebuild": "npm run build:neon && tsc && node scripts/neon-build.js --strip && node scripts/strip.js", + "prebuild": "prebuild --runtime napi --target 6 --prepack scripts/neon-build.js --strip", "docs-wiki-build": "typedoc --githubPages false --disableSources --excludePrivate --excludeInternal --excludeNotDocumented --plugin typedoc-plugin-markdown --theme markdown --hideBreadcrumbs --entryDocument api_ref.md --readme none --hideGenerator --sort source-order --exclude ./**/src/index.ts --out ../../../documentation/docs/libraries/nodejs/references/ ./lib/index.ts", "test": "jest --forceExit" }, @@ -55,5 +54,10 @@ "tar": "^4.4.19", "simple-get": "^2.8.2", "json5": "^2.2.2" + }, + "binary": { + "napi_versions": [ + 6 + ] } } diff --git a/client/bindings/nodejs/scripts/electron-neon-build.js b/client/bindings/nodejs/scripts/electron-neon-build.js deleted file mode 100644 index 316b756a2..000000000 --- a/client/bindings/nodejs/scripts/electron-neon-build.js +++ /dev/null @@ -1,11 +0,0 @@ -const { promisify } = require('util'); -const moveArtifact = require('./move-artifact'); -const build = promisify(require('electron-build-env')); - -build(['yarn', 'build:neon'], { - electron: process.env.CURRENT_ELECTRON_VERSION, -}).then(() => { - moveArtifact(); - process.exit(0) -}); - diff --git a/client/bindings/nodejs/scripts/electron-prebuild.js b/client/bindings/nodejs/scripts/electron-prebuild.js deleted file mode 100644 index 48e71711b..000000000 --- a/client/bindings/nodejs/scripts/electron-prebuild.js +++ /dev/null @@ -1,23 +0,0 @@ -const { spawnSync } = require('child_process'); -const { resolve } = require('path'); -const ELECTRON_VERSIONS = ['13.6.9', '14.2.9', '15.5.7', '16.2.8', '17.4.11', '18.3.6', '19.0.10']; - -for (const version of ELECTRON_VERSIONS) { - // HACK: make electron-build-env aware of the electron version we're targeting - process.env['CURRENT_ELECTRON_VERSION'] = version; - // HACK: there are bugs in prebuild that are preventing us from using its API, so we're using the CLI instead - spawnSync( - process.platform === 'win32' ? 'yarn.cmd' : 'yarn', - [ - 'prebuild', - '-t', - version, - '-r', - 'electron', - '--prepack', - 'scripts/electron-neon-build.js', - '--strip', - ], - { stdio: 'inherit', cwd: resolve(__dirname, '../') }, - ); -} diff --git a/client/bindings/nodejs/scripts/node-neon-build.js b/client/bindings/nodejs/scripts/neon-build.js similarity index 100% rename from client/bindings/nodejs/scripts/node-neon-build.js rename to client/bindings/nodejs/scripts/neon-build.js