@@ -301,6 +301,8 @@ pub struct SpirvBuilder {
301
301
capabilities : Vec < Capability > ,
302
302
extensions : Vec < String > ,
303
303
extra_args : Vec < String > ,
304
+ // Optional location of a known `rustc_codegen_spirv` dylib
305
+ rustc_codegen_spirv_location : Option < std:: path:: PathBuf > ,
304
306
305
307
// `rustc_codegen_spirv::linker` codegen args
306
308
pub shader_panic_strategy : ShaderPanicStrategy ,
@@ -330,6 +332,7 @@ impl SpirvBuilder {
330
332
capabilities : Vec :: new ( ) ,
331
333
extensions : Vec :: new ( ) ,
332
334
extra_args : Vec :: new ( ) ,
335
+ rustc_codegen_spirv_location : None ,
333
336
334
337
shader_panic_strategy : ShaderPanicStrategy :: SilentExit ,
335
338
@@ -482,6 +485,21 @@ impl SpirvBuilder {
482
485
self
483
486
}
484
487
488
+ #[ must_use]
489
+ pub fn rustc_codegen_spirv_location (
490
+ mut self ,
491
+ path_to_dylib : impl AsRef < std:: path:: Path > ,
492
+ ) -> Self {
493
+ let path_to_dylib = path_to_dylib. as_ref ( ) . to_path_buf ( ) ;
494
+ assert ! (
495
+ path_to_dylib. is_file( ) ,
496
+ "Provided path to dylib '{}' is not a file" ,
497
+ path_to_dylib. display( )
498
+ ) ;
499
+ self . rustc_codegen_spirv_location = Some ( path_to_dylib) ;
500
+ self
501
+ }
502
+
485
503
/// Builds the module. If `print_metadata` is [`MetadataPrintout::Full`], you usually don't have to inspect the path
486
504
/// in the result, as the environment variable for the path to the module will already be set.
487
505
pub fn build ( mut self ) -> Result < CompileResult , SpirvBuilderError > {
@@ -624,7 +642,10 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
624
642
// alongside build.rs, and cargo will helpfully add it to LD_LIBRARY_PATH for us! However,
625
643
// rustc expects a full path, instead of a filename looked up via LD_LIBRARY_PATH, so we need
626
644
// to copy cargo's understanding of library lookup and find the library and its full path.
627
- let rustc_codegen_spirv = find_rustc_codegen_spirv ( ) ;
645
+ let rustc_codegen_spirv = builder
646
+ . rustc_codegen_spirv_location
647
+ . clone ( )
648
+ . unwrap_or_else ( find_rustc_codegen_spirv) ;
628
649
629
650
let mut rustflags = vec ! [
630
651
format!( "-Zcodegen-backend={}" , rustc_codegen_spirv. display( ) ) ,
0 commit comments