Skip to content

Commit e8bcf00

Browse files
committed
Make crate features no-op on incompatible targets
1 parent 5b8c55c commit e8bcf00

File tree

8 files changed

+105
-115
lines changed

8 files changed

+105
-115
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,10 @@ jobs:
132132
# build docs
133133
cargo doc --target ${{ matrix.target }} -p wgpu --no-deps --features glsl,spirv
134134
135+
# all features
136+
cargo clippy --target ${{ matrix.target }} -p wgpu --tests --all-features
137+
cargo doc --target ${{ matrix.target }} -p wgpu --no-deps --all-features
138+
135139
- name: check em
136140
if: matrix.kind == 'em'
137141
shell: bash

wgpu-core/src/device/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5530,22 +5530,22 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
55305530
let mut closures = UserClosures::default();
55315531
let mut all_queue_empty = true;
55325532

5533-
#[cfg(feature = "vulkan")]
5533+
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
55345534
{
55355535
all_queue_empty = self.poll_devices::<hal::api::Vulkan>(force_wait, &mut closures)?
55365536
&& all_queue_empty;
55375537
}
5538-
#[cfg(feature = "metal")]
5538+
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
55395539
{
55405540
all_queue_empty =
55415541
self.poll_devices::<hal::api::Metal>(force_wait, &mut closures)? && all_queue_empty;
55425542
}
5543-
#[cfg(feature = "dx12")]
5543+
#[cfg(all(feature = "dx12", windows))]
55445544
{
55455545
all_queue_empty =
55465546
self.poll_devices::<hal::api::Dx12>(force_wait, &mut closures)? && all_queue_empty;
55475547
}
5548-
#[cfg(feature = "dx11")]
5548+
#[cfg(all(feature = "dx11", windows))]
55495549
{
55505550
all_queue_empty =
55515551
self.poll_devices::<hal::api::Dx11>(force_wait, &mut closures)? && all_queue_empty;

wgpu-core/src/hub.rs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,13 +1057,13 @@ impl<A: HalApi, F: GlobalIdentityHandlerFactory> Hub<A, F> {
10571057
}
10581058

10591059
pub struct Hubs<F: GlobalIdentityHandlerFactory> {
1060-
#[cfg(feature = "vulkan")]
1060+
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
10611061
vulkan: Hub<hal::api::Vulkan, F>,
1062-
#[cfg(feature = "metal")]
1062+
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
10631063
metal: Hub<hal::api::Metal, F>,
1064-
#[cfg(feature = "dx12")]
1064+
#[cfg(all(feature = "dx12", windows))]
10651065
dx12: Hub<hal::api::Dx12, F>,
1066-
#[cfg(feature = "dx11")]
1066+
#[cfg(all(feature = "dx11", windows))]
10671067
dx11: Hub<hal::api::Dx11, F>,
10681068
#[cfg(feature = "gles")]
10691069
gl: Hub<hal::api::Gles, F>,
@@ -1072,13 +1072,13 @@ pub struct Hubs<F: GlobalIdentityHandlerFactory> {
10721072
impl<F: GlobalIdentityHandlerFactory> Hubs<F> {
10731073
fn new(factory: &F) -> Self {
10741074
Self {
1075-
#[cfg(feature = "vulkan")]
1075+
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
10761076
vulkan: Hub::new(factory),
1077-
#[cfg(feature = "metal")]
1077+
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
10781078
metal: Hub::new(factory),
1079-
#[cfg(feature = "dx12")]
1079+
#[cfg(all(feature = "dx12", windows))]
10801080
dx12: Hub::new(factory),
1081-
#[cfg(feature = "dx11")]
1081+
#[cfg(all(feature = "dx11", windows))]
10821082
dx11: Hub::new(factory),
10831083
#[cfg(feature = "gles")]
10841084
gl: Hub::new(factory),
@@ -1089,13 +1089,13 @@ impl<F: GlobalIdentityHandlerFactory> Hubs<F> {
10891089
#[derive(Debug)]
10901090
pub struct GlobalReport {
10911091
pub surfaces: StorageReport,
1092-
#[cfg(feature = "vulkan")]
1092+
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
10931093
pub vulkan: Option<HubReport>,
1094-
#[cfg(feature = "metal")]
1094+
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
10951095
pub metal: Option<HubReport>,
1096-
#[cfg(feature = "dx12")]
1096+
#[cfg(all(feature = "dx12", windows))]
10971097
pub dx12: Option<HubReport>,
1098-
#[cfg(feature = "dx11")]
1098+
#[cfg(all(feature = "dx11", windows))]
10991099
pub dx11: Option<HubReport>,
11001100
#[cfg(feature = "gles")]
11011101
pub gl: Option<HubReport>,
@@ -1162,25 +1162,25 @@ impl<G: GlobalIdentityHandlerFactory> Global<G> {
11621162
pub fn generate_report(&self) -> GlobalReport {
11631163
GlobalReport {
11641164
surfaces: self.surfaces.data.read().generate_report(),
1165-
#[cfg(feature = "vulkan")]
1165+
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
11661166
vulkan: if self.instance.vulkan.is_some() {
11671167
Some(self.hubs.vulkan.generate_report())
11681168
} else {
11691169
None
11701170
},
1171-
#[cfg(feature = "metal")]
1171+
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
11721172
metal: if self.instance.metal.is_some() {
11731173
Some(self.hubs.metal.generate_report())
11741174
} else {
11751175
None
11761176
},
1177-
#[cfg(feature = "dx12")]
1177+
#[cfg(all(feature = "dx12", windows))]
11781178
dx12: if self.instance.dx12.is_some() {
11791179
Some(self.hubs.dx12.generate_report())
11801180
} else {
11811181
None
11821182
},
1183-
#[cfg(feature = "dx11")]
1183+
#[cfg(all(feature = "dx11", windows))]
11841184
dx11: if self.instance.dx11.is_some() {
11851185
Some(self.hubs.dx11.generate_report())
11861186
} else {
@@ -1203,19 +1203,19 @@ impl<G: GlobalIdentityHandlerFactory> Drop for Global<G> {
12031203
let mut surface_guard = self.surfaces.data.write();
12041204

12051205
// destroy hubs before the instance gets dropped
1206-
#[cfg(feature = "vulkan")]
1206+
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
12071207
{
12081208
self.hubs.vulkan.clear(&mut surface_guard, true);
12091209
}
1210-
#[cfg(feature = "metal")]
1210+
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
12111211
{
12121212
self.hubs.metal.clear(&mut surface_guard, true);
12131213
}
1214-
#[cfg(feature = "dx12")]
1214+
#[cfg(all(feature = "dx12", windows))]
12151215
{
12161216
self.hubs.dx12.clear(&mut surface_guard, true);
12171217
}
1218-
#[cfg(feature = "dx11")]
1218+
#[cfg(all(feature = "dx11", windows))]
12191219
{
12201220
self.hubs.dx11.clear(&mut surface_guard, true);
12211221
}
@@ -1261,7 +1261,7 @@ impl HalApi for hal::api::Empty {
12611261
}
12621262
}
12631263

1264-
#[cfg(feature = "vulkan")]
1264+
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
12651265
impl HalApi for hal::api::Vulkan {
12661266
const VARIANT: Backend = Backend::Vulkan;
12671267
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {
@@ -1285,7 +1285,7 @@ impl HalApi for hal::api::Vulkan {
12851285
}
12861286
}
12871287

1288-
#[cfg(feature = "metal")]
1288+
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
12891289
impl HalApi for hal::api::Metal {
12901290
const VARIANT: Backend = Backend::Metal;
12911291
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {
@@ -1309,7 +1309,7 @@ impl HalApi for hal::api::Metal {
13091309
}
13101310
}
13111311

1312-
#[cfg(feature = "dx12")]
1312+
#[cfg(all(feature = "dx12", windows))]
13131313
impl HalApi for hal::api::Dx12 {
13141314
const VARIANT: Backend = Backend::Dx12;
13151315
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {
@@ -1333,7 +1333,7 @@ impl HalApi for hal::api::Dx12 {
13331333
}
13341334
}
13351335

1336-
#[cfg(feature = "dx11")]
1336+
#[cfg(all(feature = "dx11", windows))]
13371337
impl HalApi for hal::api::Dx11 {
13381338
const VARIANT: Backend = Backend::Dx11;
13391339
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance {

0 commit comments

Comments
 (0)