From 7f7674600b676c6dae79dd65a94da5407fa4b1b7 Mon Sep 17 00:00:00 2001 From: Dennis Ameling Date: Wed, 18 Nov 2020 21:02:46 +0100 Subject: [PATCH] Switch to N-API prebuilds --- .github/workflows/ci.yml | 30 ++++++++++++++------- .travis.yml | 6 ++--- appveyor.yml | 14 +++++----- binding.gyp | 3 +++ package.json | 18 ++++++++----- script/download-node-lib-win-arm64.ps1 | 36 ++++++++++++++++++++++++++ 6 files changed, 82 insertions(+), 25 deletions(-) create mode 100644 script/download-node-lib-win-arm64.ps1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 80c61803..90823bdf 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -15,6 +15,8 @@ jobs: CC: "clang" CXX: "clang++" npm_config_clang: "1" + # Needed until macos-11.0 hosted runners are available + SDKROOT: "/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk" strategy: matrix: @@ -45,6 +47,15 @@ jobs: if: ${{ matrix.os == 'ubuntu-16.04' }} name: Install additional dependencies + # This step can be removed as soon as official Windows arm64 builds are published: + # https://github.com/nodejs/build/issues/2450#issuecomment-705853342 + - run: | + $NodeVersion = (node --version) -replace '^.' + $NodeFallbackVersion = "15.2.1" + & .\script\download-node-lib-win-arm64.ps1 $NodeVersion $NodeFallbackVersion + if: ${{ matrix.os == 'windows-latest' }} + name: Install Windows arm64 node.lib + - run: npm install name: Setup environment @@ -65,24 +76,23 @@ jobs: if: ${{ matrix.os != 'ubuntu-16.04' }} name: Run tests (Windows/macOS) - - run: | - npm run prebuild-node - npm run prebuild-electron + - run: npm run prebuild-napi-x64 name: Prebuild (x64) - - run: | - npm run prebuild-electron-arm64 - npm run prebuild-node-ia32 - npm run prebuild-electron-ia32 + - run: npm run prebuild-napi-arm64 + name: Prebuild (arm64) + if: ${{ matrix.os != 'ubuntu-16.04' }} + + - run: npm run prebuild-napi-ia32 if: ${{ matrix.os == 'windows-latest' }} - name: Prebuild (Windows x86 + ARM64) + name: Prebuild (Windows x86) - run: | mkdir -p prebuilds && chmod 777 prebuilds docker build -t node-keytar/i386 docker/i386 - docker run --rm -v ${PWD}:/project node-keytar/i386 /bin/bash -c "cd /project && npm run prebuild-node-ia32 && npm run prebuild-electron-ia32 && rm -rf build" + docker run --rm -v ${PWD}:/project node-keytar/i386 /bin/bash -c "cd /project && npm run prebuild-napi-ia32 && rm -rf build" docker build -t node-keytar/arm64-cross-compile docker/arm64-cross-compile - docker run --rm -v ${PWD}:/project node-keytar/arm64-cross-compile /bin/bash -c "cd /project && npm run prebuild-electron-arm64" + docker run --rm -v ${PWD}:/project node-keytar/arm64-cross-compile /bin/bash -c "cd /project && npm run prebuild-napi-arm64" if: ${{ matrix.os == 'ubuntu-16.04' }} name: Prebuild (Linux x86 + ARM64) diff --git a/.travis.yml b/.travis.yml index 1dde81cb..f7dd2b49 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,11 @@ language: node_js sudo: required -dist: trusty +dist: xenial os: - linux - osx node_js: 15 +osx_image: xcode12.3 env: - CC=clang CXX=clang++ npm_config_clang=1 @@ -50,8 +51,7 @@ install: script: - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then xvfb-run ./script/cibuild; fi - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm test; fi - - npm run prebuild-node - - npm run prebuild-electron + - npm run prebuild-napi-x64 - | if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then mkdir -p prebuilds && chmod 777 prebuilds diff --git a/appveyor.yml b/appveyor.yml index 2a85a35a..f32a73c1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,6 @@ version: "{build}" -image: Visual Studio 2017 +image: Visual Studio 2019 platform: - x64 @@ -22,11 +22,13 @@ install: build_script: - npm test - - npm run prebuild-node - - npm run prebuild-node-ia32 - - npm run prebuild-electron - - npm run prebuild-electron-ia32 - - npm run prebuild-electron-arm64 + - npm run prebuild-napi-x64 + - npm run prebuild-napi-ia32 + - ps: | + $NodeVersion = (node --version) -replace '^.' + $NodeFallbackVersion = "15.2.1" + & .\script\download-node-lib-win-arm64.ps1 $NodeVersion $NodeFallbackVersion + - npm run prebuild-napi-arm64 - if defined APPVEYOR_REPO_TAG_NAME (npm run upload) test: off diff --git a/binding.gyp b/binding.gyp index 59f9c4c1..9be3dcb4 100644 --- a/binding.gyp +++ b/binding.gyp @@ -2,6 +2,9 @@ 'targets': [ { 'target_name': 'keytar', + 'defines': [ + "NAPI_VERSION=<(napi_build_version)", + ], 'cflags!': [ '-fno-exceptions' ], 'cflags_cc!': [ '-fno-exceptions' ], 'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', diff --git a/package.json b/package.json index 89fd2c89..4f1401b0 100644 --- a/package.json +++ b/package.json @@ -35,11 +35,9 @@ "lint": "npm run cpplint", "cpplint": "node-cpplint --filters legal-copyright,build-include,build-namespaces src/*.cc", "test": "npm run lint && npm rebuild && mocha --require babel-core/register spec/", - "prebuild-node": "prebuild -t 8.9.0 -t 9.4.0 -t 10.11.0 -t 11.9.0 -t 12.0.0 -t 13.0.0 -t 14.0.0 -t 15.0.0 --strip", - "prebuild-node-ia32": "prebuild -t 8.9.0 -t 9.4.0 -a ia32 --strip", - "prebuild-electron": "prebuild -t 7.0.0 -t 8.0.0 -t 9.0.0 -t 10.0.0 -t 11.0.0 -r electron --strip", - "prebuild-electron-arm64": "prebuild -t 7.0.0 -t 8.0.0 -t 9.0.0 -t 10.0.0 -t 11.0.0 -r electron -a arm64 --strip", - "prebuild-electron-ia32": "prebuild -t 7.0.0 -t 8.0.0 -t 9.0.0 -t 10.0.0 -t 11.0.0 -r electron -a ia32 --strip", + "prebuild-napi-x64": "prebuild -t 3 -r napi -a x64 --strip", + "prebuild-napi-ia32": "prebuild -t 3 -r napi -a ia32 --strip", + "prebuild-napi-arm64": "prebuild -t 3 -r napi -a arm64 --strip", "upload": "node ./script/upload.js", "postpublish": "git push --follow-tags" }, @@ -48,7 +46,6 @@ "babel-plugin-transform-async-to-generator": "^6.24.1", "chai": "^4.2.0", "mocha": "^8.0.1", - "node-abi": "^2.19.3", "node-cpplint": "~0.4.0", "node-gyp": "^7.0.0", "prebuild": "^10.0.1" @@ -56,5 +53,14 @@ "dependencies": { "node-addon-api": "^3.0.0", "prebuild-install": "^6.0.0" + }, + "binary": { + "napi_versions": [ + 3 + ] + }, + "config": { + "runtime": "napi", + "target": 3 } } diff --git a/script/download-node-lib-win-arm64.ps1 b/script/download-node-lib-win-arm64.ps1 new file mode 100644 index 00000000..7cad5526 --- /dev/null +++ b/script/download-node-lib-win-arm64.ps1 @@ -0,0 +1,36 @@ +# This script can be removed as soon as official Windows arm64 builds are published: +# https://github.com/nodejs/build/issues/2450#issuecomment-705853342 + +$nodeVersion = $args[0] +$fallbackVersion = $args[1] + +If ($null -eq $nodeVersion -Or $null -eq $fallbackVersion) { + Write-Error "No NodeJS version given as argument to this file. Run it like download-nodejs-win-arm64.ps1 NODE_VERSION NODE_FALLBACK_VERSION" + exit 1 +} + +$url = "https://unofficial-builds.nodejs.org/download/release/v$nodeVersion/win-arm64/node.lib" +$fallbackUrl = "https://unofficial-builds.nodejs.org/download/release/v$fallbackVersion/win-arm64/node.lib" + +# Always write to the $nodeVersion cache folder, even if we're using the fallbackVersion +$cacheFolder = "$env:TEMP\prebuild\napi\$nodeVersion\arm64" + +If (!(Test-Path $cacheFolder)) { + New-Item -ItemType Directory -Force -Path $cacheFolder +} + +$output = "$cacheFolder\node.lib" +$start_time = Get-Date + +Try { + Invoke-WebRequest -Uri $url -OutFile $output + $downloadedNodeVersion = $nodeVersion +} Catch { + If ($_.Exception.Response -And $_.Exception.Response.StatusCode -eq "NotFound") { + Write-Output "No arm64 node.lib found for Node Windows $nodeVersion, trying fallback version $fallbackVersion..." + Invoke-WebRequest -Uri $fallbackUrl -OutFile $output + $downloadedNodeVersion = $fallbackVersion + } +} + +Write-Output "Downloaded arm64 NodeJS lib v$downloadedNodeVersion to $output in $((Get-Date).Subtract($start_time).Seconds) second(s)"