Skip to content

Commit 3583233

Browse files
committed
bootstrap: fix bug preventing the use of custom targets
the bug was caused by two factors: 1. only checking the RUST_TARGET_PATH form, not the full filepath form 2. indirectly trying to use the Debug presentation to get the file path
1 parent 54be9ad commit 3583233

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

src/bootstrap/src/core/config/config.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,17 +518,21 @@ impl TargetSelection {
518518

519519
impl fmt::Display for TargetSelection {
520520
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
521-
write!(f, "{}", self.triple)?;
522521
if let Some(file) = self.file {
523-
write!(f, "({file})")?;
522+
write!(f, "{file}")
523+
} else {
524+
write!(f, "{}", self.triple)
524525
}
525-
Ok(())
526526
}
527527
}
528528

529529
impl fmt::Debug for TargetSelection {
530530
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
531-
write!(f, "{self}")
531+
write!(f, "{}", self.triple)?;
532+
if let Some(file) = self.file {
533+
write!(f, "({file})")?;
534+
}
535+
Ok(())
532536
}
533537
}
534538

src/bootstrap/src/core/sanity.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use std::collections::HashMap;
1212
use std::env;
1313
use std::ffi::{OsStr, OsString};
1414
use std::fs;
15-
use std::path::PathBuf;
15+
use std::path::{Path, PathBuf};
1616

1717
#[cfg(not(feature = "bootstrap-self-test"))]
1818
use crate::builder::Builder;
@@ -262,7 +262,9 @@ than building it.
262262

263263
if !has_target {
264264
// This might also be a custom target, so check the target file that could have been specified by the user.
265-
if let Some(custom_target_path) = env::var_os("RUST_TARGET_PATH") {
265+
if Path::new(&target_str).exists() {
266+
has_target = true;
267+
} else if let Some(custom_target_path) = env::var_os("RUST_TARGET_PATH") {
266268
let mut target_filename = OsString::from(&target_str);
267269
// Target filename ends with `.json`.
268270
target_filename.push(".json");
@@ -277,8 +279,12 @@ than building it.
277279

278280
if !has_target {
279281
panic!(
280-
"No such target exists in the target list,
281-
specify a correct location of the JSON specification file for custom targets!"
282+
"No such target exists in the target list,\n\
283+
make sure to correctly specify the location \
284+
of the JSON specification file \
285+
for custom targets!\n\
286+
Use BOOTSTRAP_SKIP_TARGET_SANITY=1 to \
287+
bypass this check."
282288
);
283289
}
284290
}

0 commit comments

Comments
 (0)