5
5
//! From there we can look at the source code to get the required Rust toolchain.
6
6
7
7
use anyhow:: Context as _;
8
+ use std:: path:: { Path , PathBuf } ;
8
9
9
10
/// The canonical `rust-gpu` URI
10
11
const RUST_GPU_REPO : & str = "https://github.com/Rust-GPU/rust-gpu" ;
@@ -50,7 +51,7 @@ impl core::fmt::Display for SpirvSource {
50
51
51
52
impl SpirvSource {
52
53
/// 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 > > (
54
55
shader_crate_path : F ,
55
56
) -> anyhow:: Result < ( Self , chrono:: NaiveDate , String ) > {
56
57
let rust_gpu_source = Self :: get_spirv_std_dep_definition ( shader_crate_path. as_ref ( ) ) ?;
@@ -94,27 +95,22 @@ impl SpirvSource {
94
95
}
95
96
96
97
/// 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 ( ) ;
102
100
103
101
if !canonical_path. is_absolute ( ) {
102
+ let cwd = std:: env:: current_dir ( ) . context ( "no cwd" ) ?;
104
103
canonical_path = cwd. join ( canonical_path) ;
105
104
}
106
- canonical_path
105
+ canonical_path = canonical_path
107
106
. canonicalize ( )
108
107
. context ( "could not get absolute path to shader crate" ) ?;
109
108
110
109
if !canonical_path. is_dir ( ) {
111
110
log:: error!( "{shader_crate_path:?} is not a directory, aborting" ) ;
112
111
anyhow:: bail!( "{shader_crate_path:?} is not a directory" ) ;
113
112
}
114
-
115
- * shader_crate_path = canonical_path;
116
-
117
- Ok ( ( ) )
113
+ Ok ( canonical_path)
118
114
}
119
115
120
116
/// Checkout the `rust-gpu` repo to the requested version.
@@ -180,7 +176,7 @@ impl SpirvSource {
180
176
}
181
177
182
178
/// 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 > {
184
180
log:: debug!( "Parsing `rust-toolchain.toml` at {path:?} for the used toolchain" ) ;
185
181
186
182
let contents = std:: fs:: read_to_string ( path. join ( "rust-toolchain.toml" ) ) ?;
@@ -198,11 +194,8 @@ impl SpirvSource {
198
194
}
199
195
200
196
/// 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) ?;
206
199
207
200
log:: debug!(
208
201
"Running `cargo tree` on {}" ,
0 commit comments