From e48f032a2e70e5ad2215c8eb89e1a1d226124382 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 18 Jun 2024 15:00:08 -0700 Subject: [PATCH 1/9] feat: support build options via npmrc --- .github/workflows/CI.yml | 37 +++++++---------- README.md | 72 +++++++++++++++++++++++++++----- binding.gyp | 29 ++++++------- script/build.ts | 88 ++++++++++++++++++++++++++++++---------- 4 files changed, 155 insertions(+), 71 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 4320d5f3..e7f63ddf 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -22,10 +22,8 @@ jobs: - x64 cpp_arch: - x64 - ARCH: + arch: - x64 - zmq_draft: - - false docker: - "" docker_cmd: @@ -35,30 +33,26 @@ jobs: - os: windows-2022 node_version: 18 node_arch: x86 - ARCH: x86 + arch: x86 cpp_arch: amd64_x86 - zmq_draft: false # - os: windows-2022 # node_version: 18 # node_arch: x64 - # ARCH: arm64 + # arch: arm64 # cpp_arch: amd64_arm64 - # zmq_draft: false - os: macos-13 node_version: 18 node_arch: x64 - ARCH: x86_64 + arch: x86_64 cpp_arch: x64 - zmq_draft: false - os: macos-14 node_version: 18 node_arch: arm64 - ARCH: arm64 + arch: arm64 cpp_arch: amd64_arm64 - zmq_draft: false # Alpine - os: ubuntu-22.04 @@ -69,14 +63,13 @@ jobs: build.prebuild node_version: 18 node_arch: x64 - ARCH: x64 + arch: x64 cpp_arch: x64 - zmq_draft: false env: - ZMQ_DRAFT: ${{ matrix.zmq_draft }} - ZMQ_SHARED: false - ARCH: ${{ matrix.ARCH }} + npm_config_zmq_draft: false + npm_config_zmq_shared: false + npm_config_arch: ${{ matrix.arch }} steps: - uses: actions/checkout@v4 @@ -88,10 +81,10 @@ jobs: ./build/ key: "cache-OS:${{ matrix.os }}-arch:${{ matrix.node_arch - }}-ZMQ_DRAFT:${{ matrix.zmq_draft }}-Node:${{ matrix.node_version - }}-${{ hashFiles('./package.json') }}" + }}-ZMQ_DRAFT:${{ env.npm_config_zmq_draft }}-Node:${{ + matrix.node_version }}-${{ hashFiles('./package.json') }}" restore-keys: | - "cache-OS:${{ matrix.os }}-arch:${{ matrix.node_arch }}-ZMQ_DRAFT:${{ matrix.zmq_draft }}-Node:${{ matrix.node_version }}-" + "cache-OS:${{ matrix.os }}-arch:${{ matrix.node_arch }}-ZMQ_DRAFT:${{ env.npm_config_zmq_draft }}-Node:${{ matrix.node_version }}-" - name: Setup Cpp if: ${{ !matrix.docker }} @@ -115,12 +108,12 @@ jobs: architecture: ${{ matrix.node_arch }} - name: Install Mac-OS x86_64 Dependencies - if: ${{ contains(matrix.os, 'macos') && matrix.ARCH == 'x86_64' }} + if: ${{ contains(matrix.os, 'macos') && matrix.arch == 'x86_64' }} run: | brew install libsodium gnutls - name: Install Mac-OS arm64 Dependencies - if: ${{ contains(matrix.os, 'macos') && matrix.ARCH == 'arm64' }} + if: ${{ contains(matrix.os, 'macos') && matrix.arch == 'arm64' }} run: | brew uninstall libsodium --force --ignore-dependencies source ./script/macos-arm-deps.sh @@ -155,7 +148,7 @@ jobs: if: "${{ contains(matrix.os, 'ubuntu') && !matrix.docker }}" run: pnpm run lint-test - - name: Test (Debug) + - name: Test if: ${{ !matrix.docker }} uses: nick-fields/retry@v3 with: diff --git a/README.md b/README.md index 024afce8..5a88d935 100644 --- a/README.md +++ b/README.md @@ -81,26 +81,76 @@ source: - CMake 2.8+ - curl -To install from source: +To install from source, specify `build_from_source=true` in a `.npmrc` file -```sh -npm install zeromq@6.0.0-beta.20 --build-from-source +``` +build_from_source=true ``` -If you want to link against a shared ZeroMQ library, you can build skip -downloading `libzmq` and link with the installed library instead as follows: +When building from source, you can also specify additional build options in a +`.npmrc` file in your project: -```sh -npm install zeromq@6.0.0-beta.20 --zmq-shared +
+Available Build Options + +#### Draft support + +By default `libzmq` is built with support for `Draft` patterns (e.g. +`server-client`, `radio-dish`, `scatter-gather`). If you want to build `libzmq` +without support for `Draft`, you can specify the following in `.npmrc`: + +``` +zmq_draft=false ``` -If you wish to use any DRAFT sockets then it is also necessary to compile the -library from source: +#### Shared library support -```sh -npm install zeromq@6.0.0-beta.20 --zmq-draft +If you want to link against a shared ZeroMQ library installed on your system, +you can build skip downloading `libzmq` and link with the installed library +instead by specifying the following in `.npmrc`: + +```ini +zmq_shared=true +``` + +#### Alternative libzmq version + +You can specify an alternative version or Git revision of `libzmq` to build +against by specifying the following in `.npmrc`: + +```ini +zmq_version="4.3.5" ``` +#### Debug build of libzmq + +If you want to build `libzmq` with debug symbols, you can specify the following +in `.npmrc`: + +```ini +zmq_build_type="Debug" +``` + +#### Cross-compilation for different architectures + +If you want to cross-compile for a different architecture, you can specify the +following in `.npmrc`: + +```ini +arch="arm64" +``` + +#### MacOS Deployment Target + +If you want to specify the MacOS deployment target, you can specify the +following in `.npmrc`: + +```ini +macos_deployment_target="10.15" +``` + +
+ ## Examples **Note:** These examples assume the reader is familiar with ZeroMQ. If you are diff --git a/binding.gyp b/binding.gyp index 9b979e20..868a3961 100644 --- a/binding.gyp +++ b/binding.gyp @@ -12,24 +12,19 @@ { 'target_name': 'libzmq', 'type': 'none', - - 'conditions': [ - ["zmq_shared == 'false'", { - 'actions': [{ - 'action_name': 'build_libzmq', - 'inputs': [], - 'conditions': [ - ['OS != "win"', { - 'outputs': ['<(module_root_dir)/build/libzmq/lib/libzmq.a', '<(module_root_dir)/build/libzmq/include/zmq.h', '<(module_root_dir)/build/libzmq/include/zmq_utils.h'], - }], - ['OS == "win"', { - 'outputs': ['<(module_root_dir)/build/libzmq/lib/libzmq.lib', '<(module_root_dir)/build/libzmq/include/zmq.h', '<(module_root_dir)/build/libzmq/include/zmq_utils.h'], - }], - ], - 'action': ['node', '<(module_root_dir)/script/build.js'], + 'actions': [{ + 'action_name': 'build_libzmq', + 'inputs': [], + 'conditions': [ + ['OS != "win"', { + 'outputs': ['<(module_root_dir)/build/libzmq/lib/libzmq.a', '<(module_root_dir)/build/libzmq/include/zmq.h', '<(module_root_dir)/build/libzmq/include/zmq_utils.h'], }], - }], - ], + ['OS == "win"', { + 'outputs': ['<(module_root_dir)/build/libzmq/lib/libzmq.lib', '<(module_root_dir)/build/libzmq/include/zmq.h', '<(module_root_dir)/build/libzmq/include/zmq_utils.h'], + }], + ], + 'action': ['node', '<(module_root_dir)/script/build.js'], + }], }, { diff --git a/script/build.ts b/script/build.ts index b342e18c..45b5a0a3 100644 --- a/script/build.ts +++ b/script/build.ts @@ -4,11 +4,62 @@ import {mkdir, cd, exec, find, mv} from "shelljs" const root = dirname(__dirname) +type Options = { + zmq_shared: boolean + zmq_version: string + zmq_draft: boolean + zmq_build_type: string + arch: string + macosx_deployment_target?: string +} + +function toBool(value: string | undefined): boolean | undefined { + switch (value) { + case "true": + case "1": + return true + case "false": + case "0": + return false + default: + return undefined + } +} + +function toString(value: string | undefined): string | undefined { + switch (value) { + case undefined: + case "": + return undefined + default: + return value + } +} + +function parseOptions(): Options { + return { + zmq_shared: toBool(process.env.npm_config_zmq_shared) ?? false, + zmq_draft: toBool(process.env.npm_config_zmq_draft) ?? false, + zmq_version: + toString(process.env.npm_config_zmq_version) ?? + "5657b4586f24ec433930e8ece02ddba7afcf0fe0", + zmq_build_type: + toString(process.env.npm_config_zmq_build_type) ?? "Release", + arch: toString(process.env.npm_config_arch) ?? process.arch, + macosx_deployment_target: + toString(process.env.npm_config_macosx_deployment_target) ?? "10.15", + } +} + function main() { - const zmq_rev = - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions - process.env.ZMQ_VERSION || "5657b4586f24ec433930e8ece02ddba7afcf0fe0" - const src_url = `https://github.com/zeromq/libzmq/archive/${zmq_rev}.tar.gz` + const opts = parseOptions() + console.log("Building libzmq with options ", opts) + + if (opts.zmq_shared) { + return + } + + const src_url = `https://github.com/zeromq/libzmq/archive/${opts.zmq_version}.tar.gz` const libzmq_build_prefix = `${root}/build/libzmq-staging` const libzmq_install_prefix = `${root}/build/libzmq` @@ -17,29 +68,25 @@ function main() { process.platform === "win32" ? ".lib" : ".a" }` - const src_dir = `libzmq-${zmq_rev}` - const tarball = `libzmq-${zmq_rev}.tar.gz` - - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions - const CMAKE_BUILD_TYPE = process.env.CMAKE_BUILD_TYPE || "Release" + const src_dir = `libzmq-${opts.zmq_version}` + const tarball = `libzmq-${opts.zmq_version}.tar.gz` 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") { + if (opts.zmq_build_type !== "Debug") { build_options += " -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL" } else { build_options += " -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL" } } - build_options += archCMakeOptions() + build_options += archCMakeOptions(opts) if (process.platform === "darwin") { - const MACOSX_DEPLOYMENT_TARGET = "10.15" - process.env.MACOSX_DEPLOYMENT_TARGET = MACOSX_DEPLOYMENT_TARGET - build_options += ` -DCMAKE_OSX_DEPLOYMENT_TARGET=${MACOSX_DEPLOYMENT_TARGET}` + process.env.MACOSX_DEPLOYMENT_TARGET = opts.macosx_deployment_target + build_options += ` -DCMAKE_OSX_DEPLOYMENT_TARGET=${opts.macosx_deployment_target}` } mkdir("-p", libzmq_build_prefix) @@ -65,12 +112,12 @@ function main() { exec(`tar xzf "${tarball}"`, execOptions) } - if (process.env.ZMQ_DRAFT === "true") { + if (opts.zmq_draft) { console.log("Enabling draft support") build_options += " -DENABLE_DRAFTS=ON" } - console.log(`Building libzmq ${CMAKE_BUILD_TYPE}`) + console.log(`Building libzmq ${opts.zmq_build_type}`) // ClangFormat include causes issues but is not required to build. const clang_format_file = `${src_dir}/builds/cmake/Modules/ClangFormat.cmake` @@ -78,11 +125,11 @@ function main() { writeFileSync(clang_format_file, "") } - const cmake_configure = `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 -DWITH_LIBSODIUM=OFF` + const cmake_configure = `cmake -S "${src_dir}" -B ./build ${build_options} -DCMAKE_BUILD_TYPE=${opts.zmq_build_type} -DCMAKE_INSTALL_PREFIX="${libzmq_install_prefix}" -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_STATIC=ON -DBUILD_TESTS=OFF -DBUILD_SHARED=OFF -DWITH_DOCS=OFF -DWITH_LIBSODIUM=OFF` console.log(cmake_configure) exec(cmake_configure, execOptions) - const cmake_build = `cmake --build ./build --config ${CMAKE_BUILD_TYPE} --target install --parallel` + const cmake_build = `cmake --build ./build --config ${opts.zmq_build_type} --target install --parallel` console.log(cmake_build) exec(cmake_build, execOptions) @@ -95,9 +142,8 @@ function main() { main() -function archCMakeOptions() { - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions - const arch = (process.env.ARCH || process.arch).toLowerCase() +function archCMakeOptions(opts: Options) { + const arch = opts.arch.toLowerCase() if (process.platform === "win32") { // CMAKE_GENERATOR_PLATFORM only supported on Windows From 6f5715ad3458316e7c2437ab81f10ff0fe2d2eaa Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 18 Jun 2024 21:59:12 -0700 Subject: [PATCH 2/9] chore: use default pnpm options --- .npmrc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.npmrc b/.npmrc index 83a8ac89..7cd35e4d 100644 --- a/.npmrc +++ b/.npmrc @@ -1,6 +1,2 @@ -public-hoist-pattern[]=* -package-lock=false -lockfile=true -prefer-frozen-lockfile=false -strict-peer-dependencies=false +# Zmq settings build-from-source=true From 2a1ffb9d57b906299cc07ec4cc45c5d697d63220 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 18 Jun 2024 22:19:49 -0700 Subject: [PATCH 3/9] build: parse the prebuild arch via npmrc --- script/prebuild.mts | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/script/prebuild.mts b/script/prebuild.mts index d7dd86bb..aa74ce5b 100644 --- a/script/prebuild.mts +++ b/script/prebuild.mts @@ -1,10 +1,33 @@ import {execaCommandSync} from "execa" +type Options = { + arch: string +} + +function toString(value: string | undefined): string | undefined { + switch (value) { + case undefined: + case "": + return undefined + default: + return value + } +} + +function parserOptions(): Options { + return { + arch: toString(process.env.npm_config_arch) ?? process.arch, + } +} + async function main() { - console.log("Building distribution binary...") + const opts = parserOptions() + + console.log("Building distribution binary with options ", opts) - const prebuildArch = getNodearch() + const prebuildArch = getNodearch(opts) + // TODO test the triple feature if (typeof process.env.TRIPLE === "string") { const TRIPLE = process.env.TRIPLE @@ -45,10 +68,8 @@ main().catch(e => { throw e }) -function getNodearch(): string { - // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions - const arch = process.env.ARCH || process.arch - switch (arch) { +function getNodearch(opts: Options): string { + switch (opts.arch) { case "x86": { return "ia32" } @@ -56,7 +77,7 @@ function getNodearch(): string { return "x64" } default: { - return arch + return opts.arch } } } From 50ee02d3a282213201b5795e1c7ffa10dc2607b0 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 18 Jun 2024 22:34:01 -0700 Subject: [PATCH 4/9] build: set the arch env variables for prebuild --- script/prebuild.mts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/script/prebuild.mts b/script/prebuild.mts index aa74ce5b..498bba7f 100644 --- a/script/prebuild.mts +++ b/script/prebuild.mts @@ -27,6 +27,11 @@ async function main() { const prebuildArch = getNodearch(opts) + process.env.ARCH = prebuildArch + process.env.npm_config_arch = prebuildArch + process.env.npm_config_target_arch = prebuildArch + process.env.PREBUILD_arch = prebuildArch + // TODO test the triple feature if (typeof process.env.TRIPLE === "string") { const TRIPLE = process.env.TRIPLE @@ -38,10 +43,6 @@ async function main() { const STRIP = `${TRIPLE}-strip` process.env.PREBUILD_STRIP_BIN = STRIP - process.env.npm_config_arch = prebuildArch - process.env.npm_config_target_arch = prebuildArch - process.env.PREBUILD_arch = prebuildArch - process.env.ZMQ_BUILD_OPTIONS = `--host=${TRIPLE}` } @@ -57,6 +58,7 @@ async function main() { } execaCommandSync(prebuildScript, { + env: process.env, shell: true, windowsHide: true, stdio: "inherit", From 6b2cb3ed21d2f1389f8f8b038ce94ccb382908a2 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 18 Jun 2024 23:18:49 -0700 Subject: [PATCH 5/9] build: refactor build option parser --- .eslintrc | 2 +- .gitignore | 16 +++++----------- .idea/.gitignore | 8 -------- .prettierignore | 2 +- .vscode/settings.json | 15 ++++++++++++++- README.md | 15 +++++++++++++-- package.json | 6 +++--- script/build.ts | 24 +----------------------- script/prebuild.mts | 12 ++---------- script/tsconfig.esm.json | 2 +- script/tsconfig.json | 12 +++++++++--- script/utils.ts | 25 +++++++++++++++++++++++++ tsconfig.docs.json | 1 + tsconfig.json | 1 + typedoc.json | 2 +- 15 files changed, 78 insertions(+), 65 deletions(-) delete mode 100644 .idea/.gitignore create mode 100644 script/utils.ts diff --git a/.eslintrc b/.eslintrc index 11651495..cea2e6c9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -19,7 +19,7 @@ "script/*.js", "script/*.d.ts", "docs/", - "docs-raw/", + "doc-unminified/", "test/unit/compat/", "test/bench/" ] diff --git a/.gitignore b/.gitignore index f369c2cc..fbd8dd1e 100644 --- a/.gitignore +++ b/.gitignore @@ -13,18 +13,12 @@ build-tmp-napi-v* test.js .cache/ test/typings-compatibility/ -/script/*.js -/script/*.mjs +/script/*js /script/*.d.ts -/script/*.d.mts -/script/*.js.map -/script/*.mjs.map -/script/*/*.js -/script/*/*.mjs -/script/*/*.d.ts -/script/*/*.js.map +/script/*.d.*ts +/script/*js.map tsconfig.tsbuildinfo -tsconfig.esm.tsbuildinfo -/docs-raw +tsconfig.*.tsbuildinfo +/doc-unminified .DS_Store .idea diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 73f69e09..00000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml -# Editor-based HTTP Client requests -/httpRequests/ diff --git a/.prettierignore b/.prettierignore index d1955fc5..41b46290 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,5 @@ /docs/ -/docs-raw +/doc-unminified /lib /prebuilds /node_modules diff --git a/.vscode/settings.json b/.vscode/settings.json index 989bd09a..a7849c88 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,18 @@ "mochaExplorer.nodeArgv": [ "--expose-gc" ], - "mochaExplorer.debuggerConfig": "JS-Attach" + "mochaExplorer.debuggerConfig": "JS-Attach", + "files.exclude": { + "**/.git": true, + "**/.DS_Store": true, + "**/Thumbs.db": true, + "**/.cache": true, + "**/script/*.js": true, + "**/script/*.mjs": true, + "**/script/*.js.map": true, + "**/script/*.mjs.map": true, + "**/script/*.d.ts": true, + "**/script/*.d.mts": true, + "**/script/*.tsbuildinfo": true, + } } diff --git a/README.md b/README.md index 5a88d935..e12af796 100644 --- a/README.md +++ b/README.md @@ -90,8 +90,10 @@ build_from_source=true When building from source, you can also specify additional build options in a `.npmrc` file in your project: +### Available Build Options +
-Available Build Options +👉🏻 Options #### Draft support @@ -99,10 +101,19 @@ By default `libzmq` is built with support for `Draft` patterns (e.g. `server-client`, `radio-dish`, `scatter-gather`). If you want to build `libzmq` without support for `Draft`, you can specify the following in `.npmrc`: -``` +```ini zmq_draft=false ``` +#### Not Synchronous Resolve + +If you want to send/receive on the socket immediately, you can specify the +following in `.npmrc`: + +```ini +zmq_no_sync_resolve="true" +``` + #### Shared library support If you want to link against a shared ZeroMQ library installed on your system, diff --git a/package.json b/package.json index 224e7fa9..b8e914d0 100644 --- a/package.json +++ b/package.json @@ -83,13 +83,13 @@ ], "scripts": { "install": "(npm run build.js || echo ok) && aminya-node-gyp-build --build-from-source", - "clean": "shx rm -rf ./build ./lib/ ./prebuilds ./script/*.js ./script/*.js.map ./script/*.d.ts ./script/*.tsbuildinfo", + "clean": "shx rm -rf ./build ./lib/ ./prebuilds ./script/*.js ./script/*.mjs ./script/*.js.map ./script/*.mjs.map ./script/*.d.ts ./script/*.d.mts ./script/*.cjs ./scripts/*.cjs.map ./scripts/*.d.cts ./script/*.tsbuildinfo", "clean.release": "shx rm -rf ./build/Release", "clean.temp": "shx rm -rf ./tmp && shx mkdir -p ./tmp", "build.library": "tsc -p ./src/tsconfig.json", - "build.script": "tsc -p ./script/tsconfig.json && tsc -p ./script/tsconfig.esm.json", + "build.script": "tsc -p ./script/tsconfig.esm.json && tsc -p ./script/tsconfig.json", "build.js": "run-p build.script build.library", - "build.doc": "typedoc --options ./typedoc.json && minify-all -s docs-raw -d docs --jsCompressor terser", + "build.doc": "typedoc --options ./typedoc.json && minify-all -s docs-unminified -d docs --jsCompressor terser && shx rm -rf docs-unminified", "deploy.doc": "run-s build.doc && gh-pages --dist \"./docs\"", "build.prebuild": "run-s build.js && node ./script/prebuild.mjs", "build.native": "node-gyp configure --release && node-gyp configure --release -- -f compile_commands_json && node-gyp build --release", diff --git a/script/build.ts b/script/build.ts index 45b5a0a3..73319d66 100644 --- a/script/build.ts +++ b/script/build.ts @@ -1,6 +1,7 @@ import {dirname} from "path" import {existsSync, writeFileSync} from "fs" import {mkdir, cd, exec, find, mv} from "shelljs" +import {toBool, toString} from "./utils.js" const root = dirname(__dirname) @@ -13,29 +14,6 @@ type Options = { macosx_deployment_target?: string } -function toBool(value: string | undefined): boolean | undefined { - switch (value) { - case "true": - case "1": - return true - case "false": - case "0": - return false - default: - return undefined - } -} - -function toString(value: string | undefined): string | undefined { - switch (value) { - case undefined: - case "": - return undefined - default: - return value - } -} - function parseOptions(): Options { return { zmq_shared: toBool(process.env.npm_config_zmq_shared) ?? false, diff --git a/script/prebuild.mts b/script/prebuild.mts index 498bba7f..99a5076d 100644 --- a/script/prebuild.mts +++ b/script/prebuild.mts @@ -1,19 +1,11 @@ import {execaCommandSync} from "execa" +import * as buildUtils from "./utils.js" +const {toString} = buildUtils type Options = { arch: string } -function toString(value: string | undefined): string | undefined { - switch (value) { - case undefined: - case "": - return undefined - default: - return value - } -} - function parserOptions(): Options { return { arch: toString(process.env.npm_config_arch) ?? process.arch, diff --git a/script/tsconfig.esm.json b/script/tsconfig.esm.json index 9789fa80..b0034fab 100644 --- a/script/tsconfig.esm.json +++ b/script/tsconfig.esm.json @@ -5,5 +5,5 @@ "moduleResolution": "node" }, "include": ["./**/*.mts"], - "exclude": [] + "exclude": ["./**/*.d.mts"] } diff --git a/script/tsconfig.json b/script/tsconfig.json index 35018299..7b200ed4 100644 --- a/script/tsconfig.json +++ b/script/tsconfig.json @@ -1,8 +1,14 @@ { "extends": "../tsconfig.json", "compilerOptions": { - "outDir": "./" + "outDir": "./", }, - "include": ["./**/*.ts"], - "exclude": [] + "include": [ + "./**/*.ts", + "./**/*.cts" + ], + "exclude": [ + "./**/*.d.ts", + "./**/*.d.cts" + ] } diff --git a/script/utils.ts b/script/utils.ts new file mode 100644 index 00000000..72f9fb48 --- /dev/null +++ b/script/utils.ts @@ -0,0 +1,25 @@ +export function toBool(value: string | undefined): boolean | undefined { + switch (value) { + case "true": + case "1": + return true + case "false": + case "0": + return false + case undefined: + case "": + return undefined + default: + throw new Error(`Invalid boolean value: ${value}`) + } +} + +export function toString(value: string | undefined): string | undefined { + switch (value) { + case undefined: + case "": + return undefined + default: + return value + } +} diff --git a/tsconfig.docs.json b/tsconfig.docs.json index 2fd3c814..e6397746 100644 --- a/tsconfig.docs.json +++ b/tsconfig.docs.json @@ -9,6 +9,7 @@ "exclude": [ "script/**/*", "test/**/*", + "build/**/*", "examples/**/*", "src/errors.ts", "src/util.ts" diff --git a/tsconfig.json b/tsconfig.json index ca487d00..bd1d7379 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -5,6 +5,7 @@ "target": "es2020", "declaration": true, "module": "commonjs", + "moduleResolution": "node", "types": [ "node", "mocha" diff --git a/typedoc.json b/typedoc.json index 16277d4d..195d096c 100644 --- a/typedoc.json +++ b/typedoc.json @@ -3,7 +3,7 @@ "name": "zeromq.js", "entryPoints": ["./src/index.ts"], "tsconfig": "./tsconfig.docs.json", - "out": "docs-raw", + "out": "docs-unminified", "excludePrivate": true, "excludeExternals": false, "exclude": [ From fffbdd21883610373bc41ed78f6b5f2de9db2c38 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Tue, 18 Jun 2024 23:29:50 -0700 Subject: [PATCH 6/9] ci: specify ARCH env variable --- .github/workflows/CI.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index e7f63ddf..1e844282 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -70,6 +70,7 @@ jobs: npm_config_zmq_draft: false npm_config_zmq_shared: false npm_config_arch: ${{ matrix.arch }} + ARCH: ${{ matrix.arch }} steps: - uses: actions/checkout@v4 From b3b7895cf2d88a8815843e3c30f5f8b021026003 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 19 Jun 2024 16:09:58 -0700 Subject: [PATCH 7/9] ci: specify the target arch config env variable --- .github/workflows/CI.yml | 2 +- README.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 1e844282..c4b9bd11 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -70,7 +70,7 @@ jobs: npm_config_zmq_draft: false npm_config_zmq_shared: false npm_config_arch: ${{ matrix.arch }} - ARCH: ${{ matrix.arch }} + npm_config_target_arch: ${{ matrix.arch }} steps: - uses: actions/checkout@v4 diff --git a/README.md b/README.md index e12af796..8f9e8169 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,7 @@ following in `.npmrc`: ```ini arch="arm64" +target_arch="arm64" ``` #### MacOS Deployment Target From 729e0d2231c742f5529630a172aba59517deefe7 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 19 Jun 2024 16:18:53 -0700 Subject: [PATCH 8/9] ci: use node arch for npm_config_arch values --- .github/workflows/CI.yml | 22 +++++++--------------- script/macos-arm-deps.sh | 1 - 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index c4b9bd11..b6e7698e 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -22,8 +22,6 @@ jobs: - x64 cpp_arch: - x64 - arch: - - x64 docker: - "" docker_cmd: @@ -32,8 +30,7 @@ jobs: include: - os: windows-2022 node_version: 18 - node_arch: x86 - arch: x86 + node_arch: ia32 cpp_arch: amd64_x86 # - os: windows-2022 @@ -45,13 +42,11 @@ jobs: - os: macos-13 node_version: 18 node_arch: x64 - arch: x86_64 cpp_arch: x64 - os: macos-14 node_version: 18 node_arch: arm64 - arch: arm64 cpp_arch: amd64_arm64 # Alpine @@ -63,14 +58,13 @@ jobs: build.prebuild node_version: 18 node_arch: x64 - arch: x64 cpp_arch: x64 env: npm_config_zmq_draft: false npm_config_zmq_shared: false - npm_config_arch: ${{ matrix.arch }} - npm_config_target_arch: ${{ matrix.arch }} + npm_config_arch: ${{ matrix.node_arch }} + npm_config_target_arch: ${{ matrix.node_arch }} steps: - uses: actions/checkout@v4 @@ -81,9 +75,8 @@ jobs: ./node_modules/ ./build/ key: - "cache-OS:${{ matrix.os }}-arch:${{ matrix.node_arch - }}-ZMQ_DRAFT:${{ env.npm_config_zmq_draft }}-Node:${{ - matrix.node_version }}-${{ hashFiles('./package.json') }}" + # prettier-ignore + "cache-OS:${{ matrix.os }}-arch:${{ matrix.node_arch}}-ZMQ_DRAFT:${{env.npm_config_zmq_draft }}-Node:${{ matrix.node_version}}-${{hashFiles('./package.json') }}" restore-keys: | "cache-OS:${{ matrix.os }}-arch:${{ matrix.node_arch }}-ZMQ_DRAFT:${{ env.npm_config_zmq_draft }}-Node:${{ matrix.node_version }}-" @@ -109,18 +102,17 @@ jobs: architecture: ${{ matrix.node_arch }} - name: Install Mac-OS x86_64 Dependencies - if: ${{ contains(matrix.os, 'macos') && matrix.arch == 'x86_64' }} + if: ${{ contains(matrix.os, 'macos') && matrix.node_arch == 'x64' }} run: | brew install libsodium gnutls - name: Install Mac-OS arm64 Dependencies - if: ${{ contains(matrix.os, 'macos') && matrix.arch == 'arm64' }} + if: ${{ contains(matrix.os, 'macos') && matrix.node_arch == 'arm64' }} run: | brew uninstall libsodium --force --ignore-dependencies source ./script/macos-arm-deps.sh echo "PATH=$PATH" >> $GITHUB_ENV echo "PKG_CONFIG_PATH=$PKG_CONFIG_PATH" >> $GITHUB_ENV - echo "npm_config_target_arch=$npm_config_target_arch" >> $GITHUB_ENV - name: Install Dependencies and Build if: ${{ !matrix.docker }} diff --git a/script/macos-arm-deps.sh b/script/macos-arm-deps.sh index 2c70cdeb..a676df0a 100755 --- a/script/macos-arm-deps.sh +++ b/script/macos-arm-deps.sh @@ -44,4 +44,3 @@ export PATH="$HOME/arm-target/lib/:$PATH" SODIUM_PATH=$(~/arm-target/bin/pkg-config libsodium --libs-only-L | sed -e 's/-L//g') # print only -L and replace "-L" itself export PATH="$SODIUM_PATH:$PATH" export PKG_CONFIG_PATH="$SODIUM_PATH:$PKG_CONFIG_PATH" -export npm_config_target_arch=arm64 From 01e4fe979137b7c92066cc133304a2ff4ec65f4b Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Wed, 19 Jun 2024 16:48:25 -0700 Subject: [PATCH 9/9] ci: fix the the setup_node_arch --- .github/workflows/CI.yml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index b6e7698e..7c494919 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -65,6 +65,7 @@ jobs: npm_config_zmq_shared: false npm_config_arch: ${{ matrix.node_arch }} npm_config_target_arch: ${{ matrix.node_arch }} + setup_node_arch: ${{ matrix.node_arch }} steps: - uses: actions/checkout@v4 @@ -80,6 +81,13 @@ jobs: restore-keys: | "cache-OS:${{ matrix.os }}-arch:${{ matrix.node_arch }}-ZMQ_DRAFT:${{ env.npm_config_zmq_draft }}-Node:${{ matrix.node_version }}-" + - name: Env map + run: | + if [ "${{ matrix.node_arch }}" = "ia32" ]; then + echo "setup_node_arch=x86" > $GITHUB_ENV + fi + shell: bash + - name: Setup Cpp if: ${{ !matrix.docker }} uses: aminya/setup-cpp@v1 @@ -99,7 +107,7 @@ jobs: uses: actions/setup-node@v4 with: node-version: ${{ matrix.node_version }} - architecture: ${{ matrix.node_arch }} + architecture: ${{ env.setup_node_arch }} - name: Install Mac-OS x86_64 Dependencies if: ${{ contains(matrix.os, 'macos') && matrix.node_arch == 'x64' }}