@@ -88,8 +88,12 @@ impl SpirvSource {
88
88
Self :: CratesIO ( Version :: parse ( rust_gpu_version) ?)
89
89
}
90
90
} else {
91
- Self :: get_rust_gpu_deps_from_shader ( shader_crate_path)
92
- . context ( "get_rust_gpu_deps_from_shader" ) ?
91
+ Self :: get_rust_gpu_deps_from_shader ( shader_crate_path) . with_context ( || {
92
+ format ! (
93
+ "get spirv-std dependency from shader crate '{}'" ,
94
+ shader_crate_path. display( )
95
+ )
96
+ } ) ?
93
97
} ;
94
98
Ok ( source)
95
99
}
@@ -144,8 +148,8 @@ impl SpirvSource {
144
148
let parse_git = || {
145
149
let link = & source. repr . get ( 4 ..) ?;
146
150
let sharp_index = link. find ( '#' ) ?;
147
- let question_mark_index = link. find ( '?' ) ? ;
148
- let url = link. get ( ..question_mark_index ) ?. to_owned ( ) ;
151
+ let url_end = link. find ( '?' ) . unwrap_or ( sharp_index ) ;
152
+ let url = link. get ( ..url_end ) ?. to_owned ( ) ;
149
153
let rev = link. get ( sharp_index + 1 ..) ?. to_owned ( ) ;
150
154
Some ( Self :: Git { url, rev } )
151
155
} ;
@@ -244,6 +248,7 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
244
248
#[ cfg( test) ]
245
249
mod test {
246
250
use super :: * ;
251
+ use cargo_metadata:: { PackageBuilder , PackageId , Source } ;
247
252
248
253
#[ test_log:: test]
249
254
fn parsing_spirv_std_dep_for_shader_template ( ) {
@@ -277,4 +282,50 @@ mod test {
277
282
. unwrap ( ) ;
278
283
assert_eq ! ( "https___github_com_Rust-GPU_rust-gpu+86fc4803" , & name) ;
279
284
}
285
+
286
+ #[ test_log:: test]
287
+ fn parse_git_with_rev ( ) {
288
+ let source = parse_git (
289
+ "git+https://github.com/Rust-GPU/rust-gpu?rev=86fc48032c4cd4afb74f1d81ae859711d20386a1#86fc4803" ,
290
+ ) ;
291
+ assert_eq ! (
292
+ source,
293
+ SpirvSource :: Git {
294
+ url: "https://github.com/Rust-GPU/rust-gpu" . to_owned( ) ,
295
+ rev: "86fc4803" . to_owned( ) ,
296
+ }
297
+ )
298
+ }
299
+
300
+ #[ test_log:: test]
301
+ fn parse_git_no_question_mark ( ) {
302
+ // taken directly from Graphite
303
+ let source = parse_git (
304
+ "git+https://github.com/Rust-GPU/rust-gpu.git#6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" ,
305
+ ) ;
306
+ assert_eq ! (
307
+ source,
308
+ SpirvSource :: Git {
309
+ url: "https://github.com/Rust-GPU/rust-gpu.git" . to_owned( ) ,
310
+ rev: "6e2c84d4fe64e32df4c060c5a7f3e35a32e45421" . to_owned( ) ,
311
+ }
312
+ )
313
+ }
314
+
315
+ fn parse_git ( source : & str ) -> SpirvSource {
316
+ let package = PackageBuilder :: new (
317
+ "spirv-std" ,
318
+ Version :: new ( 0 , 9 , 0 ) ,
319
+ PackageId {
320
+ repr : "" . to_owned ( ) ,
321
+ } ,
322
+ "" ,
323
+ )
324
+ . source ( Some ( Source {
325
+ repr : source. to_owned ( ) ,
326
+ } ) )
327
+ . build ( )
328
+ . unwrap ( ) ;
329
+ SpirvSource :: parse_spirv_std_source_and_version ( & package) . unwrap ( )
330
+ }
280
331
}
0 commit comments