@@ -303,6 +303,8 @@ pub struct SpirvBuilder {
303303 extra_args : Vec < String > ,
304304 // Optional location of a known `rustc_codegen_spirv` dylib
305305 rustc_codegen_spirv_location : Option < std:: path:: PathBuf > ,
306+ // Optional location of a known "target-spec" file
307+ path_to_target_spec : Option < PathBuf > ,
306308
307309 // `rustc_codegen_spirv::linker` codegen args
308310 pub shader_panic_strategy : ShaderPanicStrategy ,
@@ -333,6 +335,7 @@ impl SpirvBuilder {
333335 extensions : Vec :: new ( ) ,
334336 extra_args : Vec :: new ( ) ,
335337 rustc_codegen_spirv_location : None ,
338+ path_to_target_spec : None ,
336339
337340 shader_panic_strategy : ShaderPanicStrategy :: SilentExit ,
338341
@@ -348,6 +351,16 @@ impl SpirvBuilder {
348351 }
349352 }
350353
354+ /// Sets the path of the "target specification" file.
355+ ///
356+ /// For more info on "target specification" see
357+ /// [this RFC](https://rust-lang.github.io/rfcs/0131-target-specification.html).
358+ #[ must_use]
359+ pub fn target_spec ( mut self , p : impl AsRef < Path > ) -> Self {
360+ self . path_to_target_spec = Some ( p. as_ref ( ) . to_path_buf ( ) ) ;
361+ self
362+ }
363+
351364 /// Whether to print build.rs cargo metadata (e.g. cargo:rustc-env=var=val). Defaults to [`MetadataPrintout::Full`].
352365 #[ must_use]
353366 pub fn print_metadata ( mut self , v : MetadataPrintout ) -> Self {
@@ -794,9 +807,11 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
794807 // FIXME(eddyb) consider moving `target-specs` into `rustc_codegen_spirv_types`.
795808 // FIXME(eddyb) consider the `RUST_TARGET_PATH` env var alternative.
796809 cargo. arg ( "--target" ) . arg (
797- Path :: new ( env ! ( "CARGO_MANIFEST_DIR" ) )
798- . join ( "target-specs" )
799- . join ( format ! ( "{}.json" , builder. target) ) ,
810+ builder. path_to_target_spec . clone ( ) . unwrap_or_else ( || {
811+ PathBuf :: from ( env ! ( "CARGO_MANIFEST_DIR" ) )
812+ . join ( "target-specs" )
813+ . join ( format ! ( "{}.json" , builder. target) )
814+ } ) ,
800815 ) ;
801816
802817 if let Some ( default_features) = builder. shader_crate_features . default_features {
0 commit comments