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 @@ -403,6 +403,26 @@ pub fn warning(message: &str) {
403403 emit ( "warning" , message) ;
404404}
405405
406+ /// The `error` instruction tells Cargo to display an error after the build script has finished
407+ /// running, and then fail the build.
408+ ///
409+ /// <div class="warning">
410+ ///
411+ /// Build script libraries should carefully consider if they want to use [`error`] versus
412+ /// returning a `Result`. It may be better to return a `Result`, and allow the caller to decide if the
413+ /// error is fatal or not. The caller can then decide whether or not to display the `Err` variant
414+ /// using [`error`].
415+ ///
416+ /// </div>
417+ #[ doc = respected_msrv ! ( "1.84" ) ]
418+ #[ track_caller]
419+ pub fn error ( message : & str ) {
420+ if message. contains ( '\n' ) {
421+ panic ! ( "cannot emit warning: message contains newline" ) ;
422+ }
423+ emit ( "error" , message) ;
424+ }
425+
406426/// Metadata, used by `links` scripts.
407427#[ track_caller]
408428pub fn metadata ( key : & str , val : & str ) {
You can’t perform that action at this time.
0 commit comments