@@ -81,79 +81,42 @@ use serde::Deserialize;
81
81
use std:: borrow:: Borrow ;
82
82
use std:: collections:: HashMap ;
83
83
use std:: env;
84
- use std:: error:: Error ;
85
- use std:: fmt;
86
84
use std:: fs:: File ;
87
85
use std:: io:: BufReader ;
88
86
use std:: path:: { Path , PathBuf } ;
89
87
use std:: process:: { Command , Stdio } ;
88
+ use thiserror:: Error ;
90
89
91
90
pub use rustc_codegen_spirv_types:: Capability ;
92
91
pub use rustc_codegen_spirv_types:: { CompileResult , ModuleResult } ;
93
92
94
- #[ derive( Debug ) ]
93
+ #[ derive( Debug , Error ) ]
95
94
#[ non_exhaustive]
96
95
pub enum SpirvBuilderError {
96
+ #[ error( "`target` must be set, for example `spirv-unknown-vulkan1.2`" ) ]
97
+ NoTargetSet ,
98
+ #[ error( "expected `{SPIRV_TARGET_PREFIX}...` target, found `{target}`" ) ]
97
99
NonSpirvTarget { target : String } ,
100
+ #[ error( "SPIR-V target `{SPIRV_TARGET_PREFIX}-{target_env}` is not supported" ) ]
98
101
UnsupportedSpirvTargetEnv { target_env : String } ,
102
+ #[ error( "`path_to_crate` must be set" ) ]
103
+ NoCratePathSet ,
104
+ #[ error( "crate path {0} does not exist" ) ]
99
105
CratePathDoesntExist ( PathBuf ) ,
106
+ #[ error( "build failed" ) ]
100
107
BuildFailed ,
108
+ #[ error( "multi-module build cannot be used with print_metadata = MetadataPrintout::Full" ) ]
101
109
MultiModuleWithPrintMetadata ,
110
+ #[ error( "watching within build scripts will prevent build completion" ) ]
102
111
WatchWithPrintMetadata ,
103
- MetadataFileMissing ( std:: io:: Error ) ,
104
- MetadataFileMalformed ( serde_json:: Error ) ,
112
+ #[ error( "multi-module metadata file missing" ) ]
113
+ MetadataFileMissing ( #[ from] std:: io:: Error ) ,
114
+ #[ error( "unable to parse multi-module metadata file" ) ]
115
+ MetadataFileMalformed ( #[ from] serde_json:: Error ) ,
105
116
}
106
117
107
118
const SPIRV_TARGET_PREFIX : & str = "spirv-unknown-" ;
108
119
109
- impl fmt:: Display for SpirvBuilderError {
110
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
111
- match self {
112
- Self :: NonSpirvTarget { target } => {
113
- write ! (
114
- f,
115
- "expected `{SPIRV_TARGET_PREFIX}...` target, found `{target}`"
116
- )
117
- }
118
- Self :: UnsupportedSpirvTargetEnv { target_env } if target_env. starts_with ( "opencl" ) => {
119
- write ! (
120
- f,
121
- "OpenCL targets like `{SPIRV_TARGET_PREFIX}-{target_env}` are not supported"
122
- )
123
- }
124
- Self :: UnsupportedSpirvTargetEnv { target_env } if target_env. starts_with ( "webgpu" ) => {
125
- write ! (
126
- f,
127
- "WebGPU targets like `{SPIRV_TARGET_PREFIX}-{target_env}` are not supported, \
128
- consider using `{SPIRV_TARGET_PREFIX}-vulkan1.0` instead"
129
- )
130
- }
131
- Self :: UnsupportedSpirvTargetEnv { target_env } => {
132
- write ! (
133
- f,
134
- "SPIR-V target `{SPIRV_TARGET_PREFIX}-{target_env}` is not supported"
135
- )
136
- }
137
- Self :: CratePathDoesntExist ( path) => {
138
- write ! ( f, "crate path {} does not exist" , path. display( ) )
139
- }
140
- Self :: BuildFailed => f. write_str ( "build failed" ) ,
141
- Self :: MultiModuleWithPrintMetadata => f. write_str (
142
- "multi-module build cannot be used with print_metadata = MetadataPrintout::Full" ,
143
- ) ,
144
- Self :: WatchWithPrintMetadata => {
145
- f. write_str ( "watching within build scripts will prevent build completion" )
146
- }
147
- Self :: MetadataFileMissing ( _) => f. write_str ( "multi-module metadata file missing" ) ,
148
- Self :: MetadataFileMalformed ( _) => {
149
- f. write_str ( "unable to parse multi-module metadata file" )
150
- }
151
- }
152
- }
153
- }
154
-
155
- impl Error for SpirvBuilderError { }
156
-
157
120
#[ derive( Debug , PartialEq , Eq , Clone , Copy ) ]
158
121
pub enum MetadataPrintout {
159
122
/// Print no cargo metadata.
0 commit comments