Skip to content

Commit 6309051

Browse files
authored
Make strum a dev-only dependency (gfx-rs#7776)
1 parent e9af205 commit 6309051

3 files changed

Lines changed: 22 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ Naga now infers the correct binding layout when a resource appears only in an as
100100
- Mark `readonly_and_readwrite_storage_textures` & `packed_4x8_integer_dot_product` language extensions as implemented. By @teoxoy in [#7543](https://github.com/gfx-rs/wgpu/pull/7543)
101101
- `naga::back::hlsl::Writer::new` has a new `pipeline_options` argument. `hlsl::PipelineOptions::default()` can be passed as a default. The `shader_stage` and `entry_point` members of `pipeline_options` can be used to write only a single entry point when using the HLSL and MSL backends (GLSL and SPIR-V already had this functionality). The Metal and DX12 HALs now write only a single entry point when loading shaders. By @andyleiserson in [#7626](https://github.com/gfx-rs/wgpu/pull/7626).
102102
- Implemented `early_depth_test` for SPIR-V backend, enabling `SHADER_EARLY_DEPTH_TEST` for Vulkan. Additionally, fixed conservative depth optimizations when using `early_depth_test`. The syntax for forcing early depth tests is now `@early_depth_test(force)` instead of `@early_depth_test`. By @dzamkov in [#7676](https://github.com/gfx-rs/wgpu/pull/7676).
103+
- `ImplementedLanguageExtension::VARIANTS` is now implemented manually rather than derived using `strum` (allowing `strum` to become a dev-only dependency) so it is no longer a member of the `strum::VARIANTS` trait. Unless you are using this trait as a bound this should have no effect.
103104

104105
#### D3D12
105106

naga/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ arbitrary = [
5858
]
5959
spv-in = ["dep:petgraph", "petgraph/graphmap", "dep:spirv"]
6060
spv-out = ["dep:spirv"]
61-
wgsl-in = ["dep:hexf-parse", "dep:strum", "dep:unicode-ident", "compact"]
61+
wgsl-in = ["dep:hexf-parse", "dep:unicode-ident", "compact"]
6262
wgsl-out = []
6363

6464
## Enables outputting to HLSL (Microsoft's High-Level Shader Language).
@@ -95,7 +95,6 @@ libm = { workspace = true, default-features = false }
9595
log.workspace = true
9696
num-traits.workspace = true
9797
once_cell = { workspace = true, features = ["alloc", "race"] }
98-
strum = { workspace = true, optional = true }
9998
spirv = { workspace = true, optional = true }
10099
thiserror.workspace = true
101100
serde = { workspace = true, features = ["alloc", "derive"], optional = true }
@@ -117,6 +116,7 @@ ron.workspace = true
117116
rspirv.workspace = true
118117
serde = { workspace = true, features = ["default", "derive"] }
119118
spirv = { workspace = true, features = ["deserialize"] }
119+
strum = { workspace = true }
120120
toml.workspace = true
121121
walkdir.workspace = true
122122

naga/src/front/wgsl/parse/directive/language_extension.rs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
//!
33
//! The focal point of this module is the [`LanguageExtension`] API.
44
5-
use strum::VariantArray;
6-
75
/// A language extension recognized by Naga, but not guaranteed to be present in all environments.
86
///
97
/// WGSL spec.: <https://www.w3.org/TR/WGSL/#language-extensions-sec>
@@ -54,14 +52,22 @@ impl LanguageExtension {
5452
}
5553

5654
/// A variant of [`LanguageExtension::Implemented`].
57-
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, VariantArray)]
55+
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
56+
#[cfg_attr(test, derive(strum::VariantArray))]
5857
pub enum ImplementedLanguageExtension {
5958
ReadOnlyAndReadWriteStorageTextures,
6059
Packed4x8IntegerDotProduct,
6160
PointerCompositeAccess,
6261
}
6362

6463
impl ImplementedLanguageExtension {
64+
/// A slice of all variants of [`ImplementedLanguageExtension`].
65+
pub const VARIANTS: &'static [Self] = &[
66+
Self::ReadOnlyAndReadWriteStorageTextures,
67+
Self::Packed4x8IntegerDotProduct,
68+
Self::PointerCompositeAccess,
69+
];
70+
6571
/// Returns slice of all variants of [`ImplementedLanguageExtension`].
6672
pub const fn all() -> &'static [Self] {
6773
Self::VARIANTS
@@ -83,6 +89,16 @@ impl ImplementedLanguageExtension {
8389
}
8490
}
8591

92+
#[test]
93+
/// Asserts that the manual implementation of VARIANTS is the same as the derived strum version would be
94+
/// while still allowing strum to be a dev-only dependency
95+
fn test_manual_variants_array_is_correct() {
96+
assert_eq!(
97+
<ImplementedLanguageExtension as strum::VariantArray>::VARIANTS,
98+
ImplementedLanguageExtension::VARIANTS
99+
);
100+
}
101+
86102
/// A variant of [`LanguageExtension::Unimplemented`].
87103
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
88104
pub enum UnimplementedLanguageExtension {

0 commit comments

Comments
 (0)