Skip to content

Commit bc46332

Browse files
khardixmcollina
authored andcommitted
build: parametrize the location of wasm-opt (#3454)
The wasm-opt binary may be available in different place than the local directory (`./wasm-opt`) – for example, in /usr/bin/wasm-opt. Similarly to the other parametrized WASM build options, use WASM_OPT environment variable to identify the wanted binary, with fallback to the previous value. Even with the environment variable available, the `hasOptimizer` is kept to make the optimization optional. Signed-off-by: Jan Staněk <[email protected]>
1 parent 5287054 commit bc46332

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

CONTRIBUTING.md

+1
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ an unbundled version instead of bundling one in `libnode.so`.
159159
To enable this, pass `EXTERNAL_PATH=/path/to/global/node_modules/undici` to `build/wasm.js`.
160160
Pass this path with `loader.js` appended to `--shared-builtin-undici/undici-path` in Node.js's `configure.py`.
161161
If building on a non-Alpine Linux distribution, you may need to also set the `WASM_CC`, `WASM_CFLAGS`, `WASM_LDFLAGS` and `WASM_LDLIBS` environment variables before running `build/wasm.js`.
162+
Similarly, you can set the `WASM_OPT` environment variable to utilize your own `wasm-opt` optimizer.
162163

163164
<a id="benchmarks"></a>
164165
### Benchmarks

build/wasm.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const WASM_CC = process.env.WASM_CC || 'clang'
1414
let WASM_CFLAGS = process.env.WASM_CFLAGS || '--sysroot=/usr/share/wasi-sysroot -target wasm32-unknown-wasi'
1515
let WASM_LDFLAGS = process.env.WASM_LDFLAGS || ''
1616
const WASM_LDLIBS = process.env.WASM_LDLIBS || ''
17+
const WASM_OPT = process.env.WASM_OPT || './wasm-opt'
1718

1819
// For compatibility with Node.js' `configure --shared-builtin-undici/undici-path ...`
1920
const EXTERNAL_PATH = process.env.EXTERNAL_PATH
@@ -77,7 +78,7 @@ const hasApk = (function () {
7778
try { execSync('command -v apk'); return true } catch (error) { return false }
7879
})()
7980
const hasOptimizer = (function () {
80-
try { execSync('./wasm-opt --version'); return true } catch (error) { return false }
81+
try { execSync(`${WASM_OPT} --version`); return true } catch (error) { return false }
8182
})()
8283
if (hasApk) {
8384
// Gather information about the tools used for the build
@@ -97,7 +98,7 @@ ${join(WASM_SRC, 'src')}/*.c \
9798
${WASM_LDLIBS}`, { stdio: 'inherit' })
9899

99100
if (hasOptimizer) {
100-
execSync(`./wasm-opt ${WASM_OPT_FLAGS} -o ${join(WASM_OUT, 'llhttp.wasm')} ${join(WASM_OUT, 'llhttp.wasm')}`, { stdio: 'inherit' })
101+
execSync(`${WASM_OPT} ${WASM_OPT_FLAGS} -o ${join(WASM_OUT, 'llhttp.wasm')} ${join(WASM_OUT, 'llhttp.wasm')}`, { stdio: 'inherit' })
101102
}
102103
writeWasmChunk('llhttp.wasm', 'llhttp-wasm.js')
103104

@@ -109,7 +110,7 @@ ${join(WASM_SRC, 'src')}/*.c \
109110
${WASM_LDLIBS}`, { stdio: 'inherit' })
110111

111112
if (hasOptimizer) {
112-
execSync(`./wasm-opt ${WASM_OPT_FLAGS} --enable-simd -o ${join(WASM_OUT, 'llhttp_simd.wasm')} ${join(WASM_OUT, 'llhttp_simd.wasm')}`, { stdio: 'inherit' })
113+
execSync(`${WASM_OPT} ${WASM_OPT_FLAGS} --enable-simd -o ${join(WASM_OUT, 'llhttp_simd.wasm')} ${join(WASM_OUT, 'llhttp_simd.wasm')}`, { stdio: 'inherit' })
113114
}
114115
writeWasmChunk('llhttp_simd.wasm', 'llhttp_simd-wasm.js')
115116

0 commit comments

Comments
 (0)