From f4e0d264ccc25745adff4c59555859bd59745994 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Sun, 19 Jan 2025 11:25:16 +0100 Subject: [PATCH 1/6] Use crate indirections to enable feature depending on platforms --- Cargo.lock | 24 ++++++ Cargo.toml | 9 +++ wgpu-core-conditional/arch-wasm32/Cargo.toml | 18 +++++ wgpu-core-conditional/arch-wasm32/src/lib.rs | 1 + .../native-non-apple/Cargo.toml | 22 ++++++ .../native-non-apple/src/lib.rs | 1 + wgpu-core-conditional/vendor-apple/Cargo.toml | 22 ++++++ wgpu-core-conditional/vendor-apple/src/lib.rs | 1 + wgpu-core/src/lib.rs | 4 +- wgpu/Cargo.toml | 76 ++++++++----------- wgpu/build.rs | 20 ++++- wgpu/src/api/instance.rs | 52 ++++--------- wgpu/src/backend/wgpu_core.rs | 4 +- wgpu/src/lib.rs | 2 +- wgpu/src/util/init.rs | 4 +- 15 files changed, 168 insertions(+), 92 deletions(-) create mode 100644 wgpu-core-conditional/arch-wasm32/Cargo.toml create mode 100644 wgpu-core-conditional/arch-wasm32/src/lib.rs create mode 100644 wgpu-core-conditional/native-non-apple/Cargo.toml create mode 100644 wgpu-core-conditional/native-non-apple/src/lib.rs create mode 100644 wgpu-core-conditional/vendor-apple/Cargo.toml create mode 100644 wgpu-core-conditional/vendor-apple/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index b66579b839..5eafd1d66e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4027,6 +4027,9 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "wgpu-core", + "wgpu-core-if-arch-wasm32", + "wgpu-core-if-native-non-apple", + "wgpu-core-if-vendor-apple", "wgpu-hal", "wgpu-types", ] @@ -4074,6 +4077,27 @@ dependencies = [ "wgpu-types", ] +[[package]] +name = "wgpu-core-if-arch-wasm32" +version = "24.0.0" +dependencies = [ + "wgpu-core", +] + +[[package]] +name = "wgpu-core-if-native-non-apple" +version = "24.0.0" +dependencies = [ + "wgpu-core", +] + +[[package]] +name = "wgpu-core-if-vendor-apple" +version = "24.0.0" +dependencies = [ + "wgpu-core", +] + [[package]] name = "wgpu-example-01-hello-compute" version = "0.0.0" diff --git a/Cargo.toml b/Cargo.toml index 5e5efd0513..5345f812dc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,6 +21,9 @@ members = [ "wgpu-macros", "wgpu-types", "wgpu", + "wgpu-core-conditional/arch-wasm32", + "wgpu-core-conditional/native-non-apple", + "wgpu-core-conditional/vendor-apple", ] exclude = [] default-members = [ @@ -40,6 +43,9 @@ default-members = [ "wgpu-macros", "wgpu-types", "wgpu", + "wgpu-core-conditional/arch-wasm32", + "wgpu-core-conditional/native-non-apple", + "wgpu-core-conditional/vendor-apple", ] [workspace.lints.clippy] @@ -66,6 +72,9 @@ wgpu = { version = "24.0.0", path = "./wgpu", default-features = false, features "static-dxc", ] } wgpu-core = { version = "24.0.0", path = "./wgpu-core" } +wgpu-core-if-arch-wasm32 = { version = "24.0.0", path = "./wgpu-core-conditional/arch-wasm32" } +wgpu-core-if-native-non-apple = { version = "24.0.0", path = "./wgpu-core-conditional/native-non-apple" } +wgpu-core-if-vendor-apple = { version = "24.0.0", path = "./wgpu-core-conditional/vendor-apple" } wgpu-hal = { version = "24.0.0", path = "./wgpu-hal" } wgpu-macros = { version = "24.0.0", path = "./wgpu-macros" } wgpu-test = { version = "24.0.0", path = "./tests" } diff --git a/wgpu-core-conditional/arch-wasm32/Cargo.toml b/wgpu-core-conditional/arch-wasm32/Cargo.toml new file mode 100644 index 0000000000..654235a387 --- /dev/null +++ b/wgpu-core-conditional/arch-wasm32/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "wgpu-core-if-arch-wasm32" +version.workspace = true +authors.workspace = true +edition.workspace = true +description = "Workaround crate for enabling features in wgpu-core when targeting wasm32" +homepage.workspace = true +repository.workspace = true +keywords.workspace = true +license.workspace = true + +[lib] + +[features] +gles = ["wgpu-core/gles"] + +[target.'cfg(target_arch = "wasm32")'.dependencies] +wgpu-core.workspace = true diff --git a/wgpu-core-conditional/arch-wasm32/src/lib.rs b/wgpu-core-conditional/arch-wasm32/src/lib.rs new file mode 100644 index 0000000000..174c77f96a --- /dev/null +++ b/wgpu-core-conditional/arch-wasm32/src/lib.rs @@ -0,0 +1 @@ +//! No code. See README.md for details. diff --git a/wgpu-core-conditional/native-non-apple/Cargo.toml b/wgpu-core-conditional/native-non-apple/Cargo.toml new file mode 100644 index 0000000000..21182ce72a --- /dev/null +++ b/wgpu-core-conditional/native-non-apple/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "wgpu-core-if-native-non-apple" +version.workspace = true +authors.workspace = true +edition.workspace = true +description = "Workaround crate for enabling features in wgpu-core when targeting macOS/iOS" +homepage.workspace = true +repository.workspace = true +keywords.workspace = true +license.workspace = true + +[lib] + +[features] +gles = ["wgpu-core/gles"] +renderdoc = ["wgpu-core/renderdoc"] +vulkan = ["wgpu-core/vulkan"] + +raw-window-handle = ["wgpu-core/raw-window-handle"] + +[target.'cfg(any(windows, all(unix, not(target_arch = "wasm32"), not(target_vendor = "apple"))))'.dependencies] +wgpu-core.workspace = true diff --git a/wgpu-core-conditional/native-non-apple/src/lib.rs b/wgpu-core-conditional/native-non-apple/src/lib.rs new file mode 100644 index 0000000000..174c77f96a --- /dev/null +++ b/wgpu-core-conditional/native-non-apple/src/lib.rs @@ -0,0 +1 @@ +//! No code. See README.md for details. diff --git a/wgpu-core-conditional/vendor-apple/Cargo.toml b/wgpu-core-conditional/vendor-apple/Cargo.toml new file mode 100644 index 0000000000..17a7c6a377 --- /dev/null +++ b/wgpu-core-conditional/vendor-apple/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "wgpu-core-if-vendor-apple" +version.workspace = true +authors.workspace = true +edition.workspace = true +description = "Workaround crate for enabling features in wgpu-core when targeting macOS/iOS" +homepage.workspace = true +repository.workspace = true +keywords.workspace = true +license.workspace = true + +[lib] + +[features] +gles = ["wgpu-core/gles"] +metal = ["wgpu-core/metal"] +vulkan = ["wgpu-core/vulkan"] + +raw-window-handle = ["wgpu-core/raw-window-handle"] + +[target.'cfg(target_vendor = "apple")'.dependencies] +wgpu-core.workspace = true diff --git a/wgpu-core-conditional/vendor-apple/src/lib.rs b/wgpu-core-conditional/vendor-apple/src/lib.rs new file mode 100644 index 0000000000..174c77f96a --- /dev/null +++ b/wgpu-core-conditional/vendor-apple/src/lib.rs @@ -0,0 +1 @@ +//! No code. See README.md for details. diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 47aaa87a51..0d0957c7df 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -56,8 +56,8 @@ // (the only reason to use wgpu-core on the web in the first place) that have atomics enabled. #![cfg_attr(not(send_sync), allow(clippy::arc_with_non_send_sync))] -extern crate wgpu_hal as hal; -extern crate wgpu_types as wgt; +pub extern crate wgpu_hal as hal; +pub extern crate wgpu_types as wgt; pub mod binding_model; pub mod command; diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 5f70401579..456d0cc2d8 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -28,33 +28,40 @@ ignored = ["cfg_aliases"] [lib] [features] -default = ["wgsl", "dx12", "metal", "webgpu"] +default = ["wgsl", "dx12", "metal", "vulkan", "gles", "webgpu"] #! ### Backends # -------------------------------------------------------------------- -#! ⚠️ WIP: Not all backends can be manually configured today. -#! On Windows, Linux & Android the Vulkan & GLES backends are always enabled. -#! See [#3514](https://github.com/gfx-rs/wgpu/issues/3514) for more details. ## Enables the DX12 backend on Windows. -dx12 = ["wgpu-core?/dx12"] +# Dx12 doesn't do anything on non-windows wgpu-core & wgpu-hal, so we don't need a proxy crate here. +dx12 = ["wgpu-core/dx12"] ## Enables the Metal backend on macOS & iOS. -metal = ["wgpu-core?/metal"] +# Metal doesn't do anything on non-Apple wgpu-core & wgpu-hal, but we already have a proxy crate for Apple platforms anyways. +metal = ["wgpu-core-if-vendor-apple/metal"] -## Enables the WebGPU backend on Wasm. Disabled when targeting `emscripten`. -webgpu = ["naga?/wgsl-out"] - -## Enables the GLES backend via [ANGLE](https://github.com/google/angle) on macOS using. -angle = ["wgpu-core?/gles"] +## Enables the Vulkan backend on Windows, Linux, and Android. +## +## For enabling Vulkan on macOS & iOS, use the `vulkan-portability` feature. +vulkan = ["wgpu-core-if-native-non-apple/vulkan"] ## Enables the Vulkan backend on macOS & iOS. -vulkan-portability = ["wgpu-core?/vulkan"] +vulkan-portability = ["wgpu-core-if-vendor-apple/vulkan"] -## Enables the GLES backend on Wasm +## Enables the OpenGL/GLES backend on Windows, Linux, and Android. ## -## * ⚠️ WIP: Currently will also enable GLES dependencies on any other targets. -webgl = ["dep:wgpu-hal", "wgpu-core/gles"] +## For enabling WebGL use the `webgl` feature, for enabling OpenGL via ANGLE on macOS use the `angle` feature. +gles = ["wgpu-core-if-native-non-apple/gles"] + +## Enables the GLES backend via [ANGLE](https://github.com/google/angle) on macOS using. +angle = ["wgpu-core-if-vendor-apple/gles"] + +## Enables GLES backend (WebGL) on Wasm +webgl = ["wgpu-core-if-arch-wasm32/gles"] + +## Enables the WebGPU backend on Wasm. Disabled when targeting `emscripten`. +webgpu = ["naga?/wgsl-out"] #! **Note:** In the documentation, if you see that an item depends on a backend, #! it means that the item is only available when that backend is enabled _and_ the backend @@ -134,8 +141,11 @@ static-dxc = ["wgpu-hal/static-dxc"] [dependencies] naga = { workspace = true, optional = true } -wgpu-core = { workspace = true, optional = true } +wgpu-core = { workspace = true, optional = true, features = [ + "raw-window-handle", +] } wgpu-types = { workspace = true, features = ["serde"] } +wgpu-hal = { workspace = true, optional = true, features = ["renderdoc"] } arrayvec.workspace = true bitflags.workspace = true @@ -148,40 +158,16 @@ serde = { workspace = true, features = ["default", "derive"], optional = true } smallvec.workspace = true static_assertions.workspace = true +wgpu-core-if-arch-wasm32 = { workspace = true, optional = true } +wgpu-core-if-native-non-apple = { workspace = true, optional = true } +wgpu-core-if-vendor-apple = { workspace = true, optional = true } + + ######################################## # Target Specific Feature Dependencies # ######################################## - -# Windows -[target.'cfg(windows)'.dependencies] -wgpu-core = { workspace = true, features = [ - "raw-window-handle", - "vulkan", - "gles", -] } -wgpu-hal = { workspace = true, features = ["renderdoc"] } - -# Apple Platforms -[target.'cfg(target_vendor = "apple")'.dependencies] -wgpu-core = { workspace = true, features = ["raw-window-handle"] } -wgpu-hal = { workspace = true, features = [] } - -# Linux + Android -[target.'cfg(any(target_os = "linux", target_os = "android"))'.dependencies] -wgpu-core = { workspace = true, features = [ - "raw-window-handle", - "vulkan", - "gles", -] } -wgpu-hal = { workspace = true, features = ["renderdoc"] } - # Webassembly [target.'cfg(all(target_arch = "wasm32", not(target_os = "emscripten")))'.dependencies] -wgpu-core = { workspace = true, optional = true, features = [ - "raw-window-handle", -] } -wgpu-hal = { workspace = true, optional = true } - js-sys = { workspace = true, features = ["default"] } parking_lot.workspace = true wasm-bindgen-futures.workspace = true diff --git a/wgpu/build.rs b/wgpu/build.rs index d853281dfa..9c8feab72d 100644 --- a/wgpu/build.rs +++ b/wgpu/build.rs @@ -1,16 +1,30 @@ fn main() { cfg_aliases::cfg_aliases! { native: { not(target_arch = "wasm32") }, - webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgl") }, - webgpu: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgpu") }, Emscripten: { all(target_arch = "wasm32", target_os = "emscripten") }, - wgpu_core: { any(native, webgl, Emscripten) }, send_sync: { any( not(target_arch = "wasm32"), all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics")) ) }, + + webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgl") }, + webgpu: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgpu") }, dx12: { all(target_os = "windows", feature = "dx12") }, metal: { all(target_vendor = "apple", feature = "metal") }, + vulkan: { + any(all(feature = "vulkan-portability", target_vendor = "apple"), + all(feature = "vulkan", native, not(target_vendor = "apple")) + )}, + gles: { + any( + webgl, + all(feature = "angle", target_vendor = "apple"), + all(feature = "gles", native, not(target_vendor = "apple")) + ) + }, + + wgpu_core: { any(dx12, webgl, metal, vulkan) }, + // This alias is _only_ if _we_ need naga in the wrapper. wgpu-core provides // its own re-export of naga, which can be used in other situations naga: { any(feature = "naga-ir", feature = "spirv", feature = "glsl") }, diff --git a/wgpu/src/api/instance.rs b/wgpu/src/api/instance.rs index a8daf37fdc..3b54ec4658 100644 --- a/wgpu/src/api/instance.rs +++ b/wgpu/src/api/instance.rs @@ -60,45 +60,23 @@ impl Instance { /// /// `InstanceDescriptor::backends` does not need to be a subset of this, /// but any backend that is not in this set, will not be picked. - /// - /// TODO: Right now it's otherwise not possible yet to opt-out of all features on some platforms. - /// See - /// * Windows/Linux/Android: always enables Vulkan and GLES with no way to opt out pub const fn enabled_backend_features() -> Backends { let mut backends = Backends::empty(); - - if cfg!(native) { - if cfg!(metal) { - backends = backends.union(Backends::METAL); - } - if cfg!(dx12) { - backends = backends.union(Backends::DX12); - } - - // Windows, Android, Linux currently always enable Vulkan and OpenGL. - // See - if cfg!(target_os = "windows") || cfg!(unix) { - backends = backends.union(Backends::VULKAN).union(Backends::GL); - } - - // Vulkan on Mac/iOS is only available through vulkan-portability. - if cfg!(target_vendor = "apple") && cfg!(feature = "vulkan-portability") { - backends = backends.union(Backends::VULKAN); - } - - // GL on Mac is only available through angle. - if cfg!(target_os = "macos") && cfg!(feature = "angle") { - backends = backends.union(Backends::GL); - } - } else { - if cfg!(webgpu) { - backends = backends.union(Backends::BROWSER_WEBGPU); - } - if cfg!(webgl) { - backends = backends.union(Backends::GL); - } + if cfg!(metal) { + backends = backends.union(Backends::METAL); + } + if cfg!(dx12) { + backends = backends.union(Backends::DX12); + } + if cfg!(vulkan) { + backends = backends.union(Backends::VULKAN); + } + if cfg!(gles) { + backends = backends.union(Backends::GL); + } + if cfg!(webgpu) { + backends = backends.union(Backends::BROWSER_WEBGPU); } - backends } @@ -221,7 +199,7 @@ impl Instance { /// # Arguments /// /// - `backends` - Backends from which to enumerate adapters. - #[cfg(native)] + #[cfg(all(native, wgpu_core))] pub fn enumerate_adapters(&self, backends: Backends) -> Vec { let Some(core_instance) = self.inner.as_core_opt() else { return Vec::new(); diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 36438abfdc..42d6d158fa 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -61,7 +61,7 @@ impl ContextWgpuCore { pub unsafe fn create_adapter_from_hal( &self, - hal_adapter: hal::ExposedAdapter, + hal_adapter: crate::hal::ExposedAdapter, ) -> wgc::id::AdapterId { unsafe { self.0.create_adapter_from_hal(hal_adapter.into(), None) } } @@ -95,7 +95,7 @@ impl ContextWgpuCore { pub unsafe fn create_device_from_hal( &self, adapter: &CoreAdapter, - hal_device: hal::OpenDevice, + hal_device: crate::hal::OpenDevice, desc: &crate::DeviceDescriptor<'_>, trace_dir: Option<&std::path::Path>, ) -> Result<(CoreDevice, CoreQueue), crate::RequestDeviceError> { diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 29cf6fe163..aa12e758f0 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -28,7 +28,7 @@ #[cfg(wgpu_core)] pub extern crate wgpu_core as wgc; #[cfg(wgpu_core)] -pub extern crate wgpu_hal as hal; +pub use wgpu_core::hal; pub extern crate wgpu_types as wgt; // diff --git a/wgpu/src/util/init.rs b/wgpu/src/util/init.rs index 54de26da65..d48047eb03 100644 --- a/wgpu/src/util/init.rs +++ b/wgpu/src/util/init.rs @@ -4,7 +4,7 @@ use crate::{Adapter, Instance, RequestAdapterOptions, Surface}; use crate::Backends; /// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable. -#[cfg(native)] +#[cfg(all(native, wgpu_core))] pub fn initialize_adapter_from_env( instance: &Instance, compatible_surface: Option<&Surface<'_>>, @@ -36,7 +36,7 @@ pub fn initialize_adapter_from_env( } /// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable. -#[cfg(not(native))] +#[cfg(not(all(native, wgpu_core)))] pub fn initialize_adapter_from_env( _instance: &Instance, _compatible_surface: Option<&Surface<'_>>, From 0456cc6c87ffd710b2285380ecbbb0150b4becf7 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Sat, 25 Jan 2025 18:26:31 +0100 Subject: [PATCH 2/6] don't build with serde unless serde is actually enabled TODO: we should test this on ci with cargo tree, it's too easy to sneak back in --- wgpu-types/Cargo.toml | 4 ++-- wgpu/Cargo.toml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/wgpu-types/Cargo.toml b/wgpu-types/Cargo.toml index 653f988b7b..e10288c92e 100644 --- a/wgpu-types/Cargo.toml +++ b/wgpu-types/Cargo.toml @@ -40,12 +40,12 @@ default = ["std"] std = ["js-sys/std", "web-sys/std"] strict_asserts = [] fragile-send-sync-non-atomic-wasm = [] -serde = ["dep:serde"] +serde = ["dep:serde", "bitflags/serde"] # Enables some internal instrumentation for debugging purposes. counters = [] [dependencies] -bitflags = { workspace = true, features = ["serde"] } +bitflags.workspace = true log.workspace = true serde = { workspace = true, default-features = false, features = [ "alloc", diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 456d0cc2d8..94fe43ec5d 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -91,7 +91,7 @@ naga-ir = ["dep:naga"] strict_asserts = ["wgpu-core?/strict_asserts", "wgpu-types/strict_asserts"] ## Enables serialization via `serde` on common wgpu types. -serde = ["dep:serde", "wgpu-core/serde"] +serde = ["dep:serde", "wgpu-core?/serde", "wgpu-types/serde"] # Uncomment once we get to https://github.com/gfx-rs/wgpu/issues/5974 # ## Allow writing of trace capture files. See [`Adapter::request_device`]. @@ -144,7 +144,7 @@ naga = { workspace = true, optional = true } wgpu-core = { workspace = true, optional = true, features = [ "raw-window-handle", ] } -wgpu-types = { workspace = true, features = ["serde"] } +wgpu-types = { workspace = true } wgpu-hal = { workspace = true, optional = true, features = ["renderdoc"] } arrayvec.workspace = true From 9b35692727a6fc75206751adb7d8e16ebb87ac01 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Sun, 26 Jan 2025 17:09:48 +0100 Subject: [PATCH 3/6] fix wgpu_core cfg in wgpu not enabled with `gles` --- wgpu/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/build.rs b/wgpu/build.rs index 9c8feab72d..2b0ced54f9 100644 --- a/wgpu/build.rs +++ b/wgpu/build.rs @@ -23,7 +23,7 @@ fn main() { ) }, - wgpu_core: { any(dx12, webgl, metal, vulkan) }, + wgpu_core: { any(webgl, dx12, metal, vulkan, gles) }, // This alias is _only_ if _we_ need naga in the wrapper. wgpu-core provides // its own re-export of naga, which can be used in other situations From 39ac474ef6a6c9249b3e5f9166d31966f8118ead Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Sun, 26 Jan 2025 17:10:02 +0100 Subject: [PATCH 4/6] Fix enabled features for wgpu within crate --- Cargo.toml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 5345f812dc..e684eaf355 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -67,9 +67,13 @@ naga = { version = "24.0.0", path = "./naga" } wgpu = { version = "24.0.0", path = "./wgpu", default-features = false, features = [ "serde", "wgsl", + "static-dxc", + + # Enabled all native non-indirect (not going through additional layers like Angle) backends for testing. "dx12", "metal", - "static-dxc", + "vulkan", + "gles", ] } wgpu-core = { version = "24.0.0", path = "./wgpu-core" } wgpu-core-if-arch-wasm32 = { version = "24.0.0", path = "./wgpu-core-conditional/arch-wasm32" } From d24dbc9b0ee54256a256287dc053c8e3cc5398a3 Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Sun, 26 Jan 2025 17:23:21 +0100 Subject: [PATCH 5/6] fix dx12 enabling wgpu-core on linux - add another workaround crate --- Cargo.lock | 4 ++-- Cargo.toml | 9 ++++++--- wgpu-core-conditional/arch-wasm32/Cargo.toml | 2 +- .../native-non-apple/Cargo.toml | 4 +--- .../{vendor-apple => target-apple}/Cargo.toml | 4 ++-- .../{vendor-apple => target-apple}/src/lib.rs | 0 .../target-windows/Cargo.toml | 18 ++++++++++++++++++ .../target-windows/src/lib.rs | 1 + wgpu/Cargo.toml | 17 ++++++++++------- 9 files changed, 41 insertions(+), 18 deletions(-) rename wgpu-core-conditional/{vendor-apple => target-apple}/Cargo.toml (76%) rename wgpu-core-conditional/{vendor-apple => target-apple}/src/lib.rs (100%) create mode 100644 wgpu-core-conditional/target-windows/Cargo.toml create mode 100644 wgpu-core-conditional/target-windows/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 5eafd1d66e..1709bd99df 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4029,7 +4029,7 @@ dependencies = [ "wgpu-core", "wgpu-core-if-arch-wasm32", "wgpu-core-if-native-non-apple", - "wgpu-core-if-vendor-apple", + "wgpu-core-if-target-apple", "wgpu-hal", "wgpu-types", ] @@ -4092,7 +4092,7 @@ dependencies = [ ] [[package]] -name = "wgpu-core-if-vendor-apple" +name = "wgpu-core-if-target-apple" version = "24.0.0" dependencies = [ "wgpu-core", diff --git a/Cargo.toml b/Cargo.toml index e684eaf355..af588d1e2d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,8 @@ members = [ "wgpu", "wgpu-core-conditional/arch-wasm32", "wgpu-core-conditional/native-non-apple", - "wgpu-core-conditional/vendor-apple", + "wgpu-core-conditional/target-apple", + "wgpu-core-conditional/target-windows", ] exclude = [] default-members = [ @@ -45,7 +46,8 @@ default-members = [ "wgpu", "wgpu-core-conditional/arch-wasm32", "wgpu-core-conditional/native-non-apple", - "wgpu-core-conditional/vendor-apple", + "wgpu-core-conditional/target-apple", + "wgpu-core-conditional/target-windows", ] [workspace.lints.clippy] @@ -78,7 +80,8 @@ wgpu = { version = "24.0.0", path = "./wgpu", default-features = false, features wgpu-core = { version = "24.0.0", path = "./wgpu-core" } wgpu-core-if-arch-wasm32 = { version = "24.0.0", path = "./wgpu-core-conditional/arch-wasm32" } wgpu-core-if-native-non-apple = { version = "24.0.0", path = "./wgpu-core-conditional/native-non-apple" } -wgpu-core-if-vendor-apple = { version = "24.0.0", path = "./wgpu-core-conditional/vendor-apple" } +wgpu-core-if-target-apple = { version = "24.0.0", path = "./wgpu-core-conditional/target-apple" } +wgpu-core-if-target-windows = { version = "24.0.0", path = "./wgpu-core-conditional/target-windows" } wgpu-hal = { version = "24.0.0", path = "./wgpu-hal" } wgpu-macros = { version = "24.0.0", path = "./wgpu-macros" } wgpu-test = { version = "24.0.0", path = "./tests" } diff --git a/wgpu-core-conditional/arch-wasm32/Cargo.toml b/wgpu-core-conditional/arch-wasm32/Cargo.toml index 654235a387..544c3c64dc 100644 --- a/wgpu-core-conditional/arch-wasm32/Cargo.toml +++ b/wgpu-core-conditional/arch-wasm32/Cargo.toml @@ -3,7 +3,7 @@ name = "wgpu-core-if-arch-wasm32" version.workspace = true authors.workspace = true edition.workspace = true -description = "Workaround crate for enabling features in wgpu-core when targeting wasm32" +description = "Workaround crate for enabling in wgpu-core when targeting wasm32" homepage.workspace = true repository.workspace = true keywords.workspace = true diff --git a/wgpu-core-conditional/native-non-apple/Cargo.toml b/wgpu-core-conditional/native-non-apple/Cargo.toml index 21182ce72a..c9c9d7f918 100644 --- a/wgpu-core-conditional/native-non-apple/Cargo.toml +++ b/wgpu-core-conditional/native-non-apple/Cargo.toml @@ -3,7 +3,7 @@ name = "wgpu-core-if-native-non-apple" version.workspace = true authors.workspace = true edition.workspace = true -description = "Workaround crate for enabling features in wgpu-core when targeting macOS/iOS" +description = "Workaround crate for enabling in wgpu-core when targeting native unix platforms excluding macOS/iOS/tvOS/VisionOS" homepage.workspace = true repository.workspace = true keywords.workspace = true @@ -16,7 +16,5 @@ gles = ["wgpu-core/gles"] renderdoc = ["wgpu-core/renderdoc"] vulkan = ["wgpu-core/vulkan"] -raw-window-handle = ["wgpu-core/raw-window-handle"] - [target.'cfg(any(windows, all(unix, not(target_arch = "wasm32"), not(target_vendor = "apple"))))'.dependencies] wgpu-core.workspace = true diff --git a/wgpu-core-conditional/vendor-apple/Cargo.toml b/wgpu-core-conditional/target-apple/Cargo.toml similarity index 76% rename from wgpu-core-conditional/vendor-apple/Cargo.toml rename to wgpu-core-conditional/target-apple/Cargo.toml index 17a7c6a377..3d9f2cd3fc 100644 --- a/wgpu-core-conditional/vendor-apple/Cargo.toml +++ b/wgpu-core-conditional/target-apple/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "wgpu-core-if-vendor-apple" +name = "wgpu-core-if-target-apple" version.workspace = true authors.workspace = true edition.workspace = true -description = "Workaround crate for enabling features in wgpu-core when targeting macOS/iOS" +description = "Workaround crate for enabling wgpu-core when targeting macOS/iOS/tvOS/VisionOS" homepage.workspace = true repository.workspace = true keywords.workspace = true diff --git a/wgpu-core-conditional/vendor-apple/src/lib.rs b/wgpu-core-conditional/target-apple/src/lib.rs similarity index 100% rename from wgpu-core-conditional/vendor-apple/src/lib.rs rename to wgpu-core-conditional/target-apple/src/lib.rs diff --git a/wgpu-core-conditional/target-windows/Cargo.toml b/wgpu-core-conditional/target-windows/Cargo.toml new file mode 100644 index 0000000000..942e25fd3c --- /dev/null +++ b/wgpu-core-conditional/target-windows/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "wgpu-core-if-target-windows" +version.workspace = true +authors.workspace = true +edition.workspace = true +description = "Workaround crate for enabling wgpu-core when targeting windows" +homepage.workspace = true +repository.workspace = true +keywords.workspace = true +license.workspace = true + +[lib] + +[features] +dx12 = ["wgpu-core/dx12"] + +[target.'cfg(windows)'.dependencies] +wgpu-core.workspace = true diff --git a/wgpu-core-conditional/target-windows/src/lib.rs b/wgpu-core-conditional/target-windows/src/lib.rs new file mode 100644 index 0000000000..174c77f96a --- /dev/null +++ b/wgpu-core-conditional/target-windows/src/lib.rs @@ -0,0 +1 @@ +//! No code. See README.md for details. diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index 94fe43ec5d..f46569b071 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -34,12 +34,14 @@ default = ["wgsl", "dx12", "metal", "vulkan", "gles", "webgpu"] # -------------------------------------------------------------------- ## Enables the DX12 backend on Windows. -# Dx12 doesn't do anything on non-windows wgpu-core & wgpu-hal, so we don't need a proxy crate here. -dx12 = ["wgpu-core/dx12"] +# Note that while wgpu-hal ignores dx12 for non-windows targets, we still need to use a proxy crate, +# since for non-windows targets we don't want to include wgpu-core in the first place via this feature. +dx12 = ["wgpu-core-if-target-windows/dx12"] ## Enables the Metal backend on macOS & iOS. -# Metal doesn't do anything on non-Apple wgpu-core & wgpu-hal, but we already have a proxy crate for Apple platforms anyways. -metal = ["wgpu-core-if-vendor-apple/metal"] +# Note that while wgpu-hal ignores metal for non-apple targets, we still need to use a proxy crate, +# since for non-apple targets we don't want to include wgpu-core in the first place via this feature. +metal = ["wgpu-core-if-target-apple/metal"] ## Enables the Vulkan backend on Windows, Linux, and Android. ## @@ -47,7 +49,7 @@ metal = ["wgpu-core-if-vendor-apple/metal"] vulkan = ["wgpu-core-if-native-non-apple/vulkan"] ## Enables the Vulkan backend on macOS & iOS. -vulkan-portability = ["wgpu-core-if-vendor-apple/vulkan"] +vulkan-portability = ["wgpu-core-if-target-apple/vulkan"] ## Enables the OpenGL/GLES backend on Windows, Linux, and Android. ## @@ -55,7 +57,7 @@ vulkan-portability = ["wgpu-core-if-vendor-apple/vulkan"] gles = ["wgpu-core-if-native-non-apple/gles"] ## Enables the GLES backend via [ANGLE](https://github.com/google/angle) on macOS using. -angle = ["wgpu-core-if-vendor-apple/gles"] +angle = ["wgpu-core-if-target-apple/gles"] ## Enables GLES backend (WebGL) on Wasm webgl = ["wgpu-core-if-arch-wasm32/gles"] @@ -160,7 +162,8 @@ static_assertions.workspace = true wgpu-core-if-arch-wasm32 = { workspace = true, optional = true } wgpu-core-if-native-non-apple = { workspace = true, optional = true } -wgpu-core-if-vendor-apple = { workspace = true, optional = true } +wgpu-core-if-target-apple = { workspace = true, optional = true } +wgpu-core-if-target-windows = { workspace = true, optional = true } ######################################## From f0f47c4a896ea36b2ed6c592245563ceb14b8d2c Mon Sep 17 00:00:00 2001 From: Andreas Reich Date: Sun, 26 Jan 2025 18:11:28 +0100 Subject: [PATCH 6/6] ... iterating --- Cargo.lock | 18 +++++++++---- Cargo.toml | 14 +++++----- .../{arch-wasm32 => arch-wasm}/Cargo.toml | 4 +-- wgpu-core-conditional/arch-wasm/src/lib.rs | 4 +++ wgpu-core-conditional/arch-wasm32/src/lib.rs | 1 - .../native-non-apple/src/lib.rs | 1 - wgpu-core-conditional/target-apple/src/lib.rs | 3 +++ .../Cargo.toml | 6 ++--- .../target-unix-non-apple/src/lib.rs | 4 +++ .../target-windows/Cargo.toml | 2 ++ .../target-windows/src/lib.rs | 3 +++ wgpu/Cargo.toml | 24 ++++++++++------- wgpu/build.rs | 7 ++--- wgpu/src/lib.rs | 26 ++++++++++++------- 14 files changed, 77 insertions(+), 40 deletions(-) rename wgpu-core-conditional/{arch-wasm32 => arch-wasm}/Cargo.toml (88%) create mode 100644 wgpu-core-conditional/arch-wasm/src/lib.rs delete mode 100644 wgpu-core-conditional/arch-wasm32/src/lib.rs delete mode 100644 wgpu-core-conditional/native-non-apple/src/lib.rs rename wgpu-core-conditional/{native-non-apple => target-unix-non-apple}/Cargo.toml (64%) create mode 100644 wgpu-core-conditional/target-unix-non-apple/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 1709bd99df..4eb2777bff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4027,9 +4027,10 @@ dependencies = [ "wasm-bindgen-futures", "web-sys", "wgpu-core", - "wgpu-core-if-arch-wasm32", - "wgpu-core-if-native-non-apple", + "wgpu-core-if-arch-wasm", "wgpu-core-if-target-apple", + "wgpu-core-if-target-unix-non-apple", + "wgpu-core-if-target-windows", "wgpu-hal", "wgpu-types", ] @@ -4078,21 +4079,28 @@ dependencies = [ ] [[package]] -name = "wgpu-core-if-arch-wasm32" +name = "wgpu-core-if-arch-wasm" version = "24.0.0" dependencies = [ "wgpu-core", ] [[package]] -name = "wgpu-core-if-native-non-apple" +name = "wgpu-core-if-target-apple" version = "24.0.0" dependencies = [ "wgpu-core", ] [[package]] -name = "wgpu-core-if-target-apple" +name = "wgpu-core-if-target-unix-non-apple" +version = "24.0.0" +dependencies = [ + "wgpu-core", +] + +[[package]] +name = "wgpu-core-if-target-windows" version = "24.0.0" dependencies = [ "wgpu-core", diff --git a/Cargo.toml b/Cargo.toml index af588d1e2d..bb4f90e3cf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,8 +21,8 @@ members = [ "wgpu-macros", "wgpu-types", "wgpu", - "wgpu-core-conditional/arch-wasm32", - "wgpu-core-conditional/native-non-apple", + "wgpu-core-conditional/arch-wasm", + "wgpu-core-conditional/target-unix-non-apple", "wgpu-core-conditional/target-apple", "wgpu-core-conditional/target-windows", ] @@ -44,8 +44,8 @@ default-members = [ "wgpu-macros", "wgpu-types", "wgpu", - "wgpu-core-conditional/arch-wasm32", - "wgpu-core-conditional/native-non-apple", + "wgpu-core-conditional/arch-wasm", + "wgpu-core-conditional/target-unix-non-apple", "wgpu-core-conditional/target-apple", "wgpu-core-conditional/target-windows", ] @@ -78,8 +78,8 @@ wgpu = { version = "24.0.0", path = "./wgpu", default-features = false, features "gles", ] } wgpu-core = { version = "24.0.0", path = "./wgpu-core" } -wgpu-core-if-arch-wasm32 = { version = "24.0.0", path = "./wgpu-core-conditional/arch-wasm32" } -wgpu-core-if-native-non-apple = { version = "24.0.0", path = "./wgpu-core-conditional/native-non-apple" } +wgpu-core-if-arch-wasm = { version = "24.0.0", path = "./wgpu-core-conditional/arch-wasm" } +wgpu-core-if-target-unix-non-apple = { version = "24.0.0", path = "./wgpu-core-conditional/target-unix-non-apple" } wgpu-core-if-target-apple = { version = "24.0.0", path = "./wgpu-core-conditional/target-apple" } wgpu-core-if-target-windows = { version = "24.0.0", path = "./wgpu-core-conditional/target-windows" } wgpu-hal = { version = "24.0.0", path = "./wgpu-hal" } @@ -183,7 +183,7 @@ glutin_wgl_sys = "0.6" # DX12 and GLES dependencies windows = { version = "0.58", default-features = false } -# wasm32 dependencies +# wasm dependencies console_error_panic_hook = "0.1.7" console_log = "1" js-sys = { version = "0.3.70", default-features = false } diff --git a/wgpu-core-conditional/arch-wasm32/Cargo.toml b/wgpu-core-conditional/arch-wasm/Cargo.toml similarity index 88% rename from wgpu-core-conditional/arch-wasm32/Cargo.toml rename to wgpu-core-conditional/arch-wasm/Cargo.toml index 544c3c64dc..9dfc39d794 100644 --- a/wgpu-core-conditional/arch-wasm32/Cargo.toml +++ b/wgpu-core-conditional/arch-wasm/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "wgpu-core-if-arch-wasm32" +name = "wgpu-core-if-arch-wasm" version.workspace = true authors.workspace = true edition.workspace = true -description = "Workaround crate for enabling in wgpu-core when targeting wasm32" +description = "Workaround crate for enabling in wgpu-core when targeting wasm" homepage.workspace = true repository.workspace = true keywords.workspace = true diff --git a/wgpu-core-conditional/arch-wasm/src/lib.rs b/wgpu-core-conditional/arch-wasm/src/lib.rs new file mode 100644 index 0000000000..c0eb59f8c9 --- /dev/null +++ b/wgpu-core-conditional/arch-wasm/src/lib.rs @@ -0,0 +1,4 @@ +//! No code. See README.md for details. + +#[cfg(target_arch = "wasm32")] +pub use wgpu_core::*; diff --git a/wgpu-core-conditional/arch-wasm32/src/lib.rs b/wgpu-core-conditional/arch-wasm32/src/lib.rs deleted file mode 100644 index 174c77f96a..0000000000 --- a/wgpu-core-conditional/arch-wasm32/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -//! No code. See README.md for details. diff --git a/wgpu-core-conditional/native-non-apple/src/lib.rs b/wgpu-core-conditional/native-non-apple/src/lib.rs deleted file mode 100644 index 174c77f96a..0000000000 --- a/wgpu-core-conditional/native-non-apple/src/lib.rs +++ /dev/null @@ -1 +0,0 @@ -//! No code. See README.md for details. diff --git a/wgpu-core-conditional/target-apple/src/lib.rs b/wgpu-core-conditional/target-apple/src/lib.rs index 174c77f96a..a3037e84f7 100644 --- a/wgpu-core-conditional/target-apple/src/lib.rs +++ b/wgpu-core-conditional/target-apple/src/lib.rs @@ -1 +1,4 @@ //! No code. See README.md for details. + +#[cfg(target_vendor = "apple")] +pub use wgpu_core; diff --git a/wgpu-core-conditional/native-non-apple/Cargo.toml b/wgpu-core-conditional/target-unix-non-apple/Cargo.toml similarity index 64% rename from wgpu-core-conditional/native-non-apple/Cargo.toml rename to wgpu-core-conditional/target-unix-non-apple/Cargo.toml index c9c9d7f918..f374092b3c 100644 --- a/wgpu-core-conditional/native-non-apple/Cargo.toml +++ b/wgpu-core-conditional/target-unix-non-apple/Cargo.toml @@ -1,9 +1,9 @@ [package] -name = "wgpu-core-if-native-non-apple" +name = "wgpu-core-if-target-unix-non-apple" version.workspace = true authors.workspace = true edition.workspace = true -description = "Workaround crate for enabling in wgpu-core when targeting native unix platforms excluding macOS/iOS/tvOS/VisionOS" +description = "Workaround crate for enabling in wgpu-core when targeting native non-apple native unix platforms" homepage.workspace = true repository.workspace = true keywords.workspace = true @@ -16,5 +16,5 @@ gles = ["wgpu-core/gles"] renderdoc = ["wgpu-core/renderdoc"] vulkan = ["wgpu-core/vulkan"] -[target.'cfg(any(windows, all(unix, not(target_arch = "wasm32"), not(target_vendor = "apple"))))'.dependencies] +[target.'cfg(all(unix, not(target_os = "emscripten"), not(target_vendor = "apple")))'.dependencies] wgpu-core.workspace = true diff --git a/wgpu-core-conditional/target-unix-non-apple/src/lib.rs b/wgpu-core-conditional/target-unix-non-apple/src/lib.rs new file mode 100644 index 0000000000..8d2204d915 --- /dev/null +++ b/wgpu-core-conditional/target-unix-non-apple/src/lib.rs @@ -0,0 +1,4 @@ +//! No code. See README.md for details. + +#[cfg(all(unix, not(target_os = "emscripten"), not(target_vendor = "apple")))] +pub use wgpu_core::*; diff --git a/wgpu-core-conditional/target-windows/Cargo.toml b/wgpu-core-conditional/target-windows/Cargo.toml index 942e25fd3c..f19033adf7 100644 --- a/wgpu-core-conditional/target-windows/Cargo.toml +++ b/wgpu-core-conditional/target-windows/Cargo.toml @@ -13,6 +13,8 @@ license.workspace = true [features] dx12 = ["wgpu-core/dx12"] +gles = ["wgpu-core/gles"] +vulkan = ["wgpu-core/vulkan"] [target.'cfg(windows)'.dependencies] wgpu-core.workspace = true diff --git a/wgpu-core-conditional/target-windows/src/lib.rs b/wgpu-core-conditional/target-windows/src/lib.rs index 174c77f96a..858db106f1 100644 --- a/wgpu-core-conditional/target-windows/src/lib.rs +++ b/wgpu-core-conditional/target-windows/src/lib.rs @@ -1 +1,4 @@ //! No code. See README.md for details. + +#[cfg(windows)] +pub use wgpu_core::*; diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index f46569b071..d9bd9198cf 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -46,7 +46,10 @@ metal = ["wgpu-core-if-target-apple/metal"] ## Enables the Vulkan backend on Windows, Linux, and Android. ## ## For enabling Vulkan on macOS & iOS, use the `vulkan-portability` feature. -vulkan = ["wgpu-core-if-native-non-apple/vulkan"] +vulkan = [ + "wgpu-core-if-target-unix-non-apple/vulkan", + "wgpu-core-if-target-windows/vulkan", +] ## Enables the Vulkan backend on macOS & iOS. vulkan-portability = ["wgpu-core-if-target-apple/vulkan"] @@ -54,13 +57,16 @@ vulkan-portability = ["wgpu-core-if-target-apple/vulkan"] ## Enables the OpenGL/GLES backend on Windows, Linux, and Android. ## ## For enabling WebGL use the `webgl` feature, for enabling OpenGL via ANGLE on macOS use the `angle` feature. -gles = ["wgpu-core-if-native-non-apple/gles"] +gles = [ + "wgpu-core-if-target-unix-non-apple/gles", + "wgpu-core-if-target-windows/gles", +] ## Enables the GLES backend via [ANGLE](https://github.com/google/angle) on macOS using. angle = ["wgpu-core-if-target-apple/gles"] ## Enables GLES backend (WebGL) on Wasm -webgl = ["wgpu-core-if-arch-wasm32/gles"] +webgl = ["wgpu-core-if-arch-wasm/gles"] ## Enables the WebGPU backend on Wasm. Disabled when targeting `emscripten`. webgpu = ["naga?/wgsl-out"] @@ -101,7 +107,7 @@ serde = ["dep:serde", "wgpu-core?/serde", "wgpu-types/serde"] ## Allow deserializing of trace capture files that were written with the `trace` feature. ## To replay a trace file use the [wgpu player](https://github.com/gfx-rs/wgpu/tree/trunk/player). -replay = ["serde", "wgpu-core/replay"] +replay = ["serde", "wgpu-core?/replay"] #! ### Other # -------------------------------------------------------------------- @@ -109,7 +115,7 @@ replay = ["serde", "wgpu-core/replay"] ## Internally count resources and events for debugging purposes. If the counters ## feature is disabled, the counting infrastructure is removed from the build and ## the exposed counters always return 0. -counters = ["wgpu-core/counters"] +counters = ["wgpu-core?/counters"] ## Implement `Send` and `Sync` on Wasm, but only if atomics are not enabled. ## @@ -120,8 +126,8 @@ counters = ["wgpu-core/counters"] ## but on a wasm binary compiled without atomics we know we are definitely ## not in a multithreaded environment. fragile-send-sync-non-atomic-wasm = [ - "wgpu-hal/fragile-send-sync-non-atomic-wasm", - "wgpu-core/fragile-send-sync-non-atomic-wasm", + "wgpu-hal?/fragile-send-sync-non-atomic-wasm", + "wgpu-core?/fragile-send-sync-non-atomic-wasm", "wgpu-types/fragile-send-sync-non-atomic-wasm", ] @@ -160,8 +166,8 @@ serde = { workspace = true, features = ["default", "derive"], optional = true } smallvec.workspace = true static_assertions.workspace = true -wgpu-core-if-arch-wasm32 = { workspace = true, optional = true } -wgpu-core-if-native-non-apple = { workspace = true, optional = true } +wgpu-core-if-arch-wasm = { workspace = true, optional = true } +wgpu-core-if-target-unix-non-apple = { workspace = true, optional = true } wgpu-core-if-target-apple = { workspace = true, optional = true } wgpu-core-if-target-windows = { workspace = true, optional = true } diff --git a/wgpu/build.rs b/wgpu/build.rs index 2b0ced54f9..5dcbe22674 100644 --- a/wgpu/build.rs +++ b/wgpu/build.rs @@ -1,6 +1,8 @@ fn main() { cfg_aliases::cfg_aliases! { native: { not(target_arch = "wasm32") }, + + unix_non_apple: { all(native, not(target_vendor = "apple"), unix) }, Emscripten: { all(target_arch = "wasm32", target_os = "emscripten") }, send_sync: { any( not(target_arch = "wasm32"), @@ -13,13 +15,12 @@ fn main() { metal: { all(target_vendor = "apple", feature = "metal") }, vulkan: { any(all(feature = "vulkan-portability", target_vendor = "apple"), - all(feature = "vulkan", native, not(target_vendor = "apple")) + all(feature = "vulkan", unix_non_apple) )}, gles: { any( - webgl, all(feature = "angle", target_vendor = "apple"), - all(feature = "gles", native, not(target_vendor = "apple")) + all(feature = "gles", unix_non_apple) ) }, diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index aa12e758f0..e78bfecaeb 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -25,10 +25,18 @@ #![allow(clippy::arc_with_non_send_sync)] #![cfg_attr(not(any(wgpu_core, webgpu)), allow(unused))] +#[cfg(all(wgpu_core, not(native)))] +pub extern crate wgpu_core_if_arch_wasm as wgc; +#[cfg(all(wgpu_core, target_vendor = "apple"))] +pub extern crate wgpu_core_if_target_apple as wgc; +#[cfg(all(wgpu_core, windows))] +pub extern crate wgpu_core_if_target_windows as wgc; +#[cfg(all(wgpu_core, unix_non_apple))] +pub extern crate wgpu_core_if_unix_non_apple as wgc; + #[cfg(wgpu_core)] -pub extern crate wgpu_core as wgc; -#[cfg(wgpu_core)] -pub use wgpu_core::hal; +pub use wgc::hal; + pub extern crate wgpu_types as wgt; // @@ -89,18 +97,18 @@ pub use wgt::ImageCopyExternalImage; #[cfg(any(webgpu, webgl))] pub use wgt::{CopyExternalImageSourceInfo, ExternalImageSource}; -/// Re-export of our `naga` dependency. -/// -#[cfg(wgpu_core)] -#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))] -// We re-export wgpu-core's re-export of naga, as we may not have direct access to it. -pub use ::wgc::naga; /// Re-export of our `naga` dependency. /// #[cfg(all(not(wgpu_core), naga))] #[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))] // If that's not available, we re-export our own. pub use naga; +/// Re-export of our `naga` dependency. +/// +#[cfg(wgpu_core)] +#[cfg_attr(docsrs, doc(cfg(any(wgpu_core, naga))))] +// We re-export wgpu-core's re-export of naga, as we may not have direct access to it. +pub use wgc::naga; /// Re-export of our `raw-window-handle` dependency. ///