Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make all backends controlled by features (using a very ugly workaround) #6949

Draft
wants to merge 6 commits into
base: trunk
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ members = [
"wgpu-macros",
"wgpu-types",
"wgpu",
"wgpu-core-conditional/arch-wasm",
"wgpu-core-conditional/target-unix-non-apple",
"wgpu-core-conditional/target-apple",
"wgpu-core-conditional/target-windows",
]
exclude = []
default-members = [
Expand All @@ -40,6 +44,10 @@ default-members = [
"wgpu-macros",
"wgpu-types",
"wgpu",
"wgpu-core-conditional/arch-wasm",
"wgpu-core-conditional/target-unix-non-apple",
"wgpu-core-conditional/target-apple",
"wgpu-core-conditional/target-windows",
]

[workspace.lints.clippy]
Expand All @@ -61,11 +69,19 @@ 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-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" }
wgpu-macros = { version = "24.0.0", path = "./wgpu-macros" }
wgpu-test = { version = "24.0.0", path = "./tests" }
Expand Down Expand Up @@ -167,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 }
Expand Down
18 changes: 18 additions & 0 deletions wgpu-core-conditional/arch-wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[package]
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 wasm"
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
4 changes: 4 additions & 0 deletions wgpu-core-conditional/arch-wasm/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! No code. See README.md for details.

#[cfg(target_arch = "wasm32")]
pub use wgpu_core::*;
22 changes: 22 additions & 0 deletions wgpu-core-conditional/target-apple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[package]
name = "wgpu-core-if-target-apple"
version.workspace = true
authors.workspace = true
edition.workspace = true
description = "Workaround crate for enabling wgpu-core when targeting macOS/iOS/tvOS/VisionOS"
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
4 changes: 4 additions & 0 deletions wgpu-core-conditional/target-apple/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! No code. See README.md for details.

#[cfg(target_vendor = "apple")]
pub use wgpu_core;
20 changes: 20 additions & 0 deletions wgpu-core-conditional/target-unix-non-apple/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
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 non-apple native unix platforms"
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"]

[target.'cfg(all(unix, not(target_os = "emscripten"), not(target_vendor = "apple")))'.dependencies]
wgpu-core.workspace = true
4 changes: 4 additions & 0 deletions wgpu-core-conditional/target-unix-non-apple/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::*;
20 changes: 20 additions & 0 deletions wgpu-core-conditional/target-windows/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[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"]
gles = ["wgpu-core/gles"]
vulkan = ["wgpu-core/vulkan"]

[target.'cfg(windows)'.dependencies]
wgpu-core.workspace = true
4 changes: 4 additions & 0 deletions wgpu-core-conditional/target-windows/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! No code. See README.md for details.

#[cfg(windows)]
pub use wgpu_core::*;
4 changes: 2 additions & 2 deletions wgpu-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions wgpu-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
97 changes: 46 additions & 51 deletions wgpu/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,48 @@ 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"]
# 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 = ["wgpu-core?/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 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-target-unix-non-apple/vulkan",
"wgpu-core-if-target-windows/vulkan",
]

## Enables the Vulkan backend on macOS & iOS.
vulkan-portability = ["wgpu-core?/vulkan"]
vulkan-portability = ["wgpu-core-if-target-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-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-wasm/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
Expand Down Expand Up @@ -84,23 +99,23 @@ 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`].
# trace = ["serde", "wgpu-core/trace"]

## 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
# --------------------------------------------------------------------

## 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.
##
Expand All @@ -111,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",
]

Expand All @@ -134,8 +149,11 @@ static-dxc = ["wgpu-hal/static-dxc"]

[dependencies]
naga = { workspace = true, optional = true }
wgpu-core = { workspace = true, optional = true }
wgpu-types = { workspace = true, features = ["serde"] }
wgpu-core = { workspace = true, optional = true, features = [
"raw-window-handle",
] }
wgpu-types = { workspace = true }
wgpu-hal = { workspace = true, optional = true, features = ["renderdoc"] }

arrayvec.workspace = true
bitflags.workspace = true
Expand All @@ -148,40 +166,17 @@ serde = { workspace = true, features = ["default", "derive"], optional = true }
smallvec.workspace = true
static_assertions.workspace = 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 }


########################################
# 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
Expand Down
Loading
Loading