From f9454d156566615931d1d2bf6879599527d30246 Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Sun, 21 Jan 2024 14:36:29 +1100 Subject: [PATCH] Error on missing web_sys_unstable_apis (#5104) --- .cargo/config.toml | 3 +++ .github/workflows/ci.yml | 2 +- wgpu/src/backend/mod.rs | 18 ++++++++++++++++-- wgpu/src/lib.rs | 4 ++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/.cargo/config.toml b/.cargo/config.toml index b75130124b..8434ec2cc6 100644 --- a/.cargo/config.toml +++ b/.cargo/config.toml @@ -5,3 +5,6 @@ xtask = "run --manifest-path xtask/Cargo.toml" rustflags = [ "--cfg=web_sys_unstable_apis" ] +rustdocflags = [ +"--cfg=web_sys_unstable_apis" +] diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 48a67b7926..6bb8d38245 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -56,7 +56,7 @@ env: RUST_BACKTRACE: full PKG_CONFIG_ALLOW_CROSS: 1 # allow android to work RUSTFLAGS: --cfg=web_sys_unstable_apis -D warnings - RUSTDOCFLAGS: -Dwarnings + RUSTDOCFLAGS: --cfg=web_sys_unstable_apis -D warnings WASM_BINDGEN_TEST_TIMEOUT: 300 # 5 minutes CACHE_SUFFIX: c # cache busting diff --git a/wgpu/src/backend/mod.rs b/wgpu/src/backend/mod.rs index 02d9632efb..9a0b7ef28a 100644 --- a/wgpu/src/backend/mod.rs +++ b/wgpu/src/backend/mod.rs @@ -1,9 +1,23 @@ -#[cfg(webgpu)] +#[cfg(all(webgpu, web_sys_unstable_apis))] mod webgpu; -#[cfg(webgpu)] +#[cfg(all(webgpu, web_sys_unstable_apis))] pub(crate) use webgpu::{get_browser_gpu_property, ContextWebGpu}; +#[cfg(all(webgpu, not(web_sys_unstable_apis)))] +compile_error!( + "webgpu feature used without web_sys_unstable_apis config: +Here are some ways to resolve this: +* If you wish to use webgpu backend, create a .cargo/config.toml in the root of the repo containing: + [build] + rustflags = [ \"--cfg=web_sys_unstable_apis\" ] + rustdocflags = [ \"--cfg=web_sys_unstable_apis\" ] +* If you wish to disable webgpu backend and instead use webgl backend, change your wgpu Cargo.toml entry to: + wgpu = { version = \"\", default-features = false, features = [\"webgl\"] } +" +); + #[cfg(wgpu_core)] mod wgpu_core; + #[cfg(wgpu_core)] pub(crate) use wgpu_core::ContextWgpuCore; diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index e94d45561f..a7dc98fff8 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -1812,7 +1812,7 @@ impl Instance { ); } - #[cfg(webgpu)] + #[cfg(all(webgpu, web_sys_unstable_apis))] { let is_only_available_backend = !cfg!(wgpu_core); let requested_webgpu = _instance_desc.backends.contains(Backends::BROWSER_WEBGPU); @@ -3086,7 +3086,7 @@ impl<'a> BufferSlice<'a> { /// this function directly hands you the ArrayBuffer that we mapped the data into in js. /// /// This is only available on WebGPU, on any other backends this will return `None`. - #[cfg(webgpu)] + #[cfg(all(webgpu, web_sys_unstable_apis))] pub fn get_mapped_range_as_array_buffer(&self) -> Option { self.buffer .context