@@ -42,10 +42,11 @@ use crate::util::{internal, profile};
42
42
use anyhow:: { bail, Context as _} ;
43
43
use cargo_platform:: Cfg ;
44
44
use cargo_util:: paths;
45
+ use cargo_util_schemas:: manifest:: RustVersion ;
45
46
use std:: collections:: hash_map:: { Entry , HashMap } ;
46
47
use std:: collections:: { BTreeSet , HashSet } ;
47
48
use std:: path:: { Path , PathBuf } ;
48
- use std:: str;
49
+ use std:: str:: { self , FromStr } ;
49
50
use std:: sync:: { Arc , Mutex } ;
50
51
51
52
/// Deprecated: A build script instruction that tells Cargo to display a warning after the
@@ -413,8 +414,10 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
413
414
let nightly_features_allowed = cx. bcx . config . nightly_features_allowed ;
414
415
let extra_check_cfg = cx. bcx . config . cli_unstable ( ) . check_cfg ;
415
416
let targets: Vec < Target > = unit. pkg . targets ( ) . to_vec ( ) ;
417
+ let msrv = unit. pkg . rust_version ( ) . cloned ( ) ;
416
418
// Need a separate copy for the fresh closure.
417
419
let targets_fresh = targets. clone ( ) ;
420
+ let msrv_fresh = msrv. clone ( ) ;
418
421
419
422
let env_profile_name = unit. profile . name . to_uppercase ( ) ;
420
423
let built_with_debuginfo = cx
@@ -560,6 +563,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
560
563
extra_check_cfg,
561
564
nightly_features_allowed,
562
565
& targets,
566
+ & msrv,
563
567
) ?;
564
568
565
569
if json_messages {
@@ -588,6 +592,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult<Job> {
588
592
extra_check_cfg,
589
593
nightly_features_allowed,
590
594
& targets_fresh,
595
+ & msrv_fresh,
591
596
) ?,
592
597
} ;
593
598
@@ -644,6 +649,7 @@ impl BuildOutput {
644
649
extra_check_cfg : bool ,
645
650
nightly_features_allowed : bool ,
646
651
targets : & [ Target ] ,
652
+ msrv : & Option < RustVersion > ,
647
653
) -> CargoResult < BuildOutput > {
648
654
let contents = paths:: read_bytes ( path) ?;
649
655
BuildOutput :: parse (
@@ -655,6 +661,7 @@ impl BuildOutput {
655
661
extra_check_cfg,
656
662
nightly_features_allowed,
657
663
targets,
664
+ msrv,
658
665
)
659
666
}
660
667
@@ -675,6 +682,7 @@ impl BuildOutput {
675
682
extra_check_cfg : bool ,
676
683
nightly_features_allowed : bool ,
677
684
targets : & [ Target ] ,
685
+ msrv : & Option < RustVersion > ,
678
686
) -> CargoResult < BuildOutput > {
679
687
let mut library_paths = Vec :: new ( ) ;
680
688
let mut library_links = Vec :: new ( ) ;
@@ -715,6 +723,25 @@ impl BuildOutput {
715
723
const DOCS_LINK_SUGGESTION : & str = "See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \
716
724
for more information about build script outputs.";
717
725
726
+ fn check_minimum_supported_rust_version_for_new_syntax (
727
+ pkg_descr : & str ,
728
+ msrv : & Option < RustVersion > ,
729
+ ) -> CargoResult < ( ) > {
730
+ let new_syntax_added_in = & RustVersion :: from_str ( "1.77.0" ) ?;
731
+
732
+ if let Some ( msrv) = msrv {
733
+ if msrv < new_syntax_added_in {
734
+ bail ! (
735
+ "the `cargo::` syntax for build script output instructions was added in \
736
+ Rust 1.77.0, but the minimum supported Rust version of `{pkg_descr}` is {msrv}.\n \
737
+ {DOCS_LINK_SUGGESTION}"
738
+ ) ;
739
+ }
740
+ }
741
+
742
+ Ok ( ( ) )
743
+ }
744
+
718
745
fn parse_directive < ' a > (
719
746
whence : & str ,
720
747
line : & str ,
@@ -768,6 +795,7 @@ impl BuildOutput {
768
795
} ;
769
796
let mut old_syntax = false ;
770
797
let ( key, value) = if let Some ( data) = line. strip_prefix ( "cargo::" ) {
798
+ check_minimum_supported_rust_version_for_new_syntax ( pkg_descr, msrv) ?;
771
799
// For instance, `cargo::rustc-flags=foo` or `cargo::metadata=foo=bar`.
772
800
parse_directive ( whence. as_str ( ) , line, data, old_syntax) ?
773
801
} else if let Some ( data) = line. strip_prefix ( "cargo:" ) {
@@ -1220,6 +1248,7 @@ fn prev_build_output(cx: &mut Context<'_, '_>, unit: &Unit) -> (Option<BuildOutp
1220
1248
cx. bcx . config . cli_unstable ( ) . check_cfg ,
1221
1249
cx. bcx . config . nightly_features_allowed ,
1222
1250
unit. pkg . targets ( ) ,
1251
+ & unit. pkg . rust_version ( ) . cloned ( ) ,
1223
1252
)
1224
1253
. ok ( ) ,
1225
1254
prev_script_out_dir,
0 commit comments