Skip to content

Commit 103ed0c

Browse files
committed
Search for target_triple.json only if builtin target not found
Before this commit, if the builtin target was found, but an error happened when instantiating it (e.g. validating the target specification file failed, etc.), then we ignored those errors and proceeded to try to find a `target_triple.json` file, and if that failed, reported that as an error. With this commit, if rustc is supposed to provide the builtin target, and something fails while instantiating it, that error will get properly propagated.
1 parent f66e469 commit 103ed0c

File tree

1 file changed

+16
-6
lines changed
  • src/librustc_target/spec

1 file changed

+16
-6
lines changed

src/librustc_target/spec/mod.rs

+16-6
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ impl ToJson for MergeFunctions {
259259
}
260260
}
261261

262+
pub enum LoadTargetError {
263+
BuiltinTargetNotFound(String),
264+
Other(String),
265+
}
266+
262267
pub type LinkArgs = BTreeMap<LinkerFlavor, Vec<String>>;
263268
pub type TargetResult = Result<Target, String>;
264269

@@ -269,21 +274,24 @@ macro_rules! supported_targets {
269274
/// List of supported targets
270275
const TARGETS: &[&str] = &[$($triple),*];
271276

272-
fn load_specific(target: &str) -> TargetResult {
277+
fn load_specific(target: &str) -> Result<Target, LoadTargetError> {
273278
match target {
274279
$(
275280
$triple => {
276-
let mut t = $module::target()?;
281+
let mut t = $module::target()
282+
.map_err(LoadTargetError::Other)?;
277283
t.options.is_builtin = true;
278284

279285
// round-trip through the JSON parser to ensure at
280286
// run-time that the parser works correctly
281-
t = Target::from_json(t.to_json())?;
287+
t = Target::from_json(t.to_json())
288+
.map_err(LoadTargetError::Other)?;
282289
debug!("Got builtin target: {:?}", t);
283290
Ok(t)
284291
},
285292
)+
286-
_ => Err(format!("Unable to find target: {}", target))
293+
_ => Err(LoadTargetError::BuiltinTargetNotFound(
294+
format!("Unable to find target: {}", target)))
287295
}
288296
}
289297

@@ -1176,8 +1184,10 @@ impl Target {
11761184
match *target_triple {
11771185
TargetTriple::TargetTriple(ref target_triple) => {
11781186
// check if triple is in list of supported targets
1179-
if let Ok(t) = load_specific(target_triple) {
1180-
return Ok(t)
1187+
match load_specific(target_triple) {
1188+
Ok(t) => return Ok(t),
1189+
Err(LoadTargetError::BuiltinTargetNotFound(_)) => (),
1190+
Err(LoadTargetError::Other(e)) => return Err(e),
11811191
}
11821192

11831193
// search for a file named `target_triple`.json in RUST_TARGET_PATH

0 commit comments

Comments
 (0)