Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/tools/ports/emdawnwebgpu.py
4130 views
1
# Copyright 2025 The Emscripten Authors. All rights reserved.
2
# Emscripten is available under two separate licenses, the MIT license and the
3
# University of Illinois/NCSA Open Source License. Both these licenses can be
4
# found in the LICENSE file.
5
6
# https://dawn.googlesource.com/dawn/+/80062b708e44aa4d8c48e555ed0cc801396069f6/src/emdawnwebgpu/pkg/README.md
7
r"""
8
The full README of Emdawnwebgpu follows.
9
10
# Emdawnwebgpu
11
12
Emdawnwebgpu is Dawn's implementation of webgpu.h for Emscripten (on top of the
13
WebGPU JS API). It is a fork of Emscripten's original `USE_WEBGPU` bindings,
14
and while it is maintained in Dawn, it works in any browser supporting WebGPU
15
(modulo individual feature support).
16
17
Emdawnwebgpu provides everything necessary to use `<webgpu/webgpu.h>` and the
18
Dawn-style `<webgpu/webgpu_cpp.h>` with Emscripten.
19
20
<!-- TODO(crbug.com/430616385): Link to a sample project. -->
21
22
If you find an issue in this release, please download the latest Emdawnwebgpu
23
release (see below) and latest Emscripten and verify the bug, then report it at
24
<https://crbug.com/new?component=1570785&noWizard=True>.
25
26
## API Stability
27
28
Core parts of `webgpu.h` (defined in
29
<https://github.com/webgpu-native/webgpu-headers>) are considered stable APIs
30
and should not change, except for bugfixes (though guarantees are not made).
31
Dawn/Emscripten-specific parts, and all of `webgpu_cpp.h`, are **NOT**
32
considered stable, and may change.
33
34
## How to use Emdawnwebgpu
35
36
Emdawnwebgpu is distributed in several ways. Choose the one that works for you.
37
38
In all cases, it is important to enable Closure to reduce code size in release
39
builds. Pass the following flag to `emcc` during linking:
40
41
--closure=1
42
43
### Targeting Web only
44
45
#### Easiest: "Remote" port built into Emscripten
46
47
Recent releases of Emscripten vendor a copy of a "remote" port which
48
automatically downloads a pinned version of Emdawnwebgpu and configures it.
49
50
Pass the following flag to `emcc` during both compilation and linking:
51
52
--use-port=emdawnwebgpu
53
54
#### Latest: "Remote" port from Dawn release
55
56
This is the same as the built-in port, but you can download a newer version if
57
you need recent bugfixes or features in Emdawnwebgpu that haven't been rolled
58
into Emscripten yet. **Requires Emscripten 4.0.10+.**
59
60
Download and extract the `emdawnwebgpu-*.remoteport.py` file from
61
<https://github.com/google/dawn/releases>.
62
63
Pass the following flag to `emcc` during both compilation and linking:
64
65
--use-port=path/to/emdawnwebgpu_remoteport_file.py
66
67
#### Latest, without automatic downloading: "Local" port from Dawn release
68
69
Use this method if your build system requires sources to be local (e.g. checked
70
into your repository) instead of automatically downloaded, or if you use
71
Emscripten before 4.0.10.
72
**Note that Emdawnwebgpu may not work with older Emscripten releases.**
73
74
Download and extract the `emdawnwebgpu_pkg-*.zip` package from
75
<https://github.com/google/dawn/releases>.
76
(Note the package is text-only and does not contain any binaries, but see below
77
if you need to build the package from the original source.)
78
79
Pass the following flag to `emcc` during both compilation and linking:
80
81
--use-port=path/to/emdawnwebgpu_pkg/emdawnwebgpu.port.py
82
83
If (and only if) using Emscripten before 4.0.7, pass this flag during linking:
84
85
--closure-args=--externs=path/to/emdawnwebgpu_pkg/webgpu/src/webgpu-externs.js
86
87
### Cross-targeting Web/Native
88
89
#### Using CMake
90
91
Use this method if your project uses CMake and targets both Emscripten and
92
native platforms.
93
94
<https://developer.chrome.com/docs/web-platform/webgpu/build-app>
95
96
#### Building the package locally to use with a non-CMake project
97
98
If your project already has Dawn source, or you otherwise want to cross-target
99
Web and native with your non-CMake project, you can use CMake to build
100
`emdawnwebgpu_pkg` locally (similar to how you would build binary libraries
101
to link with in native), then use the "Local" port instructions above.
102
103
<https://dawn.googlesource.com/dawn/+/refs/heads/main/src/emdawnwebgpu/README.md>
104
105
## Port options
106
107
Options can be set by appending `:key1=value:key2=value` to `--use-port`.
108
For information about port options, run:
109
110
emcc --use-port=emdawnwebgpu:help
111
emcc --use-port=path/to/emdawnwebgpu_remoteport_file.py:help
112
emcc --use-port=path/to/emdawnwebgpu_pkg/emdawnwebgpu.port.py:help
113
114
### C++ bindings
115
116
By default, C++ bindings are provided in the include path. Note that unlike
117
`webgpu.h`, these are not intended to be fully stable. If you don't want these
118
for any reason (you have custom bindings, you're using a pinned snapshot of
119
`webgpu_cpp.h`, etc.), you can set the option `cpp_bindings=false`:
120
121
--use-port=emdawnwebgpu:cpp_bindings=false
122
--use-port=path/to/emdawnwebgpu_remoteport_file.py:cpp_bindings=false
123
--use-port=path/to/emdawnwebgpu_pkg/emdawnwebgpu.port.py:cpp_bindings=false
124
125
## Embuilder
126
127
If your build process needs a separate step to build the port before linking,
128
use Emscripten's `embuilder`.
129
130
Under `embuilder`, some options cannot be set automatically, so they must be
131
set manually. For details, see `OPTIONS` in `emdawnwebgpu.port.py` (in the
132
package zip).
133
"""
134
135
TAG = 'v20250807.221415'
136
137
EXTERNAL_PORT = f'https://github.com/google/dawn/releases/download/{TAG}/emdawnwebgpu_pkg-{TAG}.zip'
138
SHA512 = 'ab9f3af2536ef3a29c20bb9c69f45b5ee512b8e33fb559f8d0bf4529cd2c11e2fbfb919c3d936e3b32af0e92bd710af71a1700776b5e56c99297cfbc3b73ceec'
139
PORT_FILE = 'emdawnwebgpu_pkg/emdawnwebgpu.port.py'
140
141
# Port information (required)
142
143
# - Visible in emcc --show-ports and emcc --use-port=emdawnwebgpu:help
144
LICENSE = "Some files: BSD 3-Clause License. Other files: Emscripten's license (available under both MIT License and University of Illinois/NCSA Open Source License)"
145
146
# - Visible in emcc --use-port=emdawnwebgpu:help
147
DESCRIPTION = "Emdawnwebgpu implements webgpu.h on WebGPU, replacing -sUSE_WEBGPU. **For info on usage and filing feedback, see link below.**"
148
URL = 'https://dawn.googlesource.com/dawn/+/80062b708e44aa4d8c48e555ed0cc801396069f6/src/emdawnwebgpu/pkg/README.md'
149
150