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

Commit 4739ab2

Browse files
committed
Switch to N-API prebuilds
1 parent 8e977a8 commit 4739ab2

File tree

4 files changed

+71
-14
lines changed

4 files changed

+71
-14
lines changed

.github/workflows/ci.yml

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

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

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

69-
- run: |
70-
npm run prebuild-node
71-
npm run prebuild-electron
80+
- run: npm run prebuild-napi-x64
7281
name: Prebuild (x64)
7382

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

8091
- run: |
8192
mkdir -p prebuilds && chmod 777 prebuilds
8293
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-electron-ia32 && rm -rf build"
94+
docker run --rm -v ${PWD}:/project node-keytar/i386 /bin/bash -c "cd /project && npm run prebuild-napi-ia32 && rm -rf build"
8495
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"
96+
docker run --rm -v ${PWD}:/project node-keytar/arm64-cross-compile /bin/bash -c "cd /project && npm run prebuild-napi-arm64"
8697
if: ${{ matrix.os == 'ubuntu-16.04' }}
8798
name: Prebuild (Linux x86 + ARM64)
8899

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-5
Original file line numberDiff line numberDiff line change
@@ -35,24 +35,31 @@
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 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-electron": "prebuild -t 10.0.0 -t 11.0.0 -t 12.0.0 -r electron --strip",
40-
"prebuild-electron-arm64": "prebuild -t 10.0.0 -t 11.0.0 -t 12.0.0 -r electron -a arm64 --strip",
41-
"prebuild-electron-ia32": "prebuild -t 10.0.0 -t 11.0.0 -t 12.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",
4241
"upload": "node ./script/upload.js"
4342
},
4443
"devDependencies": {
4544
"babel-core": "^6.26.3",
4645
"babel-plugin-transform-async-to-generator": "^6.24.1",
4746
"chai": "^4.2.0",
4847
"mocha": "^8.0.1",
49-
"node-abi": "^2.19.3",
5048
"node-cpplint": "~0.4.0",
5149
"node-gyp": "^8.0.0",
5250
"prebuild": "^10.0.1"
5351
},
5452
"dependencies": {
5553
"node-addon-api": "^3.0.0",
5654
"prebuild-install": "^6.0.0"
55+
},
56+
"binary": {
57+
"napi_versions": [
58+
3
59+
]
60+
},
61+
"config": {
62+
"runtime": "napi",
63+
"target": 3
5764
}
5865
}
+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)