Skip to content

Commit 3a0ec08

Browse files
committed
Add cargo gpu show capabilities command
1 parent 95efce2 commit 3a0ec08

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

crates/cargo-gpu/src/show.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ pub enum Info {
1919
SpirvSource(SpirvSourceDep),
2020
/// The git commitsh of this cli tool.
2121
Commitsh,
22+
/// All the available SPIR-V capabilities that can be set with `--capability`
23+
Capabilities,
2224
}
2325

2426
/// `cargo gpu show`
@@ -53,8 +55,27 @@ impl Show {
5355
Info::Commitsh => {
5456
println!("{}", std::env!("GIT_HASH"));
5557
}
58+
Info::Capabilities => {
59+
println!("All available options to the `cargo gpu build --capability` argument:");
60+
#[expect(
61+
clippy::use_debug,
62+
reason = "It's easier to just use `Debug` formatting than implementing `Display`"
63+
)]
64+
for capability in Self::capability_variants_iter() {
65+
println!(" {capability:?}");
66+
}
67+
}
5668
}
5769

5870
Ok(())
5971
}
72+
73+
/// Iterator over all `Capability` variants.
74+
fn capability_variants_iter() -> impl Iterator<Item = spirv_builder_cli::spirv::Capability> {
75+
// Since spirv::Capability is repr(u32) we can iterate over
76+
// u32s until some maximum
77+
#[expect(clippy::as_conversions, reason = "We know all variants are repr(u32)")]
78+
let last_capability = spirv_builder_cli::spirv::Capability::CacheControlsINTEL as u32;
79+
(0..=last_capability).filter_map(spirv_builder_cli::spirv::Capability::from_u32)
80+
}
6081
}

crates/spirv-builder-cli/src/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct BuildArgs {
5454
pub debug: bool,
5555

5656
/// Enables the provided SPIR-V capabilities.
57-
/// See: `impl core::str::FromStr for spirv_builder::Capability`
57+
/// See: `cargo gpu show capabilities`
5858
#[arg(long, value_parser=Self::spirv_capability)]
5959
pub capability: Vec<spirv::Capability>,
6060

0 commit comments

Comments
 (0)