@@ -4,11 +4,62 @@ 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
+ switch ( value ) {
18
+ case "true" :
19
+ case "1" :
20
+ return true
21
+ case "false" :
22
+ case "0" :
23
+ return false
24
+ default :
25
+ return undefined
26
+ }
27
+ }
28
+
29
+ function toString ( value : string | undefined ) : string | undefined {
30
+ switch ( value ) {
31
+ case undefined :
32
+ case "" :
33
+ return undefined
34
+ default :
35
+ return value
36
+ }
37
+ }
38
+
39
+ function parseOptions ( ) : Options {
40
+ return {
41
+ zmq_shared : toBool ( process . env . npm_config_zmq_shared ) ?? false ,
42
+ zmq_draft : toBool ( process . env . npm_config_zmq_draft ) ?? false ,
43
+ zmq_version :
44
+ toString ( process . env . npm_config_zmq_version ) ??
45
+ "5657b4586f24ec433930e8ece02ddba7afcf0fe0" ,
46
+ zmq_build_type :
47
+ toString ( process . env . npm_config_zmq_build_type ) ?? "Release" ,
48
+ arch : toString ( process . env . npm_config_arch ) ?? process . arch ,
49
+ macosx_deployment_target :
50
+ toString ( process . env . npm_config_macosx_deployment_target ) ?? "10.15" ,
51
+ }
52
+ }
53
+
7
54
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`
55
+ const opts = parseOptions ( )
56
+ console . log ( "Building libzmq with options " , opts )
57
+
58
+ if ( opts . zmq_shared ) {
59
+ return
60
+ }
61
+
62
+ const src_url = `https://github.com/zeromq/libzmq/archive/${ opts . zmq_version } .tar.gz`
12
63
13
64
const libzmq_build_prefix = `${ root } /build/libzmq-staging`
14
65
const libzmq_install_prefix = `${ root } /build/libzmq`
@@ -17,29 +68,25 @@ function main() {
17
68
process . platform === "win32" ? ".lib" : ".a"
18
69
} `
19
70
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"
71
+ const src_dir = `libzmq-${ opts . zmq_version } `
72
+ const tarball = `libzmq-${ opts . zmq_version } .tar.gz`
25
73
26
74
let build_options : string = ""
27
75
28
76
// https://cmake.org/cmake/help/latest/variable/CMAKE_MSVC_RUNTIME_LIBRARY.html
29
77
if ( process . platform === "win32" ) {
30
- if ( CMAKE_BUILD_TYPE !== "Debug" ) {
78
+ if ( opts . zmq_build_type !== "Debug" ) {
31
79
build_options += " -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDLL"
32
80
} else {
33
81
build_options += " -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreadedDebugDLL"
34
82
}
35
83
}
36
84
37
- build_options += archCMakeOptions ( )
85
+ build_options += archCMakeOptions ( opts )
38
86
39
87
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 } `
88
+ process . env . MACOSX_DEPLOYMENT_TARGET = opts . macosx_deployment_target
89
+ build_options += ` -DCMAKE_OSX_DEPLOYMENT_TARGET=${ opts . macosx_deployment_target } `
43
90
}
44
91
45
92
mkdir ( "-p" , libzmq_build_prefix )
@@ -65,24 +112,24 @@ function main() {
65
112
exec ( `tar xzf "${ tarball } "` , execOptions )
66
113
}
67
114
68
- if ( process . env . ZMQ_DRAFT === "true" ) {
115
+ if ( opts . zmq_draft ) {
69
116
console . log ( "Enabling draft support" )
70
117
build_options += " -DENABLE_DRAFTS=ON"
71
118
}
72
119
73
- console . log ( `Building libzmq ${ CMAKE_BUILD_TYPE } ` )
120
+ console . log ( `Building libzmq ${ opts . zmq_build_type } ` )
74
121
75
122
// ClangFormat include causes issues but is not required to build.
76
123
const clang_format_file = `${ src_dir } /builds/cmake/Modules/ClangFormat.cmake`
77
124
if ( existsSync ( clang_format_file ) ) {
78
125
writeFileSync ( clang_format_file , "" )
79
126
}
80
127
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`
128
+ 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
129
console . log ( cmake_configure )
83
130
exec ( cmake_configure , execOptions )
84
131
85
- const cmake_build = `cmake --build ./build --config ${ CMAKE_BUILD_TYPE } --target install --parallel`
132
+ const cmake_build = `cmake --build ./build --config ${ opts . zmq_build_type } --target install --parallel`
86
133
console . log ( cmake_build )
87
134
exec ( cmake_build , execOptions )
88
135
@@ -95,9 +142,8 @@ function main() {
95
142
96
143
main ( )
97
144
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 ( )
145
+ function archCMakeOptions ( opts : Options ) {
146
+ const arch = opts . arch . toLowerCase ( )
101
147
102
148
if ( process . platform === "win32" ) {
103
149
// CMAKE_GENERATOR_PLATFORM only supported on Windows
0 commit comments