mirror of
https://github.com/rust-lang/cargo.git
synced 2025-09-25 11:14:46 +00:00
feat(build-rs): Add the 'error' directive
This commit is contained in:
parent
260fcab3b3
commit
5fa8a686fa
@ -403,6 +403,26 @@ pub fn warning(message: &str) {
|
||||
emit("warning", message);
|
||||
}
|
||||
|
||||
/// The `error` instruction tells Cargo to display an error after the build script has finished
|
||||
/// running, and then fail the build.
|
||||
///
|
||||
/// <div class="warning">
|
||||
///
|
||||
/// Build script libraries should carefully consider if they want to use [`error`] versus
|
||||
/// returning a `Result`. It may be better to return a `Result`, and allow the caller to decide if the
|
||||
/// error is fatal or not. The caller can then decide whether or not to display the `Err` variant
|
||||
/// using [`error`].
|
||||
///
|
||||
/// </div>
|
||||
#[doc = respected_msrv!("1.84")]
|
||||
#[track_caller]
|
||||
pub fn error(message: &str) {
|
||||
if message.contains('\n') {
|
||||
panic!("cannot emit warning: message contains newline");
|
||||
}
|
||||
emit("error", message);
|
||||
}
|
||||
|
||||
/// Metadata, used by `links` scripts.
|
||||
#[track_caller]
|
||||
pub fn metadata(key: &str, val: &str) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user