diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index c921986a838..a3da04224c9 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -42,18 +42,23 @@ use crate::util::{internal, profile}; use anyhow::{bail, Context as _}; use cargo_platform::Cfg; use cargo_util::paths; +use cargo_util_schemas::manifest::RustVersion; use std::collections::hash_map::{Entry, HashMap}; use std::collections::{BTreeSet, HashSet}; use std::path::{Path, PathBuf}; -use std::str; +use std::str::{self, FromStr}; use std::sync::{Arc, Mutex}; +/// Deprecated: A build script instruction that tells Cargo to display a warning after the +/// build script has finished running. Read [the doc] for more. +/// +/// [the doc]: https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#cargo-warning +const OLD_CARGO_WARNING_SYNTAX: &str = "cargo:warning="; /// A build script instruction that tells Cargo to display a warning after the /// build script has finished running. Read [the doc] for more. /// /// [the doc]: https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#cargo-warning -const CARGO_WARNING: &str = "cargo:warning="; - +const NEW_CARGO_WARNING_SYNTAX: &str = "cargo::warning="; /// Contains the parsed output of a custom build script. #[derive(Clone, Debug, Hash, Default)] pub struct BuildOutput { @@ -146,7 +151,7 @@ pub struct BuildDeps { pub rerun_if_env_changed: Vec, } -/// Represents one of the instructions from `cargo:rustc-link-arg-*` build +/// Represents one of the instructions from `cargo::rustc-link-arg-*` build /// script instruction family. /// /// In other words, indicates targets that custom linker arguments applies to. @@ -156,19 +161,19 @@ pub struct BuildDeps { /// [1]: https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#cargorustc-link-argflag #[derive(Clone, Hash, Debug, PartialEq, Eq)] pub enum LinkArgTarget { - /// Represents `cargo:rustc-link-arg=FLAG`. + /// Represents `cargo::rustc-link-arg=FLAG`. All, - /// Represents `cargo:rustc-cdylib-link-arg=FLAG`. + /// Represents `cargo::rustc-cdylib-link-arg=FLAG`. Cdylib, - /// Represents `cargo:rustc-link-arg-bins=FLAG`. + /// Represents `cargo::rustc-link-arg-bins=FLAG`. Bin, - /// Represents `cargo:rustc-link-arg-bin=BIN=FLAG`. + /// Represents `cargo::rustc-link-arg-bin=BIN=FLAG`. SingleBin(String), - /// Represents `cargo:rustc-link-arg-tests=FLAG`. + /// Represents `cargo::rustc-link-arg-tests=FLAG`. Test, - /// Represents `cargo:rustc-link-arg-benches=FLAG`. + /// Represents `cargo::rustc-link-arg-benches=FLAG`. Bench, - /// Represents `cargo:rustc-link-arg-examples=FLAG`. + /// Represents `cargo::rustc-link-arg-examples=FLAG`. Example, } @@ -409,8 +414,10 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { let nightly_features_allowed = cx.bcx.config.nightly_features_allowed; let extra_check_cfg = cx.bcx.config.cli_unstable().check_cfg; let targets: Vec = unit.pkg.targets().to_vec(); + let msrv = unit.pkg.rust_version().cloned(); // Need a separate copy for the fresh closure. let targets_fresh = targets.clone(); + let msrv_fresh = msrv.clone(); let env_profile_name = unit.profile.name.to_uppercase(); let built_with_debuginfo = cx @@ -478,7 +485,10 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { let output = cmd .exec_with_streaming( &mut |stdout| { - if let Some(warning) = stdout.strip_prefix(CARGO_WARNING) { + if let Some(warning) = stdout + .strip_prefix(OLD_CARGO_WARNING_SYNTAX) + .or(stdout.strip_prefix(NEW_CARGO_WARNING_SYNTAX)) + { warnings_in_case_of_panic.push(warning.to_owned()); } if extra_verbose { @@ -553,6 +563,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { extra_check_cfg, nightly_features_allowed, &targets, + &msrv, )?; if json_messages { @@ -581,6 +592,7 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { extra_check_cfg, nightly_features_allowed, &targets_fresh, + &msrv_fresh, )?, }; @@ -637,6 +649,7 @@ impl BuildOutput { extra_check_cfg: bool, nightly_features_allowed: bool, targets: &[Target], + msrv: &Option, ) -> CargoResult { let contents = paths::read_bytes(path)?; BuildOutput::parse( @@ -648,6 +661,7 @@ impl BuildOutput { extra_check_cfg, nightly_features_allowed, targets, + msrv, ) } @@ -668,6 +682,7 @@ impl BuildOutput { extra_check_cfg: bool, nightly_features_allowed: bool, targets: &[Target], + msrv: &Option, ) -> CargoResult { let mut library_paths = Vec::new(); let mut library_links = Vec::new(); @@ -680,50 +695,139 @@ impl BuildOutput { let mut rerun_if_env_changed = Vec::new(); let mut warnings = Vec::new(); let whence = format!("build script of `{}`", pkg_descr); + // Old syntax: + // cargo:rustc-flags=VALUE + // cargo:KEY=VALUE (for other unreserved keys) + // New syntax: + // cargo::rustc-flags=VALUE + // cargo::metadata=KEY=VALUE (for other unreserved keys) + // Due to backwards compatibility, no new keys can be added to this old format. + const RESERVED_PREFIXES: &[&str] = &[ + "rustc-flags=", + "rustc-link-lib=", + "rustc-link-search=", + "rustc-link-arg-cdylib=", + "rustc-link-arg-bins=", + "rustc-link-arg-bin=", + "rustc-link-arg-tests=", + "rustc-link-arg-benches=", + "rustc-link-arg-examples=", + "rustc-link-arg=", + "rustc-cfg=", + "rustc-check-cfg=", + "rustc-env=", + "warning=", + "rerun-if-changed=", + "rerun-if-env-changed=", + ]; + const DOCS_LINK_SUGGESTION: &str = "See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \ + for more information about build script outputs."; + + fn check_minimum_supported_rust_version_for_new_syntax( + pkg_descr: &str, + msrv: &Option, + ) -> CargoResult<()> { + let new_syntax_added_in = &RustVersion::from_str("1.77.0")?; + + if let Some(msrv) = msrv { + if msrv < new_syntax_added_in { + 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\ + {DOCS_LINK_SUGGESTION}" + ); + } + } + + Ok(()) + } + + fn parse_directive<'a>( + whence: &str, + line: &str, + data: &'a str, + old_syntax: bool, + ) -> CargoResult<(&'a str, &'a str)> { + let mut iter = data.splitn(2, "="); + let key = iter.next(); + let value = iter.next(); + match (key, value) { + (Some(a), Some(b)) => Ok((a, b.trim_end())), + _ => bail!( + "invalid output in {whence}: `{line}`\n\ + Expected a line with `{syntax}KEY=VALUE` with an `=` character, \ + but none was found.\n\ + {DOCS_LINK_SUGGESTION}", + syntax = if old_syntax { "cargo:" } else { "cargo::" }, + ), + } + } + + fn parse_metadata<'a>( + whence: &str, + line: &str, + data: &'a str, + old_syntax: bool, + ) -> CargoResult<(&'a str, &'a str)> { + let mut iter = data.splitn(2, "="); + let key = iter.next(); + let value = iter.next(); + match (key, value) { + (Some(a), Some(b)) => Ok((a, b.trim_end())), + _ => bail!( + "invalid output in {whence}: `{line}`\n\ + Expected a line with `{syntax}KEY=VALUE` with an `=` character, \ + but none was found.\n\ + {DOCS_LINK_SUGGESTION}", + syntax = if old_syntax { + "cargo:" + } else { + "cargo::metadata=" + }, + ), + } + } for line in input.split(|b| *b == b'\n') { let line = match str::from_utf8(line) { Ok(line) => line.trim(), Err(..) => continue, }; - let data = match line.split_once(':') { - Some(("cargo", val)) => { - if val.starts_with(":") { - // Line started with `cargo::`. - bail!("unsupported output in {whence}: `{line}`\n\ - Found a `cargo::key=value` build directive which is reserved for future use.\n\ - Either change the directive to `cargo:key=value` syntax (note the single `:`) or upgrade your version of Rust.\n\ - See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \ - for more information about build script outputs."); - } - val + 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)? + } else if let Some(data) = line.strip_prefix("cargo:") { + old_syntax = true; + // For instance, `cargo:rustc-flags=foo`. + if RESERVED_PREFIXES + .iter() + .any(|prefix| data.starts_with(prefix)) + { + parse_directive(whence.as_str(), line, data, old_syntax)? + } else { + // For instance, `cargo:foo=bar`. + ("metadata", data) } - _ => continue, - }; - - // getting the `key=value` part of the line - let (key, value) = match data.split_once('=') { - Some((a,b)) => (a, b.trim_end()), - // Line started with `cargo:` but didn't match `key=value`. - _ => bail!("invalid output in {}: `{}`\n\ - Expected a line with `cargo:key=value` with an `=` character, \ - but none was found.\n\ - See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \ - for more information about build script outputs.", whence, line), + } else { + // Skip this line since it doesn't start with "cargo:" or "cargo::". + continue; }; - // This will rewrite paths if the target directory has been moved. let value = value.replace( script_out_dir_when_generated.to_str().unwrap(), script_out_dir.to_str().unwrap(), ); + let syntax_prefix = if old_syntax { "cargo:" } else { "cargo::" }; macro_rules! check_and_add_target { ($target_kind: expr, $is_target_kind: expr, $link_type: expr) => { if !targets.iter().any(|target| $is_target_kind(target)) { bail!( - "invalid instruction `cargo:{}` from {}\n\ + "invalid instruction `{}{}` from {}\n\ The package {} does not have a {} target.", + syntax_prefix, key, whence, pkg_descr, @@ -746,14 +850,14 @@ impl BuildOutput { "rustc-link-arg-cdylib" | "rustc-cdylib-link-arg" => { if !targets.iter().any(|target| target.is_cdylib()) { warnings.push(format!( - "cargo:{} was specified in the build script of {}, \ + "{}{} was specified in the build script of {}, \ but that package does not contain a cdylib target\n\ \n\ Allowing this was an unintended change in the 1.50 \ release, and may become an error in the future. \ For more information, see \ .", - key, pkg_descr + syntax_prefix, key, pkg_descr )); } linker_args.push((LinkArgTarget::Cdylib, value)) @@ -764,11 +868,13 @@ impl BuildOutput { "rustc-link-arg-bin" => { let (bin_name, arg) = value.split_once('=').ok_or_else(|| { anyhow::format_err!( - "invalid instruction `cargo:{}={}` from {}\n\ - The instruction should have the form cargo:{}=BIN=ARG", + "invalid instruction `{}{}={}` from {}\n\ + The instruction should have the form {}{}=BIN=ARG", + syntax_prefix, key, value, whence, + syntax_prefix, key ) })?; @@ -777,8 +883,9 @@ impl BuildOutput { .any(|target| target.is_bin() && target.name() == bin_name) { bail!( - "invalid instruction `cargo:{}` from {}\n\ + "invalid instruction `{}{}` from {}\n\ The package {} does not have a bin target with the name `{}`.", + syntax_prefix, key, whence, pkg_descr, @@ -807,7 +914,10 @@ impl BuildOutput { if extra_check_cfg { check_cfgs.push(value.to_string()); } else { - warnings.push(format!("cargo:{} requires -Zcheck-cfg flag", key)); + warnings.push(format!( + "{}{} requires -Zcheck-cfg flag", + syntax_prefix, key + )); } } "rustc-env" => { @@ -864,7 +974,15 @@ impl BuildOutput { "warning" => warnings.push(value.to_string()), "rerun-if-changed" => rerun_if_changed.push(PathBuf::from(value)), "rerun-if-env-changed" => rerun_if_env_changed.push(value.to_string()), - _ => metadata.push((key.to_string(), value.to_string())), + "metadata" => { + let (key, value) = parse_metadata(whence.as_str(), line, &value, old_syntax)?; + metadata.push((key.to_owned(), value.to_owned())); + } + _ => bail!( + "invalid output in {whence}: `{line}`\n\ + Unknown key: `{key}`.\n\ + {DOCS_LINK_SUGGESTION}", + ), } } @@ -882,9 +1000,9 @@ impl BuildOutput { }) } - /// Parses [`cargo:rustc-flags`] instruction. + /// Parses [`cargo::rustc-flags`] instruction. /// - /// [`cargo:rustc-flags`]: https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#cargorustc-flagsflags + /// [`cargo::rustc-flags`]: https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#cargorustc-flagsflags pub fn parse_rustc_flags( value: &str, whence: &str, @@ -930,9 +1048,9 @@ impl BuildOutput { Ok((library_paths, library_links)) } - /// Parses [`cargo:rustc-env`] instruction. + /// Parses [`cargo::rustc-env`] instruction. /// - /// [`cargo:rustc-env`]: https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-env + /// [`cargo::rustc-env`]: https://doc.rust-lang.org/nightly/cargo/reference/build-scripts.html#rustc-env pub fn parse_rustc_env(value: &str, whence: &str) -> CargoResult<(String, String)> { match value.split_once('=') { Some((n, v)) => Ok((n.to_owned(), v.to_owned())), @@ -1130,6 +1248,7 @@ fn prev_build_output(cx: &mut Context<'_, '_>, unit: &Unit) -> (Option { s.dirty_because(unit, "the local lengths changed")?; s.note( - "This could happen because of added/removed `cargo:rerun-if` instructions in the build script", + "This could happen because of added/removed `cargo::rerun-if` instructions in the build script", )?; Ok(()) diff --git a/src/doc/src/faq.md b/src/doc/src/faq.md index 9d4a982d047..e4206481cd0 100644 --- a/src/doc/src/faq.md +++ b/src/doc/src/faq.md @@ -242,7 +242,7 @@ Cargo has no way right now of after-the-fact debugging "why was that rebuilt?" Some issues we've seen historically which can cause crates to get rebuilt are: -* A build script prints `cargo:rerun-if-changed=foo` where `foo` is a file that +* A build script prints `cargo::rerun-if-changed=foo` where `foo` is a file that doesn't exist and nothing generates it. In this case Cargo will keep running the build script thinking it will generate the file but nothing ever does. The fix is to avoid printing `rerun-if-changed` in this scenario. @@ -280,38 +280,38 @@ issue](https://github.com/rust-lang/cargo/issues/new)! Have you seen the error message above? -This is one of the most annoying error message for Cargo users. There are several -situations may lead us to a version conflict. Below we'll walk through possible +This is one of the most annoying error message for Cargo users. There are several +situations may lead us to a version conflict. Below we'll walk through possible causes and provide diagnostic techniques to help you out there: -- The project and its dependencies use [links] to repeatedly link the local - library. Cargo forbids linking two packages with the same native library, so - even with multiple layers of dependencies it is not allowed. In this case, the - error message will prompt: `Only one package in the dependency graph may specify - the same links value`, you may need to manually check and delete duplicate link +- The project and its dependencies use [links] to repeatedly link the local + library. Cargo forbids linking two packages with the same native library, so + even with multiple layers of dependencies it is not allowed. In this case, the + error message will prompt: `Only one package in the dependency graph may specify + the same links value`, you may need to manually check and delete duplicate link values. The community also have [conventions in place] to alleviate this. -- When depending on different crates in the project, if these crates use the same - dependent library, but the version used is restricted, making it impossible to - determine the correct version, it will also cause conflicts. The error message - will prompt: `all possible versions conflict with previously selected packages`. +- When depending on different crates in the project, if these crates use the same + dependent library, but the version used is restricted, making it impossible to + determine the correct version, it will also cause conflicts. The error message + will prompt: `all possible versions conflict with previously selected packages`. You may need to modify the version requirements to make them consistent. -- If there are multiple versions of dependencies in the project, when using - [`direct-minimal-versions`], the minimum version requirements cannot be met, +- If there are multiple versions of dependencies in the project, when using + [`direct-minimal-versions`], the minimum version requirements cannot be met, which will cause conflicts. You may need to modify version requirements of your direct dependencies to meet the minimum SemVer version accordingly. -- If the dependent crate does not have the features you choose, it will also - cause conflicts. At this time, you need to check the dependent version and its +- If the dependent crate does not have the features you choose, it will also + cause conflicts. At this time, you need to check the dependent version and its features. -- Conflicts may occur when merging branches or PRs, if there are non-trivial - conflicts, you can reset all "yours" changes, fix all other conflicts in the - branch, and then run some cargo command (like `cargo tree` or `cargo check`), - which should re-update the lockfile with your own local changes. If you previously - ran some `cargo update` commands in your branch, you can re-run them that this - time. The community has been looking to resolve merge conflicts with `Cargo.lock` +- Conflicts may occur when merging branches or PRs, if there are non-trivial + conflicts, you can reset all "yours" changes, fix all other conflicts in the + branch, and then run some cargo command (like `cargo tree` or `cargo check`), + which should re-update the lockfile with your own local changes. If you previously + ran some `cargo update` commands in your branch, you can re-run them that this + time. The community has been looking to resolve merge conflicts with `Cargo.lock` and `Cargo.toml` using a [custom merge tool]. diff --git a/src/doc/src/reference/build-script-examples.md b/src/doc/src/reference/build-script-examples.md index e55d4704dc1..9bcb392c2db 100644 --- a/src/doc/src/reference/build-script-examples.md +++ b/src/doc/src/reference/build-script-examples.md @@ -71,7 +71,7 @@ fn main() { } " ).unwrap(); - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=build.rs"); } ``` @@ -173,9 +173,9 @@ fn main() { .current_dir(&Path::new(&out_dir)) .status().unwrap(); - println!("cargo:rustc-link-search=native={}", out_dir); - println!("cargo:rustc-link-lib=static=hello"); - println!("cargo:rerun-if-changed=src/hello.c"); + println!("cargo::rustc-link-search=native={}", out_dir); + println!("cargo::rustc-link-lib=static=hello"); + println!("cargo::rerun-if-changed=src/hello.c"); } ``` @@ -214,7 +214,7 @@ fn main() { cc::Build::new() .file("src/hello.c") .compile("hello"); - println!("cargo:rerun-if-changed=src/hello.c"); + println!("cargo::rerun-if-changed=src/hello.c"); } ``` @@ -316,7 +316,7 @@ The build script is fairly simple: fn main() { pkg_config::Config::new().probe("zlib").unwrap(); - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=build.rs"); } ``` @@ -344,9 +344,9 @@ Run `cargo build -vv` to see the output from the build script. On a system with `libz` already installed, it may look something like this: ```text -[libz-sys 0.1.0] cargo:rustc-link-search=native=/usr/lib -[libz-sys 0.1.0] cargo:rustc-link-lib=z -[libz-sys 0.1.0] cargo:rerun-if-changed=build.rs +[libz-sys 0.1.0] cargo::rustc-link-search=native=/usr/lib +[libz-sys 0.1.0] cargo::rustc-link-lib=z +[libz-sys 0.1.0] cargo::rerun-if-changed=build.rs ``` Nice! `pkg-config` did all the work of finding the library and telling Cargo @@ -408,7 +408,7 @@ fn main() { cfg.include(include); } cfg.compile("zuser"); - println!("cargo:rerun-if-changed=src/zuser.c"); + println!("cargo::rerun-if-changed=src/zuser.c"); } ``` @@ -440,7 +440,7 @@ script looks something [like this](https://github.com/sfackler/rust-openssl/blob/dc72a8e2c429e46c275e528b61a733a66e7877fc/openssl-sys/build/main.rs#L216): ```rust,ignore -println!("cargo:version_number={:x}", openssl_version); +println!("cargo::version_number={:x}", openssl_version); ``` This instruction causes the `DEP_OPENSSL_VERSION_NUMBER` environment variable @@ -460,19 +460,19 @@ if let Ok(version) = env::var("DEP_OPENSSL_VERSION_NUMBER") { let version = u64::from_str_radix(&version, 16).unwrap(); if version >= 0x1_00_01_00_0 { - println!("cargo:rustc-cfg=ossl101"); + println!("cargo::rustc-cfg=ossl101"); } if version >= 0x1_00_02_00_0 { - println!("cargo:rustc-cfg=ossl102"); + println!("cargo::rustc-cfg=ossl102"); } if version >= 0x1_01_00_00_0 { - println!("cargo:rustc-cfg=ossl110"); + println!("cargo::rustc-cfg=ossl110"); } if version >= 0x1_01_00_07_0 { - println!("cargo:rustc-cfg=ossl110g"); + println!("cargo::rustc-cfg=ossl110g"); } if version >= 0x1_01_01_00_0 { - println!("cargo:rustc-cfg=ossl111"); + println!("cargo::rustc-cfg=ossl111"); } } ``` diff --git a/src/doc/src/reference/build-scripts.md b/src/doc/src/reference/build-scripts.md index 451850388ce..e49d3c78b2c 100644 --- a/src/doc/src/reference/build-scripts.md +++ b/src/doc/src/reference/build-scripts.md @@ -15,7 +15,7 @@ that script and execute it just before building the package. // Example custom build script. fn main() { // Tell Cargo that if the given file changes, to rerun this build script. - println!("cargo:rerun-if-changed=src/hello.c"); + println!("cargo::rerun-if-changed=src/hello.c"); // Use the `cc` crate to build a C file and statically link it. cc::Build::new() .file("src/hello.c") @@ -42,7 +42,7 @@ scripts. Just before a package is built, Cargo will compile a build script into an executable (if it has not already been built). It will then run the script, which may perform any number of tasks. The script may communicate with Cargo -by printing specially formatted commands prefixed with `cargo:` to stdout. +by printing specially formatted commands prefixed with `cargo::` to stdout. The build script will be rebuilt if any of its source files or dependencies change. @@ -74,16 +74,23 @@ directory specified in the [`OUT_DIR` environment variable][build-env]. Scripts should not modify any files outside of that directory. Build scripts communicate with Cargo by printing to stdout. Cargo will -interpret each line that starts with `cargo:` as an instruction that will +interpret each line that starts with `cargo::` as an instruction that will influence compilation of the package. All other lines are ignored. -> Note: The order of `cargo:` instructions printed by the build script *may* +> **Note:** The old invocation prefix `cargo:` (one colon only) is deprecated +> and won't get any new features. To migrate, use two-colons prefix `cargo::`, +> which was added in Rust 1.77. If you were using `cargo:KEY=VALUE` for +> arbitrary links manifest key-value pairs, it is encouraged to switch to +> `cargo::metadata=KEY=VALUE`. Stick to `cargo:` only if the support of Rust +> version older than 1.77 is required. + +> The order of `cargo::` instructions printed by the build script *may* > affect the order of arguments that `cargo` passes to `rustc`. In turn, the > order of arguments passed to `rustc` may affect the order of arguments passed > to the linker. Therefore, you will want to pay attention to the order of the > build script's instructions. For example, if object `foo` needs to link against > library `bar`, you may want to make sure that library `bar`'s -> [`cargo:rustc-link-lib`](#rustc-link-lib) instruction appears *after* +> [`cargo::rustc-link-lib`](#rustc-link-lib) instruction appears *after* > instructions to link object `foo`. The output of the script is hidden from the terminal during normal @@ -99,40 +106,39 @@ configuration). The stderr output is also saved in that same directory. The following is a summary of the instructions that Cargo recognizes, with each one detailed below. -* [`cargo:rerun-if-changed=PATH`](#rerun-if-changed) --- Tells Cargo when to +* [`cargo::rerun-if-changed=PATH`](#rerun-if-changed) --- Tells Cargo when to re-run the script. -* [`cargo:rerun-if-env-changed=VAR`](#rerun-if-env-changed) --- Tells Cargo when +* [`cargo::rerun-if-env-changed=VAR`](#rerun-if-env-changed) --- Tells Cargo when to re-run the script. -* [`cargo:rustc-link-arg=FLAG`](#rustc-link-arg) --- Passes custom flags to a +* [`cargo::rustc-link-arg=FLAG`](#rustc-link-arg) --- Passes custom flags to a linker for benchmarks, binaries, `cdylib` crates, examples, and tests. -* [`cargo:rustc-link-arg-bin=BIN=FLAG`](#rustc-link-arg-bin) --- Passes custom +* [`cargo::rustc-link-arg-bin=BIN=FLAG`](#rustc-link-arg-bin) --- Passes custom flags to a linker for the binary `BIN`. -* [`cargo:rustc-link-arg-bins=FLAG`](#rustc-link-arg-bins) --- Passes custom +* [`cargo::rustc-link-arg-bins=FLAG`](#rustc-link-arg-bins) --- Passes custom flags to a linker for binaries. -* [`cargo:rustc-link-arg-tests=FLAG`](#rustc-link-arg-tests) --- Passes custom +* [`cargo::rustc-link-arg-tests=FLAG`](#rustc-link-arg-tests) --- Passes custom flags to a linker for tests. -* [`cargo:rustc-link-arg-examples=FLAG`](#rustc-link-arg-examples) --- Passes custom +* [`cargo::rustc-link-arg-examples=FLAG`](#rustc-link-arg-examples) --- Passes custom flags to a linker for examples. -* [`cargo:rustc-link-arg-benches=FLAG`](#rustc-link-arg-benches) --- Passes custom +* [`cargo::rustc-link-arg-benches=FLAG`](#rustc-link-arg-benches) --- Passes custom flags to a linker for benchmarks. -* [`cargo:rustc-link-lib=LIB`](#rustc-link-lib) --- Adds a library to +* [`cargo::rustc-link-lib=LIB`](#rustc-link-lib) --- Adds a library to link. -* [`cargo:rustc-link-search=[KIND=]PATH`](#rustc-link-search) --- Adds to the +* [`cargo::rustc-link-search=[KIND=]PATH`](#rustc-link-search) --- Adds to the library search path. -* [`cargo:rustc-flags=FLAGS`](#rustc-flags) --- Passes certain flags to the +* [`cargo::rustc-flags=FLAGS`](#rustc-flags) --- Passes certain flags to the compiler. -* [`cargo:rustc-cfg=KEY[="VALUE"]`](#rustc-cfg) --- Enables compile-time `cfg` +* [`cargo::rustc-cfg=KEY[="VALUE"]`](#rustc-cfg) --- Enables compile-time `cfg` settings. -* [`cargo:rustc-env=VAR=VALUE`](#rustc-env) --- Sets an environment variable. -* [`cargo:rustc-cdylib-link-arg=FLAG`](#rustc-cdylib-link-arg) --- Passes custom +* [`cargo::rustc-env=VAR=VALUE`](#rustc-env) --- Sets an environment variable. +* [`cargo::rustc-cdylib-link-arg=FLAG`](#rustc-cdylib-link-arg) --- Passes custom flags to a linker for cdylib crates. -* [`cargo:warning=MESSAGE`](#cargo-warning) --- Displays a warning on the +* [`cargo::warning=MESSAGE`](#cargo-warning) --- Displays a warning on the terminal. -* [`cargo:KEY=VALUE`](#the-links-manifest-key) --- Metadata, used by `links` +* [`cargo::metadata=KEY=VALUE`](#the-links-manifest-key) --- Metadata, used by `links` scripts. - -### `cargo:rustc-link-arg=FLAG` {#rustc-link-arg} +### `cargo::rustc-link-arg=FLAG` {#rustc-link-arg} The `rustc-link-arg` instruction tells Cargo to pass the [`-C link-arg=FLAG` option][link-arg] to the compiler, but only when building supported targets @@ -142,23 +148,21 @@ linker script. [link-arg]: ../../rustc/codegen-options/index.md#link-arg -### `cargo:rustc-link-arg-bin=BIN=FLAG` {#rustc-link-arg-bin} +### `cargo::rustc-link-arg-bin=BIN=FLAG` {#rustc-link-arg-bin} The `rustc-link-arg-bin` instruction tells Cargo to pass the [`-C link-arg=FLAG` option][link-arg] to the compiler, but only when building the binary target with name `BIN`. Its usage is highly platform specific. It is useful to set a linker script or other linker options. - -### `cargo:rustc-link-arg-bins=FLAG` {#rustc-link-arg-bins} +### `cargo::rustc-link-arg-bins=FLAG` {#rustc-link-arg-bins} The `rustc-link-arg-bins` instruction tells Cargo to pass the [`-C link-arg=FLAG` option][link-arg] to the compiler, but only when building a binary target. Its usage is highly platform specific. It is useful to set a linker script or other linker options. - -### `cargo:rustc-link-lib=LIB` {#rustc-link-lib} +### `cargo::rustc-link-lib=LIB` {#rustc-link-lib} The `rustc-link-lib` instruction tells Cargo to link the given library using the compiler's [`-l` flag][option-link]. This is typically used to link a @@ -182,27 +186,25 @@ The optional `KIND` may be one of `dylib`, `static`, or `framework`. See the [option-link]: ../../rustc/command-line-arguments.md#option-l-link-lib [FFI]: ../../nomicon/ffi.md - -### `cargo:rustc-link-arg-tests=FLAG` {#rustc-link-arg-tests} +### `cargo::rustc-link-arg-tests=FLAG` {#rustc-link-arg-tests} The `rustc-link-arg-tests` instruction tells Cargo to pass the [`-C link-arg=FLAG` option][link-arg] to the compiler, but only when building a tests target. - -### `cargo:rustc-link-arg-examples=FLAG` {#rustc-link-arg-examples} +### `cargo::rustc-link-arg-examples=FLAG` {#rustc-link-arg-examples} The `rustc-link-arg-examples` instruction tells Cargo to pass the [`-C link-arg=FLAG` option][link-arg] to the compiler, but only when building an examples target. -### `cargo:rustc-link-arg-benches=FLAG` {#rustc-link-arg-benches} +### `cargo::rustc-link-arg-benches=FLAG` {#rustc-link-arg-benches} The `rustc-link-arg-benches` instruction tells Cargo to pass the [`-C link-arg=FLAG` option][link-arg] to the compiler, but only when building a benchmark target. -### `cargo:rustc-link-search=[KIND=]PATH` {#rustc-link-search} +### `cargo::rustc-link-search=[KIND=]PATH` {#rustc-link-search} The `rustc-link-search` instruction tells Cargo to pass the [`-L` flag][option-search] to the compiler to add a directory to the library search @@ -220,14 +222,14 @@ is fine). [option-search]: ../../rustc/command-line-arguments.md#option-l-search-path -### `cargo:rustc-flags=FLAGS` {#rustc-flags} +### `cargo::rustc-flags=FLAGS` {#rustc-flags} The `rustc-flags` instruction tells Cargo to pass the given space-separated flags to the compiler. This only allows the `-l` and `-L` flags, and is equivalent to using [`rustc-link-lib`](#rustc-link-lib) and [`rustc-link-search`](#rustc-link-search). -### `cargo:rustc-cfg=KEY[="VALUE"]` {#rustc-cfg} +### `cargo::rustc-cfg=KEY[="VALUE"]` {#rustc-cfg} The `rustc-cfg` instruction tells Cargo to pass the given value to the [`--cfg` flag][option-cfg] to the compiler. This may be used for compile-time @@ -239,16 +241,16 @@ used to enable an optional dependency, or enable other Cargo features. Be aware that [Cargo features] use the form `feature="foo"`. `cfg` values passed with this flag are not restricted to that form, and may provide just a single identifier, or any arbitrary key/value pair. For example, emitting -`cargo:rustc-cfg=abc` will then allow code to use `#[cfg(abc)]` (note the lack +`cargo::rustc-cfg=abc` will then allow code to use `#[cfg(abc)]` (note the lack of `feature=`). Or an arbitrary key/value pair may be used with an `=` symbol -like `cargo:rustc-cfg=my_component="foo"`. The key should be a Rust +like `cargo::rustc-cfg=my_component="foo"`. The key should be a Rust identifier, the value should be a string. [cargo features]: features.md [conditional compilation]: ../../reference/conditional-compilation.md [option-cfg]: ../../rustc/command-line-arguments.md#option-cfg -### `cargo:rustc-env=VAR=VALUE` {#rustc-env} +### `cargo::rustc-env=VAR=VALUE` {#rustc-env} The `rustc-env` instruction tells Cargo to set the given environment variable when compiling the package. The value can be then retrieved by the [`env!` @@ -268,15 +270,14 @@ Cargo][env-cargo]. [env-macro]: ../../std/macro.env.html [env-cargo]: environment-variables.md#environment-variables-cargo-sets-for-crates -### `cargo:rustc-cdylib-link-arg=FLAG` {#rustc-cdylib-link-arg} +### `cargo::rustc-cdylib-link-arg=FLAG` {#rustc-cdylib-link-arg} The `rustc-cdylib-link-arg` instruction tells Cargo to pass the [`-C link-arg=FLAG` option][link-arg] to the compiler, but only when building a `cdylib` library target. Its usage is highly platform specific. It is useful to set the shared library version or the runtime-path. - -### `cargo:warning=MESSAGE` {#cargo-warning} +### `cargo::warning=MESSAGE` {#cargo-warning} The `warning` instruction tells Cargo to display a warning after the build script has finished running. Warnings are only shown for `path` dependencies @@ -321,7 +322,7 @@ FAQ](../faq.md#why-is-cargo-rebuilding-my-code). [`exclude` and `include` fields]: manifest.md#the-exclude-and-include-fields -### `cargo:rerun-if-changed=PATH` {#rerun-if-changed} +### `cargo::rerun-if-changed=PATH` {#rerun-if-changed} The `rerun-if-changed` instruction tells Cargo to re-run the build script if the file at the given path has changed. Currently, Cargo only uses the @@ -333,14 +334,14 @@ If the path points to a directory, it will scan the entire directory for any modifications. If the build script inherently does not need to re-run under any circumstance, -then emitting `cargo:rerun-if-changed=build.rs` is a simple way to prevent it +then emitting `cargo::rerun-if-changed=build.rs` is a simple way to prevent it from being re-run (otherwise, the default if no `rerun-if` instructions are emitted is to scan the entire package directory for changes). Cargo automatically handles whether or not the script itself needs to be recompiled, and of course the script will be re-run after it has been recompiled. Otherwise, specifying `build.rs` is redundant and unnecessary. -### `cargo:rerun-if-env-changed=NAME` {#rerun-if-env-changed} +### `cargo::rerun-if-env-changed=NAME` {#rerun-if-env-changed} The `rerun-if-env-changed` instruction tells Cargo to re-run the build script if the value of an environment variable of the given name has changed. @@ -351,7 +352,6 @@ variables like `TARGET` that [Cargo sets for build scripts][build-env]. The environment variables in use are those received by `cargo` invocations, not those received by the executable of the build script. - ## The `links` Manifest Key The `package.links` key may be set in the `Cargo.toml` manifest to declare diff --git a/src/doc/src/reference/external-tools.md b/src/doc/src/reference/external-tools.md index e835ea3ee50..bb379aeb046 100644 --- a/src/doc/src/reference/external-tools.md +++ b/src/doc/src/reference/external-tools.md @@ -205,22 +205,22 @@ may be found in [the chapter on build scripts](build-scripts.md). "reason": "build-script-executed", /* The Package ID, a unique identifier for referring to the package. */ "package_id": "my-package 0.1.0 (path+file:///path/to/my-package)", - /* Array of libraries to link, as indicated by the `cargo:rustc-link-lib` + /* Array of libraries to link, as indicated by the `cargo::rustc-link-lib` instruction. Note that this may include a "KIND=" prefix in the string where KIND is the library kind. */ "linked_libs": ["foo", "static=bar"], /* Array of paths to include in the library search path, as indicated by - the `cargo:rustc-link-search` instruction. Note that this may include a + the `cargo::rustc-link-search` instruction. Note that this may include a "KIND=" prefix in the string where KIND is the library kind. */ "linked_paths": ["/some/path", "native=/another/path"], - /* Array of cfg values to enable, as indicated by the `cargo:rustc-cfg` + /* Array of cfg values to enable, as indicated by the `cargo::rustc-cfg` instruction. */ "cfgs": ["cfg1", "cfg2=\"string\""], /* Array of [KEY, VALUE] arrays of environment variables to set, as - indicated by the `cargo:rustc-env` instruction. + indicated by the `cargo::rustc-env` instruction. */ "env": [ ["SOME_KEY", "some value"], diff --git a/src/doc/src/reference/unstable.md b/src/doc/src/reference/unstable.md index 813276cb6ef..2a9916e1524 100644 --- a/src/doc/src/reference/unstable.md +++ b/src/doc/src/reference/unstable.md @@ -1095,7 +1095,7 @@ You can use the flag like this: cargo check -Z unstable-options -Z check-cfg ``` -### `cargo:rustc-check-cfg=CHECK_CFG` +### `cargo::rustc-check-cfg=CHECK_CFG` The `rustc-check-cfg` instruction tells Cargo to pass the given value to the `--check-cfg` flag to the compiler. This may be used for compile-time @@ -1111,7 +1111,7 @@ You can use the instruction like this: ```rust,no_run // build.rs -println!("cargo:rustc-check-cfg=cfg(foo, bar)"); +println!("cargo::rustc-check-cfg=cfg(foo, bar)"); ``` ``` diff --git a/tests/testsuite/build.rs b/tests/testsuite/build.rs index dd67161d6b1..176ec706dfd 100644 --- a/tests/testsuite/build.rs +++ b/tests/testsuite/build.rs @@ -4161,7 +4161,7 @@ fn compiler_json_error_format() { ) .file( "build.rs", - "fn main() { println!(\"cargo:rustc-cfg=xyz\") }", + "fn main() { println!(\"cargo::rustc-cfg=xyz\") }", ) .file("src/main.rs", "fn main() { let unused = 92; }") .file("bar/Cargo.toml", &basic_manifest("bar", "0.5.0")) @@ -5314,11 +5314,11 @@ fn deterministic_cfg_flags() { "build.rs", r#" fn main() { - println!("cargo:rustc-cfg=cfg_a"); - println!("cargo:rustc-cfg=cfg_b"); - println!("cargo:rustc-cfg=cfg_c"); - println!("cargo:rustc-cfg=cfg_d"); - println!("cargo:rustc-cfg=cfg_e"); + println!("cargo::rustc-cfg=cfg_a"); + println!("cargo::rustc-cfg=cfg_b"); + println!("cargo::rustc-cfg=cfg_c"); + println!("cargo::rustc-cfg=cfg_d"); + println!("cargo::rustc-cfg=cfg_e"); } "#, ) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index f7361fcf302..c67bb1140a7 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -824,7 +824,7 @@ fn custom_build_script_wrong_rustc_flags() { .file("src/main.rs", "fn main() {}") .file( "build.rs", - r#"fn main() { println!("cargo:rustc-flags=-aaa -bbb"); }"#, + r#"fn main() { println!("cargo::rustc-flags=-aaa -bbb"); }"#, ) .build(); @@ -870,7 +870,7 @@ fn custom_build_script_rustc_flags() { "foo/build.rs", r#" fn main() { - println!("cargo:rustc-flags=-l nonexistinglib -L /dummy/path1 -L /dummy/path2"); + println!("cargo::rustc-flags=-l nonexistinglib -L /dummy/path1 -L /dummy/path2"); } "#, ) @@ -929,7 +929,7 @@ fn custom_build_script_rustc_flags_no_space() { "foo/build.rs", r#" fn main() { - println!("cargo:rustc-flags=-lnonexistinglib -L/dummy/path1 -L/dummy/path2"); + println!("cargo::rustc-flags=-lnonexistinglib -L/dummy/path1 -L/dummy/path2"); } "#, ) @@ -1308,8 +1308,8 @@ fn links_passes_env_vars() { let lib = env::var("CARGO_MANIFEST_LINKS").unwrap(); assert_eq!(lib, "foo"); - println!("cargo:foo=bar"); - println!("cargo:bar=baz"); + println!("cargo::metadata=foo=bar"); + println!("cargo::metadata=bar=baz"); } "#, ) @@ -1375,8 +1375,8 @@ fn rebuild_continues_to_pass_env_vars() { r#" use std::time::Duration; fn main() { - println!("cargo:foo=bar"); - println!("cargo:bar=baz"); + println!("cargo::metadata=foo=bar"); + println!("cargo::metadata=bar=baz"); std::thread::sleep(Duration::from_millis(500)); } "#, @@ -1522,7 +1522,7 @@ fn propagation_of_l_flags() { .file("a/src/lib.rs", "") .file( "a/build.rs", - r#"fn main() { println!("cargo:rustc-flags=-L bar"); }"#, + r#"fn main() { println!("cargo::rustc-flags=-L bar"); }"#, ) .file( "b/Cargo.toml", @@ -1595,7 +1595,7 @@ fn propagation_of_l_flags_new() { "a/build.rs", r#" fn main() { - println!("cargo:rustc-link-search=bar"); + println!("cargo::rustc-link-search=bar"); } "#, ) @@ -1903,8 +1903,8 @@ fn output_separate_lines() { "build.rs", r#" fn main() { - println!("cargo:rustc-flags=-L foo"); - println!("cargo:rustc-flags=-l static=foo"); + println!("cargo::rustc-flags=-L foo"); + println!("cargo::rustc-flags=-l static=foo"); } "#, ) @@ -1941,10 +1941,10 @@ fn output_separate_lines_new() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-search=foo"); - println!("cargo:rustc-link-lib=static=foo"); - println!("cargo:rustc-link-lib=bar"); - println!("cargo:rustc-link-search=bar"); + println!("cargo::rustc-link-search=foo"); + println!("cargo::rustc-link-lib=static=foo"); + println!("cargo::rustc-link-lib=bar"); + println!("cargo::rustc-link-search=bar"); } "#, ) @@ -2318,7 +2318,7 @@ fn build_script_with_dynamic_native_dependency() { fs::copy(root.join("builder.dll.lib"), out_dir.join("builder.dll.lib")).unwrap(); } - println!("cargo:rustc-link-search=native={}", out_dir.display()); + println!("cargo::rustc-link-search=native={}", out_dir.display()); } "#, ) @@ -2486,7 +2486,7 @@ fn cfg_feedback() { .file("src/main.rs", "#[cfg(foo)] fn main() {}") .file( "build.rs", - r#"fn main() { println!("cargo:rustc-cfg=foo"); }"#, + r#"fn main() { println!("cargo::rustc-cfg=foo"); }"#, ) .build(); p.cargo("build -v").run(); @@ -2540,7 +2540,7 @@ fn cfg_test() { ) .file( "build.rs", - r#"fn main() { println!("cargo:rustc-cfg=foo"); }"#, + r#"fn main() { println!("cargo::rustc-cfg=foo"); }"#, ) .file( "src/lib.rs", @@ -2605,7 +2605,7 @@ fn cfg_doc() { ) .file( "build.rs", - r#"fn main() { println!("cargo:rustc-cfg=foo"); }"#, + r#"fn main() { println!("cargo::rustc-cfg=foo"); }"#, ) .file("src/lib.rs", "#[cfg(foo)] pub fn foo() {}") .file( @@ -2620,7 +2620,7 @@ fn cfg_doc() { ) .file( "bar/build.rs", - r#"fn main() { println!("cargo:rustc-cfg=bar"); }"#, + r#"fn main() { println!("cargo::rustc-cfg=bar"); }"#, ) .file("bar/src/lib.rs", "#[cfg(bar)] pub fn bar() {}") .build(); @@ -2773,7 +2773,7 @@ fn env_build() { ) .file( "build.rs", - r#"fn main() { println!("cargo:rustc-env=FOO=foo"); }"#, + r#"fn main() { println!("cargo::rustc-env=FOO=foo"); }"#, ) .build(); p.cargo("build -v").run(); @@ -2795,7 +2795,7 @@ fn env_test() { ) .file( "build.rs", - r#"fn main() { println!("cargo:rustc-env=FOO=foo"); }"#, + r#"fn main() { println!("cargo::rustc-env=FOO=foo"); }"#, ) .file( "src/lib.rs", @@ -2855,7 +2855,7 @@ fn env_doc() { ) .file( "build.rs", - r#"fn main() { println!("cargo:rustc-env=FOO=foo"); }"#, + r#"fn main() { println!("cargo::rustc-env=FOO=foo"); }"#, ) .build(); p.cargo("doc -v").run(); @@ -2905,7 +2905,7 @@ fn flags_go_into_tests() { "a/build.rs", r#" fn main() { - println!("cargo:rustc-link-search=test"); + println!("cargo::rustc-link-search=test"); } "#, ) @@ -2999,7 +2999,7 @@ fn diamond_passes_args_only_once() { "c/build.rs", r#" fn main() { - println!("cargo:rustc-link-search=native=test"); + println!("cargo::rustc-link-search=native=test"); } "#, ) @@ -3046,7 +3046,7 @@ fn adding_an_override_invalidates() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-search=native=foo"); + println!("cargo::rustc-link-search=native=foo"); } "#, ) @@ -3274,8 +3274,8 @@ fn generate_good_d_files() { "awoo/build.rs", r#" fn main() { - println!("cargo:rerun-if-changed=build.rs"); - println!("cargo:rerun-if-changed=barkbarkbark"); + println!("cargo::rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=barkbarkbark"); } "#, ) @@ -3353,8 +3353,8 @@ fn generate_good_d_files_for_external_tools() { "awoo/build.rs", r#" fn main() { - println!("cargo:rerun-if-changed=build.rs"); - println!("cargo:rerun-if-changed=barkbarkbark"); + println!("cargo::rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=barkbarkbark"); } "#, ) @@ -3415,8 +3415,8 @@ fn rebuild_only_on_explicit_paths() { "build.rs", r#" fn main() { - println!("cargo:rerun-if-changed=foo"); - println!("cargo:rerun-if-changed=bar"); + println!("cargo::rerun-if-changed=foo"); + println!("cargo::rerun-if-changed=bar"); } "#, ) @@ -3543,7 +3543,7 @@ fn doctest_receives_build_link_args() { "a/build.rs", r#" fn main() { - println!("cargo:rustc-link-search=native=bar"); + println!("cargo::rustc-link-search=native=bar"); } "#, ) @@ -3577,7 +3577,7 @@ fn please_respect_the_dag() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-search=native=foo"); + println!("cargo::rustc-link-search=native=foo"); } "#, ) @@ -3597,7 +3597,7 @@ fn please_respect_the_dag() { "a/build.rs", r#" fn main() { - println!("cargo:rustc-link-search=native=bar"); + println!("cargo::rustc-link-search=native=bar"); } "#, ) @@ -3632,7 +3632,7 @@ fn non_utf8_output() { out.write_all(b"\xff\xff\n").unwrap(); // now print some cargo metadata that's utf8 - println!("cargo:rustc-cfg=foo"); + println!("cargo::rustc-cfg=foo"); // now print more non-utf8 out.write_all(b"\xff\xff\n").unwrap(); @@ -3765,8 +3765,8 @@ fn warnings_emitted() { "build.rs", r#" fn main() { - println!("cargo:warning=foo"); - println!("cargo:warning=bar"); + println!("cargo::warning=foo"); + println!("cargo::warning=bar"); } "#, ) @@ -3805,8 +3805,8 @@ fn warnings_emitted_when_build_script_panics() { "build.rs", r#" fn main() { - println!("cargo:warning=foo"); - println!("cargo:warning=bar"); + println!("cargo::warning=foo"); + println!("cargo::warning=bar"); panic!(); } "#, @@ -3827,8 +3827,8 @@ fn warnings_hidden_for_upstream() { "build.rs", r#" fn main() { - println!("cargo:warning=foo"); - println!("cargo:warning=bar"); + println!("cargo::warning=foo"); + println!("cargo::warning=bar"); } "#, ) @@ -3886,8 +3886,8 @@ fn warnings_printed_on_vv() { "build.rs", r#" fn main() { - println!("cargo:warning=foo"); - println!("cargo:warning=bar"); + println!("cargo::warning=foo"); + println!("cargo::warning=bar"); } "#, ) @@ -4003,7 +4003,7 @@ fn links_with_dots() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-search=bar") + println!("cargo::rustc-link-search=bar") } "#, ) @@ -4158,7 +4158,7 @@ fn assume_build_script_when_build_rs_present() { "build.rs", r#" fn main() { - println!("cargo:rustc-cfg=foo"); + println!("cargo::rustc-cfg=foo"); } "#, ) @@ -4194,7 +4194,7 @@ fn if_build_set_to_false_dont_treat_build_rs_as_build_script() { "build.rs", r#" fn main() { - println!("cargo:rustc-cfg=foo"); + println!("cargo::rustc-cfg=foo"); } "#, ) @@ -4223,7 +4223,7 @@ fn deterministic_rustc_dependency_flags() { "build.rs", r#" fn main() { - println!("cargo:rustc-flags=-L native=test1"); + println!("cargo::rustc-flags=-L native=test1"); } "#, ) @@ -4244,7 +4244,7 @@ fn deterministic_rustc_dependency_flags() { "build.rs", r#" fn main() { - println!("cargo:rustc-flags=-L native=test2"); + println!("cargo::rustc-flags=-L native=test2"); } "#, ) @@ -4265,7 +4265,7 @@ fn deterministic_rustc_dependency_flags() { "build.rs", r#" fn main() { - println!("cargo:rustc-flags=-L native=test3"); + println!("cargo::rustc-flags=-L native=test3"); } "#, ) @@ -4286,7 +4286,7 @@ fn deterministic_rustc_dependency_flags() { "build.rs", r#" fn main() { - println!("cargo:rustc-flags=-L native=test4"); + println!("cargo::rustc-flags=-L native=test4"); } "#, ) @@ -4457,13 +4457,13 @@ fn _rename_with_link_search_path(cross: bool) { // handle windows, like below drop(fs::copy(root.join("foo.dll.lib"), dst_dir.join("foo.dll.lib"))); - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=build.rs"); if cfg!(target_env = "msvc") { - println!("cargo:rustc-link-lib=foo.dll"); + println!("cargo::rustc-link-lib=foo.dll"); } else { - println!("cargo:rustc-link-lib=foo"); + println!("cargo::rustc-link-lib=foo"); } - println!("cargo:rustc-link-search=all={}", + println!("cargo::rustc-link-search=all={}", dst.parent().unwrap().display()); } "#, @@ -4576,10 +4576,10 @@ fn optional_build_script_dep() { fn main() { #[cfg(feature = "bar")] { - println!("cargo:rustc-env=FOO={}", bar::bar()); + println!("cargo::rustc-env=FOO={}", bar::bar()); return } - println!("cargo:rustc-env=FOO=0"); + println!("cargo::rustc-env=FOO=0"); } "#, ) @@ -4680,7 +4680,7 @@ fn using_rerun_if_changed_does_not_rebuild() { "build.rs", r#" fn main() { - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=build.rs"); } "#, ) @@ -4718,7 +4718,7 @@ fn links_interrupted_can_restart() { "build.rs", r#" fn main() { - println!("cargo:rerun-if-env-changed=SOMEVAR"); + println!("cargo::rerun-if-env-changed=SOMEVAR"); } "#, ) @@ -4747,7 +4747,7 @@ fn links_interrupted_can_restart() { r#" use std::env; fn main() { - println!("cargo:rebuild-if-changed=build.rs"); + println!("cargo::metadata=rebuild-if-changed=build.rs"); if std::path::Path::new("abort").exists() { panic!("Crash!"); } @@ -4825,7 +4825,7 @@ fn rerun_if_directory() { "build.rs", r#" fn main() { - println!("cargo:rerun-if-changed=somedir"); + println!("cargo::rerun-if-changed=somedir"); } "#, ) @@ -4944,7 +4944,7 @@ fn rerun_if_published_directory() { r#" fn main() { // Changing to mylib/balrog.c will not trigger a rebuild - println!("cargo:rerun-if-changed=mylib"); + println!("cargo::rerun-if-changed=mylib"); } "#, ) @@ -4989,7 +4989,7 @@ fn rerun_if_published_directory() { "build.rs", r#" fn main() { - println!("cargo:rerun-if-changed=mylib"); + println!("cargo::rerun-if-changed=mylib"); } "#, ) @@ -5048,7 +5048,7 @@ fn test_with_dep_metadata() { "bar/build.rs", r#" fn main() { - println!("cargo:foo=bar"); + println!("cargo::metadata=foo=bar"); } "#, ) @@ -5111,8 +5111,8 @@ fn duplicate_script_with_extra_env() { "foo/build.rs", r#" fn main() { - println!("cargo:rustc-env=CRATE_TARGET={}", std::env::var("TARGET").unwrap()); - println!("cargo:rustc-cfg=mycfg=\"{}\"", std::env::var("TARGET").unwrap()); + println!("cargo::rustc-env=CRATE_TARGET={}", std::env::var("TARGET").unwrap()); + println!("cargo::rustc-cfg=mycfg=\"{}\"", std::env::var("TARGET").unwrap()); } "#, ) @@ -5157,7 +5157,7 @@ fn wrong_output() { "build.rs", r#" fn main() { - println!("cargo:example"); + println!("cargo::example"); } "#, ) @@ -5168,8 +5168,8 @@ fn wrong_output() { .with_stderr( "\ [COMPILING] foo [..] -error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo:example` -Expected a line with `cargo:key=value` with an `=` character, but none was found. +error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo::example` +Expected a line with `cargo::KEY=VALUE` with an `=` character, but none was found. See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \ for more information about build script outputs. ", @@ -5178,7 +5178,121 @@ for more information about build script outputs. } #[cargo_test] -fn wrong_syntax_with_two_colons() { +fn custom_build_closes_stdin() { + // Ensure stdin is closed to prevent deadlock. + // See https://github.com/rust-lang/cargo/issues/11196 + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.5.0" + build = "build.rs" + "#, + ) + .file("src/main.rs", "fn main() {}") + .file( + "build.rs", + r#"fn main() { + let mut line = String::new(); + std::io::stdin().read_line(&mut line).unwrap(); + }"#, + ) + .build(); + p.cargo("build").run(); +} + +#[cargo_test] +fn test_old_syntax() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + build = "build.rs" + "#, + ) + .file( + "src/main.rs", + r#" + const FOO: &'static str = env!("FOO"); + fn main() { + println!("{}", FOO); + } + "#, + ) + .file( + "build.rs", + r#"fn main() { + println!("cargo:rustc-env=FOO=foo"); + println!("cargo:foo=foo"); + }"#, + ) + .build(); + p.cargo("build -v").run(); + p.cargo("run -v").with_stdout("foo\n").run(); +} + +#[cargo_test] +fn test_invalid_old_syntax() { + // Unexpected metadata value. + let p = project() + .file("src/lib.rs", "") + .file( + "build.rs", + r#" + fn main() { + println!("cargo:foo"); + } + "#, + ) + .build(); + p.cargo("build") + .with_status(101) + .with_stderr( + "\ +[COMPILING] foo [..] +error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo:foo` +Expected a line with `cargo:KEY=VALUE` with an `=` character, but none was found. +See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \ +for more information about build script outputs. +", + ) + .run(); +} + +#[cargo_test] +fn test_invalid_new_syntax() { + // Unexpected metadata value. + let p = project() + .file("src/lib.rs", "") + .file( + "build.rs", + r#" + fn main() { + println!("cargo::metadata=foo"); + } + "#, + ) + .build(); + + p.cargo("build") + .with_status(101) + .with_stderr( + "\ +[COMPILING] foo [..] +error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo::metadata=foo` +Expected a line with `cargo::metadata=KEY=VALUE` with an `=` character, but none was found. +See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \ +for more information about build script outputs. +", + ) + .run(); + // `cargo::` can not be used with the unknown key. let p = project() .file("src/lib.rs", "") .file( @@ -5196,9 +5310,8 @@ fn wrong_syntax_with_two_colons() { .with_stderr( "\ [COMPILING] foo [..] -error: unsupported output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo::foo=bar` -Found a `cargo::key=value` build directive which is reserved for future use. -Either change the directive to `cargo:key=value` syntax (note the single `:`) or upgrade your version of Rust. +error: invalid output in build script of `foo v0.0.1 ([ROOT]/foo)`: `cargo::foo=bar` +Unknown key: `foo`. See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \ for more information about build script outputs. ", @@ -5207,9 +5320,7 @@ for more information about build script outputs. } #[cargo_test] -fn custom_build_closes_stdin() { - // Ensure stdin is closed to prevent deadlock. - // See https://github.com/rust-lang/cargo/issues/11196 +fn test_new_syntax_with_old_msrv() { let p = project() .file( "Cargo.toml", @@ -5217,17 +5328,67 @@ fn custom_build_closes_stdin() { [package] name = "foo" version = "0.5.0" + authors = [] build = "build.rs" + rust-version = "1.60.0" + "#, + ) + .file("src/lib.rs", "") + .file( + "build.rs", + r#" + fn main() { + println!("cargo::metadata=foo=bar"); + } + "#, + ) + .build(); + + p.cargo("build") + .with_status(101) + .with_stderr_contains( + "\ +[COMPILING] foo [..] +error: the `cargo::` syntax for build script output instructions was added in Rust 1.77.0, \ +but the minimum supported Rust version of `foo v0.5.0 ([ROOT]/foo)` is 1.60.0. +See https://doc.rust-lang.org/cargo/reference/build-scripts.html#outputs-of-the-build-script \ +for more information about build script outputs. +", + ) + .run(); +} + +#[cargo_test] +fn test_old_syntax_with_old_msrv() { + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.0.1" + authors = [] + build = "build.rs" + rust-version = "1.60.0" + "#, + ) + .file( + "src/main.rs", + r#" + const FOO: &'static str = env!("FOO"); + fn main() { + println!("{}", FOO); + } "#, ) - .file("src/main.rs", "fn main() {}") .file( "build.rs", r#"fn main() { - let mut line = String::new(); - std::io::stdin().read_line(&mut line).unwrap(); + println!("cargo:rustc-env=FOO=foo"); + println!("cargo:foo=foo"); }"#, ) .build(); - p.cargo("build").run(); + p.cargo("build -v").run(); + p.cargo("run -v").with_stdout("foo\n").run(); } diff --git a/tests/testsuite/build_script_env.rs b/tests/testsuite/build_script_env.rs index 5220506a709..94c096124e9 100644 --- a/tests/testsuite/build_script_env.rs +++ b/tests/testsuite/build_script_env.rs @@ -12,7 +12,7 @@ fn rerun_if_env_changes() { "build.rs", r#" fn main() { - println!("cargo:rerun-if-env-changed=FOO"); + println!("cargo::rerun-if-env-changed=FOO"); } "#, ) @@ -66,8 +66,8 @@ fn rerun_if_env_or_file_changes() { "build.rs", r#" fn main() { - println!("cargo:rerun-if-env-changed=FOO"); - println!("cargo:rerun-if-changed=foo"); + println!("cargo::rerun-if-env-changed=FOO"); + println!("cargo::rerun-if-changed=foo"); } "#, ) @@ -112,7 +112,7 @@ fn rerun_if_env_or_file_changes() { fn rustc_bootstrap() { let build_rs = r#" fn main() { - println!("cargo:rustc-env=RUSTC_BOOTSTRAP=1"); + println!("cargo::rustc-env=RUSTC_BOOTSTRAP=1"); } "#; let p = project() diff --git a/tests/testsuite/build_script_extra_link_arg.rs b/tests/testsuite/build_script_extra_link_arg.rs index 964a55e97f6..49c33d979fc 100644 --- a/tests/testsuite/build_script_extra_link_arg.rs +++ b/tests/testsuite/build_script_extra_link_arg.rs @@ -16,7 +16,7 @@ fn build_script_extra_link_arg_bin() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-arg-bins=--this-is-a-bogus-flag"); + println!("cargo::rustc-link-arg-bins=--this-is-a-bogus-flag"); } "#, ) @@ -53,9 +53,9 @@ fn build_script_extra_link_arg_bin_single() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-arg-bins=--bogus-flag-all"); - println!("cargo:rustc-link-arg-bin=foo=--bogus-flag-foo"); - println!("cargo:rustc-link-arg-bin=bar=--bogus-flag-bar"); + println!("cargo::rustc-link-arg-bins=--bogus-flag-all"); + println!("cargo::rustc-link-arg-bin=foo=--bogus-flag-foo"); + println!("cargo::rustc-link-arg-bin=bar=--bogus-flag-bar"); } "#, ) @@ -81,7 +81,7 @@ fn build_script_extra_link_arg() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-arg=--this-is-a-bogus-flag"); + println!("cargo::rustc-link-arg=--this-is-a-bogus-flag"); } "#, ) @@ -102,7 +102,7 @@ fn link_arg_missing_target() { .file("src/lib.rs", "") .file( "build.rs", - r#"fn main() { println!("cargo:rustc-link-arg-cdylib=--bogus"); }"#, + r#"fn main() { println!("cargo::rustc-link-arg-cdylib=--bogus"); }"#, ) .build(); @@ -112,28 +112,28 @@ fn link_arg_missing_target() { // .with_status(101) // .with_stderr("\ // [COMPILING] foo [..] - // error: invalid instruction `cargo:rustc-link-arg-cdylib` from build script of `foo v0.0.1 ([ROOT]/foo)` + // error: invalid instruction `cargo::rustc-link-arg-cdylib` from build script of `foo v0.0.1 ([ROOT]/foo)` // The package foo v0.0.1 ([ROOT]/foo) does not have a cdylib target. // ") // .run(); p.change_file( "build.rs", - r#"fn main() { println!("cargo:rustc-link-arg-bins=--bogus"); }"#, + r#"fn main() { println!("cargo::rustc-link-arg-bins=--bogus"); }"#, ); p.cargo("check") .with_status(101) .with_stderr("\ [COMPILING] foo [..] -error: invalid instruction `cargo:rustc-link-arg-bins` from build script of `foo v0.0.1 ([ROOT]/foo)` +error: invalid instruction `cargo::rustc-link-arg-bins` from build script of `foo v0.0.1 ([ROOT]/foo)` The package foo v0.0.1 ([ROOT]/foo) does not have a bin target. ") .run(); p.change_file( "build.rs", - r#"fn main() { println!("cargo:rustc-link-arg-bin=abc=--bogus"); }"#, + r#"fn main() { println!("cargo::rustc-link-arg-bin=abc=--bogus"); }"#, ); p.cargo("check") @@ -141,7 +141,7 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target. .with_stderr( "\ [COMPILING] foo [..] -error: invalid instruction `cargo:rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)` +error: invalid instruction `cargo::rustc-link-arg-bin` from build script of `foo v0.0.1 ([ROOT]/foo)` The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `abc`. ", ) @@ -149,7 +149,7 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `ab p.change_file( "build.rs", - r#"fn main() { println!("cargo:rustc-link-arg-bin=abc"); }"#, + r#"fn main() { println!("cargo::rustc-link-arg-bin=abc"); }"#, ); p.cargo("check") @@ -157,8 +157,8 @@ The package foo v0.0.1 ([ROOT]/foo) does not have a bin target with the name `ab .with_stderr( "\ [COMPILING] foo [..] -error: invalid instruction `cargo:rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)` -The instruction should have the form cargo:rustc-link-arg-bin=BIN=ARG +error: invalid instruction `cargo::rustc-link-arg-bin=abc` from build script of `foo v0.0.1 ([ROOT]/foo)` +The instruction should have the form cargo::rustc-link-arg-bin=BIN=ARG ", ) .run(); @@ -192,7 +192,7 @@ fn cdylib_link_arg_transitive() { "bar/build.rs", r#" fn main() { - println!("cargo:rustc-link-arg-cdylib=--bogus"); + println!("cargo::rustc-link-arg-cdylib=--bogus"); } "#, ) @@ -204,7 +204,7 @@ fn cdylib_link_arg_transitive() { [COMPILING] bar v1.0.0 [..] [RUNNING] `rustc --crate-name build_script_build bar/build.rs [..] [RUNNING] `[..]build-script-build[..] -warning: bar@1.0.0: cargo:rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \ +warning: bar@1.0.0: cargo::rustc-link-arg-cdylib was specified in the build script of bar v1.0.0 \ ([ROOT]/foo/bar), but that package does not contain a cdylib target Allowing this was an unintended change in the 1.50 release, and may become an error in \ @@ -230,7 +230,7 @@ fn link_arg_transitive_not_allowed() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-arg=--bogus"); + println!("cargo::rustc-link-arg=--bogus"); } "#, ) @@ -289,7 +289,7 @@ fn link_arg_with_doctest() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-arg=--this-is-a-bogus-flag"); + println!("cargo::rustc-link-arg=--this-is-a-bogus-flag"); } "#, ) @@ -313,7 +313,7 @@ fn build_script_extra_link_arg_tests() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-arg-tests=--this-is-a-bogus-flag"); + println!("cargo::rustc-link-arg-tests=--this-is-a-bogus-flag"); } "#, ) @@ -337,7 +337,7 @@ fn build_script_extra_link_arg_benches() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-arg-benches=--this-is-a-bogus-flag"); + println!("cargo::rustc-link-arg-benches=--this-is-a-bogus-flag"); } "#, ) @@ -361,7 +361,7 @@ fn build_script_extra_link_arg_examples() { "build.rs", r#" fn main() { - println!("cargo:rustc-link-arg-examples=--this-is-a-bogus-flag"); + println!("cargo::rustc-link-arg-examples=--this-is-a-bogus-flag"); } "#, ) diff --git a/tests/testsuite/check_cfg.rs b/tests/testsuite/check_cfg.rs index 42cfe606563..47d4e278dbc 100644 --- a/tests/testsuite/check_cfg.rs +++ b/tests/testsuite/check_cfg.rs @@ -343,7 +343,7 @@ fn build_script_feedback() { .file("src/main.rs", "fn main() {}") .file( "build.rs", - r#"fn main() { println!("cargo:rustc-check-cfg=cfg(foo)"); }"#, + r#"fn main() { println!("cargo::rustc-check-cfg=cfg(foo)"); }"#, ) .build(); @@ -369,7 +369,7 @@ fn build_script_doc() { .file("src/main.rs", "fn main() {}") .file( "build.rs", - r#"fn main() { println!("cargo:rustc-check-cfg=cfg(foo)"); }"#, + r#"fn main() { println!("cargo::rustc-check-cfg=cfg(foo)"); }"#, ) .build(); @@ -477,9 +477,9 @@ fn build_script_test() { ) .file( "build.rs", - r#"fn main() { - println!("cargo:rustc-check-cfg=cfg(foo)"); - println!("cargo:rustc-cfg=foo"); + r#"fn main() { + println!("cargo::rustc-check-cfg=cfg(foo)"); + println!("cargo::rustc-cfg=foo"); }"#, ) .file( @@ -531,16 +531,16 @@ fn build_script_feature_gate() { ) .file( "build.rs", - r#"fn main() { - println!("cargo:rustc-check-cfg=cfg(foo)"); - println!("cargo:rustc-cfg=foo"); + r#"fn main() { + println!("cargo::rustc-check-cfg=cfg(foo)"); + println!("cargo::rustc-cfg=foo"); }"#, ) .file("src/main.rs", "fn main() {}") .build(); p.cargo("check") - .with_stderr_contains("warning[..]cargo:rustc-check-cfg requires -Zcheck-cfg flag") + .with_stderr_contains("warning[..]cargo::rustc-check-cfg requires -Zcheck-cfg flag") .with_status(0) .run(); } diff --git a/tests/testsuite/cross_compile.rs b/tests/testsuite/cross_compile.rs index b57ba2c7a89..32c1a4bf5a1 100644 --- a/tests/testsuite/cross_compile.rs +++ b/tests/testsuite/cross_compile.rs @@ -721,7 +721,7 @@ fn build_script_needed_for_host_and_target() { use std::env; fn main() { let target = env::var("TARGET").unwrap(); - println!("cargo:rustc-flags=-L /path/to/{}", target); + println!("cargo::rustc-flags=-L /path/to/{}", target); } "#, ) @@ -1098,7 +1098,10 @@ fn platform_specific_variables_reflected_in_build_scripts() { build = "build.rs" "#, ) - .file("d1/build.rs", r#"fn main() { println!("cargo:val=1") }"#) + .file( + "d1/build.rs", + r#"fn main() { println!("cargo::metadata=val=1") }"#, + ) .file("d1/src/lib.rs", "") .file( "d2/Cargo.toml", @@ -1111,7 +1114,10 @@ fn platform_specific_variables_reflected_in_build_scripts() { build = "build.rs" "#, ) - .file("d2/build.rs", r#"fn main() { println!("cargo:val=1") }"#) + .file( + "d2/build.rs", + r#"fn main() { println!("cargo::metadata=val=1") }"#, + ) .file("d2/src/lib.rs", "") .build(); diff --git a/tests/testsuite/dep_info.rs b/tests/testsuite/dep_info.rs index e9ea47792ec..4741ebd2b1f 100644 --- a/tests/testsuite/dep_info.rs +++ b/tests/testsuite/dep_info.rs @@ -570,7 +570,7 @@ fn non_local_build_script() { "build.rs", r#" fn main() { - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=build.rs"); } "#, ) diff --git a/tests/testsuite/doc.rs b/tests/testsuite/doc.rs index 37dd47d76fd..c80f23d91f7 100644 --- a/tests/testsuite/doc.rs +++ b/tests/testsuite/doc.rs @@ -1021,7 +1021,7 @@ fn features() { "bar/build.rs", r#" fn main() { - println!("cargo:rustc-cfg=bar"); + println!("cargo::rustc-cfg=bar"); } "#, ) diff --git a/tests/testsuite/features2.rs b/tests/testsuite/features2.rs index 125a293a004..29516d8ec43 100644 --- a/tests/testsuite/features2.rs +++ b/tests/testsuite/features2.rs @@ -494,7 +494,7 @@ fn build_script_runtime_features() { if is_set("CARGO_FEATURE_BUILD") { res |= 4; } - println!("cargo:rustc-cfg=RunCustomBuild=\"{}\"", res); + println!("cargo::rustc-cfg=RunCustomBuild=\"{}\"", res); let mut res = 0; if cfg!(feature = "normal") { @@ -506,7 +506,7 @@ fn build_script_runtime_features() { if cfg!(feature = "build") { res |= 4; } - println!("cargo:rustc-cfg=CustomBuild=\"{}\"", res); + println!("cargo::rustc-cfg=CustomBuild=\"{}\"", res); } "#, ) @@ -562,7 +562,7 @@ fn build_script_runtime_features() { r#" fn main() { assert_eq!(common::foo(), common::build_time()); - println!("cargo:rustc-cfg=from_build=\"{}\"", common::foo()); + println!("cargo::rustc-cfg=from_build=\"{}\"", common::foo()); } "#, ) @@ -1792,8 +1792,8 @@ fn shared_dep_same_but_dependencies() { "subdep/src/lib.rs", r#" pub fn feat_func() { - #[cfg(feature = "feat")] println!("cargo:warning=feat: enabled"); - #[cfg(not(feature = "feat"))] println!("cargo:warning=feat: not enabled"); + #[cfg(feature = "feat")] println!("cargo::warning=feat: enabled"); + #[cfg(not(feature = "feat"))] println!("cargo::warning=feat: not enabled"); } "#, ) @@ -1813,7 +1813,7 @@ warning: bin2@0.1.0: feat: enabled ) .run(); p.process(p.bin("bin1")) - .with_stdout("cargo:warning=feat: not enabled") + .with_stdout("cargo::warning=feat: not enabled") .run(); // Make sure everything stays cached. diff --git a/tests/testsuite/freshness.rs b/tests/testsuite/freshness.rs index 2d9b3df68ce..1f81b544ce1 100644 --- a/tests/testsuite/freshness.rs +++ b/tests/testsuite/freshness.rs @@ -658,7 +658,7 @@ fn rerun_if_changed_in_dep() { "a/build.rs", r#" fn main() { - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=build.rs"); } "#, ) @@ -1730,8 +1730,8 @@ fn dirty_both_lib_and_test() { .success(), "slib build failed" ); - println!("cargo:rustc-link-lib=slib"); - println!("cargo:rustc-link-search={}", out_dir.display()); + println!("cargo::rustc-link-lib=slib"); + println!("cargo::rustc-link-search={}", out_dir.display()); } "#, ) @@ -1772,7 +1772,7 @@ fn script_fails_stay_dirty() { r#" mod helper; fn main() { - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=build.rs"); helper::doit(); } "#, @@ -1810,7 +1810,7 @@ fn simulated_docker_deps_stay_cached() { "build.rs", r#" fn main() { - println!("cargo:rerun-if-env-changed=SOMEVAR"); + println!("cargo::rerun-if-env-changed=SOMEVAR"); } "#, ) @@ -1821,7 +1821,7 @@ fn simulated_docker_deps_stay_cached() { "build.rs", r#" fn main() { - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=build.rs"); } "#, ) @@ -2107,7 +2107,7 @@ fn move_target_directory_with_path_deps() { use std::path::Path; fn main() { - println!("cargo:rerun-if-changed=build.rs"); + println!("cargo::rerun-if-changed=build.rs"); let out_dir = env::var("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("hello.rs"); fs::write(&dest_path, r#" @@ -2148,9 +2148,9 @@ fn rerun_if_changes() { "build.rs", r#" fn main() { - println!("cargo:rerun-if-env-changed=FOO"); + println!("cargo::rerun-if-env-changed=FOO"); if std::env::var("FOO").is_ok() { - println!("cargo:rerun-if-env-changed=BAR"); + println!("cargo::rerun-if-env-changed=BAR"); } } "#, @@ -2648,7 +2648,7 @@ fn env_build_script_no_rebuild() { "build.rs", r#" fn main() { - println!("cargo:rustc-env=FOO=bar"); + println!("cargo::rustc-env=FOO=bar"); } "#, ) diff --git a/tests/testsuite/profile_overrides.rs b/tests/testsuite/profile_overrides.rs index 65d9f3b5192..eda34ad34c9 100644 --- a/tests/testsuite/profile_overrides.rs +++ b/tests/testsuite/profile_overrides.rs @@ -502,9 +502,9 @@ fn build_override_shared() { r#" fn main() { if std::env::var("DEBUG").unwrap() != "false" { - println!("cargo:rustc-cfg=foo_debug"); + println!("cargo::rustc-cfg=foo_debug"); } else { - println!("cargo:rustc-cfg=foo_release"); + println!("cargo::rustc-cfg=foo_release"); } } "#, diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index c7ddd5d9e35..4537b2caa16 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -1202,8 +1202,8 @@ fn run_with_library_paths() { &format!( r##" fn main() {{ - println!(r#"cargo:rustc-link-search=native={}"#); - println!(r#"cargo:rustc-link-search={}"#); + println!(r#"cargo::rustc-link-search=native={}"#); + println!(r#"cargo::rustc-link-search={}"#); }} "##, dir1.display(), @@ -1261,9 +1261,9 @@ fn library_paths_sorted_alphabetically() { &format!( r##" fn main() {{ - println!(r#"cargo:rustc-link-search=native={}"#); - println!(r#"cargo:rustc-link-search=native={}"#); - println!(r#"cargo:rustc-link-search=native={}"#); + println!(r#"cargo::rustc-link-search=native={}"#); + println!(r#"cargo::rustc-link-search=native={}"#); + println!(r#"cargo::rustc-link-search=native={}"#); }} "##, dir1.display(), @@ -1535,8 +1535,8 @@ fn run_link_system_path_macos() { &format!( r#" fn main() {{ - println!("cargo:rustc-link-lib=foo"); - println!("cargo:rustc-link-search={}"); + println!("cargo::rustc-link-lib=foo"); + println!("cargo::rustc-link-search={}"); }} "#, p.target_debug_dir().display() diff --git a/tests/testsuite/warn_on_failure.rs b/tests/testsuite/warn_on_failure.rs index f2c2bb0713f..110364c83b7 100644 --- a/tests/testsuite/warn_on_failure.rs +++ b/tests/testsuite/warn_on_failure.rs @@ -24,10 +24,10 @@ fn make_lib(lib_src: &str) { r#" fn main() {{ use std::io::Write; - println!("cargo:warning={{}}", "{}"); + println!("cargo::warning={{}}", "{}"); println!("hidden stdout"); write!(&mut ::std::io::stderr(), "hidden stderr"); - println!("cargo:warning={{}}", "{}"); + println!("cargo::warning={{}}", "{}"); }} "#, WARNING1, WARNING2