@@ -135,19 +135,34 @@ struct Spirv {
135
135
channel : String ,
136
136
}
137
137
138
+ impl Default for Spirv {
139
+ fn default ( ) -> Self {
140
+ Self {
141
+ dep : Self :: DEFAULT_DEP . into ( ) ,
142
+ channel : Self :: DEFAULT_CHANNEL . into ( ) ,
143
+ }
144
+ }
145
+ }
146
+
138
147
impl core:: fmt:: Display for Spirv {
139
148
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
140
149
format ! ( "{}+{}" , self . dep, self . channel) . fmt ( f)
141
150
}
142
151
}
143
152
144
153
impl Spirv {
154
+ const DEFAULT_DEP : & str = r#"{ git = "https://github.com/Rust-GPU/rust-gpu.git" }"# ;
155
+ const DEFAULT_CHANNEL : & str = "nightly-2024-04-24" ;
156
+
145
157
/// Returns a string suitable to use as a directory.
146
158
///
147
159
/// Created from the spirv-builder source dep and the rustc channel.
148
160
fn to_dirname ( & self ) -> String {
149
161
self . to_string ( )
150
- . replace ( [ std:: path:: MAIN_SEPARATOR , '.' , ':' , '@' , '=' ] , "_" )
162
+ . replace (
163
+ [ std:: path:: MAIN_SEPARATOR , '\\' , '/' , '.' , ':' , '@' , '=' ] ,
164
+ "_" ,
165
+ )
151
166
. split ( [ '{' , '}' , ' ' , '\n' , '"' , '\'' ] )
152
167
. collect :: < Vec < _ > > ( )
153
168
. concat ( )
@@ -258,16 +273,13 @@ fn target_spec_dir() -> std::path::PathBuf {
258
273
#[ derive( Parser , Debug ) ]
259
274
struct Install {
260
275
/// spirv-builder dependency, written just like in a Cargo.toml file.
261
- #[ clap(
262
- long,
263
- default_value = r#"{ git = "https://github.com/Rust-GPU/rust-gpu.git" }"#
264
- ) ]
276
+ #[ clap( long, default_value = Spirv :: DEFAULT_DEP ) ]
265
277
spirv_builder : String ,
266
278
267
279
/// Rust toolchain channel to use to build `spirv-builder`.
268
280
///
269
281
/// This must match the `spirv_builder` argument.
270
- #[ clap( long, default_value = "nightly-2024-04-24" ) ]
282
+ #[ clap( long, default_value = Spirv :: DEFAULT_CHANNEL ) ]
271
283
rust_toolchain : String ,
272
284
273
285
/// Force `spirv-builder-cli` and `rustc_codegen_spirv` to be rebuilt.
@@ -312,6 +324,7 @@ impl Install {
312
324
fn run ( & self ) -> ( std:: path:: PathBuf , std:: path:: PathBuf ) {
313
325
// Ensure the cache dir exists
314
326
let cache_dir = cache_dir ( ) ;
327
+ log:: info!( "cache directory is '{}'" , cache_dir. display( ) ) ;
315
328
std:: fs:: create_dir_all ( & cache_dir) . unwrap_or_else ( |e| {
316
329
log:: error!(
317
330
"could not create cache directory '{}': {e}" ,
@@ -381,12 +394,21 @@ impl Install {
381
394
panic ! ( "spirv-builder-cli build failed" ) ;
382
395
}
383
396
384
- let cli_path = release. join ( "spirv-builder-cli" ) ;
397
+ let cli_path = if cfg ! ( target_os = "windows" ) {
398
+ release. join ( "spirv-builder-cli" ) . with_extension ( "exe" )
399
+ } else {
400
+ release. join ( "spirv-builder-cli" )
401
+ } ;
385
402
if cli_path. is_file ( ) {
386
403
log:: info!( "successfully built {}" , cli_path. display( ) ) ;
387
404
std:: fs:: rename ( & cli_path, & dest_cli_path) . unwrap ( ) ;
388
405
} else {
389
406
log:: error!( "could not find {}" , cli_path. display( ) ) ;
407
+ log:: debug!( "contents of '{}':" , release. display( ) ) ;
408
+ for entry in std:: fs:: read_dir ( & release) . unwrap ( ) {
409
+ let entry = entry. unwrap ( ) ;
410
+ log:: debug!( "{}" , entry. file_name( ) . to_string_lossy( ) ) ;
411
+ }
390
412
panic ! ( "spirv-builder-cli build failed" ) ;
391
413
}
392
414
}
@@ -757,7 +779,7 @@ fn dump_full_usage_for_readme() {
757
779
println ! ( "{}" , buffer) ;
758
780
}
759
781
760
- fn write_help ( buffer : & mut impl std:: io:: Write , cmd : & mut clap:: Command , depth : usize ) {
782
+ fn write_help ( buffer : & mut impl std:: io:: Write , cmd : & mut clap:: Command , _depth : usize ) {
761
783
if cmd. get_name ( ) == "help" {
762
784
return ;
763
785
}
@@ -774,14 +796,31 @@ fn write_help(buffer: &mut impl std::io::Write, cmd: &mut clap::Command, depth:
774
796
775
797
for sub in cmd. get_subcommands_mut ( ) {
776
798
let _ = writeln ! ( buffer) ;
777
- write_help ( buffer, sub, depth + 1 ) ;
799
+ write_help ( buffer, sub, _depth + 1 ) ;
778
800
}
779
801
}
780
802
781
803
#[ cfg( test) ]
782
804
mod test {
783
805
use super :: * ;
784
806
807
+ #[ test]
808
+ fn cached_checkout_dir_sanity ( ) {
809
+ // Test that
810
+ let spirv = Spirv :: default ( ) ;
811
+ let dir = spirv. cached_checkout_path ( ) ;
812
+ let name = dir
813
+ . file_name ( )
814
+ . unwrap ( )
815
+ . to_str ( )
816
+ . map ( |s| s. to_string ( ) )
817
+ . unwrap ( ) ;
818
+ assert_eq ! (
819
+ "git_https___github_com_Rust-GPU_rust-gpu_git+nightly-2024-04-24" ,
820
+ & name
821
+ ) ;
822
+ }
823
+
785
824
#[ test]
786
825
fn builder_from_params ( ) {
787
826
let shader_crate = std:: path:: PathBuf :: from ( "../shader-crate-template" ) ;
0 commit comments