build: WASM npm build runs out-of-source (out-of-tree)
npm/build.sh built in-tree: it cd'd into the source root, ran `./configure` there, appended the WASM defs.mak to the source-tree defs.mak, and copied magic.js/.wasm out of the source magic/ dir. Run each variant in a dedicated out-of-source build dir instead (build-wasm-<variant>, overridable via WASM_BUILD_DIR): * configure is invoked as "$REPO_ROOT/configure" from $build_dir, so config.status and all generated files land under $build_dir; the source tree is only read (VPATH). * the WASM defs.mak is appended to $build_dir/defs.mak. * artifacts are copied from $build_dir/magic/. * a fresh `rm -rf $build_dir` per run replaces the old in-tree `make distclean` (which also removes the need to touch the source tree, and sidesteps the tracked-rules.mak distclean hazard entirely). CRLF stripping now targets the source-tree configure inputs explicitly. Note: build-wasm-<variant> dirs are not gitignored (left per task scope); they are disposable and recreated each run. (Static edit; not runtime-verified — emscripten is not available here.) Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
222b39ec9c
commit
5342474b27
35
npm/build.sh
35
npm/build.sh
|
|
@ -155,29 +155,32 @@ ensure_tcl_built() {
|
||||||
build_variant() {
|
build_variant() {
|
||||||
local variant=$1
|
local variant=$1
|
||||||
local out_dir="$SCRIPT_DIR/$variant"
|
local out_dir="$SCRIPT_DIR/$variant"
|
||||||
|
# Out-of-source build directory (sibling of the TCL WASM build dir). Magic
|
||||||
|
# now supports VPATH builds, so the WASM build reads from the source tree and
|
||||||
|
# writes only under $build_dir — the source tree is never mutated. A fresh
|
||||||
|
# dir per run replaces the old in-tree `make distclean`.
|
||||||
|
local build_dir="${WASM_BUILD_DIR:-$REPO_ROOT/build-wasm-$variant}"
|
||||||
|
|
||||||
echo
|
echo
|
||||||
echo "==============================================================="
|
echo "==============================================================="
|
||||||
echo "=== building variant: $variant"
|
echo "=== building variant: $variant (build dir: $build_dir)"
|
||||||
echo "==============================================================="
|
echo "==============================================================="
|
||||||
|
|
||||||
cd "$REPO_ROOT"
|
rm -rf "$build_dir"
|
||||||
|
mkdir -p "$build_dir"
|
||||||
|
|
||||||
# Full clean — distclean removes the generated defs.mak and module objects.
|
# Strip Windows CRLF line endings on the configure inputs (in the source tree,
|
||||||
if [ -f defs.mak ]; then
|
# read by configure; no-op on Linux-native files).
|
||||||
emmake make distclean || true
|
sed_strip_cr "$REPO_ROOT/configure"
|
||||||
fi
|
find "$REPO_ROOT/scripts/" -type f -print0 | while IFS= read -r -d '' f; do sed_strip_cr "$f"; done
|
||||||
rm -f defs.mak database/database.h
|
|
||||||
|
|
||||||
# Strip Windows CRLF line endings (no-op on Linux-native files).
|
cd "$build_dir"
|
||||||
sed_strip_cr configure
|
|
||||||
find scripts/ -type f -print0 | while IFS= read -r -d '' f; do sed_strip_cr "$f"; done
|
|
||||||
|
|
||||||
if [ "$variant" = "tcl" ]; then
|
if [ "$variant" = "tcl" ]; then
|
||||||
ensure_tcl_built
|
ensure_tcl_built
|
||||||
CFLAGS="--std=c17 -D_DEFAULT_SOURCE=1 -DEMSCRIPTEN=1 ${EXTRA_CFLAGS}" \
|
CFLAGS="--std=c17 -D_DEFAULT_SOURCE=1 -DEMSCRIPTEN=1 ${EXTRA_CFLAGS}" \
|
||||||
LDFLAGS="${EXTRA_LDFLAGS}" \
|
LDFLAGS="${EXTRA_LDFLAGS}" \
|
||||||
emconfigure ./configure \
|
emconfigure "$REPO_ROOT/configure" \
|
||||||
--without-cairo --without-opengl --without-x --without-tk \
|
--without-cairo --without-opengl --without-x --without-tk \
|
||||||
--with-tcl="$TCL_WASM_PREFIX/lib" \
|
--with-tcl="$TCL_WASM_PREFIX/lib" \
|
||||||
--with-tclincls="$TCL_WASM_PREFIX/include" \
|
--with-tclincls="$TCL_WASM_PREFIX/include" \
|
||||||
|
|
@ -189,7 +192,7 @@ build_variant() {
|
||||||
else
|
else
|
||||||
CFLAGS="--std=c17 -D_DEFAULT_SOURCE=1 -DEMSCRIPTEN=1 ${EXTRA_CFLAGS}" \
|
CFLAGS="--std=c17 -D_DEFAULT_SOURCE=1 -DEMSCRIPTEN=1 ${EXTRA_CFLAGS}" \
|
||||||
LDFLAGS="${EXTRA_LDFLAGS}" \
|
LDFLAGS="${EXTRA_LDFLAGS}" \
|
||||||
emconfigure ./configure \
|
emconfigure "$REPO_ROOT/configure" \
|
||||||
--without-cairo --without-opengl --without-x \
|
--without-cairo --without-opengl --without-x \
|
||||||
--without-tk --without-tcl \
|
--without-tk --without-tcl \
|
||||||
--disable-readline --disable-compression \
|
--disable-readline --disable-compression \
|
||||||
|
|
@ -198,7 +201,7 @@ build_variant() {
|
||||||
${EXTRA_CONFIGURE_ARGS:-}
|
${EXTRA_CONFIGURE_ARGS:-}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat toolchains/emscripten/defs.mak >> defs.mak
|
cat "$REPO_ROOT/toolchains/emscripten/defs.mak" >> defs.mak
|
||||||
|
|
||||||
#
|
#
|
||||||
echo "===== defs.mak ====="
|
echo "===== defs.mak ====="
|
||||||
|
|
@ -211,9 +214,9 @@ build_variant() {
|
||||||
emmake make mains
|
emmake make mains
|
||||||
|
|
||||||
mkdir -p "$out_dir"
|
mkdir -p "$out_dir"
|
||||||
cp magic/magic.js "$out_dir/"
|
cp "$build_dir/magic/magic.js" "$out_dir/"
|
||||||
cp magic/magic.wasm "$out_dir/"
|
cp "$build_dir/magic/magic.wasm" "$out_dir/"
|
||||||
test -f magic/magic.wasm.map && cp magic/magic.wasm.map "$out_dir/"
|
test -f "$build_dir/magic/magic.wasm.map" && cp "$build_dir/magic/magic.wasm.map" "$out_dir/"
|
||||||
echo "Copied magic.js + magic.wasm into npm/$variant/"
|
echo "Copied magic.js + magic.wasm into npm/$variant/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue