From 2607f6d30fd492fe0657cbd23b278cff7d8aadd3 Mon Sep 17 00:00:00 2001 From: Tor Hovland <55164+torhovland@users.noreply.github.com> Date: Tue, 7 May 2024 10:58:55 +0200 Subject: [PATCH] Old syntax suggestion. --- src/cargo/core/compiler/custom_build.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 0e1ca88ea6d..318602d8ffb 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -725,13 +725,26 @@ impl BuildOutput { fn check_minimum_supported_rust_version_for_new_syntax( pkg_descr: &str, msrv: &Option, + key: &str, ) -> CargoResult<()> { if let Some(msrv) = msrv { let new_syntax_added_in = RustVersion::from_str("1.77.0")?; if !new_syntax_added_in.is_compatible_with(msrv.as_partial()) { + let prefix = format!("{key}="); + + let old_syntax_suggestion = RESERVED_PREFIXES + .contains(&&*prefix) + .then(|| { + format!( + "Consider using the old `cargo:` syntax in front of `{prefix}`.\n" + ) + }) + .unwrap_or_default(); + bail!( "the `cargo::` syntax for build script output instructions was added in \ Rust 1.77.0, but the minimum supported Rust version of `{pkg_descr}` is {msrv}.\n\ + {old_syntax_suggestion}\ {DOCS_LINK_SUGGESTION}" ); } @@ -793,9 +806,10 @@ impl BuildOutput { }; let mut old_syntax = false; let (key, value) = if let Some(data) = line.strip_prefix("cargo::") { - check_minimum_supported_rust_version_for_new_syntax(pkg_descr, msrv)?; // For instance, `cargo::rustc-flags=foo` or `cargo::metadata=foo=bar`. - parse_directive(whence.as_str(), line, data, old_syntax)? + let (key, value) = parse_directive(whence.as_str(), line, data, old_syntax)?; + check_minimum_supported_rust_version_for_new_syntax(pkg_descr, msrv, key)?; + (key, value) } else if let Some(data) = line.strip_prefix("cargo:") { old_syntax = true; // For instance, `cargo:rustc-flags=foo`.