@@ -88,11 +88,10 @@ use std::path::{Path, PathBuf};
8888use std:: process:: { Command , Stdio } ;
8989use thiserror:: Error ;
9090
91- pub use rustc_codegen_spirv_types:: Capability ;
92- pub use rustc_codegen_spirv_types:: { CompileResult , ModuleResult } ;
93-
9491#[ cfg( feature = "watch" ) ]
9592pub use self :: watch:: { SpirvWatcher , SpirvWatcherError } ;
93+ pub use rustc_codegen_spirv_types:: Capability ;
94+ pub use rustc_codegen_spirv_types:: { CompileResult , ModuleResult , TargetSpecVersion } ;
9695
9796#[ derive( Debug , Error ) ]
9897#[ non_exhaustive]
@@ -113,11 +112,6 @@ pub enum SpirvBuilderError {
113112 MissingRustcCodegenSpirvDylib ,
114113 #[ error( "`rustc_codegen_spirv_location` path '{0}' is not a file" ) ]
115114 RustcCodegenSpirvDylibDoesNotExist ( PathBuf ) ,
116- #[ error(
117- "Without feature `include-target-specs`, instead of setting a `target`, \
118- you need to set the path of the target spec file of your particular target with `path_to_target_spec`"
119- ) ]
120- MissingTargetSpec ,
121115 #[ error( "build failed" ) ]
122116 BuildFailed ,
123117 #[ error( "multi-module build cannot be used with print_metadata = MetadataPrintout::Full" ) ]
@@ -458,12 +452,6 @@ pub struct SpirvBuilder {
458452 #[ cfg_attr( feature = "clap" , clap( skip) ) ]
459453 pub toolchain_rustc_version : Option < Version > ,
460454
461- /// The path of the "target specification" file.
462- ///
463- /// For more info on "target specification" see
464- /// [this RFC](https://rust-lang.github.io/rfcs/0131-target-specification.html).
465- #[ cfg_attr( feature = "clap" , clap( skip) ) ]
466- pub path_to_target_spec : Option < PathBuf > ,
467455 /// Set the target dir path to use for building shaders. Relative paths will be resolved
468456 /// relative to the `target` dir of the shader crate, absolute paths are used as is.
469457 /// Defaults to `spirv-builder`, resulting in the path `./target/spirv-builder`.
@@ -514,7 +502,6 @@ impl Default for SpirvBuilder {
514502 extensions : Vec :: new ( ) ,
515503 extra_args : Vec :: new ( ) ,
516504 rustc_codegen_spirv_location : None ,
517- path_to_target_spec : None ,
518505 target_dir_path : None ,
519506 toolchain_overwrite : None ,
520507 toolchain_rustc_version : None ,
@@ -535,16 +522,6 @@ impl SpirvBuilder {
535522 }
536523 }
537524
538- /// Sets the path of the "target specification" file.
539- ///
540- /// For more info on "target specification" see
541- /// [this RFC](https://rust-lang.github.io/rfcs/0131-target-specification.html).
542- #[ must_use]
543- pub fn target_spec ( mut self , p : impl AsRef < Path > ) -> Self {
544- self . path_to_target_spec = Some ( p. as_ref ( ) . to_path_buf ( ) ) ;
545- self
546- }
547-
548525 /// Whether to print build.rs cargo metadata (e.g. cargo:rustc-env=var=val). Defaults to [`MetadataPrintout::Full`].
549526 #[ must_use]
550527 pub fn print_metadata ( mut self , v : MetadataPrintout ) -> Self {
@@ -802,16 +779,17 @@ fn join_checking_for_separators(strings: Vec<impl Borrow<str>>, sep: &str) -> St
802779
803780// Returns path to the metadata json.
804781fn invoke_rustc ( builder : & SpirvBuilder ) -> Result < PathBuf , SpirvBuilderError > {
805- let target = builder
806- . target
807- . as_ref ( )
808- . ok_or ( SpirvBuilderError :: MissingTarget ) ?;
809782 let path_to_crate = builder
810783 . path_to_crate
811784 . as_ref ( )
812785 . ok_or ( SpirvBuilderError :: MissingCratePath ) ?;
786+ let target_env;
813787 {
814- let target_env = target. strip_prefix ( SPIRV_TARGET_PREFIX ) . ok_or_else ( || {
788+ let target = builder
789+ . target
790+ . as_ref ( )
791+ . ok_or ( SpirvBuilderError :: MissingTarget ) ?;
792+ target_env = target. strip_prefix ( SPIRV_TARGET_PREFIX ) . ok_or_else ( || {
815793 SpirvBuilderError :: NonSpirvTarget {
816794 target : target. clone ( ) ,
817795 }
@@ -1032,19 +1010,10 @@ fn invoke_rustc(builder: &SpirvBuilder) -> Result<PathBuf, SpirvBuilderError> {
10321010 cargo. args ( extra_cargoflags. split_whitespace ( ) ) ;
10331011 }
10341012
1035- // FIXME(eddyb) consider moving `target-specs` into `rustc_codegen_spirv_types`.
1036- // FIXME(eddyb) consider the `RUST_TARGET_PATH` env var alternative.
1037-
1038- // NOTE(firestar99) rustc 1.76 has been tested to correctly parse modern
1039- // target_spec jsons, some later version requires them, some earlier
1040- // version fails with them (notably our 0.9.0 release)
1041- if toolchain_rustc_version >= Version :: new ( 1 , 76 , 0 ) {
1042- let path_opt = builder. path_to_target_spec . clone ( ) ;
1043- let path = path_opt. ok_or ( SpirvBuilderError :: MissingTargetSpec ) ?;
1044- cargo. arg ( "--target" ) . arg ( path) ;
1045- } else {
1046- cargo. arg ( "--target" ) . arg ( target) ;
1047- }
1013+ let target_spec_dir = target_dir. join ( "target-specs" ) ;
1014+ let target =
1015+ TargetSpecVersion :: target_arg ( toolchain_rustc_version, target_env, & target_spec_dir) ?;
1016+ cargo. arg ( "--target" ) . arg ( target) ;
10481017
10491018 if !builder. shader_crate_features . default_features {
10501019 cargo. arg ( "--no-default-features" ) ;
0 commit comments