@@ -301,6 +301,8 @@ pub struct SpirvBuilder {
301301 capabilities : Vec < Capability > ,
302302 extensions : Vec < String > ,
303303 extra_args : Vec < String > ,
304+ // Optional location of a known `rustc_codegen_spirv` dylib
305+ rustc_codegen_spirv_location : Option < std:: path:: PathBuf > ,
304306
305307 // `rustc_codegen_spirv::linker` codegen args
306308 pub shader_panic_strategy : ShaderPanicStrategy ,
@@ -330,6 +332,7 @@ impl SpirvBuilder {
330332 capabilities : Vec :: new ( ) ,
331333 extensions : Vec :: new ( ) ,
332334 extra_args : Vec :: new ( ) ,
335+ rustc_codegen_spirv_location : None ,
333336
334337 shader_panic_strategy : ShaderPanicStrategy :: SilentExit ,
335338
@@ -482,6 +485,21 @@ impl SpirvBuilder {
482485 self
483486 }
484487
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+
485503 /// Builds the module. If `print_metadata` is [`MetadataPrintout::Full`], you usually don't have to inspect the path
486504 /// in the result, as the environment variable for the path to the module will already be set.
487505 pub fn build ( mut self ) -> Result < CompileResult , SpirvBuilderError > {
@@ -624,7 +642,10 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
624642 // alongside build.rs, and cargo will helpfully add it to LD_LIBRARY_PATH for us! However,
625643 // rustc expects a full path, instead of a filename looked up via LD_LIBRARY_PATH, so we need
626644 // 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) ;
628649
629650 let mut rustflags = vec ! [
630651 format!( "-Zcodegen-backend={}" , rustc_codegen_spirv. display( ) ) ,
0 commit comments