Skip to content

Commit f9454d1

Browse files
rukaicwfitzgerald
authored andcommitted
Error on missing web_sys_unstable_apis (gfx-rs#5104)
1 parent e1481b6 commit f9454d1

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

.cargo/config.toml

+3
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@ xtask = "run --manifest-path xtask/Cargo.toml"
55
rustflags = [
66
"--cfg=web_sys_unstable_apis"
77
]
8+
rustdocflags = [
9+
"--cfg=web_sys_unstable_apis"
10+
]

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ env:
5656
RUST_BACKTRACE: full
5757
PKG_CONFIG_ALLOW_CROSS: 1 # allow android to work
5858
RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings
59-
RUSTDOCFLAGS: -Dwarnings
59+
RUSTDOCFLAGS: --cfg=web_sys_unstable_apis -D warnings
6060
WASM_BINDGEN_TEST_TIMEOUT: 300 # 5 minutes
6161
CACHE_SUFFIX: c # cache busting
6262

wgpu/src/backend/mod.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
#[cfg(webgpu)]
1+
#[cfg(all(webgpu, web_sys_unstable_apis))]
22
mod webgpu;
3-
#[cfg(webgpu)]
3+
#[cfg(all(webgpu, web_sys_unstable_apis))]
44
pub(crate) use webgpu::{get_browser_gpu_property, ContextWebGpu};
55

6+
#[cfg(all(webgpu, not(web_sys_unstable_apis)))]
7+
compile_error!(
8+
"webgpu feature used without web_sys_unstable_apis config:
9+
Here are some ways to resolve this:
10+
* If you wish to use webgpu backend, create a .cargo/config.toml in the root of the repo containing:
11+
[build]
12+
rustflags = [ \"--cfg=web_sys_unstable_apis\" ]
13+
rustdocflags = [ \"--cfg=web_sys_unstable_apis\" ]
14+
* If you wish to disable webgpu backend and instead use webgl backend, change your wgpu Cargo.toml entry to:
15+
wgpu = { version = \"\", default-features = false, features = [\"webgl\"] }
16+
"
17+
);
18+
619
#[cfg(wgpu_core)]
720
mod wgpu_core;
21+
822
#[cfg(wgpu_core)]
923
pub(crate) use wgpu_core::ContextWgpuCore;

wgpu/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1812,7 +1812,7 @@ impl Instance {
18121812
);
18131813
}
18141814

1815-
#[cfg(webgpu)]
1815+
#[cfg(all(webgpu, web_sys_unstable_apis))]
18161816
{
18171817
let is_only_available_backend = !cfg!(wgpu_core);
18181818
let requested_webgpu = _instance_desc.backends.contains(Backends::BROWSER_WEBGPU);
@@ -3086,7 +3086,7 @@ impl<'a> BufferSlice<'a> {
30863086
/// this function directly hands you the ArrayBuffer that we mapped the data into in js.
30873087
///
30883088
/// This is only available on WebGPU, on any other backends this will return `None`.
3089-
#[cfg(webgpu)]
3089+
#[cfg(all(webgpu, web_sys_unstable_apis))]
30903090
pub fn get_mapped_range_as_array_buffer(&self) -> Option<js_sys::ArrayBuffer> {
30913091
self.buffer
30923092
.context

0 commit comments

Comments
 (0)