#!/usr/bin/env bash set -euo pipefail cd "$(dirname "$0")" linuxcnc_root=${LINUXCNC_ROOT:-../linuxcnc} manifest=${1:-linuxcnc-rs274-wasm-source-files.txt} if [[ ! -f "$manifest" ]]; then echo "missing manifest: $manifest" >&2 exit 1 fi if [[ ! -d "$linuxcnc_root" ]]; then echo "missing LinuxCNC root: $linuxcnc_root" >&2 exit 1 fi manifest=$(cd "$(dirname "$manifest")" && pwd)/$(basename "$manifest") linuxcnc_root=$(cd "$linuxcnc_root" && pwd) default_manifest="$PWD/linuxcnc-rs274-wasm-source-files.txt" # This script writes fixed build and public artifact paths, so serialize it. exec 9>"${TMPDIR:-/tmp}/cnc_sim_build_wasm.lock" flock 9 manifest_core_count=0 manifest_blocked_count=0 manifest_core_sources=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_wasm_manifest_core.XXXXXX.txt") manifest_blocked_sources=$(mktemp "${TMPDIR:-/tmp}/cnc_sim_wasm_manifest_blocked.XXXXXX.txt") trap 'rm -f "$manifest_core_sources" "$manifest_blocked_sources"' EXIT LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-wasm-manifest-sources.sh "$manifest" core > "$manifest_core_sources" LINUXCNC_ROOT="$linuxcnc_root" ./list-linuxcnc-wasm-manifest-sources.sh "$manifest" blocked > "$manifest_blocked_sources" manifest_core_count=$(wc -l < "$manifest_core_sources") manifest_blocked_count=$(wc -l < "$manifest_blocked_sources") if [[ "$manifest_core_count" -eq 0 || "$manifest_blocked_count" -eq 0 ]]; then echo "unexpected wasm manifest partition: core=$manifest_core_count blocked=$manifest_blocked_count" >&2 exit 1 fi if [[ "$manifest" == "$default_manifest" ]] && [[ "$manifest_core_count" -ne 25 || "$manifest_blocked_count" -ne 1 ]]; then echo "unexpected wasm manifest partition: core=$manifest_core_count blocked=$manifest_blocked_count" >&2 exit 1 fi echo "LinuxCNC wasm blocker scan" ./test-linuxcnc-wasm-blockers.sh "$manifest" echo "LinuxCNC wasm-safe source syntax probe" ./test-linuxcnc-wasm-source-syntax.sh "$manifest" echo "LinuxCNC wasm-safe source object probe" ./test-linuxcnc-wasm-source-objects.sh "$manifest" echo "LinuxCNC wasm-safe CMake probe target" ./test-linuxcnc-wasm-cmake-safe-probe.sh "$manifest" echo "LinuxCNC wasm tooldata shim link probe" ./test-linuxcnc-wasm-tooldata-link.sh echo "LinuxCNC wasm tooldata_common link probe" ./test-linuxcnc-wasm-tooldata-common-link.sh echo "LinuxCNC wasm tooldata_mmap symbol probe" ./test-linuxcnc-wasm-tooldata-mmap-symbols.sh echo "LinuxCNC wasm tooldata runtime symbol probe" ./test-linuxcnc-wasm-tooldata-runtime-symbols.sh echo "LinuxCNC wasm interp_base link probe" ./test-linuxcnc-wasm-interp-base-link.sh echo "LinuxCNC wasm interp_find link probe" ./test-linuxcnc-wasm-interp-find-link.sh echo "LinuxCNC wasm python_plugin link probe" ./test-linuxcnc-wasm-python-plugin-link.sh echo "LinuxCNC wasm rs274ngc_pre object probe" ./test-linuxcnc-wasm-rs274ngc-pre-object.sh echo "LinuxCNC wasm rs274ngc_pre link blocker scan" ./test-linuxcnc-wasm-rs274ngc-pre-link-blockers.sh "$manifest" echo "LinuxCNC wasm rs274ngc_pre link probe" ./test-linuxcnc-wasm-rs274ngc-pre-link.sh "$manifest" if ! command -v emcmake >/dev/null 2>&1; then echo "Emscripten is required. Install/activate emsdk so emcmake and emcc are in PATH." >&2 exit 1 fi emcmake cmake -S core -B build/wasm \ -DCMAKE_BUILD_TYPE=Release \ -DCNC_SIM_LINUXCNC_ROOT="$linuxcnc_root" \ -DCNC_SIM_LINUXCNC_WASM_SOURCE_MANIFEST="$manifest" \ -DCNC_SIM_ENABLE_LINUXCNC_WASM_SAFE_PROBE=ON cmake --build build/wasm mkdir -p web/public cp build/wasm/cnc_sim.js web/public/ cp build/wasm/cnc_sim.wasm web/public/