Skip to content

Commit

Permalink
Better error message when failing on unknown targets (#1313)
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm authored Dec 4, 2024
1 parent 75973f4 commit b62d8c7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ enum ErrorKind {
ToolFamilyMacroNotFound,
/// Invalid target.
InvalidTarget,
/// Unknown target.
UnknownTarget,
/// Invalid rustc flag.
InvalidFlag,
#[cfg(feature = "parallel")]
Expand Down Expand Up @@ -3979,7 +3981,7 @@ impl Default for Build {
}

fn fail(s: &str) -> ! {
eprintln!("\n\nerror occurred: {}\n\n", s);
eprintln!("\n\nerror occurred in cc-rs: {}\n\n", s);
std::process::exit(1);
}

Expand Down
16 changes: 14 additions & 2 deletions src/target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,20 @@ impl FromStr for TargetInfo<'_> {
Ok(info.clone())
} else {
Err(Error::new(
ErrorKind::InvalidTarget,
format!("unknown target `{target_triple}`"),
ErrorKind::UnknownTarget,
format!(
"unknown target `{target_triple}`.
NOTE: `cc-rs` only supports a fixed set of targets when not in a build script.
- If adding a new target, you will need to fork of `cc-rs` until the target
has landed on nightly and the auto-generated list has been updated. See also
the `rustc` dev guide on adding a new target:
https://rustc-dev-guide.rust-lang.org/building/new-target.html
- If using a custom target, prefer to upstream it to `rustc` if possible,
otherwise open an issue with `cc-rs`:
https://github.com/rust-lang/cc-rs/issues/new
"
),
))
}
}
Expand Down

0 comments on commit b62d8c7

Please sign in to comment.