Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build with node-gyp #10

Merged
merged 13 commits into from
Nov 28, 2020
11 changes: 8 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ jobs:
strategy:
fail-fast: false
matrix:
# windows-latest disabled by now, unable to build
os: [ubuntu-latest, macos-latest]
os: [ubuntu-latest, macos-latest, windows-latest]
node: [10, 11, 12, 13, 14]
steps:
- uses: actions/checkout@v2
Expand All @@ -57,6 +56,12 @@ jobs:
name: blst_wrap.cpp
path: prebuild/

# Solution from: https://github.com/nodejs/node-gyp/issues/1898#issuecomment-540864130
# Solution edit: https://github.com/nodejs/node-gyp/issues/119#issuecomment-331778053
- name: Install windows build tools
if: matrix.os == 'windows-latest' && matrix.node <= 11
run: yarn add windows-build-tools --ignore-scripts

- name: Install && Build TS + bindings
run: yarn bootstrap
- name: Test
Expand Down Expand Up @@ -93,7 +98,7 @@ jobs:
name: binding.node
path: prebuild/

- name: Install && Build TS + bindings
- name: Build .ts source for release
run: yarn bootstrap

- name: Create Github release with prebuilds
Expand Down
1 change: 1 addition & 0 deletions .mocharc.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
colors: true
require: ts-node/register
exit: true
2 changes: 1 addition & 1 deletion blst
Submodule blst updated 50 files
+38 −24 .github/workflows/ci.yml
+8 −14 .travis.yml
+1 −1 README.md
+45 −5 bindings/blst.h
+19 −7 bindings/go/assembly.S
+198 −124 bindings/go/blst.go
+30 −22 bindings/go/blst.tgo
+88 −45 bindings/go/blst_minpk.tgo
+114 −51 bindings/go/blst_minpk_test.go
+114 −51 bindings/go/blst_minsig_test.go
+2 −12 bindings/go/blst_px.tgo
+14 −2 bindings/node.js/binding.gyp
+1 −1 bindings/rust/Cargo.toml
+47 −18 bindings/rust/benches/blst_benches.rs
+31 −37 bindings/rust/build.rs
+67 −5 bindings/rust/src/bindings.rs
+245 −72 bindings/rust/src/lib.rs
+18 −6 build/assembly.S
+744 −0 build/coff/ct_inverse_mod_384-armv8.S
+1,271 −0 build/coff/ctq_inverse_mod_384-x86_64.s
+1,632 −0 build/coff/ctx_inverse_mod_384-x86_64.s
+732 −0 build/elf/ct_inverse_mod_384-armv8.S
+1,246 −0 build/elf/ctq_inverse_mod_384-x86_64.s
+1,611 −0 build/elf/ctx_inverse_mod_384-x86_64.s
+732 −0 build/mach-o/ct_inverse_mod_384-armv8.S
+1,238 −0 build/mach-o/ctq_inverse_mod_384-x86_64.s
+1,603 −0 build/mach-o/ctx_inverse_mod_384-x86_64.s
+6 −0 build/win64/blst.def
+733 −0 build/win64/ct_inverse_mod_384-armv8.asm
+1,274 −0 build/win64/ctq_inverse_mod_384-x86_64.asm
+1,633 −0 build/win64/ctx_inverse_mod_384-x86_64.asm
+116 −37 src/aggregate.c
+620 −0 src/asm/ct_inverse_mod_384-armv8.pl
+906 −0 src/asm/ctq_inverse_mod_384-x86_64.pl
+989 −0 src/asm/ctx_inverse_mod_384-x86_64.pl
+12 −3 src/asm/div3w-x86_64.pl
+15 −15 src/e1.c
+15 −15 src/e2.c
+5 −5 src/ec_mult.h
+8 −8 src/ec_ops.h
+18 −33 src/exp.c
+12 −25 src/exp2.c
+17 −17 src/exports.c
+108 −9 src/fields.h
+6 −8 src/fp12_tower.c
+17 −10 src/map_to_g1.c
+17 −10 src/map_to_g2.c
+344 −25 src/no_asm.h
+3 −3 src/point.h
+62 −31 src/vect.h
13 changes: 0 additions & 13 deletions build.node.sh

