Skip to content

Commit f5660df

Browse files
committed
some clippy fixes
1 parent 7f6552f commit f5660df

File tree

7 files changed

+46
-24
lines changed

7 files changed

+46
-24
lines changed

crates/cargo-gpu/src/args.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
//! Args for building and installing. Previously in `spirv-tools-cli` but got moved here.
2+
3+
use spirv_builder::SpirvBuilder;
4+
5+
/// All args for a build and install
16
#[derive(clap::Parser, Debug, Clone, serde::Deserialize, serde::Serialize)]
27
pub struct AllArgs {
8+
/// build args
39
#[clap(flatten)]
410
pub build: BuildArgs,
511

12+
/// install args
613
#[clap(flatten)]
714
pub install: InstallArgs,
815
}
916

17+
/// Args for just a build
1018
#[derive(clap::Parser, Debug, Clone, serde::Deserialize, serde::Serialize)]
1119
pub struct BuildArgs {
1220
/// Path to the output directory for the compiled shaders.
@@ -17,24 +25,31 @@ pub struct BuildArgs {
1725
#[clap(long, short, action)]
1826
pub watch: bool,
1927

28+
/// the flattened [`SpirvBuilder`]
2029
#[clap(flatten)]
2130
#[serde(flatten)]
22-
pub spirv_builder: spirv_builder::SpirvBuilder,
31+
pub spirv_builder: SpirvBuilder,
2332

2433
///Renames the manifest.json file to the given name
2534
#[clap(long, short, default_value = "manifest.json")]
2635
pub manifest_file: String,
2736
}
2837

38+
/// Args for an install
2939
#[derive(clap::Parser, Debug, Clone, serde::Deserialize, serde::Serialize)]
3040
pub struct InstallArgs {
41+
/// path to the `rustc_codegen_spirv` dylib
3142
#[clap(long, hide(true), default_value = "INTERNALLY_SET")]
3243
pub dylib_path: std::path::PathBuf,
3344

3445
/// Directory containing the shader crate to compile.
3546
#[clap(long, default_value = "./")]
3647
pub shader_crate: std::path::PathBuf,
3748

49+
#[expect(
50+
clippy::doc_markdown,
51+
reason = "The URL should appear literally like this. But Clippy wants it to be a in markdown clickable link"
52+
)]
3853
/// Source of `spirv-builder` dependency
3954
/// Eg: "https://github.com/Rust-GPU/rust-gpu"
4055
#[clap(long)]
@@ -81,8 +96,8 @@ pub struct InstallArgs {
8196
///
8297
/// This hack is possible because the change from v3 to v4 only involves a minor change to the
8398
/// way source URLs are encoded. See these PRs for more details:
84-
/// * https://github.com/rust-lang/cargo/pull/12280
85-
/// * https://github.com/rust-lang/cargo/pull/14595
99+
/// * <https://github.com/rust-lang/cargo/pull/12280>
100+
/// * <https://github.com/rust-lang/cargo/pull/14595>
86101
#[clap(long, action, verbatim_doc_comment)]
87102
pub force_overwrite_lockfiles_v4_to_v3: bool,
88103
}

crates/cargo-gpu/src/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl Build {
5656
.spirv_builder
5757
.target
5858
.as_ref()
59-
.expect("target to be set")
59+
.context("expect target to be set")?
6060
))
6161
.display()
6262
.to_string(),

crates/cargo-gpu/src/install.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,13 @@ impl Install {
9393
}
9494

9595
/// Create the `rustc_codegen_spirv_dummy` crate that depends on `rustc_codegen_spirv`
96-
fn write_source_files(&self, spirv_cli: &SpirvCli, checkout: &Path) -> anyhow::Result<()> {
96+
fn write_source_files(spirv_cli: &SpirvCli, checkout: &Path) -> anyhow::Result<()> {
9797
{
9898
let main = "fn main() {}";
9999
let src = checkout.join("src");
100100
std::fs::create_dir_all(&src).context("creating directory for 'src'")?;
101101
std::fs::write(src.join("main.rs"), main).context("writing 'main.rs'")?;
102-
}
102+
};
103103

104104
{
105105
let version_spec = match &spirv_cli.source {
@@ -126,7 +126,7 @@ package = "rustc_codegen_spirv"
126126
);
127127
std::fs::write(checkout.join("Cargo.toml"), cargo_toml)
128128
.context("writing 'Cargo.toml'")?;
129-
}
129+
};
130130
Ok(())
131131
}
132132

@@ -185,8 +185,7 @@ package = "rustc_codegen_spirv"
185185
"writing rustc_codegen_spirv_dummy source files into '{}'",
186186
checkout.display()
187187
);
188-
self.write_source_files(&spirv_version, &checkout)
189-
.context("writing source files")?;
188+
Self::write_source_files(&spirv_version, &checkout).context("writing source files")?;
190189
self.write_target_spec_files()
191190
.context("writing target spec files")?;
192191

@@ -201,7 +200,7 @@ package = "rustc_codegen_spirv"
201200
.arg(format!("+{}", spirv_version.channel))
202201
.args(["build", "--release"]);
203202

