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

Rewrite the build script #519

Merged
merged 10 commits into from
Nov 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -9,5 +9,5 @@
"rules": {
"@typescript-eslint/quotes": ["error", "double"]
},
"ignorePatterns": ["node_modules/", "build/", "lib/", "libzmq/", "tmp/", "zmq/"]
"ignorePatterns": ["node_modules/", "build/", "lib/", "libzmq/", "tmp/", "zmq/", "v5-compat.d.ts", "draft.d.ts"]
}
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -107,4 +107,4 @@ jobs:

- name: Lint
if: contains(matrix.os, 'ubuntu')
run: npm run lint
run: npm run lint-test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -11,3 +11,5 @@ lib/binary/napi-v*/*.node
build-tmp-napi-v*
prebuilds
test.js
.cache/
test/typings-compatibility/
15 changes: 12 additions & 3 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -16,9 +16,16 @@
["zmq_shared == 'false'", {
'actions': [{
'action_name': 'build_libzmq',
'inputs': ['package.json'],
'outputs': ['libzmq/lib'],
'action': ['sh', '<(PRODUCT_DIR)/../../script/build.sh', '<(CONFIGURATION_NAME)'],
'inputs': ['package.json', './script/build.ts'],
'conditions': [
['OS != "win"', {
'outputs': ['build/libzmq/lib/libzmq.a', 'build/libzmq/include/zmq.h', 'build/libzmq/include/zmq_utils.h'],
}],
['OS == "win"', {
'outputs': ['build/libzmq/lib/libzmq.lib', 'build/libzmq/include/zmq.h', 'build/libzmq/include/zmq_utils.h'],
}],
],
'action': ['ts-node', '<(PRODUCT_DIR)/../../script/build.ts'],
}],
}],
],
@@ -95,6 +102,7 @@
],
'conditions': [
['OS == "linux" or OS == "freebsd" or OS == "openbsd" or OS == "solaris"', {
# flag removal
'cflags_cc!': [
'-std=gnu++0x',
'-std=gnu++1y'
@@ -172,6 +180,7 @@
'defines': [
'NAPI_CPP_EXCEPTIONS',
],
# flag removal
'cflags_cc!': [
"-fno-exceptions",
],
27 changes: 18 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -17,14 +17,18 @@
"url": "https://github.com/zeromq/zeromq.js.git"
},
"dependencies": {
"node-gyp-build": "^4.5.0"
"@types/node": "^18.11.9",
"@types/shelljs": "^0.8.11",
"cross-env": "^7.0.3",
"node-gyp-build": "^4.5.0",
"shelljs": "^0.8.5",
"ts-node": "10.9"
},
"devDependencies": {
"@gnd/typedoc": "^0.15.0-0",
"@types/chai": ">=4.3",
"@types/fs-extra": "^9.0.13",
"@types/mocha": ">=10.0",
"@types/node": ">=18.11",
"@types/semver": ">=7",
"@types/weak-napi": "^2.0.1",
"benchmark": ">=2",
@@ -38,13 +42,14 @@
"mocha": ">=10.1",
"node-addon-api": "^5.0.0",
"node-fetch": "^3.3.0",
"node-gyp": "^9.3.0",
"npm-run-all2": "^6.0.4",
"prebuildify": "^5.0.1",
"prettier": "^2.7.1",
"semver": ">=7",
"shx": "^0.3.4",
"tar-fs": "^2.1.1",
"ts-morph": "^16.0.0",
"ts-node": ">=10",
"typescript": "4.8",
"weak-napi": "^2.0.2"
},
@@ -75,12 +80,16 @@
"build.js": "tsc --project tsconfig-build.json && node script/ci/downlevel-dts.js",
"build.doc": "typedoc --out docs --name zeromq.js --excludeProtected --excludePrivate --excludeNotExported --excludeExternals --externalPattern 'src/+(draft|native|compat).ts' --tsconfig tsconfig-build.json --mode file",
"prebuild": "ts-node -P ./tsconfig.json ./script/prebuild.ts",
"build.native": "prebuildify --napi --build-from-source",
"build.native.debug": "npm run build.native -- --debug",
"build": "npm run build.js && npm run build.native",
"build.debug": "npm run build.js && npm run build.native.debug",
"test": "npm run build.debug && mocha",
"lint": "sh script/lint.sh",
"build.native": "node-gyp configure --release && node-gyp build --release",
"build.native.debug": "cross-env CMAKE_BUILD_TYPE=Debug node-gyp configure --debug && cross-env CMAKE_BUILD_TYPE=Debug node-gyp build --debug",
"build": "run-p build.js build.native",
"build.debug": "run-p build.js build.native.debug",
"test": "run-s build.debug && mocha",
"lint.clang-format": "clang-format -i -style=file src/*.{cc,h} src/*/*.h",
"lint-test.eslint": "eslint **/*.{ts,tsx,js,jsx,cjs,mjs,json,yaml} --no-error-on-unmatched-pattern --cache --cache-location ./.cache/eslint/",
"lint.eslint": "run-s lint-test.eslint -- --fix",
"lint": "run-p lint.eslint lint.clang-format",
"lint-test": "run-s lint-test.eslint",
"bench": "node --expose-gc test/bench"
},
"keywords": [
589 changes: 544 additions & 45 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

80 changes: 0 additions & 80 deletions script/build.sh

This file was deleted.

88 changes: 88 additions & 0 deletions script/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import {dirname} from "path"
import {existsSync, writeFileSync} from "fs"
import {mkdir, cd, exec, find, mv} from "shelljs"

const root = dirname(__dirname)

function main() {
const zmq_version = process.env.ZMQ_VERSION ?? "4.3.4"
const src_url = `https://github.com/zeromq/libzmq/releases/download/v${zmq_version}/zeromq-${zmq_version}.tar.gz`

const libzmq_build_prefix = `${root}/build/libzmq-staging`
const libzmq_install_prefix = `${root}/build/libzmq`

const artifact = `${libzmq_build_prefix}/lib/libzmq.${
process.platform === "win32" ? ".lib" : ".a"
}`

const src_dir = `zeromq-${zmq_version}`
const tarball = `zeromq-${zmq_version}.tar.gz`

const CMAKE_BUILD_TYPE = process.env.CMAKE_BUILD_TYPE ?? "Release"

let build_options: string = ""

// https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html
if (process.platform === "win32") {
if (CMAKE_BUILD_TYPE !== "Debug") {
build_options += " -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL"
} else {
build_options += " -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL"
}
}

// Handle x86
if (process.arch === "ia32" || process.env.ARCH === "x86") {
build_options += " -DCMAKE_GENERATOR_PLATFORM=x86"
}

if (process.platform === "darwin") {
process.env.MACOSX_DEPLOYMENT_TARGET = "10.15"
}

mkdir("-p", libzmq_build_prefix)
cd(libzmq_build_prefix)

if (existsSync(artifact)) {
console.log("Found previously built libzmq; skipping rebuild...")
return
}

if (existsSync(tarball)) {
console.log("Found libzmq source; skipping download...")
} else {
console.log("Downloading libzmq source...")
exec(`curl "${src_url}" -fsSL -o "${tarball}"`)
}

if (!existsSync(src_dir)) {
exec(`tar xzf "${tarball}"`)
}

if (process.env.npm_config_zmq_draft === "true") {
console.log("Enabling draft support")
build_options += " -DENABLE_DRAFTS=ON"
}

console.log(`Building libzmq ${CMAKE_BUILD_TYPE}`)

// ClangFormat include causes issues but is not required to build.
const clang_format_file = `${src_dir}/builds/cmake/Modules/ClangFormat.cmake`
if (existsSync(clang_format_file)) {
writeFileSync(clang_format_file, "")
}

exec(
`cmake -S "${src_dir}" -B ./build ${build_options} -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX="${libzmq_install_prefix}" -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_STATIC=ON -DBUILD_TESTS=OFF -DBUILD_SHARED=OFF -DWITH_DOCS=OFF`,
)

exec(`cmake --build ./build --config ${CMAKE_BUILD_TYPE} --target install`)

if (process.platform === "win32") {
// rename libzmq-v143-mt-s-4_3_4.lib to libzmq.lib
const build_file = find(`${libzmq_install_prefix}/lib/*.lib`)[0]
mv(build_file, `${libzmq_install_prefix}/lib/libzmq.lib`)
}
}

main()
17 changes: 0 additions & 17 deletions script/lint.sh

This file was deleted.

2 changes: 1 addition & 1 deletion script/prebuild.ts
Original file line number Diff line number Diff line change
@@ -28,7 +28,7 @@ async function main() {
process.env.ZMQ_BUILD_OPTIONS = `--host=${TRIPLE}`
}

let prebuildScript = `prebuildify --napi --arch=${prebuildArch} -t 12.0.0 -t electron@9.4.4 --strip --tag-libc`
let prebuildScript = `prebuildify --napi --arch=${prebuildArch} --strip --tag-libc`

if (process.env.ALPINE_CHROOT) {
prebuildScript = `/alpine/enter-chroot ${prebuildScript}`
12 changes: 1 addition & 11 deletions test/unit/typings-compatibility-test.ts
Original file line number Diff line number Diff line change
@@ -21,18 +21,8 @@ import {assert} from "chai"

type TestDef = {version: string; minTarget: string; requiredLibs?: string[]}

// NOTE tsc version 2.9.x (and lower) will not work with current typings!
const tsVersions: TestDef[] = [
// typescript 3.0.x - 3.3.x:
// must either have a target that supports AsyncIterators,
// or include a typings library that supports AsyncIterator
// TODO might support older TypeScript

// typescript 3.4.x - 3.7.x:
// these include typings for AsyncIterator by default
{version: "3.4.x", minTarget: "es3"},
{version: "3.5.x", minTarget: "es3"},
{version: "3.6.x", minTarget: "es3"},
// the oldest supported version
{version: "3.7.x", minTarget: "es3"},

// 4.x
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
"exclude": ["*.d.ts"],
"compilerOptions": {
"allowJs": false,
"target": "ES2020",
"target": "es2020",
"outDir": "lib",
"declaration": true,
"module": "commonjs",