File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -411,6 +411,26 @@ pub fn warning(message: &str) {
411
411
emit ( "warning" , message) ;
412
412
}
413
413
414
+ /// The `error` instruction tells Cargo to display an error after the build script has finished
415
+ /// running, and then fail the build.
416
+ ///
417
+ /// <div class="warning">
418
+ ///
419
+ /// Build script libraries should carefully consider if they want to use [`error`] versus
420
+ /// returning a `Result`. It may be better to return a `Result`, and allow the caller to decide if the
421
+ /// error is fatal or not. The caller can then decide whether or not to display the `Err` variant
422
+ /// using [`error`].
423
+ ///
424
+ /// </div>
425
+ #[ doc = respected_msrv ! ( "1.84" ) ]
426
+ #[ track_caller]
427
+ pub fn error ( message : & str ) {
428
+ if message. contains ( '\n' ) {
429
+ panic ! ( "cannot emit warning: message contains newline" ) ;
430
+ }
431
+ emit ( "error" , message) ;
432
+ }
433
+
414
434
/// Metadata, used by `links` scripts.
415
435
#[ track_caller]
416
436
pub fn metadata ( key : & str , val : & str ) {
You can’t perform that action at this time.
0 commit comments