Skip to content

Commit 5b0a4ef

Browse files
committed
feat: add CMake/npm options for Curve, Draft, Sodium, Websockets
1 parent 6c63384 commit 5b0a4ef

File tree

3 files changed

+176
-48
lines changed

3 files changed

+176
-48
lines changed

CMakeLists.txt

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
11
cmake_minimum_required(VERSION 3.16)
22

3-
include(FetchContent)
4-
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
5-
cmake_policy(SET CMP0135 NEW)
3+
macro(set_option_from_env OPTION_NAME)
4+
string(TOLOWER ${OPTION_NAME} OPTION_NAME_LOWER)
5+
if(DEFINED ENV{npm_config_${OPTION_NAME_LOWER}})
6+
if("$ENV{npm_config_${OPTION_NAME_LOWER}}" STREQUAL "true")
7+
set("${OPTION_NAME}"
8+
ON
9+
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
10+
elseif("$ENV{npm_config_${OPTION_NAME_LOWER}}" STREQUAL "false")
11+
set("${OPTION_NAME}"
12+
OFF
13+
CACHE BOOL "npm_config_${OPTION_NAME_LOWER}")
14+
else()
15+
set("${OPTION_NAME}"
16+
"$ENV{npm_config_${OPTION_NAME_LOWER}}"
17+
CACHE STRING "npm_config_${OPTION_NAME_LOWER}")
18+
endif()
19+
endif()
20+
if(${OPTION_NAME})
21+
string(REPLACE "zmq_" "" OPTION_NAME_LOWER "${OPTION_NAME_LOWER}")
22+
string(REPLACE "_" "-" OPTION_NAME_LOWER "${OPTION_NAME_LOWER}")
23+
list(APPEND VCPKG_MANIFEST_FEATURES ${OPTION_NAME_LOWER})
24+
endif()
25+
message(STATUS "${OPTION_NAME}: ${${OPTION_NAME}}")
26+
endmacro()
27+
28+
option(ZMQ_DRAFT "Build and install draft APIs" OFF)
29+
set_option_from_env(ZMQ_DRAFT)
30+
31+
option(ZMQ_CURVE "Enable CURVE security" OFF)
32+
set_option_from_env(ZMQ_CURVE)
33+
34+
option(ZMQ_SODIUM "Using libsodium for CURVE security" OFF)
35+
set_option_from_env(ZMQ_SODIUM)
36+
37+
option(ZMQ_WEBSOCKETS "Enable WebSocket transport" OFF)
38+
set_option_from_env(ZMQ_WEBSOCKETS)
39+
40+
option(ZMQ_WEBSOCKETS_SECURE "Enable WebSocket transport with TSL (wss)" OFF)
41+
set_option_from_env(ZMQ_WEBSOCKETS_SECURE)
42+
43+
option(ZMQ_NO_SYNC_RESOLVE "send/receive on the socket immediately" OFF)
44+
set_option_from_env(ZMQ_NO_SYNC_RESOLVE)
45+
46+
if(APPLE)
47+
option(MACOSX_DEPLOYMENT_TARGET "MacOS deployment target" "10.15")
48+
set_option_from_env(MACOSX_DEPLOYMENT_TARGET)
649
endif()
750

51+
# MacOS deployment target
852
if(WIN32)
953
if("${PLATFORM}" STREQUAL "x86")
1054
set(CMAKE_SYSTEM_PROCESSOR "x86")
@@ -19,6 +63,11 @@ if(WIN32)
1963
set(CMAKE_TOOLCHAIN_FILE ";")
2064
endif()
2165

66+
include(FetchContent)
67+
if(CMAKE_VERSION VERSION_GREATER_EQUAL "3.24.0")
68+
cmake_policy(SET CMP0135 NEW)
69+
endif()
70+
2271
# Add project_options from https://github.com/aminya/project_options Change the
2372
# version in the following URL to update the package (watch the releases of the
2473
# repository for future updates)
@@ -60,6 +109,13 @@ add_library(
60109

61110
target_link_libraries(addon PRIVATE project_options project_warnings)
62111

112+
if(ZMQ_DRAFT)
113+
target_compile_definitions(addon PRIVATE ZMQ_BUILD_DRAFT_API)
114+
endif()
115+
if(ZMQ_NO_SYNC_RESOLVE)
116+
target_compile_definitions(addon PRIVATE ZMQ_NO_SYNC_RESOLVE)
117+
endif()
118+
63119
# ZeroMQ
64120
find_package(ZeroMQ CONFIG REQUIRED)
65121
target_link_system_libraries(addon PRIVATE libzmq libzmq-static)

README.md

Lines changed: 58 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,39 @@
2222

2323
## Table of contents
2424

25-
- [Installation](#installation)
26-
- [Prebuilt binaries](#prebuilt-binaries)
27-
- [Building from source](#building-from-source)
28-
- [Examples](#examples)
29-
- [Push/Pull](#pushpull)
30-
- [Pub/Sub](#pubsub)
31-
- [Req/Rep](#reqrep)
25+
- [ZeroMQ.js Next Generation](#zeromqjs-next-generation)
26+
- [Useful links](#useful-links)
27+
- [Table of contents](#table-of-contents)
28+
- [Installation](#installation)
29+
- [Prebuilt binaries](#prebuilt-binaries)
30+
- [Building from source](#building-from-source)
31+
- [Available Build Options](#available-build-options)
32+
- [Curve support](#curve-support)
33+
- [Libsodium for Curve](#libsodium-for-curve)
34+
- [Draft support](#draft-support)
35+
- [Websocket support](#websocket-support)
36+
- [Secure Websocket support](#secure-websocket-support)
37+
- [Not Synchronous Resolve](#not-synchronous-resolve)
38+
- [MacOS Deployment Target](#macos-deployment-target)
39+
- [Examples](#examples)
40+
- [Basic Usage](#basic-usage)
41+
- [Push/Pull](#pushpull)
42+
- [`producer.js`](#producerjs)
43+
- [`worker.js`](#workerjs)
44+
- [Pub/Sub](#pubsub)
45+
- [`publisher.js`](#publisherjs)
46+
- [`subscriber.js`](#subscriberjs)
47+
- [Req/Rep](#reqrep)
48+
- [`client.js`](#clientjs)
49+
- [`server.js`](#serverjs)
50+
- [Zeromq 4 and 5 Compatibility layer](#zeromq-4-and-5-compatibility-layer)
3251
- [TypeScript](#typescript)
33-
- [More examples](#more-examples)
34-
- [Compatibility layer for version 4/5](#compatibility-layer-for-version-45)
35-
- [Contribution](#contribution)
36-
- [History](#history)
52+
- [Contribution](#contribution)
53+
- [Dependencies](#dependencies)
54+
- [Defining new options](#defining-new-options)
55+
- [Testing](#testing)
56+
- [Publishing](#publishing)
57+
- [History](#history)
3758

3859
## Installation
3960

@@ -76,9 +97,9 @@ during build, you can build this package from source.
7697
Make sure you have the following installed before attempting to build from
7798
source:
7899

79-
- Node.js 10+ or Electron 3+
100+
- Node.js 12+ or Electron
80101
- A working C++17 compiler toolchain with make
81-
- Python 3 with Node 12.13+ (or legacy Python 2.7)
102+
- Python 3 with Node 12+ (or legacy Python 2.7)
82103
- CMake 2.8+
83104
- curl
84105

@@ -96,67 +117,62 @@ When building from source, you can also specify additional build options in a
96117
<details>
97118
<summary>👉🏻 Options</summary>
98119

99-
#### Draft support
120+
### Curve support
100121

101-
By default `libzmq` is built with support for `Draft` patterns (e.g.
102-
`server-client`, `radio-dish`, `scatter-gather`). If you want to build `libzmq`
103-
without support for `Draft`, you can specify the following in `.npmrc`:
122+
Enables CURVE security for encrypted communications. To enable CURVE support, add the following to your .npmrc:
104123

105124
```ini
106-
zmq_draft=false
125+
zmq_curve="true"
107126
```
108127

109-
#### Not Synchronous Resolve
128+
### Libsodium for Curve
110129

111-
If you want to send/receive on the socket immediately, you can specify the
112-
following in `.npmrc`:
130+
Enable libsodium for CURVE security instead of the built-in tweetnacl implementation. This can provide better performance for CURVE operations. To use libsodium, add the following to your .npmrc:
113131

114132
```ini
115-
zmq_no_sync_resolve="true"
133+
zmq_sodium="true"
116134
```
117135

118-
#### Shared library support
136+
#### Draft support
119137

120-
If you want to link against a shared ZeroMQ library installed on your system,
121-
you can build skip downloading `libzmq` and link with the installed library
122-
instead by specifying the following in `.npmrc`:
138+
By default `libzmq` is built with support for `Draft` patterns (e.g.
139+
`server-client`, `radio-dish`, `scatter-gather`). If you want to build `libzmq`
140+
without support for `Draft`, you can specify the following in `.npmrc`:
123141

124142
```ini
125-
zmq_shared=true
143+
zmq_draft=false
126144
```
127145

128-
#### Alternative libzmq version
146+
#### Websocket support
129147

130-
You can specify an alternative version or Git revision of `libzmq` to build
131-
against by specifying the following in `.npmrc`:
148+
Enables WebSocket transport, allowing ZeroMQ to communicate over WebSockets. To enable WebSocket support, add the following to your .npmrc:
132149

133150
```ini
134-
zmq_version="4.3.5"
151+
zmq_websockets="true"
135152
```
136153

137-
#### Debug build of libzmq
154+
#### Secure Websocket support
138155

139-
If you want to build `libzmq` with debug symbols, you can specify the following
140-
in `.npmrc`:
156+
Enables WebSocket transport with TLS (wss), providing secure WebSocket communications. To enable secure WebSocket support, add the following to your .npmrc:
141157

142158
```ini
143-
zmq_build_type="Debug"
159+
zmq_websockets_secure="true"
144160
```
145161

146-
#### Cross-compilation for different architectures
162+
#### Not Synchronous Resolve
147163

148-
If you want to cross-compile for a different architecture, you can specify the
149-
following in `.npmrc`:
164+
Enables immediate send/receive on the socket without synchronous resolution.
165+
This option can improve performance in certain scenarios by allowing operations
166+
to proceed without waiting for synchronous resolution. To enable this feature,
167+
add the following to your `.npmrc`:
150168

151169
```ini
152-
arch="arm64"
153-
target_arch="arm64"
170+
zmq_no_sync_resolve="true"
154171
```
155172

156173
#### MacOS Deployment Target
157174

158-
If you want to specify the MacOS deployment target, you can specify the
159-
following in `.npmrc`:
175+
Specifies the minimum macOS version that the binary will be compatible with. This is particularly useful when building for different macOS versions. To set this, add the following to your .npmrc, replacing 10.15 with your desired minimum macOS version:
160176

161177
```ini
162178
macos_deployment_target="10.15"

vcpkg.json

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,64 @@
66
"dependencies": [
77
{
88
"name": "zeromq",
9-
"version>=": "4.3.5#2",
10-
"features": []
9+
"version>=": "4.3.5#2"
1110
}
12-
]
11+
],
12+
"features": {
13+
"curve": {
14+
"description": "Enable CURVE security",
15+
"dependencies": [
16+
{
17+
"name": "zeromq",
18+
"features": [
19+
"curve"
20+
]
21+
}
22+
]
23+
},
24+
"draft": {
25+
"description": "Build and install draft APIs",
26+
"dependencies": [
27+
{
28+
"name": "zeromq",
29+
"features": [
30+
"draft"
31+
]
32+
}
33+
]
34+
},
35+
"sodium": {
36+
"description": "Using libsodium for CURVE security",
37+
"dependencies": [
38+
{
39+
"name": "zeromq",
40+
"features": [
41+
"sodium"
42+
]
43+
}
44+
]
45+
},
46+
"websockets": {
47+
"description": "Enable WebSocket transport",
48+
"dependencies": [
49+
{
50+
"name": "zeromq",
51+
"features": [
52+
"websockets"
53+
]
54+
}
55+
]
56+
},
57+
"websockets-secure": {
58+
"description": "Enable WebSocket transport with TSL (wss)",
59+
"dependencies": [
60+
{
61+
"name": "zeromq",
62+
"features": [
63+
"websockets-secure"
64+
]
65+
}
66+
]
67+
}
68+
}
1369
}

0 commit comments

Comments
 (0)