Skip to content

Commit 6f2248d

Browse files
committed
Support target-spec json file extension in various cases (case-insensitive)
1 parent 524d806 commit 6f2248d

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

compiler/rustc_session/src/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,7 @@ fn collect_print_requests(
19911991

19921992
pub fn parse_target_triple(early_dcx: &EarlyDiagCtxt, matches: &getopts::Matches) -> TargetTriple {
19931993
match matches.opt_str("target") {
1994-
Some(target) if target.ends_with(".json") => {
1994+
Some(target) if TargetTriple::has_json_ext(&target) => {
19951995
let path = Path::new(&target);
19961996
TargetTriple::from_path(path).unwrap_or_else(|_| {
19971997
early_dcx.early_fatal(format!("target file {path:?} does not exist"))

compiler/rustc_target/src/spec/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3709,6 +3709,18 @@ impl TargetTriple {
37093709
}
37103710
}
37113711
}
3712+
3713+
/// Helper function to check if the given `triple` ends with `".json"` __case-insensitive__.
3714+
/// Does not check if the path exists.
3715+
pub fn has_json_ext<S: AsRef<str>>(triple: S) -> bool {
3716+
const EXT: &'static str = ".json";
3717+
triple.as_ref().ends_with(EXT) || {
3718+
let s = triple.as_ref();
3719+
s.get(s.len().wrapping_sub(EXT.len())..)
3720+
.map(|ext| ext.eq_ignore_ascii_case(EXT))
3721+
.unwrap_or_default()
3722+
}
3723+
}
37123724
}
37133725

37143726
impl fmt::Display for TargetTriple {

0 commit comments

Comments
 (0)