Skip to content

Commit cb1d8b1

Browse files
committed
spirv_source minor cleanup
1 parent 66896f8 commit cb1d8b1

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

crates/cargo-gpu/src/spirv_source.rs

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! From there we can look at the source code to get the required Rust toolchain.
66
77
use anyhow::Context as _;
8+
use std::path::{Path, PathBuf};
89

910
/// The canonical `rust-gpu` URI
1011
const RUST_GPU_REPO: &str = "https://github.com/Rust-GPU/rust-gpu";
@@ -50,7 +51,7 @@ impl core::fmt::Display for SpirvSource {
5051

5152
impl SpirvSource {
5253
/// Look into the shader crate to get the version of `rust-gpu` it's using.
53-
pub fn get_rust_gpu_deps_from_shader<F: AsRef<std::path::Path>>(
54+
pub fn get_rust_gpu_deps_from_shader<F: AsRef<Path>>(
5455
shader_crate_path: F,
5556
) -> anyhow::Result<(Self, chrono::NaiveDate, String)> {
5657
let rust_gpu_source = Self::get_spirv_std_dep_definition(shader_crate_path.as_ref())?;
@@ -94,27 +95,22 @@ impl SpirvSource {
9495
}
9596

9697
/// Make sure shader crate path is absolute and canonical.
97-
fn shader_crate_path_canonical(
98-
shader_crate_path: &mut std::path::PathBuf,
99-
) -> anyhow::Result<()> {
100-
let cwd = std::env::current_dir().context("no cwd")?;
101-
let mut canonical_path = shader_crate_path.clone();
98+
fn shader_crate_path_canonical(shader_crate_path: &Path) -> anyhow::Result<PathBuf> {
99+
let mut canonical_path = shader_crate_path.to_path_buf();
102100

103101
if !canonical_path.is_absolute() {
102+
let cwd = std::env::current_dir().context("no cwd")?;
104103
canonical_path = cwd.join(canonical_path);
105104
}
106-
canonical_path
105+
canonical_path = canonical_path
107106
.canonicalize()
108107
.context("could not get absolute path to shader crate")?;
109108

110109
if !canonical_path.is_dir() {
111110
log::error!("{shader_crate_path:?} is not a directory, aborting");
112111
anyhow::bail!("{shader_crate_path:?} is not a directory");
113112
}
114-
115-
*shader_crate_path = canonical_path;
116-
117-
Ok(())
113+
Ok(canonical_path)
118114
}
119115

120116
/// Checkout the `rust-gpu` repo to the requested version.
@@ -180,7 +176,7 @@ impl SpirvSource {
180176
}
181177

182178
/// Parse the `rust-toolchain.toml` in the working tree of the checked-out version of the `rust-gpu` repo.
183-
fn get_channel_from_toolchain_toml(path: &std::path::PathBuf) -> anyhow::Result<String> {
179+
fn get_channel_from_toolchain_toml(path: &PathBuf) -> anyhow::Result<String> {
184180
log::debug!("Parsing `rust-toolchain.toml` at {path:?} for the used toolchain");
185181

186182
let contents = std::fs::read_to_string(path.join("rust-toolchain.toml"))?;
@@ -198,11 +194,8 @@ impl SpirvSource {
198194
}
199195

200196
/// Get the shader crate's resolved `spirv_std = ...` definition in its `Cargo.toml`/`Cargo.lock`
201-
pub fn get_spirv_std_dep_definition(
202-
shader_crate_path: &std::path::Path,
203-
) -> anyhow::Result<Self> {
204-
let canonical_shader_path = shader_crate_path.to_path_buf();
205-
Self::shader_crate_path_canonical(&mut canonical_shader_path.clone())?;
197+
pub fn get_spirv_std_dep_definition(shader_crate_path: &Path) -> anyhow::Result<Self> {
198+
let canonical_shader_path = Self::shader_crate_path_canonical(shader_crate_path)?;
206199

207200
log::debug!(
208201
"Running `cargo tree` on {}",

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ fn set_codegen_spirv_location(dylib_path: std::path::PathBuf) {
4343
let dylib_path = dylib_path.parent().unwrap().to_path_buf();
4444
dylib_paths.insert(0, dylib_path);
4545

46-
let path = std::env::join_paths(dylib_paths).unwrap().into_string().unwrap();
46+
let path = std::env::join_paths(dylib_paths)
47+
.unwrap()
48+
.into_string()
49+
.unwrap();
4750

4851
log::debug!("Setting OS-dependent DLL ENV path ({env_var}) to: {path}");
4952
std::env::set_var(env_var, path);

0 commit comments

Comments
 (0)