Skip to content

Commit 10d0d70

Browse files
committed
Add 'web' feature, add missing feature enables/checks.
1 parent 2823d7e commit 10d0d70

File tree

12 files changed

+29
-26
lines changed

12 files changed

+29
-26
lines changed

.github/workflows/ci.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,8 @@ jobs:
269269
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --features glsl,spirv
270270
cargo doc --target ${{ matrix.target }} ${{ matrix.extra-flags }} --no-deps --features glsl,spirv
271271
272-
# check with no features
273-
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --no-default-features
272+
# check with only the web feature
273+
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --no-default-features --features=web
274274
275275
# all features
276276
cargo clippy --target ${{ matrix.target }} ${{ matrix.extra-flags }} --tests --all-features
@@ -481,7 +481,7 @@ jobs:
481481
- name: Execute tests
482482
run: |
483483
cd wgpu
484-
wasm-pack test --headless --chrome --no-default-features --features wgsl,webgl --workspace
484+
wasm-pack test --headless --chrome --no-default-features --features wgsl,webgl,web --workspace
485485
486486
gpu-test:
487487
# runtime is normally 5-15 minutes

examples/standalone/custom_backend/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ edition = "2021"
44
rust-version = "1.84"
55
publish = false
66

7+
[features]
8+
default = ["web"]
9+
web = ["wgpu/web"]
10+
711
[dependencies]
812
wgpu = { version = "25.0.0", features = [
913
"custom",

examples/standalone/custom_backend/src/custom.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl QueueInterface for CustomQueue {
337337
unimplemented!()
338338
}
339339

340-
#[cfg(target_arch = "wasm32")]
340+
#[cfg(all(target_arch = "wasm32", feature = "web"))]
341341
fn copy_external_image_to_texture(
342342
&self,
343343
_source: &wgpu::CopyExternalImageSourceInfo,

wgpu-hal/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ gles = [
118118
"dep:profiling",
119119
"dep:wasm-bindgen",
120120
"dep:web-sys",
121+
"wgpu-types/web",
121122
"windows/Win32_Graphics_OpenGL",
122123
"windows/Win32_Graphics_Gdi",
123124
"windows/Win32_System_LibraryLoader",

wgpu/Cargo.toml

+9-12
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,16 @@ gles = ["wgpu-core?/gles"]
4848

4949
## Enables the WebGPU backend on WebAssembly.
5050
webgpu = [
51+
"web",
5152
"naga?/wgsl-out",
5253
"dep:wasm-bindgen-futures",
53-
"dep:wasm-bindgen",
54-
"dep:js-sys",
55-
"dep:web-sys",
5654
"web-sys/Document",
5755
"web-sys/Event",
5856
"web-sys/Navigator",
5957
"web-sys/NodeList",
6058
"web-sys/Window",
6159
"web-sys/WorkerGlobalScope",
6260
"web-sys/WorkerNavigator",
63-
"wgpu-types/web",
6461
]
6562

6663
#! ### Conditional Backends
@@ -72,14 +69,7 @@ angle = ["wgpu-core?/angle"]
7269
vulkan-portability = ["wgpu-core?/vulkan-portability"]
7370

7471
## Enables the GLES backend on WebAssembly only.
75-
webgl = [
76-
"wgpu-core/webgl",
77-
"dep:wgpu-hal",
78-
"dep:smallvec",
79-
"dep:wasm-bindgen",
80-
"dep:js-sys",
81-
"dep:web-sys",
82-
]
72+
webgl = ["web", "wgpu-core/webgl", "dep:wgpu-hal", "dep:smallvec"]
8373

8474
## Enables the noop backend for testing.
8575
##
@@ -159,6 +149,13 @@ fragile-send-sync-non-atomic-wasm = [
159149
"wgpu-types/fragile-send-sync-non-atomic-wasm",
160150
]
161151

152+
## Use web-specific libraries on WASM
153+
##
154+
## Those libraties (wasm-bindgen, web-sys, js-sys) can only be used when there is a JavaScript
155+
## context around the WASM VM, e.g., when the WASM binary is used in a browser.
156+
web = ["dep:wasm-bindgen", "dep:js-sys", "dep:web-sys", "wgpu-types/web"]
157+
158+
162159
#########################
163160
# Standard Dependencies #
164161
#########################

wgpu/build.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ fn main() {
22
cfg_aliases::cfg_aliases! {
33
native: { not(target_arch = "wasm32") },
44
Emscripten: { all(target_arch = "wasm32", target_os = "emscripten") },
5+
web: { all(target_arch = "wasm32", not(Emscripten), feature = "web") },
56

67
send_sync: { any(
78
native,

wgpu/src/api/instance.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl Instance {
303303
surface
304304
}?,
305305

306-
#[cfg(any(webgpu, webgl))]
306+
#[cfg(web)]
307307
SurfaceTarget::Canvas(canvas) => {
308308
handle_source = None;
309309

@@ -322,7 +322,7 @@ impl Instance {
322322
}?
323323
}
324324

325-
#[cfg(any(webgpu, webgl))]
325+
#[cfg(web)]
326326
SurfaceTarget::OffscreenCanvas(canvas) => {
327327
handle_source = None;
328328

wgpu/src/api/queue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ impl Queue {
232232
}
233233

234234
/// Schedule a copy of data from `image` into `texture`.
235-
#[cfg(any(webgpu, webgl))]
235+
#[cfg(web)]
236236
pub fn copy_external_image_to_texture(
237237
&self,
238238
source: &wgt::CopyExternalImageSourceInfo,

wgpu/src/api/surface.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ pub enum SurfaceTarget<'window> {
243243
///
244244
/// - On WebGL2: surface creation will return an error if the browser does not support WebGL2,
245245
/// or declines to provide GPU access (such as due to a resource shortage).
246-
#[cfg(any(webgpu, webgl))]
246+
#[cfg(web)]
247247
Canvas(web_sys::HtmlCanvasElement),
248248

249249
/// Surface from a `web_sys::OffscreenCanvas`.
@@ -255,7 +255,7 @@ pub enum SurfaceTarget<'window> {
255255
///
256256
/// - On WebGL2: surface creation will return an error if the browser does not support WebGL2,
257257
/// or declines to provide GPU access (such as due to a resource shortage).
258-
#[cfg(any(webgpu, webgl))]
258+
#[cfg(web)]
259259
OffscreenCanvas(web_sys::OffscreenCanvas),
260260
}
261261

wgpu/src/backend/wgpu_core.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ impl dispatch::QueueInterface for CoreQueue {
18451845

18461846
// This method needs to exist if either webgpu or webgl is enabled,
18471847
// but we only actually have an implementation if webgl is enabled.
1848-
#[cfg(any(webgpu, webgl))]
1848+
#[cfg(web)]
18491849
#[cfg_attr(not(webgl), expect(unused_variables))]
18501850
fn copy_external_image_to_texture(
18511851
&self,

wgpu/src/dispatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub trait QueueInterface: CommonTraits {
210210
data_layout: crate::TexelCopyBufferLayout,
211211
size: crate::Extent3d,
212212
);
213-
#[cfg(any(webgpu, webgl))]
213+
#[cfg(web)]
214214
fn copy_external_image_to_texture(
215215
&self,
216216
source: &crate::CopyExternalImageSourceInfo,

wgpu/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,10 @@ pub use wgt::{
9494
pub use wgt::{ImageCopyBuffer, ImageCopyTexture, ImageCopyTextureTagged, ImageDataLayout};
9595
// wasm-only types, we try to keep as many types non-platform
9696
// specific, but these need to depend on web-sys.
97-
#[cfg(any(webgpu, webgl))]
97+
#[cfg(web)]
9898
#[expect(deprecated)]
9999
pub use wgt::ImageCopyExternalImage;
100-
#[cfg(any(webgpu, webgl))]
100+
#[cfg(web)]
101101
pub use wgt::{CopyExternalImageSourceInfo, ExternalImageSource};
102102

103103
/// Re-export of our `naga` dependency.
@@ -119,7 +119,7 @@ pub use raw_window_handle as rwh;
119119

120120
/// Re-export of our `web-sys` dependency.
121121
///
122-
#[cfg(any(webgl, webgpu))]
122+
#[cfg(web)]
123123
pub use web_sys;
124124

125125
#[doc(hidden)]

0 commit comments

Comments
 (0)