From f5bf5ba5170058f9a9634438f7ff06f1a02e1da6 Mon Sep 17 00:00:00 2001 From: Anders Leino Date: Wed, 25 Sep 2024 10:24:51 +0300 Subject: Enable emscripten builds to compile slang.dll to WebAssembly. (#5131) * Compile fixes for Wasm The issues are all are due to 'long' types being 32 bits on WASM. - class members redeclared errors - << with StringBuilder and unsigned long is ambiguous This helps to address issue #5115. * Use the host executable suffix for generators Since the generators are run at build-time, we should not use CMAKE_EXECUTABLE_SUFFIX, which is the suffix for the target platform. Instead, define CMAKE_HOST_EXECUTABLE_SUFFIX as appropriate, and use that suffix instead. This helps to address issue #5115. * Add support for Wasm as a platform This helps to address issue #5115. * Add emscripten build This closes #5115. --- docs/building.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'docs/building.md') diff --git a/docs/building.md b/docs/building.md index d86b80205..8bc20acb3 100644 --- a/docs/building.md +++ b/docs/building.md @@ -47,6 +47,20 @@ cmake --build --preset release # to build from the CLI The `vs2022-dev` preset turns on features that makes debugging easy. +### WebAssembly build + +First do a native build of the `all-generators` target, so that you get the generator executables in a path like `build\generators\Debug\bin` under the +Slang source tree. + +For an [emscripten](https://emscripten.org) -based build targeting [WebAssembly](https://webassembly.org), run: +```bash +emcmake cmake -DSLANG_GENERATORS_PATH=%SLANG_SRC_PATH%\build\generators\Debug\bin --preset emscripten -G "Ninja" +cmake --build --preset emscripten --target slang +``` + +**Note:** `emcmake` is a `cmake` wrapper that comes with [`emsdk`](https://emscripten.org/docs/getting_started/downloads.html), it will wrap your `cmake` calls with setup options that add support for emscripten. +**Note:** If this fails, try running the command that `emcmake` outputs, directly. + ## Testing ```bash -- cgit v1.2.3