Changes

Jump to: navigation, search

Mujoco WASM Build From Source

597 bytes added, 22:29, 22 July 2024
no edit summary
You could also run git show to see specific changes that have been made to the original mujoco 3.1.6. files e.g. ,5c4b86b > changes.txt
As of this writing, you'd need have to disable several features of 3.1.6 to allow for a successful WASM build.
* ==== Specific ideas for changes ====As of this writing, you'd need to disable several features of 3.1.6 to allow for a successful WASM build. For example in CMakeLists.txt, the options to build examples, simulate library, and tests for MuJoCo have been turned off by default (changed from ON to OFF). New configurations and target properties for building MuJoCo with Emscripten have been added. This includes defining source files, checking their existence, and setting specific properties and options for building WebAssembly (.wasm) and HTML output. Some target link options have been adjusted, including removing the lodepng library from the target link list. * `src/user/user_objects.cc`, comment out the line that includes `lodepng.h`. Replace the bodies of the `mjCHField::LoadPNG` and `mjCTexture::LoadPNG` functions with a single return statement.* * `src/engine/engine_util_errmem.c`, update the preprocessor condition in the `mju_writeLog` function by replacing `__STDC_VERSION_TIME_H__` with `__EMSCRIPTEN__` in the `#if` directive. The line should now include `__EMSCRIPTEN__` in the condition.
*
* In `src/userengine/user_objectsengine_crossplatform.cc comment out h`, add a conditional block specifically for Emscripten within the line that includes lodepngpreprocessor directive. Inside this block, include the `sort_r.h` header and define the `mjQUICKSORT` and `quicksortfunc` macros appropriately. Replace the bodies of This will separate the mjCHField::LoadPNG handling for Apple, Emscripten, and mjCTexture::LoadPNG functions with a single return statementother platforms.
*
* In src/engine`cmake/engine_util_errmemMujocoOptions.c update cmake` file, remove the preprocessor condition `-Wno-int-in -bool-context` compiler warning flag from the mju_writeLog function by replacing __STDC_VERSION_TIME_H__ with __EMSCRIPTEN__ in list of warnings. In the #if directive`CMakeLists. The line should now include __EMSCRIPTEN__ in txt` file, make the following changes:* Change the default values of the options to disable the conditionbuilding of examples, simulate library, tests, and Python utility libraries by setting them to OFF: * Set `MUJOCO_BUILD_EXAMPLES` to OFF. *Set `MUJOCO_BUILD_SIMULATE` to OFF. * In src/engine/engine_crossplatformSet `MUJOCO_BUILD_TESTS` to OFF. * Set `MUJOCO_TEST_PYTHON_UTIL` to OFF.h add a conditional block specifically * Remove the `lodepng` library from the `target_link_libraries` list for Emscripten within the preprocessor directive `mujoco` target. Also, for example, in the engine_crossplatform`mjxmacro.h file. Inside this block`, include the sort_r.h header and define add explicit casting to `size_t` for the mjQUICKSORT calculations of `key_mpos` and quicksortfunc macros appropriately. This will separate the handling for Apple, Emscripten`key_mquat` array sizes, ensuring correct memory allocation and other platformspreventing potential integer overflow issues.
Also, for example in mjxmacro.h you have to involve adding explicit casting to size_t for the calculations of key_mpos and key_mquat array sizes, ensuring correct memory allocation and preventing potential integer overflow issues.
We'd suggest taking a look at https://github.com/stillonearth/MuJoCo-WASM/issues/1 (older 2.3.1 build but still relevant)
emmake make
</syntaxhighlight>
 
 
=== Notes ===
* Ensure that the Emscripten environment is correctly activated before starting the build process.
* Regularly clean the build directory to maintain a clean build environment.

Navigation menu