Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 7f76746

Browse files
committed
Switch to N-API prebuilds
1 parent e792f95 commit 7f76746

File tree

6 files changed

+82
-25
lines changed

6 files changed

+82
-25
lines changed

.github/workflows/ci.yml

+20-10
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
CC: "clang"
1616
CXX: "clang++"
1717
npm_config_clang: "1"
18+
# Needed until macos-11.0 hosted runners are available
19+
SDKROOT: "/Library/Developer/CommandLineTools/SDKs/MacOSX11.1.sdk"
1820

1921
strategy:
2022
matrix:
@@ -45,6 +47,15 @@ jobs:
4547
if: ${{ matrix.os == 'ubuntu-16.04' }}
4648
name: Install additional dependencies
4749
50+
# This step can be removed as soon as official Windows arm64 builds are published:
51+
# https://github.com/nodejs/build/issues/2450#issuecomment-705853342
52+
- run: |
53+
$NodeVersion = (node --version) -replace '^.'
54+
$NodeFallbackVersion = "15.2.1"
55+
& .\script\download-node-lib-win-arm64.ps1 $NodeVersion $NodeFallbackVersion
56+
if: ${{ matrix.os == 'windows-latest' }}
57+
name: Install Windows arm64 node.lib
58+
4859
- run: npm install
4960
name: Setup environment
5061

@@ -65,24 +76,23 @@ jobs:
6576
if: ${{ matrix.os != 'ubuntu-16.04' }}
6677
name: Run tests (Windows/macOS)
6778

68-
- run: |
69-
npm run prebuild-node
70-
npm run prebuild-electron
79+
- run: npm run prebuild-napi-x64
7180
name: Prebuild (x64)
7281

73-
- run: |
74-
npm run prebuild-electron-arm64
75-
npm run prebuild-node-ia32
76-
npm run prebuild-electron-ia32
82+
- run: npm run prebuild-napi-arm64
83+
name: Prebuild (arm64)
84+
if: ${{ matrix.os != 'ubuntu-16.04' }}
85+
86+
- run: npm run prebuild-napi-ia32
7787
if: ${{ matrix.os == 'windows-latest' }}
78-
name: Prebuild (Windows x86 + ARM64)
88+
name: Prebuild (Windows x86)
7989

8090
- run: |
8191
mkdir -p prebuilds && chmod 777 prebuilds
8292
docker build -t node-keytar/i386 docker/i386
83-
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"
93+
docker run --rm -v ${PWD}:/project node-keytar/i386 /bin/bash -c "cd /project && npm run prebuild-napi-ia32 && rm -rf build"
8494
docker build -t node-keytar/arm64-cross-compile docker/arm64-cross-compile
85-
docker run --rm -v ${PWD}:/project node-keytar/arm64-cross-compile /bin/bash -c "cd /project && npm run prebuild-electron-arm64"
95+
docker run --rm -v ${PWD}:/project node-keytar/arm64-cross-compile /bin/bash -c "cd /project && npm run prebuild-napi-arm64"
8696
if: ${{ matrix.os == 'ubuntu-16.04' }}
8797
name: Prebuild (Linux x86 + ARM64)
8898

.travis.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
language: node_js
22
sudo: required
3-
dist: trusty
3+
dist: xenial
44
os:
55
- linux
66
- osx
77
node_js: 15
8+
osx_image: xcode12.3
89

910
env:
1011
- CC=clang CXX=clang++ npm_config_clang=1
@@ -50,8 +51,7 @@ install:
5051
script:
5152
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then xvfb-run ./script/cibuild; fi
5253
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then npm test; fi
53-
- npm run prebuild-node
54-
- npm run prebuild-electron
54+
- npm run prebuild-napi-x64
5555
- |
5656
if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then
5757
mkdir -p prebuilds && chmod 777 prebuilds

appveyor.yml

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: "{build}"
22

3-
image: Visual Studio 2017
3+
image: Visual Studio 2019
44
platform:
55
- x64
66

@@ -22,11 +22,13 @@ install:
2222

2323
build_script:
2424
- npm test
25-
- npm run prebuild-node
26-
- npm run prebuild-node-ia32
27-
- npm run prebuild-electron
28-
- npm run prebuild-electron-ia32
29-
- npm run prebuild-electron-arm64
25+
- npm run prebuild-napi-x64
26+
- npm run prebuild-napi-ia32
27+
- ps: |
28+
$NodeVersion = (node --version) -replace '^.'
29+
$NodeFallbackVersion = "15.2.1"
30+
& .\script\download-node-lib-win-arm64.ps1 $NodeVersion $NodeFallbackVersion
31+
- npm run prebuild-napi-arm64
3032
- if defined APPVEYOR_REPO_TAG_NAME (npm run upload)
3133

