Skip to content

Commit 4600945

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 0b5eb7b commit 4600945

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
@@ -516,17 +516,21 @@ impl TargetSelection {
516516

517517
impl fmt::Display for TargetSelection {
518518
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
519-
write!(f, "{}", self.triple)?;
520519
if let Some(file) = self.file {
521-
write!(f, "({file})")?;
520+
write!(f, "{file}")
521+
} else {
522+
write!(f, "{}", self.triple)
522523
}
523-
Ok(())
524524
}
525525
}
526526

527527
impl fmt::Debug for TargetSelection {
528528
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
529-
write!(f, "{self}")
529+
write!(f, "{}", self.triple)?;
530+
if let Some(file) = self.file {
531+
write!(f, "({file})")?;
532+
}
533+
Ok(())
530534
}
531535
}
532536

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
#[cfg(not(feature = "bootstrap-self-test"))]
1313
use std::collections::HashSet;
1414
use std::ffi::{OsStr, OsString};
15-
use std::path::PathBuf;
15+
use std::path::{Path, PathBuf};
1616
use std::{env, fs};
1717

1818
#[cfg(not(feature = "bootstrap-self-test"))]
@@ -260,7 +260,9 @@ than building it.
260260

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

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

0 commit comments

Comments
 (0)