@@ -4,11 +4,46 @@ import {mkdir, cd, exec, find, mv} from "shelljs"
4
4
5
5
const root = dirname ( __dirname )
6
6
7
+ type Options = {
8
+ zmq_shared : boolean
9
+ zmq_version : string
10
+ zmq_draft : boolean
11
+ zmq_build_type : string
12
+ arch : string
13
+ macosx_deployment_target ?: string
14
+ }
15
+
16
+ function toBool ( value : string | undefined ) : boolean | undefined {
17
+ return value === undefined ? undefined : value === "true"
18
+ }
19
+
20
+ function toString ( value : string | undefined ) : string | undefined {
21
+ return value === undefined || value === "" ? undefined : value
22
+ }
23
+
24
+ function parseOptions ( ) : Options {
25
+ return {
26
+ zmq_shared : toBool ( process . env . npm_config_zmq_shared ) ?? false ,
27
+ zmq_draft : toBool ( process . env . npm_config_zmq_draft ) ?? false ,
28
+ zmq_version :
29
+ toString ( process . env . npm_config_zmq_version ) ??
30
+ "5657b4586f24ec433930e8ece02ddba7afcf0fe0" ,
31
+ zmq_build_type :
32
+ toString ( process . env . npm_config_zmq_build_type ) ?? "Release" ,
33
+ arch : toString ( process . env . npm_config_arch ) ?? process . arch ,
34
+ macosx_deployment_target :
35
+ toString ( process . env . npm_config_macosx_deployment_target ) ?? "10.15" ,
36
+ }
37
+ }
38
+
7
39
function main ( ) {
8
- const zmq_rev =
9
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions
10
- process . env . ZMQ_VERSION || "5657b4586f24ec433930e8ece02ddba7afcf0fe0"
11
- const src_url = `https://github.com/zeromq/libzmq/archive/${ zmq_rev } .tar.gz`
40
+ const opts = parseOptions ( )
41
+
42
+ if ( opts . zmq_shared ) {
43
+ return
44
+ }
45
+
46
+ const src_url = `https://github.com/zeromq/libzmq/archive/${ opts . zmq_version } .tar.gz`
12
47
13
48
const libzmq_build_prefix = `${ root } /build/libzmq-staging`
14
49
const libzmq_install_prefix = `${ root } /build/libzmq`
@@ -17,29 +52,25 @@ function main() {
17
52
process . platform === "win32" ? ".lib" : ".a"
18
53
} `
19
54
20
- const src_dir = `libzmq-${ zmq_rev } `
21
- const tarball = `libzmq-${ zmq_rev } .tar.gz`
22
-
23
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions
24
- const CMAKE_BUILD_TYPE = process . env . CMAKE_BUILD_TYPE || "Release"
55
+ const src_dir = `libzmq-${ opts . zmq_version } `
56
+ const tarball = `libzmq-${ opts . zmq_version } .tar.gz`
25
57
26
58
let build_options : string = ""
27
59
28
60
// https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html
29
61
if ( process . platform === "win32" ) {
30
- if ( CMAKE_BUILD_TYPE !== "Debug" ) {
62
+ if ( opts . zmq_build_type !== "Debug" ) {
31
63
build_options += " -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL"
32
64
} else {
33
65
build_options += " -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL"
34
66
}
35
67
}
36
68
37
- build_options += archCMakeOptions ( )
69
+ build_options += archCMakeOptions ( opts )
38
70
39
71
if ( process . platform === "darwin" ) {
40
- const MACOSX_DEPLOYMENT_TARGET = "10.15"
41
- process . env . MACOSX_DEPLOYMENT_TARGET = MACOSX_DEPLOYMENT_TARGET
42
- build_options += ` -DCMAKE_OSX_DEPLOYMENT_TARGET=${ MACOSX_DEPLOYMENT_TARGET } `
72
+ process . env . MACOSX_DEPLOYMENT_TARGET = opts . macosx_deployment_target
73
+ build_options += ` -DCMAKE_OSX_DEPLOYMENT_TARGET=${ opts . macosx_deployment_target } `
43
74
}
44
75
45
76
mkdir ( "-p" , libzmq_build_prefix )
@@ -65,24 +96,24 @@ function main() {
65
96
exec ( `tar xzf "${ tarball } "` , execOptions )
66
97
}
67
98
68
- if ( process . env . ZMQ_DRAFT === "true" ) {
99
+ if ( opts . zmq_draft ) {
69
100
console . log ( "Enabling draft support" )
70
101
build_options += " -DENABLE_DRAFTS=ON"
71
102
}
72
103
73
- console . log ( `Building libzmq ${ CMAKE_BUILD_TYPE } ` )
104
+ console . log ( `Building libzmq ${ opts . zmq_build_type } ` )
74
105
75
106
// ClangFormat include causes issues but is not required to build.
76
107
const clang_format_file = `${ src_dir } /builds/cmake/Modules/ClangFormat.cmake`
77
108
if ( existsSync ( clang_format_file ) ) {
78
109
writeFileSync ( clang_format_file , "" )
79
110
}
80
111
81
- 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`
112
+ 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`
82
113
console . log ( cmake_configure )
83
114
exec ( cmake_configure , execOptions )
84
115
85
- const cmake_build = `cmake --build ./build --config ${ CMAKE_BUILD_TYPE } --target install --parallel`
116
+ const cmake_build = `cmake --build ./build --config ${ opts . zmq_build_type } --target install --parallel`
86
117
console . log ( cmake_build )
87
118
exec ( cmake_build , execOptions )
88
119
@@ -95,9 +126,8 @@ function main() {
95
126
96
127
main ( )
97
128
98
- function archCMakeOptions ( ) {
99
- // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing, @typescript-eslint/strict-boolean-expressions
100
- const arch = ( process . env . ARCH || process . arch ) . toLowerCase ( )
129
+ function archCMakeOptions ( opts : Options ) {
130
+ const arch = opts . arch . toLowerCase ( )
101
131
102
132
if ( process . platform === "win32" ) {
103
133
// CMAKE_GENERATOR_PLATFORM only supported on Windows
0 commit comments