3234
test: off

binding.gyp

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
'targets': [
33
{
44
'target_name': 'keytar',
5+
'defines': [
6+
"NAPI_VERSION=<(napi_build_version)",
7+
],
58
'cflags!': [ '-fno-exceptions' ],
69
'cflags_cc!': [ '-fno-exceptions' ],
710
'xcode_settings': { 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',

package.json

+12-6
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,9 @@
3535
"lint": "npm run cpplint",
3636
"cpplint": "node-cpplint --filters legal-copyright,build-include,build-namespaces src/*.cc",
3737
"test": "npm run lint && npm rebuild && mocha --require babel-core/register spec/",
38-
"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",
39-
"prebuild-node-ia32": "prebuild -t 8.9.0 -t 9.4.0 -a ia32 --strip",
40-
"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",
41-
"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",
42-
"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",
38+
"prebuild-napi-x64": "prebuild -t 3 -r napi -a x64 --strip",
39+
"prebuild-napi-ia32": "prebuild -t 3 -r napi -a ia32 --strip",
40+
"prebuild-napi-arm64": "prebuild -t 3 -r napi -a arm64 --strip",
4341
"upload": "node ./script/upload.js",
4442
"postpublish": "git push --follow-tags"
4543
},
@@ -48,13 +46,21 @@
4846
"babel-plugin-transform-async-to-generator": "^6.24.1",
4947
"chai": "^4.2.0",
5048
"mocha": "^8.0.1",
51-
"node-abi": "^2.19.3",
5249
"node-cpplint": "~0.4.0",
5350
"node-gyp": "^7.0.0",
5451
"prebuild": "^10.0.1"
5552
},
5653
"dependencies": {
5754
"node-addon-api": "^3.0.0",
5855
"prebuild-install": "^6.0.0"
56+
},
57+
"binary": {
58+
"napi_versions": [
59+
3
60+
]
61+
},
62+
"config": {
63+
"runtime": "napi",
64+
"target": 3
5965
}
6066
}
+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# This script can be removed as soon as official Windows arm64 builds are published:
2+
# https://github.com/nodejs/build/issues/2450#issuecomment-705853342
3+
4+
$nodeVersion = $args[0]
5+
$fallbackVersion = $args[1]
6+
7+
If ($null -eq $nodeVersion -Or $null -eq $fallbackVersion) {
8+
Write-Error "No NodeJS version given as argument to this file. Run it like download-nodejs-win-arm64.ps1 NODE_VERSION NODE_FALLBACK_VERSION"
9+
exit 1
10+
}
11+
12+
$url = "https://unofficial-builds.nodejs.org/download/release/v$nodeVersion/win-arm64/node.lib"
13+
$fallbackUrl = "https://unofficial-builds.nodejs.org/download/release/v$fallbackVersion/win-arm64/node.lib"
14+
15+
# Always write to the $nodeVersion cache folder, even if we're using the fallbackVersion
16+
$cacheFolder = "$env:TEMP\prebuild\napi\$nodeVersion\arm64"
17+
18+
If (!(Test-Path $cacheFolder)) {
19+
New-Item -ItemType Directory -Force -Path $cacheFolder
20+
}
21+
22+
$output = "$cacheFolder\node.lib"
23+
$start_time = Get-Date
24+
25+
Try {
26+
Invoke-WebRequest -Uri $url -OutFile $output
27+
$downloadedNodeVersion = $nodeVersion
28+
} Catch {
29+
If ($_.Exception.Response -And $_.Exception.Response.StatusCode -eq "NotFound") {
30+
Write-Output "No arm64 node.lib found for Node Windows $nodeVersion, trying fallback version $fallbackVersion..."
31+
Invoke-WebRequest -Uri $fallbackUrl -OutFile $output
32+
$downloadedNodeVersion = $fallbackVersion
33+
}
34+
}
35+
36+
Write-Output "Downloaded arm64 NodeJS lib v$downloadedNodeVersion to $output in $((Get-Date).Subtract($start_time).Seconds) second(s)"

0 commit comments

Comments
 (0)