Skip to content

Commit faafd37

Browse files
committed
add core feature
Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
1 parent be2ca12 commit faafd37

4 files changed

Lines changed: 19 additions & 19 deletions

File tree

wgpu/Cargo.toml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ ignored = ["cfg_aliases"]
2929
[lib]
3030

3131
[features]
32-
default = ["wgsl", "dx12", "metal", "webgpu"]
32+
default = ["wgsl", "dx12", "metal", "webgpu", "core"]
3333

3434
#! ### Backends
3535
# --------------------------------------------------------------------
@@ -46,6 +46,12 @@ metal = ["wgc?/metal"]
4646
## Enables the WebGPU backend on Wasm. Disabled when targeting `emscripten`.
4747
webgpu = ["naga?/wgsl-out"]
4848

49+
## Enables wgpu-core if platform supports it
50+
##
51+
## This exist so we can allow users to bring their own contexts
52+
## and not need to get wgpu-core
53+
core = ["dep:wgc", "dep:hal"]
54+
4955
## Enables the GLES backend via [ANGLE](https://github.com/google/angle) on macOS using.
5056
angle = ["wgc?/gles"]
5157

@@ -117,59 +123,53 @@ fragile-send-sync-non-atomic-wasm = [
117123
"wgt/fragile-send-sync-non-atomic-wasm",
118124
]
119125

120-
# wgpu-core is always available as an optional dependency, "wgc".
121-
# Whenever wgpu-core is selected, we want raw window handle support.
122-
[dependencies.wgc]
123-
optional = true
124-
workspace = true
125-
features = ["raw-window-handle"]
126-
127126
# wgpu-core is required whenever not targeting web APIs directly.
128127
# Whenever wgpu-core is selected, we want raw window handle support.
129128
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies.wgc]
130129
workspace = true
130+
optional = true
131131
features = ["raw-window-handle"]
132132

133133
# Enable `wgc` by default on macOS and iOS to allow the `metal` crate feature to
134134
# enable the Metal backend while being no-op on other targets.
135135
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.wgc]
136136
workspace = true
137+
optional = true
137138

138139
# We want the wgpu-core Direct3D backend and OpenGL (via WGL) on Windows.
139140
[target.'cfg(windows)'.dependencies.wgc]
140141
workspace = true
142+
optional = true
141143
features = ["gles"]
142144

143145
# We want the wgpu-core Vulkan backend on Unix (but not emscripten, macOS, iOS) and Windows.
144146
[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc]
145147
workspace = true
148+
optional = true
146149
features = ["vulkan"]
147150

148151
# We want the wgpu-core GLES backend on Unix (but not macOS, iOS).
149152
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies.wgc]
150153
workspace = true
154+
optional = true
151155
features = ["gles"]
152156

153157
[dependencies.wgt]
154158
workspace = true
155159

156160
# We need wgpu-hal unless we're targeting the web APIs.
157161
[target.'cfg(any(not(target_arch = "wasm32"), target_os = "emscripten"))'.dependencies]
158-
hal = { workspace = true }
162+
hal = { workspace = true, optional = true }
159163

160164
[target.'cfg(all(not(target_arch = "wasm32"), unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
161-
hal = { workspace = true, features = ["renderdoc"] }
165+
hal = { workspace = true, features = ["renderdoc"], optional = true }
162166

163167
[target.'cfg(windows)'.dependencies]
164168
hal = { workspace = true, features = [
165169
"dxc_shader_compiler",
166170
"renderdoc",
167171
"windows_rs",
168-
] }
169-
170-
[target.'cfg(target_arch = "wasm32")'.dependencies.hal]
171-
workspace = true
172-
optional = true
172+
], optional = true }
173173

174174
[dependencies]
175175
arrayvec.workspace = true

wgpu/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ fn main() {
44
webgl: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgl") },
55
webgpu: { all(target_arch = "wasm32", not(target_os = "emscripten"), feature = "webgpu") },
66
Emscripten: { all(target_arch = "wasm32", target_os = "emscripten") },
7-
wgpu_core: { any(native, webgl, emscripten) },
7+
wgpu_core: { all(any(native, webgl, emscripten), feature = "core") },
88
send_sync: { any(
99
not(target_arch = "wasm32"),
1010
all(feature = "fragile-send-sync-non-atomic-wasm", not(target_feature = "atomics"))

wgpu/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ impl Instance {
24282428
/// # Arguments
24292429
///
24302430
/// - `backends` - Backends from which to enumerate adapters.
2431-
#[cfg(native)]
2431+
#[cfg(all(native, wgpu_core))]
24322432
pub fn enumerate_adapters(&self, backends: Backends) -> Vec<Adapter> {
24332433
let context = Arc::clone(&self.context);
24342434
self.context

wgpu/src/util/init.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn power_preference_from_env() -> Option<PowerPreference> {
3838
}
3939

4040
/// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable.
41-
#[cfg(native)]
41+
#[cfg(all(wgpu_core, native))]
4242
pub fn initialize_adapter_from_env(
4343
instance: &Instance,
4444
compatible_surface: Option<&Surface<'_>>,
@@ -70,7 +70,7 @@ pub fn initialize_adapter_from_env(
7070
}
7171

7272
/// Initialize the adapter obeying the WGPU_ADAPTER_NAME environment variable.
73-
#[cfg(not(native))]
73+
#[cfg(not(all(native, wgpu_core)))]
7474
pub fn initialize_adapter_from_env(
7575
_instance: &Instance,
7676
_compatible_surface: Option<&Surface<'_>>,

0 commit comments

Comments
 (0)