|
59 | 59 |
|
60 | 60 | SITE_DIR="${BUILD_DIR}/site" |
61 | 61 | WASM_JS="${SITE_DIR}/spz_gatekeeper_wasm.js" |
| 62 | +WASM_BINARY="${SITE_DIR}/spz_gatekeeper_wasm.wasm" |
62 | 63 |
|
63 | 64 | fail() { |
64 | 65 | local stage="$1" code="$2" msg="$3" hint="${4:-}" |
@@ -208,14 +209,28 @@ check_symbols() { |
208 | 209 | # P3: Artifact |
209 | 210 | # --------------------------------------------------------------------------- |
210 | 211 | check_artifact() { |
| 212 | + # Check JS glue exists (always small, ~tens of KB) |
211 | 213 | if [ ! -f "${WASM_JS}" ]; then |
212 | | - fail "P3_ARTIFACT" 5 "WASM artifact not found: ${WASM_JS}" "Run build first: emcmake cmake -S cpp -B ${BUILD_DIR} && emmake cmake --build ${BUILD_DIR}" |
| 214 | + fail "P3_ARTIFACT" 5 "WASM JS glue not found: ${WASM_JS}" "Run build first: emcmake cmake -S cpp -B ${BUILD_DIR} && emmake cmake --build ${BUILD_DIR}" |
213 | 215 | fi |
214 | 216 |
|
| 217 | + # Check separate .wasm binary exists (split mode, no SINGLE_FILE) |
| 218 | + if [ ! -f "${WASM_BINARY}" ]; then |
| 219 | + fail "P3_ARTIFACT" 5 "WASM binary not found: ${WASM_BINARY}" "Ensure SINGLE_FILE=1 is removed from CMakeLists.txt (split JS+wasm mode)" |
| 220 | + fi |
| 221 | + |
| 222 | + # Check WASM binary size (the binary, not the JS glue) |
215 | 223 | local size |
216 | | - size="$(stat -c%s "${WASM_JS}" 2>/dev/null || stat -f%z "${WASM_JS}" 2>/dev/null || echo 0)" |
| 224 | + size="$(stat -c%s "${WASM_BINARY}" 2>/dev/null || stat -f%z "${WASM_BINARY}" 2>/dev/null || echo 0)" |
217 | 225 | if [ "${size}" -lt "${WASM_MIN_BYTES}" ] || [ "${size}" -gt "${WASM_MAX_BYTES}" ]; then |
218 | | - fail "P3_ARTIFACT" 5 "WASM artifact size ${size} bytes out of range [${WASM_MIN_BYTES}, ${WASM_MAX_BYTES}]" "Check -Oz/-O3 flag and -sSINGLE_FILE=1 in CMakeLists.txt" |
| 226 | + fail "P3_ARTIFACT" 5 "WASM binary size ${size} bytes out of range [${WASM_MIN_BYTES}, ${WASM_MAX_BYTES}]" "Check -Oz/-O3 flag in CMakeLists.txt" |
| 227 | + fi |
| 228 | + |
| 229 | + # JS glue should be small (< 500KB) |
| 230 | + local js_size |
| 231 | + js_size="$(stat -c%s "${WASM_JS}" 2>/dev/null || stat -f%z "${WASM_JS}" 2>/dev/null || echo 0)" |
| 232 | + if [ "${js_size}" -gt 524288 ]; then |
| 233 | + echo " WARN: WASM JS glue size ${js_size} bytes > 512KB (SINGLE_FILE may still be active)" >&2 |
219 | 234 | fi |
220 | 235 | } |
221 | 236 |
|
@@ -269,15 +284,15 @@ check_smoke() { |
269 | 284 | fail "P5_SMOKE" 7 "Local HTTP server did not become ready" |
270 | 285 | fi |
271 | 286 |
|
272 | | - # Minimal runtime sanity: the module can be instantiated. |
273 | | - if ! node -e " |
274 | | -const createModule = require('${WASM_JS}'); |
275 | | -createModule().then(m => { |
276 | | - if (typeof m.inspectSpz !== 'function' && typeof m.inspectSpzPtr !== 'function') { |
277 | | - process.exit(1); |
278 | | - } |
279 | | - process.exit(0); |
280 | | -}).catch(() => process.exit(1)); |
| 287 | + # Minimal runtime sanity: instantiate module via ES module dynamic import |
| 288 | + # (WASM is built with EXPORT_ES6=1, split mode — no CJS require) |
| 289 | + if ! node --input-type=module -e " |
| 290 | +const { default: createModule } = await import('${WASM_JS}'); |
| 291 | +const m = await createModule(); |
| 292 | +if (typeof m.inspectSpz !== 'function' && typeof m.inspectSpzPtr !== 'function') { |
| 293 | + process.exit(1); |
| 294 | +} |
| 295 | +process.exit(0); |
281 | 296 | " >/dev/null 2>&1; then |
282 | 297 | fail "P5_SMOKE" 7 "WASM module failed to instantiate or missing expected exports" |
283 | 298 | fi |
|
0 commit comments