Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/romdev-core-host/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ share one process without drawing into each other's contexts.
## Browser / bytes-only use

Everything the index exports is browser-bundleable (enforced by a gate
test: no top-level `node:` imports, no pngjs in the static closure). The
browser contract is "the caller does the I/O":
test: no top-level `node:` imports, no pngjs in the static closure), and the
2D cores' glue is linked for `node,web,worker`, so the same `.js` + `.wasm`
pair loads in a page or a Web Worker. The browser contract is "the caller
does the I/O":

```js
import { LibretroHost } from "romdev-core-host";
Expand Down
13 changes: 13 additions & 0 deletions packages/romdevtools/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@ All notable changes to `romdevtools`. Dates are release dates.
(Published as `romdev-mcp` through 0.11.0; renamed to `romdevtools` in 0.13.0 -
the `romdev-mcp` bin is kept as an alias.)

## Unreleased

- **The 2D cores and the CLI toolchains load in a browser or Web Worker.**
They were linked with `-s ENVIRONMENT=node`, so their glue began with
`await import("module")` and failed outside Node before the wasm loaded,
although they use nothing but MEMFS. The 14 2D core recipes (fceumm, fake08,
bluemsx, bsnes, geargrafx, gametank, gambatte, genesis_plus_gx, handy, mgba,
prosystem, snes9x, stella2014, vice) and `EM_CLI_FLAGS` (sdcc + sdas*/sdld,
mcpp, rgbds, cc65, asar, dasm, sjasm, tcc816, wla-dx) now link with
`node,web,worker`. Under Node nothing changes, and the `.wasm` files are the
same; only the JS glue differs. `verify-wasm.mjs` refuses to publish those
glue files if they come out node-only again.

## 0.151.1 - 2026-10-20

- **wasmcart ^0.36.1**, which ships wasmcart's test cart
Expand Down
9 changes: 8 additions & 1 deletion packages/romdevtools/scripts/_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,19 @@ require_cmd() {
}

# Common Emscripten link flags for a tool that's invoked as a CLI via callMain.
#
# ENVIRONMENT lists web + worker as well as node: these tools only ever touch
# MEMFS (inputs are written in, outputs read back), so the same glue runs in a
# browser Web Worker when the caller supplies the wasm bytes. With node alone
# emcc hard-codes ENVIRONMENT_IS_NODE=true and the glue's first act is
# `await import("module")` - unusable in a browser even though nothing in the
# tool needs Node. Node behavior is unchanged (runtime detection picks node).
EM_CLI_FLAGS=(
-O2
-s WASM=1
-s MODULARIZE=1
-s EXPORT_ES6=1
-s ENVIRONMENT=node
-s ENVIRONMENT=node,web,worker
-s ALLOW_MEMORY_GROWTH=1
-s INITIAL_MEMORY=67108864
-s STACK_SIZE=8388608
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-bluemsx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ EXPORTED_RUNTIME='["ccall","cwrap","addFunction","removeFunction","HEAPU8","HEAP
mkdir -p "$OUT"
emcc $OBJS \
-O3 -s WASM=1 -s MODULARIZE=1 -s EXPORT_ES6=1 -s EXPORT_NAME=create_bluemsx \
-s ENVIRONMENT=node -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=134217728 \
-s ENVIRONMENT=node,web,worker -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=134217728 \
-s MAXIMUM_MEMORY=536870912 -s ALLOW_TABLE_GROWTH=1 \
-s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS" \
-s EXPORTED_RUNTIME_METHODS="$EXPORTED_RUNTIME" \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-bsnes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ em++ $(cat romdev-objects.txt) \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=create_bsnes \
-s ENVIRONMENT=node \
-s ENVIRONMENT=node,web,worker \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=134217728 \
-s MAXIMUM_MEMORY=1073741824 \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-fake08.sh
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ emcc "$CORE_LIB" \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=create_fake08 \
-s ENVIRONMENT=node \
-s ENVIRONMENT=node,web,worker \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=33554432 \
-s MAXIMUM_MEMORY=268435456 \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-fceumm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ emcc "$CORE_LIB" \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=create_fceumm \
-s ENVIRONMENT=node \
-s ENVIRONMENT=node,web,worker \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=33554432 \
-s MAXIMUM_MEMORY=268435456 \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-gambatte.sh
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ emcc "$CORE_LIB" \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=create_gambatte \
-s ENVIRONMENT=node \
-s ENVIRONMENT=node,web,worker \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=33554432 \
-s MAXIMUM_MEMORY=268435456 \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-gametank.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ emcc -O2 \
vendor/audio_coprocessor.em.o vendor/emulator_config.em.o vendor/timekeeper.em.o \
vendor/mos6502/mos6502.em.o romdev_debug.c -I. \
-s WASM=1 -s MODULARIZE=1 -s EXPORT_ES6=1 -s EXPORT_NAME=create_gametank \
-s ENVIRONMENT=node -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=33554432 \
-s ENVIRONMENT=node,web,worker -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=33554432 \
-s MAXIMUM_MEMORY=268435456 -s ALLOW_TABLE_GROWTH=1 -s INVOKE_RUN=0 \
-s EXPORTED_FUNCTIONS="$EXP" -s EXPORTED_RUNTIME_METHODS="$RT" \
-o gametank_libretro.js
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-geargrafx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ EXPORTED_RUNTIME='["ccall","cwrap","addFunction","removeFunction","HEAPU8","HEAP
mkdir -p "$OUT"
emcc "$CORE_LIB" \
-O3 -s WASM=1 -s MODULARIZE=1 -s EXPORT_ES6=1 -s EXPORT_NAME=create_geargrafx \
-s ENVIRONMENT=node -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=67108864 \
-s ENVIRONMENT=node,web,worker -s ALLOW_MEMORY_GROWTH=1 -s INITIAL_MEMORY=67108864 \
-s MAXIMUM_MEMORY=268435456 -s ALLOW_TABLE_GROWTH=1 \
-s DISABLE_EXCEPTION_CATCHING=0 \
-s EXPORTED_FUNCTIONS="$EXPORTED_FUNCTIONS" \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-genesis-plus-gx.sh
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ emcc "$CORE_LIB" \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=create_genesis_plus_gx \
-s ENVIRONMENT=node \
-s ENVIRONMENT=node,web,worker \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=33554432 \
-s MAXIMUM_MEMORY=268435456 \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-handy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ emcc "$CORE_LIB" \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=create_handy \
-s ENVIRONMENT=node \
-s ENVIRONMENT=node,web,worker \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=33554432 \
-s MAXIMUM_MEMORY=268435456 \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-mgba.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ emcc "$CORE_LIB" \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=create_mgba \
-s ENVIRONMENT=node \
-s ENVIRONMENT=node,web,worker \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=67108864 \
-s MAXIMUM_MEMORY=536870912 \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-prosystem.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ emcc "$CORE_LIB" \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=create_prosystem \
-s ENVIRONMENT=node \
-s ENVIRONMENT=node,web,worker \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=33554432 \
-s MAXIMUM_MEMORY=268435456 \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-snes9x.sh
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ emcc "$CORE_LIB" \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=create_snes9x \
-s ENVIRONMENT=node \
-s ENVIRONMENT=node,web,worker \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=33554432 \
-s MAXIMUM_MEMORY=268435456 \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-stella2014.sh
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ emcc "$CORE_LIB" \
-s MODULARIZE=1 \
-s EXPORT_ES6=1 \
-s EXPORT_NAME=create_stella2014 \
-s ENVIRONMENT=node \
-s ENVIRONMENT=node,web,worker \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=33554432 \
-s MAXIMUM_MEMORY=268435456 \
Expand Down
2 changes: 1 addition & 1 deletion packages/romdevtools/scripts/build-vice.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ emcc "$CORE_LIB" \
-O3 \
-s WASM=1 -s MODULARIZE=1 -s EXPORT_ES6=1 \
-s 'EXPORT_NAME=create_vice_x64' \
-s ENVIRONMENT=node \
-s ENVIRONMENT=node,web,worker \
-s ALLOW_MEMORY_GROWTH=1 \
-s INITIAL_MEMORY=67108864 -s MAXIMUM_MEMORY=536870912 \
-s ALLOW_TABLE_GROWTH=1 \
Expand Down
38 changes: 37 additions & 1 deletion scripts/verify-wasm.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,34 @@ import path from "node:path";
// a truncated file, or a git-lfs/text pointer left where the binary should be.
const MIN_WASM_BYTES = 16 * 1024;

// Glue that must also run in a browser / Web Worker (romdev-core-host's
// bytes-only path), i.e. whatever the 2D-core recipes and EM_CLI_FLAGS link
// with `-s ENVIRONMENT=node,web,worker`. A rebuild with `ENVIRONMENT=node`
// alone hard-codes ENVIRONMENT_IS_NODE=true and the glue then dies on
// `await import("module")` outside Node - refuse to publish that.
// (NODERAWFS builds, GPU cores and the gcc-family wraps stay node-only.)
const BROWSER_GLUE = {
"romdev-core-bluemsx": ["bluemsx_libretro.js"],
"romdev-core-bsnes": ["bsnes_libretro.js"],
"romdev-core-fake08": ["fake08_libretro.js"],
"romdev-core-fceumm": ["fceumm_libretro.js"],
"romdev-core-gambatte": ["gambatte_libretro.js"],
"romdev-core-gametank": ["gametank_libretro.js"],
"romdev-core-geargrafx": ["geargrafx_libretro.js"],
"romdev-core-gpgx": ["genesis_plus_gx_libretro.js"],
"romdev-core-handy": ["handy_libretro.js"],
"romdev-core-prosystem": ["prosystem_libretro.js"],
"romdev-core-vice": ["vice_x64_libretro.js"],
"romdev-platform-atari2600": ["stella2014_libretro.js", "dasm.js"],
"romdev-platform-gba": ["mgba_libretro.js"],
"romdev-platform-snes": ["snes9x_libretro.js", "asar.js", "tcc816.js", "wla-65816.js", "wlalink.js"],
"romdev-toolchain-cc65": ["ca65.js", "cc65.js", "da65.js", "ld65.js"],
"romdev-toolchain-m68k-gcc": ["sjasm.js"],
"romdev-toolchain-rgbds": ["rgbasm.js", "rgbfix.js", "rgblink.js"],
"romdev-toolchain-sdcc": ["mcpp.js", "sdasgb.js", "sdasz80.js", "sdcc.js", "sdld.js"],
};
const NODE_ONLY_GLUE = /\bENVIRONMENT_IS_NODE\s*=\s*true\b|\bENVIRONMENT_IS_WEB\s*=\s*false\b/;

/** @returns {string[]} problems found in this package (empty = ok) */
function checkPackage(pkgDir) {
const problems = [];
Expand Down Expand Up @@ -57,6 +85,14 @@ function checkPackage(pkgDir) {
problems.push(`${name}: ${w} does not start with the wasm magic (\\0asm) - corrupt or wrong file`);
}
}
for (const glue of BROWSER_GLUE[name] ?? []) {
const p = path.join(wasmDir, glue);
if (!existsSync(p)) {
problems.push(`${name}: expected browser-capable glue ${glue} is missing`);
} else if (NODE_ONLY_GLUE.test(readFileSync(p, "utf8"))) {
problems.push(`${name}: ${glue} is node-only glue (linked with -s ENVIRONMENT=node) - rebuild with the recipe's node,web,worker flags`);
}
}
return problems;
}

Expand Down Expand Up @@ -87,4 +123,4 @@ if (allProblems.length) {
process.exit(1);
}
const checked = pkgDirs.length;
console.log(`✓ wasm verified across ${checked} package${checked === 1 ? "" : "s"} (all declared .wasm present, sized, valid magic).`);
console.log(`✓ wasm verified across ${checked} package${checked === 1 ? "" : "s"} (all declared .wasm present, sized, valid magic; browser glue not node-only).`);