55//! From there we can look at the source code to get the required Rust toolchain.
66
77use anyhow:: Context as _;
8+ use std:: path:: { Path , PathBuf } ;
89
910/// The canonical `rust-gpu` URI
1011const RUST_GPU_REPO : & str = "https://github.com/Rust-GPU/rust-gpu" ;
@@ -50,7 +51,7 @@ impl core::fmt::Display for SpirvSource {
5051
5152impl 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 {}" ,
0 commit comments