Skip to content

Commit

Permalink
Revert "chore: remove no-simd wasm of llhttp (#2871)"
Browse files Browse the repository at this point in the history
This reverts commit 3b2df8e.
  • Loading branch information
Uzlopak authored Mar 7, 2024
1 parent 6a4c8fc commit 8ca907d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# The wasm files are stored as base64 strings in the corresponding .js files
lib/llhttp/llhttp_simd.wasm
lib/llhttp/llhttp.wasm

!types/**/*
!index.d.ts
Expand Down
9 changes: 9 additions & 0 deletions build/wasm.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ module.exports = fs.readFileSync(require.resolve('./${basename(path)}'))
`)
}

// Build wasm binary
execSync(`${WASM_CC} ${WASM_CFLAGS} ${WASM_LDFLAGS} \
${join(WASM_SRC, 'src')}/*.c \
-I${join(WASM_SRC, 'include')} \
-o ${join(WASM_OUT, 'llhttp.wasm')} \
${WASM_LDLIBS}`, { stdio: 'inherit' })

writeWasmChunk('llhttp.wasm', 'llhttp-wasm.js')

// Build wasm simd binary
execSync(`${WASM_CC} ${WASM_CFLAGS} -msimd128 ${WASM_LDFLAGS} \
${join(WASM_SRC, 'src')}/*.c \
Expand Down
15 changes: 14 additions & 1 deletion lib/dispatcher/client-h1.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,20 @@ function removeAllListeners (obj) {
}

async function lazyllhttp () {
const mod = await WebAssembly.compile(require('../llhttp/llhttp_simd-wasm.js'))
const llhttpWasmData = process.env.JEST_WORKER_ID ? require('../llhttp/llhttp-wasm.js') : undefined

let mod
try {
mod = await WebAssembly.compile(require('../llhttp/llhttp_simd-wasm.js'))
} catch (e) {
/* istanbul ignore next */

// We could check if the error was caused by the simd option not
// being enabled, but the occurring of this other error
// * https://github.com/emscripten-core/emscripten/issues/11495
// got me to remove that check to avoid breaking Node 12.
mod = await WebAssembly.compile(llhttpWasmData || require('../llhttp/llhttp-wasm.js'))
}

return await WebAssembly.instantiate(mod, {
env: {
Expand Down
3 changes: 3 additions & 0 deletions lib/llhttp/llhttp-wasm.js

Large diffs are not rendered by default.

Binary file added lib/llhttp/llhttp.wasm
Binary file not shown.

0 comments on commit 8ca907d

Please sign in to comment.