Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message when failing on unknown targets #1313

Merged
merged 2 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading