Skip to content

Commit f69e624

Browse files
authored
Merge pull request #218 from desktop/enable-n-api-prebuilds
2 parents d2ccfae + 64febdb commit f69e624

File tree

4 files changed

+67
-16
lines changed

4 files changed

+67
-16
lines changed

.github/workflows/ci.yml

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ jobs:
2828
uses: actions/setup-node@v2.1.2
2929
with:
3030
node-version: 12
31+
32+
# This step can be removed as soon as official Windows arm64 builds are published:
33+
# https://github.com/nodejs/build/issues/2450#issuecomment-705853342
34+
- run: |
35+
$NodeVersion = (node --version) -replace '^.'
36+
$NodeFallbackVersion = "15.8.0"
37+
& .\script\download-node-lib-win-arm64.ps1 $NodeVersion $NodeFallbackVersion
38+
name: Install Windows arm64 node.lib
39+
3140
- name: Install and build dependencies
3241
run: yarn
3342
- name: Lint
@@ -36,16 +45,12 @@ jobs:
3645
run: yarn build
3746
- name: Test
3847
run: yarn test
39-
- name: Prebuild Node x64
40-
run: yarn prebuild-node
41-
- name: Prebuild Node x86
42-
run: yarn prebuild-node-ia32
43-
- name: Prebuild Electron x64
44-
run: yarn prebuild-electron
45-
- name: Prebuild Electron x86
46-
run: yarn prebuild-electron-ia32
47-
- name: Prebuild Electron arm64
48-
run: yarn prebuild-electron-arm64
48+
- name: Prebuild x64
49+
run: npm run prebuild-napi-x64
50+
- name: Prebuild arm64
51+
run: npm run prebuild-napi-arm64
52+
- name: Prebuild x86
53+
run: npm run prebuild-napi-ia32
4954
- name: Publish
5055
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
5156
run: yarn upload

binding.gyp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
},
1414
'include_dirs': [
1515
'<!(node -p "require(\'node-addon-api\').include_dir")' ],
16+
'defines': [
17+
"NAPI_VERSION=<(napi_build_version)",
18+
],
1619
'conditions': [
1720
['OS=="win"', {
1821
'sources': [

package.json

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
"benchmark": "ts-node benchmarks/reg.ts",
1515
"prettier": "yarn prettier --write",
1616
"check-prettier": "prettier --check \"./**/*.{ts,tsx,js,json,jsx,scss,html,yaml,yml}\"",
17-
"prebuild-node": "prebuild -t 10.11.0 -t 11.9.0 -t 12.0.0 -t 14.8.0 --strip",
18-
"prebuild-node-ia32": "prebuild -t 10.11.0 -t 11.9.0 -t 12.0.0 -t 14.8.0 -a ia32 --strip",
19-
"prebuild-electron": "prebuild -t 7.0.0 -t 8.0.0 -t 9.0.0 -t 10.0.0 -t 11.0.0 -t 12.0.0 -r electron --strip",
20-
"prebuild-electron-arm64": "prebuild -t 7.0.0 -t 8.0.0 -t 9.0.0 -t 10.0.0 -t 11.0.0 -t 12.0.0 -r electron -a arm64 --strip",
21-
"prebuild-electron-ia32": "prebuild -t 7.0.0 -t 8.0.0 -t 9.0.0 -t 10.0.0 -t 11.0.0 -t 12.0.0 -r electron -a ia32 --strip",
22-
"prebuild-all": "yarn prebuild-node && yarn prebuild-node-ia32 && yarn prebuild-electron && yarn prebuild-electron-ia32 && yarn prebuild-electron-arm64",
17+
"prebuild-napi-x64": "prebuild -t 3 -r napi -a x64 --strip",
18+
"prebuild-napi-ia32": "prebuild -t 3 -r napi -a ia32 --strip",
19+
"prebuild-napi-arm64": "prebuild -t 3 -r napi -a arm64 --strip",
20+
"prebuild-all": "yarn prebuild-napi-x64 && yarn prebuild-napi-ia32 && yarn prebuild-napi-arm64",
2321
"upload": "node ./script/upload.js"
2422
},
2523
"repository": {
@@ -48,5 +46,14 @@
4846
"dependencies": {
4947
"node-addon-api": "^3.1.0",
5048
"prebuild-install": "^5.3.5"
49+
},
50+
"binary": {
51+
"napi_versions": [
52+
3
53+
]
54+
},
55+
"config": {
56+
"runtime": "napi",
57+
"target": 3
5158
}
5259
}
Lines changed: 36 additions & 0 deletions
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)