@@ -14,6 +14,7 @@ use std::ffi::{OsStr, OsString};
14
14
use std:: fs;
15
15
use std:: path:: PathBuf ;
16
16
use std:: process:: Command ;
17
+ use walkdir:: WalkDir ;
17
18
18
19
use crate :: builder:: Kind ;
19
20
use crate :: core:: config:: Target ;
@@ -177,6 +178,34 @@ than building it.
177
178
continue ;
178
179
}
179
180
181
+ // Check if there exists a built-in target in the list of supported targets.
182
+ let mut has_target = false ;
183
+ let target_str = target. to_string ( ) ;
184
+
185
+ let supported_target_list =
186
+ output ( Command :: new ( & build. config . initial_rustc ) . args ( [ "--print" , "target-list" ] ) ) ;
187
+
188
+ has_target |= supported_target_list. contains ( & target_str) ;
189
+
190
+ // If not, check for a valid file location that may have been specified
191
+ // by the user for the custom target.
192
+ if let Some ( custom_target_path) = env:: var_os ( "RUST_TARGET_PATH" ) {
193
+ let mut target_os_str = OsString :: from ( & target_str) ;
194
+ target_os_str. push ( ".json" ) ;
195
+ // Recursively traverse through nested directories.
196
+ let walker = WalkDir :: new ( custom_target_path) . into_iter ( ) ;
197
+ for entry in walker. filter_map ( |e| e. ok ( ) ) {
198
+ has_target |= entry. file_name ( ) == target_os_str;
199
+ }
200
+ }
201
+
202
+ if !has_target && ![ "A" , "B" , "C" ] . contains ( & target_str. as_str ( ) ) {
203
+ panic ! (
204
+ "No such target exists in the target list,
205
+ specify a correct location of the JSON specification file for custom targets!"
206
+ ) ;
207
+ }
208
+
180
209
if !build. config . dry_run ( ) {
181
210
cmd_finder. must_have ( build. cc ( * target) ) ;
182
211
if let Some ( ar) = build. ar ( * target) {
0 commit comments