@@ -103,6 +103,10 @@ pub enum SpirvBuilderError {
103103 MissingCratePath ,
104104 #[ error( "crate path {0} does not exist" ) ]
105105 CratePathDoesntExist ( PathBuf ) ,
106+ #[ error(
107+ "Without feature `compile_codegen`, you need to set the path of the codegen dylib using `rustc_codegen_spirv_location(...)`"
108+ ) ]
109+ MissingCodegenBackendDylib ,
106110 #[ error( "build failed" ) ]
107111 BuildFailed ,
108112 #[ error( "multi-module build cannot be used with print_metadata = MetadataPrintout::Full" ) ]
@@ -643,27 +647,23 @@ fn dylib_path() -> Vec<PathBuf> {
643647 }
644648}
645649
646- #[ cfg( feature = "compile_codegen" ) ]
647- fn find_rustc_codegen_spirv ( ) -> PathBuf {
648- let filename = format ! (
649- "{}rustc_codegen_spirv{}" ,
650- env:: consts:: DLL_PREFIX ,
651- env:: consts:: DLL_SUFFIX
652- ) ;
653- for mut path in dylib_path ( ) {
654- path. push ( & filename) ;
655- if path. is_file ( ) {
656- return path;
650+ fn find_rustc_codegen_spirv ( ) -> Result < PathBuf , SpirvBuilderError > {
651+ if cfg ! ( feature = "compile_codegen" ) {
652+ let filename = format ! (
653+ "{}rustc_codegen_spirv{}" ,
654+ env:: consts:: DLL_PREFIX ,
655+ env:: consts:: DLL_SUFFIX
656+ ) ;
657+ for mut path in dylib_path ( ) {
658+ path. push ( & filename) ;
659+ if path. is_file ( ) {
660+ return Ok ( path) ;
661+ }
657662 }
663+ panic ! ( "Could not find {filename} in library path" ) ;
664+ } else {
665+ Err ( SpirvBuilderError :: MissingCodegenBackendDylib )
658666 }
659- panic ! ( "Could not find {filename} in library path" ) ;
660- }
661-
662- #[ cfg( not( feature = "compile_codegen" ) ) ]
663- fn find_rustc_codegen_spirv ( ) -> PathBuf {
664- panic ! (
665- "Without feature `compile_codegen`, you need to set the path of the codegen dylib using `rustc_codegen_spirv_location(...)`"
666- ) ;
667667}
668668
669669/// Joins strings together while ensuring none of the strings contain the separator.
@@ -729,10 +729,9 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
729729 // alongside build.rs, and cargo will helpfully add it to LD_LIBRARY_PATH for us! However,
730730 // rustc expects a full path, instead of a filename looked up via LD_LIBRARY_PATH, so we need
731731 // to copy cargo's understanding of library lookup and find the library and its full path.
732- let rustc_codegen_spirv = builder
733- . rustc_codegen_spirv_location
734- . clone ( )
735- . unwrap_or_else ( find_rustc_codegen_spirv) ;
732+ let rustc_codegen_spirv = Ok ( builder. rustc_codegen_spirv_location . clone ( ) )
733+ . transpose ( )
734+ . unwrap_or_else ( find_rustc_codegen_spirv) ?;
736735
737736 let mut rustflags = vec ! [
738737 format!( "-Zcodegen-backend={}" , rustc_codegen_spirv. display( ) ) ,
0 commit comments