blob: efd6491cd686b2b345a4c43a8ef974e43aca4e6f [file] [log] [blame] [view]
Loko Kung90fdaa82024-07-24 00:59:58 +00001# Dawn Emscripten Fork
2
Kai Ninomiya11784002024-07-03 19:46:03 +00003Dawn temporarily maintains a fork of the Emscripten WebGPU bindings
4(`library_webgpu.js` and friends). The forked files live in
5[`//third_party/emdawnwebgpu`](../third_party/emdawnwebgpu/)
6and the build targets in this directory produce the other files needed to build
7an Emscripten-based project using these bindings.
8
9This allows the the webgpu.h interface to be kept roughly in sync\* between the
10two implementations in a single place (the Dawn repository) instead of two,
11while also avoiding constantly breaking the version of webgpu.h that is
12currently in Emscripten. (\* Note we don't guarantee it will always be in sync,
13though - we don't have any automated testing for this, so we'll periodically fix
14it up as needed for import into other projects that use these bindings.)
15
16Changes to this code in the Dawn repository will be synced back out to the
17upstream Emscripten repository after webgpu.h becomes stable, in what should
18theoretically be one big final breaking update. Between then and now, projects
Loko Kung90fdaa82024-07-24 00:59:58 +000019can use Dawn's fork of the bindings.
20
21## Setting up Emscripten
Kai Ninomiya11784002024-07-03 19:46:03 +000022
23- Get an emsdk toolchain:
24 [instructions](https://emscripten.org/docs/getting_started/downloads.html#installation-instructions-using-the-emsdk-recommended).
25
26- Get a separate source checkout of [Emscripten](https://github.com/emscripten-core/emscripten)
27 and set it up to point at the toolchain from emsdk by creating a file at `emscripten/.emscripten`:
28
29 ```
30 LLVM_ROOT = '/path/to/emsdk/upstream/bin'
31 BINARYEN_ROOT = '/path/to/emsdk/upstream'
32 NODE_JS = '/path/to/emsdk/node/18.20.3_64bit/bin/node'
33 ```
34
35 Note this must be a source checkout of Emscripten,
36 not emsdk's `upstream/emscripten` release, which excludes necessary tools.
37
dan sinclair0ee0afa2024-10-22 22:58:25 +000038
39- Make sure you run the `./bootstrap` in the `emscripten` folder to make sure node is setup.
40
Loko Kung90fdaa82024-07-24 00:59:58 +000041## Building Dawn Emscripten bindings with GN
42
Kai Ninomiya11784002024-07-03 19:46:03 +000043- Set up a Dawn GN build, with `dawn_emscripten_dir` in the GN args set to point to
44 your Emscripten source checkout.
45
Jaswant Panchumarti36af7622024-07-15 21:03:05 +000046- Build the `emdawnwebgpu` GN build target.
Kai Ninomiya11784002024-07-03 19:46:03 +000047
Jaswant Panchumarti36af7622024-07-15 21:03:05 +000048- Configure the Emscripten build with all of the linker flags listed in `emdawnwebgpu_config`
Kai Ninomiya11784002024-07-03 19:46:03 +000049 (and without `-sUSE_WEBGPU`, because we don't want the built-in bindings).
Loko Kung90fdaa82024-07-24 00:59:58 +000050
51## Building Dawn Emscripten bindings and samples with CMake
52
53Set up the build directory using emcmake
54
55```
56mkdir out/cmake-wasm
57cd out/cmake-wasm
58
59# Make sure the path is to the source checkout of Emscripten, not emsdk's release.
60emcmake cmake -GNinja -DDAWN_EMSCRIPTEN_TOOLCHAIN="path/to/emscripten" ../..
61
62ninja
63
64# The resulting html files can then be served and viewed in a compatible Browser.
65
dan sinclair0ee0afa2024-10-22 22:58:25 +000066```