This file was deleted.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"typescript": "^4.0.3"
},
"dependencies": {
"node-fetch": "^2.6.1"
"node-fetch": "^2.6.1",
"node-gyp": "^7.1.2"
}
}
17 changes: 14 additions & 3 deletions src/scripts/buildBindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { exec } from "child_process";
import { testBindings } from "./testBindings";
import {
bindingsDirSrc,
bindingsSrc,
ensureDirFromFilepath,
prebuiltSwigSrc,
prebuiltSwigTarget,
blstWrapCppName,
findBindingsFile,
} from "./paths";
import { downloadReleaseAsset } from "./downloadReleaseAsset";

Expand All @@ -28,8 +28,15 @@ export async function buildBindings(binaryPath: string) {

// Use BLST run.me script to build libblst.a + blst.node
await new Promise((resolve, reject): void => {
const buildCmd =
process.platform === "darwin"
? // MacOS builds fail, use previous script run.me
//see tracking issue https://github.com/supranational/blst/pull/43#issuecomment-735180399
"./run.me"
: "node-gyp rebuild";

const proc = exec(
"./run.me",
buildCmd,
{
timeout: 3 * 60 * 1000, // ms
maxBuffer: 10e6, // bytes
Expand All @@ -44,9 +51,13 @@ export async function buildBindings(binaryPath: string) {
if (proc.stderr) proc.stderr.pipe(process.stderr);
});

// The output of node-gyp is not at a predictable path but various
// depending on the OS.
const bindingsFileOutput = findBindingsFile(bindingsDirSrc);

// Copy built .node file to expected path
ensureDirFromFilepath(binaryPath);
fs.copyFileSync(bindingsSrc, binaryPath);
fs.copyFileSync(bindingsFileOutput, binaryPath);

// Make sure downloaded bindings work
await testBindings(binaryPath);
Expand Down
43 changes: 42 additions & 1 deletion src/scripts/paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import fs from "fs";
import path from "path";

const rootDir = path.join(__dirname, "../..");
const bindingsName = "blst.node";

export const packageJsonPath = path.join(rootDir, "package.json");

export const bindingsDirSrc = path.join(rootDir, "blst/bindings/node.js");
export const blstWrapCppName = "blst_wrap.cpp";
export const prebuiltSwigSrc = path.join(rootDir, "prebuild", blstWrapCppName);
export const prebuiltSwigTarget = path.join(bindingsDirSrc, blstWrapCppName);
export const bindingsSrc = path.join(bindingsDirSrc, "blst.node");

export const defaultBinaryDir = path.join(rootDir, "prebuild");

Expand Down Expand Up @@ -47,6 +47,47 @@ export function ensureDirFromFilepath(filepath: string) {
}
}

/**
* The output of node-gyp is not at a predictable path but various
* depending on the OS.
* Paths based on https://github.com/TooTallNate/node-bindings/blob/c8033dcfc04c34397384e23f7399a30e6c13830d/bindings.js#L36
*/
export function findBindingsFile(dirpath: string): string {
const filepaths = [
// In dirpath
[dirpath, bindingsName],
// node-gyp's linked version in the "build" dir
[dirpath, "build", bindingsName],
// node-waf and gyp_addon (a.k.a node-gyp)
[dirpath, "build", "Debug", bindingsName],
[dirpath, "build", "Release", bindingsName],
// Debug files, for development (legacy behavior, remove for node v0.9)
[dirpath, "out", "Debug", bindingsName],
[dirpath, "Debug", bindingsName],
// Release files, but manually compiled (legacy behavior, remove for node v0.9)
[dirpath, "out", "Release", bindingsName],
[dirpath, "Release", bindingsName],
// Legacy from node-waf, node <= 0.4.x
[dirpath, "build", "default", bindingsName],
// Production "Release" buildtype binary (meh...)
[dirpath, "compiled", "version", "platform", "arch", bindingsName],
// node-qbs builds
[dirpath, "addon-build", "release", "install-root", bindingsName],
[dirpath, "addon-build", "debug", "install-root", bindingsName],
[dirpath, "addon-build", "default", "install-root", bindingsName],
// node-pre-gyp path ./lib/binding/{node_abi}-{platform}-{arch}
[dirpath, "lib", "binding", "nodePreGyp", bindingsName],
].map((pathParts) => path.join(...pathParts));

for (const filepath of filepaths) {
if (fs.existsSync(filepath)) {
return filepath;
}
}

throw Error(`Could not find bindings file. Tried:\n${filepaths.join("\n")}`);
}

export class NotNodeJsError extends Error {
constructor(missingItem: string) {
super(
Expand Down
Loading