Skip to content

Commit 7430330

Browse files
authored
Make crate features no-op on incompatible targets (#3466)
* Make crate features no-op on incompatible targets * Remove `portable_features` * Test `--all-features` in CI * Make `renderdoc` no-op on WASM * Address review
1 parent 9cdcd67 commit 7430330

File tree

13 files changed

+119
-139
lines changed

13 files changed

+119
-139
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,19 @@ jobs:
125125
126126
# build for WebGPU
127127
cargo clippy --target ${{ matrix.target }} -p wgpu --tests --features glsl,spirv
128-
129-
# build for WebGL
130-
cargo clippy --target ${{ matrix.target }} -p wgpu --tests --features webgl,glsl,spirv
131-
132-
# build docs
133128
cargo doc --target ${{ matrix.target }} -p wgpu --no-deps --features glsl,spirv
134129
130+
# all features
131+
cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-hal --tests --all-features
132+
cargo doc --target ${{ matrix.target }} -p wgpu --no-deps --all-features
133+
135134
- name: check em
136135
if: matrix.kind == 'em'
137136
shell: bash
138137
run: |
139138
set -e
140139
141-
# build for Emscripten/WebGL
140+
# build for Emscripten
142141
cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-hal --no-default-features
143142
144143
# build cube example
@@ -147,6 +146,10 @@ jobs:
147146
# build raw-gles example
148147
cargo clippy --target ${{ matrix.target }} --example raw-gles
149148
149+
# all features
150+
cargo clippy --target ${{ matrix.target }} -p wgpu-hal --all-features
151+
cargo clippy --target ${{ matrix.target }} -p wgpu --all-features
152+
150153
- name: check native
151154
if: matrix.kind == 'native'
152155
shell: bash
@@ -157,16 +160,10 @@ jobs:
157160
cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-core -p wgpu-info -p player --no-default-features
158161
159162
# Check with all features.
160-
# (But watch out for backend-selection features in wgpu-core; some of
161-
# those only build on the right platforms.)
162-
cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-info -p player --tests --all-features
163-
cargo clippy --target ${{ matrix.target }} -p wgpu-core --tests --features="portable_features"
163+
cargo clippy --target ${{ matrix.target }} -p wgpu -p wgpu-info -p player -p wgpu-core -p wgpu-hal --tests --all-features
164164
165165
# build docs
166-
# (Watch out for backend-selection features in wgpu-core; some of
167-
# those only build on the right platforms.)
168-
cargo doc --target ${{ matrix.target }} -p wgpu -p wgpu-info -p player --all-features --no-deps
169-
cargo doc --target ${{ matrix.target }} -p wgpu-core --no-deps --features="portable_features"
166+
cargo doc --target ${{ matrix.target }} -p wgpu -p wgpu-info -p player -p wgpu-core -p wgpu-hal --all-features --no-deps
170167
171168
wasm-test:
172169
name: Test WebAssembly

wgpu-core/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,6 @@ id32 = []
4949
# Enable `ShaderModuleSource::Wgsl`
5050
wgsl = ["naga/wgsl-in"]
5151

52-
# Features that are intended to work on all platforms.
53-
portable_features = ["gles", "strict_asserts", "trace", "replay", "serial-pass", "id32", "wgsl"]
54-
5552
[dependencies]
5653
arrayvec = "0.7"
5754
bitflags = "1"

wgpu-core/src/device/mod.rs

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

5563-
#[cfg(feature = "vulkan")]
5563+
#[cfg(all(feature = "vulkan", not(target_arch = "wasm32")))]
55645564
{
55655565
all_queue_empty = self.poll_devices::<hal::api::Vulkan>(force_wait, &mut closures)?
55665566
&& all_queue_empty;
55675567
}
5568-
#[cfg(feature = "metal")]
5568+
#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
55695569
{
55705570
all_queue_empty =
55715571
self.poll_devices::<hal::api::Metal>(force_wait, &mut closures)? && all_queue_empty;
55725572
}
5573-
#[cfg(feature = "dx12")]
5573+
#[cfg(all(feature = "dx12", windows))]
55745574
{
55755575
all_queue_empty =
55765576
self.poll_devices::<hal::api::Dx12>(force_wait, &mut closures)? && all_queue_empty;
55775577
}
5578-
#[cfg(feature = "dx11")]
5578+
#[cfg(all(feature = "dx11", windows))]
55795579
{
55805580
all_queue_empty =
55815581
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)