Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Commit b705e15

Browse files
committed
install-crate: clap and watch feature for optional deps
1 parent 922e8f3 commit b705e15

3 files changed

Lines changed: 18 additions & 12 deletions

File tree

crates/cargo-gpu-install/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ keywords.workspace = true
99
license.workspace = true
1010

1111
[features]
12+
clap = ["dep:clap", "spirv-builder/clap"]
13+
watch = ["spirv-builder/watch"]
1214
test = ["dep:tempfile"]
1315

1416
[dependencies]
1517
cargo_metadata.workspace = true
1618
anyhow.workspace = true
17-
spirv-builder = { workspace = true, features = ["clap", "watch"] }
18-
clap.workspace = true
19+
spirv-builder.workspace = true
20+
clap = { workspace = true, optional = true }
1921
directories.workspace = true
2022
log.workspace = true
2123
serde.workspace = true

crates/cargo-gpu-install/src/install.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,23 @@ impl InstalledBackend {
5454
clippy::struct_excessive_bools,
5555
reason = "cmdline args have many bools"
5656
)]
57-
#[derive(clap::Parser, Debug, Clone, serde::Deserialize, serde::Serialize)]
57+
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
58+
#[cfg_attr(feature = "clap", derive(clap::Parser))]
5859
#[non_exhaustive]
5960
pub struct Install {
6061
/// Cargo target to compile.
6162
///
6263
/// Conflicts with `--shader-crate`.
63-
#[clap(short, long, conflicts_with("shader_crate"))]
64+
#[cfg_attr(feature = "clap", clap(short, long, conflicts_with("shader_crate")))]
6465
pub package: Option<String>,
6566

6667
/// Directory containing the shader crate to compile.
6768
///
6869
/// Conflicts with `--package` or `-p`.
69-
#[clap(long, default_value = "./", conflicts_with("package"))]
70+
#[cfg_attr(
71+
feature = "clap",
72+
clap(long, default_value = "./", conflicts_with("package"))
73+
)]
7074
pub shader_crate: PathBuf,
7175

7276
#[expect(
@@ -75,30 +79,30 @@ pub struct Install {
7579
)]
7680
/// Source of `spirv-builder` dependency
7781
/// Eg: "https://github.com/Rust-GPU/rust-gpu"
78-
#[clap(long)]
82+
#[cfg_attr(feature = "clap", clap(long))]
7983
pub spirv_builder_source: Option<String>,
8084

8185
/// Version of `spirv-builder` dependency.
8286
/// * If `--spirv-builder-source` is not set, then this is assumed to be a crates.io semantic
8387
/// version such as "0.9.0".
8488
/// * If `--spirv-builder-source` is set, then this is assumed to be a Git "commitsh", such
8589
/// as a Git commit hash or a Git tag, therefore anything that `git checkout` can resolve.
86-
#[clap(long, verbatim_doc_comment)]
90+
#[cfg_attr(feature = "clap", clap(long, verbatim_doc_comment))]
8791
pub spirv_builder_version: Option<String>,
8892

8993
/// Force `rustc_codegen_spirv` to be rebuilt.
90-
#[clap(long)]
94+
#[cfg_attr(feature = "clap", clap(long))]
9195
pub rebuild_codegen: bool,
9296

9397
/// Assume "yes" to "Install Rust toolchain: [y/n]" prompt.
9498
///
9599
/// Defaults to `false` in cli, `true` in [`Default`]
96-
#[clap(long, action)]
100+
#[cfg_attr(feature = "clap", clap(long, action))]
97101
pub auto_install_rust_toolchain: bool,
98102

99103
/// Clear target dir of `rustc_codegen_spirv` build after a successful build, saves about
100104
/// 200MiB of disk space.
101-
#[clap(long = "no-clear-target", default_value = "true", action = clap::ArgAction::SetFalse)]
105+
#[cfg_attr(feature = "clap", clap(long = "no-clear-target", default_value = "true", action = clap::ArgAction::SetFalse))]
102106
pub clear_target: bool,
103107

104108
/// There is a tricky situation where a shader crate that depends on workspace config can have
@@ -122,7 +126,7 @@ pub struct Install {
122126
/// way source URLs are encoded. See these PRs for more details:
123127
/// * <https://github.com/rust-lang/cargo/pull/12280>
124128
/// * <https://github.com/rust-lang/cargo/pull/14595>
125-
#[clap(long, action, verbatim_doc_comment)]
129+
#[cfg_attr(feature = "clap", clap(long, action, verbatim_doc_comment))]
126130
pub force_overwrite_lockfiles_v4_to_v3: bool,
127131
}
128132

crates/cargo-gpu/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ default-run = "cargo-gpu"
1414
cargo_metadata.workspace = true
1515
anyhow.workspace = true
1616
spirv-builder = { workspace = true, features = ["clap", "watch"] }
17-
cargo-gpu-install.workspace = true
17+
cargo-gpu-install = { workspace = true, features = ["clap", "watch"] }
1818
clap.workspace = true
1919
env_logger.workspace = true
2020
log.workspace = true

0 commit comments

Comments
 (0)