Skip to content

Commit 8500fa6

Browse files
committed
TF-255: Update build for Electron 20
This commit updates the module to cause it to build for electron 20; - Increase C++ version to C++17 - Merge upstream node16 changes - Use latest version of `nan` to work around electron/electron#35193 - Do not use the v8 version of the build environment to specify the output directory, as it will likely be different from the runtime directory. - Fix test script using out of date APIs. - Introduce CI that verifies that the Linux module does in fact build and that the tests pass.
1 parent ffa0f67 commit 8500fa6

File tree

7 files changed

+46
-15
lines changed

7 files changed

+46
-15
lines changed

.github/workflows/ci.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI - Test Build
2+
3+
on:
4+
pull_request:
5+
workflow_dispatch:
6+
7+
jobs:
8+
BuildLinux:
9+
runs-on: ubuntu-20.04
10+
steps:
11+
- uses: actions/checkout@v3
12+
13+
- name: Install dependencies
14+
run: sudo ./install-deps.sh
15+
16+
- name: Test build module (linux-x64)
17+
run: npm i && file bin/linux-x64/capnp.node
18+
19+
- name: Run tests
20+
run: npm test
21+
22+
# vim: set nospell:

binding.gyp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
'target_name': 'capnp',
55
'sources': ['src/node-capnp/capnp.cc'],
66
'libraries': ['-lkj', '-lkj-async', '-lcapnp', '-lcapnpc', '-lcapnp-rpc'],
7-
'cflags_cc': ['-std=c++14'],
7+
'cflags_cc': ['-std=c++17'],
88
'cflags_cc!': ['-fno-rtti', '-fno-exceptions'],
99
'include_dirs': [
1010
'src',

build.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ var force = false, debug = false;
3131
var
3232
arch = process.arch,
3333
platform = process.platform,
34-
v8 = /[0-9]+\.[0-9]+/.exec(process.versions.v8)[0],
3534
environment = { ...process.env };
3635

3736
var patchLibPath = false, patchTool = null;
@@ -77,8 +76,10 @@ if (!{ia32: true, x64: true, arm: true}.hasOwnProperty(arch)) {
7776
process.exit(1);
7877
}
7978

80-
// Test for pre-built library
81-
var modPath = platform+ '-'+ arch+ '-v8-'+ v8;
79+
// Test for pre-built library. We do not use the v8 version in the target dir
80+
// as the v8 version we are running with currently may not be the same as that
81+
// we are building for.
82+
var modPath = platform + '-' + arch;
8283
var command = process.platform === 'win32' ? 'node-gyp.cmd' : 'node-gyp';
8384

8485
if (!force) {

install-deps.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/bin/sh
2+
3+
set -euf
4+
5+
apt-get update
6+
apt-get install -y --no-install-recommends \
7+
libcapnp-dev
8+

package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,20 @@
2121
"main": "src/node-capnp/capnp.js",
2222
"types": "src/node-capnp/capnp.d.ts",
2323
"scripts": {
24-
"install": "node ./build.js --dist-url=https://electronjs.org/headers --target=12.0.2",
25-
"test": "node src/node-capnp/capnp-test.js",
24+
"install": "node ./build.js --dist-url=https://electronjs.org/headers --target=20.0.0",
25+
"test": "electron src/node-capnp/capnp-test.js",
2626
"build:darwin": "npm run install -- --target_plat=darwin --patch_path=.libs"
2727
},
2828
"dependencies": {
29-
"nan": "^2.7.0"
29+
"nan": "^2.17.0"
30+
},
31+
"devDependencies": {
32+
"electron": "^20.0.0",
33+
"node-gyp": "^9.1.0"
3034
},
3135
"repository": {
3236
"type": "git",
33-
"url": "git://github.com/kentonv/node-capnp.git"
37+
"url": "git://github.com/fourieraudio/node-capnp.git"
3438
},
3539
"engines": {
3640
"node": ">=10.0"

src/node-capnp/capnp-test.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ try {
4242
goldenPackedFlatBinary = fs.readFileSync("src/node-capnp/testdata/packedflat");
4343
}
4444

45-
var test = require("./test.capnp");
46-
assert(test === capnp.import(__dirname + "/test.capnp"));
47-
assert(test === require("./test"));
45+
let test = capnp.importFile(__dirname + "/test.capnp");
4846

4947
assert("namespace" in capnp.importSystem("capnp/c++.capnp"));
5048

src/node-capnp/capnp.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ if (typeof CAPNP_NO_DYNAMIC_REQUIRE !== "undefined" && CAPNP_NO_DYNAMIC_REQUIRE)
2727
v8capnp = require("./capnp.node");
2828
} else {
2929
// Look for binary for this platform
30-
var v8 = "v8-"+ /[0-9]+\.[0-9]+/.exec(process.versions.v8)[0];
3130
var modPath = path.join(
32-
__dirname, "../../bin", process.platform+ "-" + process.arch + "-" + v8,
31+
__dirname, "../../bin", process.platform + "-" + process.arch,
3332
"capnp");
3433
try {
3534
fs.statSync(modPath + ".node");
@@ -38,9 +37,8 @@ if (typeof CAPNP_NO_DYNAMIC_REQUIRE !== "undefined" && CAPNP_NO_DYNAMIC_REQUIRE)
3837

3938
// Also try just "capnp.node". (Mainly for use when building with Ekam rather
4039
// than npm.)
41-
modPath = "./capnp.node";
4240
try {
43-
fs.statSync(path.join(__dirname, "capnp.node"));
41+
fs.statSync(modPath = path.join(__dirname, "capnp.node"));
4442
} catch (ex) {
4543
// Give up.
4644
throw new Error(

0 commit comments

Comments
 (0)