Skip to content

Commit 59206fd

Browse files
committed
clippy: add cargo gpu clippy
1 parent 3650e0b commit 59206fd

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

crates/cargo-gpu/src/build.rs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ pub struct BuildArgs {
2121
#[clap(long, short, action)]
2222
pub watch: bool,
2323

24-
/// the flattened [`SpirvBuilder`]
24+
/// The flattened [`SpirvBuilder`]
2525
#[clap(flatten)]
2626
#[serde(flatten)]
2727
pub spirv_builder: SpirvBuilder,
2828

29-
///Renames the manifest.json file to the given name
29+
/// Renames the `manifest.json` file to the given name
3030
#[clap(long, short, default_value = "manifest.json")]
3131
pub manifest_file: String,
32+
33+
/// When building fails with [`SpirvBuilderError::NoArtifactProduced`], count it as a success anyway.
34+
/// Used for e.g. `clippy`, which doesn't produce any artifacts. Defaults to false.
35+
#[clap(skip)]
36+
pub allow_no_artifacts: bool,
3237
}
3338

3439
impl Default for BuildArgs {
@@ -39,6 +44,7 @@ impl Default for BuildArgs {
3944
watch: false,
4045
spirv_builder: SpirvBuilder::default(),
4146
manifest_file: String::from("manifest.json"),
47+
allow_no_artifacts: false,
4248
}
4349
}
4450
}
@@ -116,8 +122,16 @@ impl Build {
116122
"Compiling shaders at {}...\n",
117123
self.install.shader_crate.display()
118124
);
119-
let result = self.build.spirv_builder.build()?;
120-
self.parse_compilation_result(&result)?;
125+
let result = self.build.spirv_builder.build();
126+
match result {
127+
Ok(result) => {
128+
self.parse_compilation_result(&result)?;
129+
}
130+
// conditionally ignore NoArtifactProduced
131+
Err(SpirvBuilderError::NoArtifactProduced { .. })
132+
if self.build.allow_no_artifacts => {}
133+
Err(err) => return Err(err.into()),
134+
}
121135
}
122136
Ok(())
123137
}

crates/cargo-gpu/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ impl Config {
3131
) -> anyhow::Result<crate::build::Build> {
3232
let mut config = metadata.as_json(shader_crate_path)?;
3333

34-
env_args.retain(|arg| !(arg == "build" || arg == "install"));
34+
env_args.retain(|arg| !(arg == "build" || arg == "install" || arg == "clippy"));
3535
let cli_args_json = Self::cli_args_to_json(env_args)?;
3636
Self::json_merge(&mut config, cli_args_json, None)?;
3737

crates/cargo-gpu/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ pub enum Command {
105105
/// Compile a shader crate to SPIR-V.
106106
Build(Box<Build>),
107107

108+
/// Run clippy on a shader crate with a SPIR-V target
109+
Clippy(Box<Build>),
110+
108111
/// Show some useful values.
109112
Show(Show),
110113

@@ -140,13 +143,17 @@ impl Command {
140143
);
141144
command.install.run()?;
142145
}
143-
Self::Build(build) => {
146+
Self::Build(build) | Self::Clippy(build) => {
144147
let shader_crate_path = &build.install.shader_crate;
145148
let mut command = config::Config::clap_command_with_cargo_config(
146149
shader_crate_path,
147150
env_args,
148151
metadata_cache,
149152
)?;
153+
if let Self::Clippy(_) = self {
154+
command.build.spirv_builder.cargo_cmd = Some("clippy".into());
155+
command.build.allow_no_artifacts = true;
156+
}
150157
log::debug!("building with final merged arguments: {command:#?}");
151158

152159
if command.build.watch {

0 commit comments

Comments
 (0)