wasm: configurable Emscripten, an optimized runtime, and separate debug runtimes - #2523
Merged
Merged
Conversation
…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)
Collaborator
|
I believe this looks correct. |
Collaborator
|
Ugh that means I need to do another wasm forced release though now I guess. |
Collaborator
|
We're updated to EmsdkDep3 now... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.txtin<install>/../wasmfor any configured Emscripten path, but onlyfetch_wasm.batwrites that marker, when it unpacks the bundled emsdk intowasm/emsdk. An Emscripten installed separately and set asEmscriptenPathcould therefore never link — BeefBuild reported "Emscripten path not configured" although the path was set. The marker is now required only whenEmscriptenPathis the bundled emsdk; any other path is validated by itsemcc, with an error naming the missing compiler.install.shalso 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/.batcompiled the runtime with-gand no optimization level, so every wasm32 program — Release included — linked an unoptimized runtime. They now build-O2by default (release);debugbuilds-O0 -gfor debugging the runtime itself;setupis unchanged; anything else prints usage and fails.Beef042RT32_wasm.agoes 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 isDynamicDebug— the same setting that selectslibBeefRT_d.aon Linux and macOS.BuildContext.GetWasmRtLibNamebuilds 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 insideemccinstead of with a clear message.Testing
Checked on Linux with BeefBuild: the default links the optimized runtime,
DynamicDebuglinks_d, a missing runtime is reported by name, and an emsdk path with no marker links.build_wasm.shwas run forrelease,debugand a bad argument.build_wasm.batfollows 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