Skip to content

wasm: configurable Emscripten, an optimized runtime, and separate debug runtimes - #2523

Merged
bfiete merged 3 commits into
beefytech:masterfrom
robknopf:pr/wasm-build
Sep 21, 2026
Merged

bfiete merged 3 commits into
beefytech:masterfrom
robknopf:pr/wasm-build

Conversation

@robknopf

Copy link
Copy Markdown
Contributor

Three fixes to the wasm32 build path, found while shipping a wasm target from Linux.

1. Link with a user-configured Emscripten. A wasm32 link required EmsdkDep2_Done.txt in <install>/../wasm for any configured Emscripten path, but only fetch_wasm.bat writes that marker, when it unpacks the bundled emsdk into wasm/emsdk. An Emscripten installed separately and set as EmscriptenPath could therefore never link — BeefBuild reported "Emscripten path not configured" although the path was set. The marker is now required only when EmscriptenPath is the bundled emsdk; any other path is validated by its emcc, with an error naming the missing compiler. install.sh also installs the wasm runtime archives (Beef*RT32_wasm*.a), since BeefBuild links against them from its bin directory.

2. Build the runtime optimized. build_wasm.sh/.bat compiled the runtime with -g and no optimization level, so every wasm32 program — Release included — linked an unoptimized runtime. They now build -O2 by default (release); debug builds -O0 -g for debugging the runtime itself; setup is unchanged; anything else prints usage and fails. Beef042RT32_wasm.a goes from 1.87 MB to 562 KB.

3. Separate debug runtimes, chosen by Beef Lib Type. Every wasm32 program linked the one Beef<ver>RT32_wasm[_pthread].a, so a debug runtime meant rebuilding that archive for every program. The debug runtimes are now their own archives (..._d.a), linked when the project's Beef Lib Type is DynamicDebug — the same setting that selects libBeefRT_d.a on Linux and macOS. BuildContext.GetWasmRtLibName builds the name for both $(LinkFlags) and the pre-link existence check; that check previously only looked for the plain archive, so a threaded project with a missing runtime failed inside emcc instead of with a clear message.

Testing

Checked on Linux with BeefBuild: the default links the optimized runtime, DynamicDebug links _d, a missing runtime is reported by name, and an emsdk path with no marker links. build_wasm.sh was run for release, debug and a bad argument. build_wasm.bat follows the same logic but I have no Windows machine to run it on — worth a look from someone who does.

https://claude.ai/code/session_01DHodcr5rq5c3MTNoUVdaWY

…ntimes

A wasm32 link needed EmsdkDep2_Done.txt in <install>/../wasm for any
configured Emscripten path, but only fetch_wasm.bat (Windows) writes that
marker, when it unpacks the bundled emsdk into wasm/emsdk. So an Emscripten
installed separately and set as EmscriptenPath could never link: BeefBuild
failed with "Emscripten path not configured" although the path was set.

The marker is now required only when EmscriptenPath is the bundled emsdk.
Any other path is checked by its emcc instead, with an error naming the
missing compiler. An empty path still reports that none is configured.

install.sh installs the wasm runtime archives (Beef*RT32_wasm*.a, built by
wasm/build_wasm.sh into IDE/dist) when present, since BeefBuild links wasm32
programs against them in its bin directory.

Checked with BeefBuild on Linux: emsdk path with no marker links; a missing
path reports the emcc it looked for; an empty path still reports it unset.

(cherry picked from commit 6cade8a)
build_wasm.sh and build_wasm.bat compiled the wasm runtime with -g and no
optimization level, so every wasm32 program, Release included, linked an
unoptimized runtime. They now build with -O2 by default ("release"), and
"debug" builds -O0 -g for debugging the runtime itself. "setup" is
unchanged, and anything else prints the usage and fails.

Debug and Release wasm32 configs both link the same Beef<ver>RT32_wasm.a,
so the scripts note that whichever was built last applies to both.

With the release build Beef042RT32_wasm.a is 562 KB instead of 1.87 MB,
and a libsk example's Release .wasm drops from 805 KB to 783 KB. The .sh
was checked on Linux (release, debug, a bad argument); the .bat follows
the same logic but hasn't been run.

(cherry picked from commit 2096eb4)
Every wasm32 program linked the one Beef<ver>RT32_wasm[_pthread].a, so a
debug runtime could only be had by rebuilding that archive, and then it
applied to every program. The debug runtimes are now their own archives,
Beef<ver>RT32_wasm_d.a and Beef<ver>RT32_wasm_pthread_d.a, linked when the
project's Beef Lib Type is DynamicDebug. That's the setting that selects
libBeefRT_d.a on Linux and macOS, so it means the same on every platform;
other settings keep the optimized runtime.

BuildContext.GetWasmRtLibName builds the name for both $(LinkFlags) and
the check before linking. The check used to look only for the plain
archive, so a threaded project whose runtime was missing failed in emcc
instead. Its error now names the missing archive, and the script for the
host (build_wasm.sh outside Windows).

build_wasm.sh and build_wasm.bat build all four archives by default;
"release" or "debug" builds two. install.sh already installs any
Beef*RT32_wasm*.a.

Checked on Linux with BeefBuild: the default links the optimized runtime,
DynamicDebug links _d, and a missing runtime is reported by name. The .bat
follows the same logic but hasn't been run.

(cherry picked from commit de7a9dc)
@bfiete

bfiete commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

I believe this looks correct.

@bfiete
bfiete merged commit fef67a4 into beefytech:master Sep 21, 2026
@bfiete

bfiete commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Ugh that means I need to do another wasm forced release though now I guess.

@bfiete

bfiete commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

We're updated to EmsdkDep3 now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants