Fix WASM build issues, improve test coverage and improve cmake files

* Ensure compiler.usethread=0 is set before compilation in single-threaded WASM builds
* Explicitly enable exceptions for the single-threaded WASM module
* Test the single-threaded module in addition to the multi-threaded module in internal and external CI
* Consolidate wasm/tests/CMakeLists.txt into wasm/CMakeLists.txt, fixing the single-threaded benchmark test build which was missing shared linker flags

PiperOrigin-RevId: 901149728
Change-Id: If4946e29e5116610782d218906cf3f5940c1cdd0
This commit is contained in:
Matija Kecman
2026-04-17 01:28:40 -07:00
committed by Copybara-Service
parent f91ce9a627
commit c23b5e8420
5 changed files with 78 additions and 87 deletions
+14
View File
@@ -4967,6 +4967,20 @@ void mjCModel::ResolveKeyframes(const mjModel* m) {
}
void mjCModel::TryCompile(mjModel*& m, mjData*& d, const mjVFS* vfs) {
#if defined(__EMSCRIPTEN__) && !defined(MUJOCO_WASM_THREADS)
// The MuJoCo compiler defaults to usethread=1, which causes it to try to
// create pthreads for compilation. In the single-threaded WASM build, this
// crashes because there is no threading support, so we disable threading on
// the internal compiler struct (not the spec) to avoid permanently mutating
// the spec (which would cause usethread="false" to appear in a saved XML).
struct ScopedDisableThreading {
mjtByte& ref;
mjtByte saved;
explicit ScopedDisableThreading(mjtByte& r) : ref(r), saved(r) { ref = 0; }
~ScopedDisableThreading() { ref = saved; }
} disable_usethread(compiler.usethread);
#endif
// check if nan test works
double test = mjNAN;
if (mjuu_defined(test)) {