@@ -93,6 +93,7 @@ use thiserror::Error;
93
93
pub use rustc_codegen_spirv_target_specs:: {
94
94
IntoSpirvTarget , SpirvTargetEnv , SpirvTargetParseError ,
95
95
} ;
96
+ pub use rustc_codegen_spirv_target_specs:: { deserialize_target, serialize_target} ;
96
97
pub use rustc_codegen_spirv_types:: * ;
97
98
98
99
#[ cfg( feature = "include-target-specs" ) ]
@@ -101,8 +102,10 @@ pub use rustc_codegen_spirv_target_specs::TARGET_SPEC_DIR_PATH;
101
102
#[ derive( Debug , Error ) ]
102
103
#[ non_exhaustive]
103
104
pub enum SpirvBuilderError {
104
- #[ error( "`target` must be set or was invalid , for example `spirv-unknown-vulkan1.2`" ) ]
105
+ #[ error( "`target` must be set, for example `spirv-unknown-vulkan1.2`" ) ]
105
106
MissingTarget ,
107
+ #[ error( "Error parsing target: {0}" ) ]
108
+ SpirvTargetParseError ( #[ from] SpirvTargetParseError ) ,
106
109
#[ error( "`path_to_crate` must be set" ) ]
107
110
MissingCratePath ,
108
111
#[ error( "crate path '{0}' does not exist" ) ]
@@ -383,10 +386,14 @@ pub struct SpirvBuilder {
383
386
clap(
384
387
long,
385
388
default_value = "spirv-unknown-vulkan1.2" ,
386
- value_parser = SpirvTargetEnv :: parse_triple
389
+ value_parser = Self :: parse_target
387
390
)
388
391
) ]
389
- pub target : Option < SpirvTargetEnv > ,
392
+ #[ serde(
393
+ serialize_with = "serialize_target" ,
394
+ deserialize_with = "deserialize_target"
395
+ ) ]
396
+ pub target : Option < Result < SpirvTargetEnv , SpirvTargetParseError > > ,
390
397
/// Cargo features specification for building the shader crate.
391
398
#[ cfg_attr( feature = "clap" , clap( flatten) ) ]
392
399
#[ serde( flatten) ]
@@ -455,6 +462,12 @@ pub struct SpirvBuilder {
455
462
456
463
#[ cfg( feature = "clap" ) ]
457
464
impl SpirvBuilder {
465
+ fn parse_target (
466
+ target : & str ,
467
+ ) -> Result < Result < SpirvTargetEnv , SpirvTargetParseError > , clap:: Error > {
468
+ Ok ( SpirvTargetEnv :: parse_triple ( target) )
469
+ }
470
+
458
471
/// Clap value parser for `Capability`.
459
472
fn parse_spirv_capability ( capability : & str ) -> Result < Capability , clap:: Error > {
460
473
use core:: str:: FromStr ;
@@ -495,7 +508,7 @@ impl SpirvBuilder {
495
508
pub fn new ( path_to_crate : impl AsRef < Path > , target : impl IntoSpirvTarget ) -> Self {
496
509
Self {
497
510
path_to_crate : Some ( path_to_crate. as_ref ( ) . to_owned ( ) ) ,
498
- target : target. to_spirv_target_env ( ) . ok ( ) ,
511
+ target : Some ( target. to_spirv_target_env ( ) ) ,
499
512
..SpirvBuilder :: default ( )
500
513
}
501
514
}
@@ -762,7 +775,10 @@ fn join_checking_for_separators(strings: Vec<impl Borrow<str>>, sep: &str) -> St
762
775
763
776
// Returns path to the metadata json.
764
777
fn invoke_rustc ( builder : & SpirvBuilder ) -> Result < PathBuf , SpirvBuilderError > {
765
- let target = builder. target . ok_or ( SpirvBuilderError :: MissingTarget ) ?;
778
+ let target = builder
779
+ . target
780
+ . clone ( )
781
+ . ok_or ( SpirvBuilderError :: MissingTarget ) ??;
766
782
let path_to_crate = builder
767
783
. path_to_crate
768
784
. as_ref ( )
0 commit comments