@@ -88,8 +88,12 @@ impl SpirvSource {
8888 Self :: CratesIO ( Version :: parse ( rust_gpu_version) ?)
8989 }
9090 } 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+ } ) ?
9397 } ;
9498 Ok ( source)
9599 }
@@ -144,8 +148,8 @@ impl SpirvSource {
144148 let parse_git = || {
145149 let link = & source. repr . get ( 4 ..) ?;
146150 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 ( ) ;
149153 let rev = link. get ( sharp_index + 1 ..) ?. to_owned ( ) ;
150154 Some ( Self :: Git { url, rev } )
151155 } ;
@@ -244,6 +248,7 @@ pub fn get_channel_from_rustc_codegen_spirv_build_script(
244248#[ cfg( test) ]
245249mod test {
246250 use super :: * ;
251+ use cargo_metadata:: { PackageBuilder , PackageId , Source } ;
247252
248253 #[ test_log:: test]
249254 fn parsing_spirv_std_dep_for_shader_template ( ) {
@@ -277,4 +282,50 @@ mod test {
277282 . unwrap ( ) ;
278283 assert_eq ! ( "https___github_com_Rust-GPU_rust-gpu+86fc4803" , & name) ;
279284 }
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+ }
280331}
0 commit comments