Skip to content

Commit

Permalink
Add emscripten build
Browse files Browse the repository at this point in the history
This closes shader-slang#5115.
  • Loading branch information
aleino-nv committed Sep 25, 2024
1 parent 5857c74 commit fd0dbc8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
18 changes: 18 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,16 @@
"CMAKE_MSVC_RUNTIME_LIBRARY": "MultiThreaded$<$<CONFIG:Debug>:Debug>"
}
},
{
"name": "emscripten",
"description": "Emscripten-based Wasm build",
"generator": "ninja",
"binaryDir": "${sourceDir}/build.em",
"cacheVariables": {
"SLANG_SLANG_LLVM_FLAVOR": "DISABLE",
"CMAKE_EXE_LINKER_FLAGS": "-sASSERTIONS -sALLOW_MEMORY_GROWTH"
}
},
{
"name": "msvc-base",
"hidden": true,
Expand Down Expand Up @@ -74,6 +84,14 @@
"configurePreset": "default",
"configuration": "Release"
},
{
"name": "emscripten",
"configurePreset": "emscripten",
"configuration": "Release",
"targets": [
"slang"
]
},
{
"name": "generators",
"inherits": "release",
Expand Down
14 changes: 14 additions & 0 deletions docs/building.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fd0dbc8

Please sign in to comment.