diff options
Diffstat (limited to 'src/web')
| -rwxr-xr-x | src/web/build.sh | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/src/web/build.sh b/src/web/build.sh index 7443f46..1f2cfae 100755 --- a/src/web/build.sh +++ b/src/web/build.sh @@ -1,16 +1,23 @@ #!/bin/bash -# builds src/web/zc.wasm (or the path given as the first argument): the microcore, with the compiler genome inside, as -# WebAssembly. needs clang with the wasm32 target and wasm-ld. the page -# (src/web/index.html) loads it next to src/web/zc.js. +# builds the browser compiler: the microcore with the compiler genome inside, as +# WebAssembly, written to build/web/zc.wasm (or the path given as the first +# argument). the page (src/web/index.html) loads it next to zc.js; `make web` +# copies both beside it, so build/web/ is the whole site. needs clang with the +# wasm32 target, #embed and wasm-ld, and the genome from `make genome`. set -e case "${1:-}" in - --help|-h) printf '%s\n' 'usage: src/web/build.sh [OUTFILE.wasm]' 'builds the browser compiler vm; defaults to src/web/zc.wasm.' 'requires clang with wasm32 support and wasm-ld.'; exit 0 ;; + --help|-h) printf '%s\n' 'usage: src/web/build.sh [OUTFILE.wasm]' 'builds the browser compiler vm; defaults to build/web/zc.wasm.' 'requires clang with wasm32 and #embed support, and wasm-ld.' 'environment: WASM_CC selects the compiler; GENOME_DIR holds genome.bin (build/core); MAP_DIR holds its memmap.h (build/core/map).'; exit 0 ;; -*) echo "web build: unknown option $1; use --help for usage" >&2; exit 2 ;; esac cd "$(dirname "$0")/../.." -clang --target=wasm32 -O2 -w -fwrapv -nostdlib -fno-builtin -mbulk-memory -DJTYPE=int \ - -Isrc/core -Isrc/micro src/micro/micro.c src/web/port_wasm.c \ +OUT=${1:-build/web/zc.wasm} +WASM_CC=${WASM_CC:-$(sh src/tools/findcc.sh --wasm)} +GENOME_DIR=${GENOME_DIR:-build/core}; MAP_DIR=${MAP_DIR:-build/core/map} +[ -f "$GENOME_DIR/genome.bin" ] || { echo "web build: no $GENOME_DIR/genome.bin; run make genome first" >&2; exit 1; } +mkdir -p "$(dirname "$OUT")" +"$WASM_CC" --target=wasm32 -O2 -w -fwrapv -nostdlib -fno-builtin -mbulk-memory -DJTYPE=int \ + -Isrc/core -I"$MAP_DIR" --embed-dir="$GENOME_DIR" -Isrc/micro src/micro/micro.c src/web/port_wasm.c \ -Wl,--no-entry -Wl,--export=wasm_input -Wl,--export=wasm_input_cap -Wl,--export=wasm_set_input -Wl,--export=wasm_run \ -Wl,--export=memory -Wl,--allow-undefined -Wl,--initial-memory=33554432 -Wl,-z,stack-size=65536 \ - -o "${1:-src/web/zc.wasm}" -ls -l "${1:-src/web/zc.wasm}" + -o "$OUT" +ls -l "$OUT" |
