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

feat: support build options via npmrc #633

Merged
merged 9 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
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
Expand Up @@ -19,7 +19,7 @@
"script/*.js",
"script/*.d.ts",
"docs/",
"docs-raw/",
"doc-unminified/",
"test/unit/compat/",
"test/bench/"
]
Expand Down
48 changes: 21 additions & 27 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ jobs:
- x64
cpp_arch:
- x64
ARCH:
- x64
zmq_draft:
- false
docker:
- ""
docker_cmd:
Expand All @@ -34,31 +30,24 @@ jobs:
include:
- os: windows-2022
node_version: 18
node_arch: x86
ARCH: x86
node_arch: ia32
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
cpp_arch: x64
zmq_draft: false

- os: macos-14
node_version: 18
node_arch: arm64
ARCH: arm64
cpp_arch: amd64_arm64
zmq_draft: false

# Alpine
- os: ubuntu-22.04
Expand All @@ -69,14 +58,14 @@ jobs:
build.prebuild
node_version: 18
node_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.node_arch }}
npm_config_target_arch: ${{ matrix.node_arch }}
setup_node_arch: ${{ matrix.node_arch }}
steps:
- uses: actions/checkout@v4

Expand All @@ -87,11 +76,17 @@ jobs:
./node_modules/
./build/
key:
"cache-OS:${{ matrix.os }}-arch:${{ matrix.node_arch
}}-ZMQ_DRAFT:${{ matrix.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:${{ 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: 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 }}
Expand All @@ -112,21 +107,20 @@ 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.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 }}
Expand Down Expand Up @@ -155,7 +149,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:
Expand Down
16 changes: 5 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

6 changes: 1 addition & 5 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/docs/
/docs-raw
/doc-unminified
/lib
/prebuilds
/node_modules
Expand Down
15 changes: 14 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
84 changes: 73 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,88 @@ 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 [email protected] --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 [email protected] --zmq-shared
### Available Build Options

<details>
<summary>👉🏻 Options</summary>

#### 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`:

```ini
zmq_draft=false
```

If you wish to use any DRAFT sockets then it is also necessary to compile the
library from source:
#### Not Synchronous Resolve

```sh
npm install [email protected] --zmq-draft
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,
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"
target_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"
```

</details>

## Examples

**Note:** These examples assume the reader is familiar with ZeroMQ. If you are
Expand Down
29 changes: 12 additions & 17 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
}],
},

{
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Loading
Loading