204-
log::debug!("building artifacts with `{:?}`", build_command);
203+
log::debug!("building artifacts with `{build_command:?}`");
205204

206205
build_command
207206
.stdout(std::process::Stdio::inherit())

crates/cargo-gpu/src/linkage.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1+
//! Mainly for the Linkage struct, which is written to a json file. Previously in `spirv-tools-cli` but got moved here.
2+
13
/// Shader source and entry point that can be used to create shader linkage.
2-
#[derive(serde::Serialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
4+
#[derive(serde::Serialize, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
35
pub struct Linkage {
6+
/// File path to the entry point's source file
47
pub source_path: String,
8+
/// Name of the entry point for spirv and vulkan
59
pub entry_point: String,
10+
/// Name of the entry point for wgsl, where `::` characters have been removed
611
pub wgsl_entry_point: String,
712
}
813

914
impl Linkage {
15+
/// Make a new `Linkage` from an entry point and source path
16+
#[expect(clippy::impl_trait_in_params, reason = "just a struct new")]
1017
pub fn new(entry_point: impl AsRef<str>, source_path: impl AsRef<std::path::Path>) -> Self {
1118
Self {
1219
// Force a forward slash convention here so it works on all OSs
1320
source_path: source_path
1421
.as_ref()
1522
.components()
16-
.map(|c| c.as_os_str().to_string_lossy())
23+
.map(|comp| comp.as_os_str().to_string_lossy())
1724
.collect::<Vec<_>>()
1825
.join("/"),
1926
wgsl_entry_point: entry_point.as_ref().replace("::", ""),
20-
entry_point: entry_point.as_ref().to_string(),
27+
entry_point: entry_point.as_ref().to_owned(),
2128
}
2229
}
2330

31+
/// The entry point function name, without the fully qualified mod path
32+
#[expect(clippy::unwrap_used, reason = "unreachable")]
2433
pub fn fn_name(&self) -> &str {
2534
self.entry_point.split("::").last().unwrap()
2635
}
@@ -30,11 +39,15 @@ impl Linkage {
3039
/// a `build-manifest.json` used by `cargo-gpu`.
3140
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq, Eq, PartialOrd, Ord)]
3241
pub struct ShaderModule {
42+
/// Name of the entry point for spirv and vulkan
3343
pub entry: String,
44+
/// File path to the entry point's source file
3445
pub path: std::path::PathBuf,
3546
}
3647

3748
impl ShaderModule {
49+
/// Make a new `ShaderModule` from an entry point and source path
50+
#[expect(clippy::impl_trait_in_params, reason = "just a struct new")]
3851
pub fn new(entry: impl AsRef<str>, path: impl AsRef<std::path::Path>) -> Self {
3952
Self {
4053
entry: entry.as_ref().into(),

crates/cargo-gpu/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,10 @@ fn run() -> anyhow::Result<()> {
165165
#[derive(clap::Subcommand)]
166166
enum Command {
167167
/// Install rust-gpu compiler artifacts.
168-
Install(Install),
168+
Install(Box<Install>),
169169

170170
/// Compile a shader crate to SPIR-V.
171-
Build(Build),
171+
Build(Box<Build>),
172172

173173
/// Show some useful values.
174174
Show(Show),

crates/cargo-gpu/src/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl Metadata {
6464
let mut crate_meta = Self::get_crate_metadata(cargo_json, path)?;
6565
log::trace!("crate_metadata: {crate_meta:#?}");
6666
if let Some(output_path) = crate_meta.pointer_mut("/build/output_dir") {
67-
log::debug!("found output-dir path in crate metadata: {:?}", output_path);
67+
log::debug!("found output-dir path in crate metadata: {output_path:?}");
6868
if let Some(output_dir) = output_path.clone().as_str() {
6969
let new_output_path = path.join(output_dir);
7070
*output_path = Value::String(format!("{}", new_output_path.display()));

crates/cargo-gpu/src/spirv_cli.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,7 @@ impl SpirvCli {
249249
RUST_VERSION_THAT_USES_V4_CARGO_LOCKS,
250250
) {
251251
log::debug!(
252-
"user's Rust is v{}, so no v3/v4 conflicts possible.",
253-
workspace_rust_version
252+
"user's Rust is v{workspace_rust_version}, so no v3/v4 conflicts possible."
254253
);
255254
return Ok(None);
256255
}
@@ -281,16 +280,12 @@ impl SpirvCli {
281280
&shader_rust_version,
282281
RUST_VERSION_THAT_USES_V4_CARGO_LOCKS,
283282
) {
284-
log::debug!(
285-
"shader's Rust is v{}, so no v3/v4 conflicts possible.",
286-
shader_rust_version
287-
);
283+
log::debug!("shader's Rust is v{shader_rust_version}, so no v3/v4 conflicts possible.");
288284
return Ok(None);
289285
}
290286

291287
log::debug!(
292-
"shader's Rust is v{}, so checking both shader and workspace `Cargo.lock` manifest versions...",
293-
shader_rust_version
288+
"shader's Rust is v{shader_rust_version}, so checking both shader and workspace `Cargo.lock` manifest versions..."
294289
);
295290

296291
if shader_crate_path.join("Cargo.lock").exists() {

0 commit comments

Comments
 (0)