Skip to content

Commit

Permalink
ci: port wasm build script to bash
Browse files Browse the repository at this point in the history
given the prior dependency on docker, and the existence of
mingw/git bash, this doesn't change platform requirements.
  • Loading branch information
tombl committed Sep 7, 2024
1 parent 421af68 commit 64572ad
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 103 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM node:22-alpine@sha256:ed9736a13b88ba55cbc08c75c9edac8ae7f72840482e40324670b
ARG UID=1000
ARG GID=1000

RUN apk add -U clang lld wasi-sdk && mkdir /home/node/llhttp
RUN apk add -U clang lld wasi-sdk bash && mkdir /home/node/llhttp

WORKDIR /home/node/llhttp

Expand Down
67 changes: 67 additions & 0 deletions bin/build_wasm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env bash

set -e

WASM_SRC="$(dirname "$0")/../"
WASM_OUT="$(dirname "$0")/../build/wasm"

cd "$WASM_SRC"

if [[ -z "$WASM_PLATFORM" && -n "$1" ]]; then
WASM_PLATFORM=$(docker info -f "{{.OSType}}/{{.Architecture}}")
fi

case "$1" in
--prebuild)
exec docker build --platform="$WASM_PLATFORM" -t llhttp_wasm_builder . --load
;;
--setup)
mkdir -p build
exit 0
;;
--docker)
cmd=(docker run --rm --platform="$WASM_PLATFORM")
if [[ -z "$CI" ]]; then
cmd+=(-it)
fi
# Try to avoid root permission problems on compiled assets
# when running on linux.
# It will work flawessly if uid === gid === 1000
# there will be some warnings otherwise.
if [[ "$(uname)" == Linux ]]; then
cmd+=(--user "$(id -u):$(id -g)")
fi
cmd+=(--mount "type=bind,source=./build,target=/home/node/llhttp/build" llhttp_wasm_builder npm run wasm)

echo "> ${cmd[*]}"
exec "${cmd[@]}"
;;
esac

mkdir -p "$WASM_OUT"

npm run build

clang \
--sysroot=/usr/share/wasi-sysroot \
-target wasm32-unknown-wasi \
-Ofast \
-fno-exceptions \
-fvisibility=hidden \
-mexec-model=reactor \
-Wl,-error-limit=0 \
-Wl,-O3 \
-Wl,--lto-O3 \
-Wl,--strip-all \
-Wl,--allow-undefined \
-Wl,--export-dynamic \
-Wl,--export-table \
-Wl,--export=malloc \
-Wl,--export=free \
-Wl,--no-entry \
build/c/*.c \
src/native/*.c \
-Ibuild \
-o "$WASM_OUT/llhttp.wasm"

cp lib/llhttp/{constants,utils}.* "$WASM_OUT/"
101 changes: 0 additions & 101 deletions bin/build_wasm.ts

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"build-ts": "tsc",
"prebuild-wasm": "npm run wasm -- --prebuild && npm run wasm -- --setup",
"build-wasm": "npm run wasm -- --docker",
"wasm": "ts-node bin/build_wasm.ts",
"wasm": "bash bin/build_wasm.sh",
"clean": "rm -rf lib && rm -rf test/tmp",
"prepare": "npm run clean && npm run build-ts",
"test": "node -r ts-node/register/type-check ./test/md-test.ts",
Expand Down

0 comments on commit 64572ad

Please sign in to comment.