Skip to content

Commit 1dadee6

Browse files
committed
Auto merge of #13808 - weihanglo:buildscript-msrv, r=epage
fix: emit 1.77 syntax error only when msrv is incompatible
2 parents e91b58d + ba5ec68 commit 1dadee6

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

src/cargo/core/compiler/custom_build.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,10 +724,9 @@ impl BuildOutput {
724724
pkg_descr: &str,
725725
msrv: &Option<RustVersion>,
726726
) -> CargoResult<()> {
727-
let new_syntax_added_in = &RustVersion::from_str("1.77.0")?;
728-
729727
if let Some(msrv) = msrv {
730-
if msrv < new_syntax_added_in {
728+
let new_syntax_added_in = RustVersion::from_str("1.77.0")?;
729+
if !new_syntax_added_in.is_compatible_with(msrv.as_partial()) {
731730
bail!(
732731
"the `cargo::` syntax for build script output instructions was added in \
733732
Rust 1.77.0, but the minimum supported Rust version of `{pkg_descr}` is {msrv}.\n\

tests/testsuite/build_script.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5502,6 +5502,39 @@ for more information about build script outputs.
55025502
.run();
55035503
}
55045504

5505+
#[cargo_test]
5506+
fn test_new_syntax_with_compatible_partial_msrv() {
5507+
let p = project()
5508+
.file(
5509+
"Cargo.toml",
5510+
r#"
5511+
[package]
5512+
name = "foo"
5513+
edition = "2015"
5514+
build = "build.rs"
5515+
rust-version = "1.77"
5516+
"#,
5517+
)
5518+
.file("src/lib.rs", "")
5519+
.file(
5520+
"build.rs",
5521+
r#"
5522+
fn main() {
5523+
println!("cargo::metadata=foo=bar");
5524+
}
5525+
"#,
5526+
)
5527+
.build();
5528+
5529+
p.cargo("check")
5530+
.with_stderr_contains(
5531+
"\
5532+
[COMPILING] foo [..]
5533+
",
5534+
)
5535+
.run();
5536+
}
5537+
55055538
#[cargo_test]
55065539
fn test_old_syntax_with_old_msrv() {
55075540
let p = project()

0 commit comments

Comments
 (0)