Repository navigation
Build prebuilt wasm modules for external C code - #84
Merged
Merged
Conversation
sjoelund
enabled auto-merge (squash)
October 2, 2026 20:29
The wasm-jit target of omc links external "C" code as WebAssembly modules, and an omc without a C compiler (the one in a browser) has no other way to run it. The new `build-wasm` command prebuilds them for every version of every indexed library: omc's `getExternalFunctions` describes a library's external functions, and the package manager compiles their `Include` sources with call wrappers from their C signatures, plus the `Library` names a repos.json `wasm` recipe covers (sources, flags, forced headers, sources kept private, files configured as CMake's `configure_file` does). C++ sources compile against libc++ with WebAssembly exceptions. Everything is built against the package manager's own libc, shipped with each bundle as one libc is loaded per simulation, and for a fixed set of wasm features that wasmtime, wasmer and V8 all run. With the toolchain these make a generation: omc keeps generations side by side and runs a model with the newest one all its libraries have, so a new libc or toolchain is a new generation and every bundle rebuilt, with no change to omc. The libc's sysroot is published as the index's `wasmToolchain`, which omc installs to compile a model's own `Include` sources with, and libc++'s headers and `libc++.so` as its optional `cxx` part, for C++ code. System libraries come from scripts under `wasm/`, once each: as modules of their own (libc++, CPython, netCDF-C, ModelicaSDF, ExternalMediaLib) or as archives with hidden symbols linked into each library using them (HDF5, zlib), so two libraries' HDF5 versions never clash. A version's modules are zipped as `<Library>-wasm32-wasip1-<hash>.zip`, the hash of what they were built from, so versions whose C code did not change share one zip-file; a library without external "C" code gets none. wasmdata.json records what was built, including the functions that did not compile, and a version is built again when its source, its recipe or omc's loader interface changes. `genindex` adds a `wasm` entry per version and the top-level `systemLibraries` and `wasmToolchain`. | Library | What it gets | |----------------|--------------------------------------------------------| | Modelica | the MSL's C libraries of the latest release, for each | | Buildings | `ModelicaBuildingsPython_3_8` over CPython 3.14 | | ExternalMedia | ExternalMediaLib 4.1.1 with CoolProp 6.7.0 | | ExternData | the `ED_*` libraries and their parsers, private HDF5 | | NcDataReader2 | `ncDataReader2` over netCDF-C 4.9.3 | | SDF | ModelicaSDF 0.4.5, private HDF5 and matio | | SystemDynamics | prototypes its sources up to 2.1.2 do not include | libc++ is LLVM 21's, with libc++abi and libunwind in one `libc++.so`; libunwind needs llvm/llvm-project#168449 and no register assembly on wasm. Both CMake projects of ExternalMedia assume a native platform, so its sources and CoolProp's are compiled directly, CoolProp told it is on POSIX. Buildings' `pythonWrapper.c` calls `pythonExchangeValuesNoModelica` without a prototype, which does not link in wasm, so its entry forces one in. WASI has no `dup`, `mkdtemp` or `mktemp`, which the MSL, ExternData and matio get from forced headers, and no `clock` without the emulated process clocks, which CoolProp gets privately. Buildings' FFD needs threads and is left out. The Jenkins image moves to Ubuntu resolute with omc from OpenModelica's nightly packages, which has `getExternalFunctions` once the OpenModelica change adding it is in, also serving updateinfo through OMPython, clang/wasm-ld 21 with the wasm32 compiler-rt, CMake and Python 3.14 for the CPython cross-build; the `cache` stage copies the zip-files to libraries.openmodelica.org/precompiled/wasm32-wasip1. Assisted-by: Claude Opus 5.5
sjoelund
force-pushed
the
wasm-externals
branch
from
October 2, 2026 20:36
2127517 to
8cc8e5a
Compare
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.
The wasm-jit target of omc links external "C" code as WebAssembly modules, and an omc without a C compiler (the one in a browser) has no other way to run it. The new
build-wasmcommand prebuilds them for every version of every indexed library: omc'sgetExternalFunctionsdescribes a library's external functions, and the package manager compiles theirIncludesources with call wrappers from their C signatures, plus theLibrarynames a repos.jsonwasmrecipe covers (sources, flags, forced headers, sources kept private, files configured as CMake'sconfigure_filedoes). C++ sources compile against libc++ with WebAssembly exceptions.Everything is built against the package manager's own libc, shipped with each bundle as one libc is loaded per simulation, and for a fixed set of wasm features that wasmtime, wasmer and V8 all run. With the toolchain these make a generation: omc keeps generations side by side and runs a model with the newest one all its libraries have, so a new libc or toolchain is a new generation and every bundle rebuilt, with no change to omc. The libc's sysroot is published as the index's
wasmToolchain, which omc installs to compile a model's ownIncludesources with, and libc++'s headers andlibc++.soas its optionalcxxpart, for C++ code.System libraries come from scripts under
wasm/, once each: as modules of their own (libc++, CPython, netCDF-C, ModelicaSDF, ExternalMediaLib) or as archives with hidden symbols linked into each library using them (HDF5, zlib), so two libraries' HDF5 versions never clash.A version's modules are zipped as
<Library>-wasm32-wasip1-<hash>.zip, the hash of what they were built from, so versions whose C code did not change share one zip-file; a library without external "C" code gets none. wasmdata.json records what was built, including the functions that did not compile, and a version is built again when its source, its recipe or omc's loader interface changes.genindexadds awasmentry per version and the top-levelsystemLibrariesandwasmToolchain.ModelicaBuildingsPython_3_8over CPython 3.14ED_*libraries and their parsers, private HDF5ncDataReader2over netCDF-C 4.9.3libc++ is LLVM 21's, with libc++abi and libunwind in one
libc++.so; libunwind needs llvm/llvm-project#168449 and no register assembly on wasm. Both CMake projects of ExternalMedia assume a native platform, so its sources and CoolProp's are compiled directly, CoolProp told it is on POSIX. Buildings'pythonWrapper.ccallspythonExchangeValuesNoModelicawithout a prototype, which does not link in wasm, so its entry forces one in. WASI has nodup,mkdtempormktemp, which the MSL, ExternData and matio get from forced headers, and noclockwithout the emulated process clocks, which CoolProp gets privately. Buildings' FFD needs threads and is left out.The Jenkins image moves to Ubuntu resolute with omc from OpenModelica's nightly packages, which has
getExternalFunctionsonce the OpenModelica change adding it is in, also serving updateinfo through OMPython, clang/wasm-ld 21 with the wasm32 compiler-rt, CMake and Python 3.14 for the CPython cross-build; thecachestage copies the zip-files to libraries.openmodelica.org/precompiled/wasm32-wasip1.Assisted-by: Claude Opus 5.5