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

Commit

Permalink
Switch to N-API prebuilds
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisameling committed Feb 18, 2021
1 parent e792f95 commit 7f76746
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 25 deletions.
30 changes: 20 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 8 additions & 6 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: "{build}"

image: Visual Studio 2017
image: Visual Studio 2019
platform:
- x64

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 12 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand All @@ -48,13 +46,21 @@
"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"
},
"dependencies": {
"node-addon-api": "^3.0.0",
"prebuild-install": "^6.0.0"
},
"binary": {
"napi_versions": [
3
]
},
"config": {
"runtime": "napi",
"target": 3
}
}
36 changes: 36 additions & 0 deletions script/download-node-lib-win-arm64.ps1
Original file line number Diff line number Diff line change
@@ -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)"

0 comments on commit 7f76746

Please sign in to comment.