From 6ee606be69c7175a3974d3ecbf47f2b44f003047 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 18 Jun 2021 11:49:12 -0700 Subject: [PATCH 01/19] Inform build scripts of rustc compiler context Fixes #9600. --- src/cargo/core/compiler/custom_build.rs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index ed13a9d3ed8..4e4c64366c6 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -249,6 +249,13 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { } } + // Also inform the build script of the rustc compiler context. + cmd.env( + "CARGO_RUSTC_WRAPPER", + bcx.rustc().wrapper.as_deref().unwrap_or(Path::new("")), + ); + cmd.env("CARGO_RUSTFLAGS", bcx.rustflags_args(unit).join(" ")); + // Gather the set of native dependencies that this package has along with // some other variables to close over. // From bdf49cb17599a4cd8cb5578da0ca6bfa844a8971 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 18 Jun 2021 11:58:36 -0700 Subject: [PATCH 02/19] Don't set RUSTC_WRAPPER if not configured --- src/cargo/core/compiler/custom_build.rs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 4e4c64366c6..948a75aa9e3 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -250,10 +250,9 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { } // Also inform the build script of the rustc compiler context. - cmd.env( - "CARGO_RUSTC_WRAPPER", - bcx.rustc().wrapper.as_deref().unwrap_or(Path::new("")), - ); + if let Some(wrapper) = bcx.rustc().wrapper.as_ref() { + cmd.env("CARGO_RUSTC_WRAPPER", wrapper); + } cmd.env("CARGO_RUSTFLAGS", bcx.rustflags_args(unit).join(" ")); // Gather the set of native dependencies that this package has along with From 44491ee8a64c0a861315bb6986e4345398d917e0 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 18 Jun 2021 11:59:06 -0700 Subject: [PATCH 03/19] Document build script envvars for rustc context --- src/doc/src/reference/environment-variables.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index acaaf32b5ac..492c06e17b6 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -334,11 +334,15 @@ let out_dir = env::var("OUT_DIR").unwrap(); * `RUSTC`, `RUSTDOC` — the compiler and documentation generator that Cargo has resolved to use, passed to the build script so it might use it as well. +* `CARGO_RUSTC_WRAPPER` — the `rustc` wrapper, if any, that Cargo is using. + See [`build.rustc-wrapper`]. * `RUSTC_LINKER` — The path to the linker binary that Cargo has resolved to use for the current target, if specified. The linker can be changed by editing `.cargo/config.toml`; see the documentation about [cargo configuration][cargo-config] for more information. +* `CARGO_RUSTFLAGS` — the `RUSTFLAGS` that Cargo invokes `rustc` with. + See [`build.rustflags`]. * `CARGO_PKG_` - The package information variables, with the same names and values as are [provided during crate building][variables set for crates]. [unix-like platforms]: ../../reference/conditional-compilation.html#unix-and-windows From 719eb593c8e167b07caf33a2b23bddd085d3b1d9 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 18 Jun 2021 12:14:58 -0700 Subject: [PATCH 04/19] Add tests for rustc context build script env vars --- tests/testsuite/build_script.rs | 82 +++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index da0bb4ba5eb..865ad9211f0 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -3,6 +3,7 @@ use cargo_test_support::compare::assert_match_exact; use cargo_test_support::paths::CargoPathExt; use cargo_test_support::registry::Package; +use cargo_test_support::tools; use cargo_test_support::{basic_manifest, cross_compile, is_coarse_mtime, project}; use cargo_test_support::{rustc_host, sleep_ms, slow_cpu_multiplier, symlink_supported}; use cargo_util::paths::remove_dir_all; @@ -115,7 +116,12 @@ fn custom_build_env_vars() { let rustdoc = env::var("RUSTDOC").unwrap(); assert_eq!(rustdoc, "rustdoc"); + assert!(env::var("RUSTC_WRAPPER").is_err()); + assert!(env::var("RUSTC_LINKER").is_err()); + + let rustflags = env::var("CARGO_RUSTFLAGS").unwrap(); + assert_eq!(rustflags, ""); }} "#, p.root() @@ -130,6 +136,82 @@ fn custom_build_env_vars() { p.cargo("build --features bar_feat").run(); } +#[cargo_test] +fn custom_build_env_var_rustflags() { + let rustflags = "--cfg=special"; + let rustflags_alt = "--cfg=notspecial"; + let p = project() + .file( + ".cargo/config", + &format!( + r#" + [build] + rustflags = ["{}"] + "#, + rustflags + ), + ) + .file( + "build.rs", + &format!( + r#" + use std::env; + + fn main() {{ + // Static assertion that exactly one of the cfg paths is always taken. + let x; + #[cfg(special)] + {{ assert_eq!(env::var("CARGO_RUSTFLAGS").unwrap(), "{}"); x = String::new(); }} + #[cfg(notspecial)] + {{ assert_eq!(env::var("CARGO_RUSTFLAGS").unwrap(), "{}"); x = String::new(); }} + let _ = x; + }} + "#, + rustflags, rustflags_alt, + ), + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check").run(); + + // RUSTFLAGS overrides build.rustflags, so --cfg=special shouldn't be passed + p.cargo("check").env("RUSTFLAGS", rustflags_alt).run(); +} + +#[cargo_test] +fn custom_build_env_var_rustc_wrapper() { + let wrapper = tools::echo_wrapper(); + let p = project() + .file( + ".cargo/config", + &format!( + r#" + [build] + rustc-wrapper = "{}" + "#, + wrapper.display() + ), + ) + .file( + "build.rs", + &format!( + r#" + use std::env; + + fn main() {{ + assert!(env::var("CARGO_RUSTC_WRAPPER").unwrap().ends_with("{}")); + }} + "#, + wrapper.display() + ), + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check").run(); +} + #[cargo_test] fn custom_build_env_var_rustc_linker() { if cross_compile::disabled() { From 8012d328ee1559ce5ddf519e7d0611fddb20d739 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 18 Jun 2021 12:40:29 -0700 Subject: [PATCH 05/19] Avoid coercing path to string for windows --- tests/testsuite/build_script.rs | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 865ad9211f0..b0fc4cb6b0a 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -183,33 +183,26 @@ fn custom_build_env_var_rustflags() { fn custom_build_env_var_rustc_wrapper() { let wrapper = tools::echo_wrapper(); let p = project() - .file( - ".cargo/config", - &format!( - r#" - [build] - rustc-wrapper = "{}" - "#, - wrapper.display() - ), - ) .file( "build.rs", - &format!( - r#" - use std::env; + r#" + use std::env; - fn main() {{ - assert!(env::var("CARGO_RUSTC_WRAPPER").unwrap().ends_with("{}")); - }} - "#, - wrapper.display() - ), + fn main() {{ + assert_eq!( + env::var("CARGO_RUSTC_WRAPPER").unwrap(), + env::var("CARGO_RUSTC_WRAPPER_CHECK").unwrap() + ); + }} + "#, ) .file("src/lib.rs", "") .build(); - p.cargo("check").run(); + p.cargo("check") + .env("CARGO_BUILD_RUSTC_WRAPPER", &wrapper) + .env("CARGO_RUSTC_WRAPPER_CHECK", &wrapper) + .run(); } #[cargo_test] From 1e407453c2e382ff94c06bb03ab7336c8e1efd95 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 24 Jun 2021 09:55:57 -0700 Subject: [PATCH 06/19] Remove CARGO_ prefix for new build script envvars --- src/cargo/core/compiler/custom_build.rs | 4 ++-- tests/testsuite/build_script.rs | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 948a75aa9e3..6d76385673d 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -251,9 +251,9 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { // Also inform the build script of the rustc compiler context. if let Some(wrapper) = bcx.rustc().wrapper.as_ref() { - cmd.env("CARGO_RUSTC_WRAPPER", wrapper); + cmd.env("RUSTC_WRAPPER", wrapper); } - cmd.env("CARGO_RUSTFLAGS", bcx.rustflags_args(unit).join(" ")); + cmd.env("RUSTFLAGS", bcx.rustflags_args(unit).join(" ")); // Gather the set of native dependencies that this package has along with // some other variables to close over. diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index b0fc4cb6b0a..10558c6547a 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -120,7 +120,7 @@ fn custom_build_env_vars() { assert!(env::var("RUSTC_LINKER").is_err()); - let rustflags = env::var("CARGO_RUSTFLAGS").unwrap(); + let rustflags = env::var("RUSTFLAGS").unwrap(); assert_eq!(rustflags, ""); }} "#, @@ -161,9 +161,9 @@ fn custom_build_env_var_rustflags() { // Static assertion that exactly one of the cfg paths is always taken. let x; #[cfg(special)] - {{ assert_eq!(env::var("CARGO_RUSTFLAGS").unwrap(), "{}"); x = String::new(); }} + {{ assert_eq!(env::var("RUSTFLAGS").unwrap(), "{}"); x = String::new(); }} #[cfg(notspecial)] - {{ assert_eq!(env::var("CARGO_RUSTFLAGS").unwrap(), "{}"); x = String::new(); }} + {{ assert_eq!(env::var("RUSTFLAGS").unwrap(), "{}"); x = String::new(); }} let _ = x; }} "#, @@ -190,7 +190,7 @@ fn custom_build_env_var_rustc_wrapper() { fn main() {{ assert_eq!( - env::var("CARGO_RUSTC_WRAPPER").unwrap(), + env::var("RUSTC_WRAPPER").unwrap(), env::var("CARGO_RUSTC_WRAPPER_CHECK").unwrap() ); }} From 49d33c4ec4f90fe366b6fdd4cf924e290cbb076c Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 24 Jun 2021 09:56:14 -0700 Subject: [PATCH 07/19] Expose cargo and rustc version envvars --- crates/cargo-test-support/src/lib.rs | 8 ++++++ src/cargo/core/compiler/custom_build.rs | 16 ++++++++++++ tests/testsuite/build_script.rs | 33 ++++++++++++++++++++++--- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index 992446f7fc8..e07b8d404cf 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -1041,6 +1041,14 @@ pub fn is_nightly() -> bool { && (vv.contains("-nightly") || vv.contains("-dev")) } +pub fn rustc_release() -> &'static str { + RUSTC_INFO + .verbose_version + .lines() + .find_map(|line| line.strip_prefix("release: ")) + .expect("verbose version has release: field") +} + pub fn process>(t: T) -> ProcessBuilder { _process(t.as_ref()) } diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 6d76385673d..b1e825f24c8 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -254,6 +254,22 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { cmd.env("RUSTC_WRAPPER", wrapper); } cmd.env("RUSTFLAGS", bcx.rustflags_args(unit).join(" ")); + let version = crate::version(); + cmd.env( + "CARGO_VERSION", + format!("{}.{}.{}", version.major, version.minor, version.patch), + ); + cmd.env("CARGO_VERSION_MAJOR", version.major.to_string()); + cmd.env("CARGO_VERSION_MINOR", version.minor.to_string()); + cmd.env("CARGO_VERSION_PATCH", version.patch.to_string()); + let version = &bcx.rustc().version; + cmd.env( + "RUSTC_VERSION", + format!("{}.{}.{}", version.major, version.minor, version.patch), + ); + cmd.env("RUSTC_VERSION_MAJOR", version.major.to_string()); + cmd.env("RUSTC_VERSION_MINOR", version.minor.to_string()); + cmd.env("RUSTC_VERSION_PATCH", version.patch.to_string()); // Gather the set of native dependencies that this package has along with // some other variables to close over. diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 10558c6547a..452ca7c526a 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -5,7 +5,9 @@ use cargo_test_support::paths::CargoPathExt; use cargo_test_support::registry::Package; use cargo_test_support::tools; use cargo_test_support::{basic_manifest, cross_compile, is_coarse_mtime, project}; -use cargo_test_support::{rustc_host, sleep_ms, slow_cpu_multiplier, symlink_supported}; +use cargo_test_support::{ + rustc_host, rustc_release, sleep_ms, slow_cpu_multiplier, symlink_supported, +}; use cargo_util::paths::remove_dir_all; use std::env; use std::fs; @@ -80,10 +82,11 @@ fn custom_build_env_vars() { ) .file("bar/src/lib.rs", "pub fn hello() {}"); + let cargo_version = cargo::version(); + let rustc_version = semver::Version::parse(rustc_release()).unwrap(); let file_content = format!( r#" use std::env; - use std::io::prelude::*; use std::path::Path; fn main() {{ @@ -122,13 +125,37 @@ fn custom_build_env_vars() { let rustflags = env::var("RUSTFLAGS").unwrap(); assert_eq!(rustflags, ""); + + let version = env::var("CARGO_VERSION").unwrap(); + assert_eq!(version, "{1}.{2}.{3}", "bad cargo version"); + let version = env::var("CARGO_VERSION_MAJOR").unwrap(); + assert_eq!(version, "{1}"); + let version = env::var("CARGO_VERSION_MINOR").unwrap(); + assert_eq!(version, "{2}"); + let version = env::var("CARGO_VERSION_PATCH").unwrap(); + assert_eq!(version, "{3}"); + + let version = env::var("RUSTC_VERSION").unwrap(); + assert_eq!(version, "{4}.{5}.{6}", "bad rust version"); + let version = env::var("RUSTC_VERSION_MAJOR").unwrap(); + assert_eq!(version, "{4}"); + let version = env::var("RUSTC_VERSION_MINOR").unwrap(); + assert_eq!(version, "{5}"); + let version = env::var("RUSTC_VERSION_PATCH").unwrap(); + assert_eq!(version, "{6}"); }} "#, p.root() .join("target") .join("debug") .join("build") - .display() + .display(), + cargo_version.major, + cargo_version.minor, + cargo_version.patch, + rustc_version.major, + rustc_version.minor, + rustc_version.patch, ); let p = p.file("bar/build.rs", &file_content).build(); From 055a2431aa05b3a66da5ad12934ae426cf47e867 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 25 Jun 2021 09:23:26 -0700 Subject: [PATCH 08/19] Ensure RUSTC_WRAPPER isn't set if no wrapper is used --- src/cargo/core/compiler/custom_build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index b1e825f24c8..18aeba09102 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -252,6 +252,8 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { // Also inform the build script of the rustc compiler context. if let Some(wrapper) = bcx.rustc().wrapper.as_ref() { cmd.env("RUSTC_WRAPPER", wrapper); + } else { + cmd.env_remove("RUSTC_WRAPPER"); } cmd.env("RUSTFLAGS", bcx.rustflags_args(unit).join(" ")); let version = crate::version(); From 715fab4ff508d96fdbcc7d1b89e562397b5584a4 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 25 Jun 2021 09:23:32 -0700 Subject: [PATCH 09/19] Update docs --- src/doc/src/reference/environment-variables.md | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index 492c06e17b6..834b59c9dca 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -334,16 +334,23 @@ let out_dir = env::var("OUT_DIR").unwrap(); * `RUSTC`, `RUSTDOC` — the compiler and documentation generator that Cargo has resolved to use, passed to the build script so it might use it as well. -* `CARGO_RUSTC_WRAPPER` — the `rustc` wrapper, if any, that Cargo is using. - See [`build.rustc-wrapper`]. +* `RUSTC_WRAPPER` — the `rustc` wrapper, if any, that Cargo is using. + See [`build.rustc-wrapper`]. * `RUSTC_LINKER` — The path to the linker binary that Cargo has resolved to use for the current target, if specified. The linker can be changed by editing `.cargo/config.toml`; see the documentation about [cargo configuration][cargo-config] for more information. -* `CARGO_RUSTFLAGS` — the `RUSTFLAGS` that Cargo invokes `rustc` with. - See [`build.rustflags`]. +* `RUSTFLAGS` — the `RUSTFLAGS` that Cargo invokes `rustc` with. + See [`build.rustflags`]. * `CARGO_PKG_` - The package information variables, with the same names and values as are [provided during crate building][variables set for crates]. +* `CARGO_VERSION` - The version of cargo used to invoke the build + script. Its constituent parts are also available as + `CARGO_VERSION_MAJOR`, `_MINOR`, and `_PATCH`. +* `RUSTC_VERSION` - The version of rustc used by the cargo that invokes + the build script. Its constituent parts are also + available as `CARGO_VERSION_MAJOR`, `_MINOR`, and + `_PATCH`. [unix-like platforms]: ../../reference/conditional-compilation.html#unix-and-windows [windows-like platforms]: ../../reference/conditional-compilation.html#unix-and-windows From c16b9d4c55f09f714ab678877665065744d9a80e Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Fri, 25 Jun 2021 11:01:20 -0700 Subject: [PATCH 10/19] Remove CARGO_VERSION* env vars Cargo and Rustc are co-versioned at the moment anyway. --- src/cargo/core/compiler/custom_build.rs | 8 ------- .../src/reference/environment-variables.md | 3 --- tests/testsuite/build_script.rs | 21 ++++--------------- 3 files changed, 4 insertions(+), 28 deletions(-) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 18aeba09102..aed838bb0a8 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -256,14 +256,6 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { cmd.env_remove("RUSTC_WRAPPER"); } cmd.env("RUSTFLAGS", bcx.rustflags_args(unit).join(" ")); - let version = crate::version(); - cmd.env( - "CARGO_VERSION", - format!("{}.{}.{}", version.major, version.minor, version.patch), - ); - cmd.env("CARGO_VERSION_MAJOR", version.major.to_string()); - cmd.env("CARGO_VERSION_MINOR", version.minor.to_string()); - cmd.env("CARGO_VERSION_PATCH", version.patch.to_string()); let version = &bcx.rustc().version; cmd.env( "RUSTC_VERSION", diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index 834b59c9dca..373612db231 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -344,9 +344,6 @@ let out_dir = env::var("OUT_DIR").unwrap(); * `RUSTFLAGS` — the `RUSTFLAGS` that Cargo invokes `rustc` with. See [`build.rustflags`]. * `CARGO_PKG_` - The package information variables, with the same names and values as are [provided during crate building][variables set for crates]. -* `CARGO_VERSION` - The version of cargo used to invoke the build - script. Its constituent parts are also available as - `CARGO_VERSION_MAJOR`, `_MINOR`, and `_PATCH`. * `RUSTC_VERSION` - The version of rustc used by the cargo that invokes the build script. Its constituent parts are also available as `CARGO_VERSION_MAJOR`, `_MINOR`, and diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 452ca7c526a..52c246a4756 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -82,7 +82,6 @@ fn custom_build_env_vars() { ) .file("bar/src/lib.rs", "pub fn hello() {}"); - let cargo_version = cargo::version(); let rustc_version = semver::Version::parse(rustc_release()).unwrap(); let file_content = format!( r#" @@ -126,23 +125,14 @@ fn custom_build_env_vars() { let rustflags = env::var("RUSTFLAGS").unwrap(); assert_eq!(rustflags, ""); - let version = env::var("CARGO_VERSION").unwrap(); - assert_eq!(version, "{1}.{2}.{3}", "bad cargo version"); - let version = env::var("CARGO_VERSION_MAJOR").unwrap(); - assert_eq!(version, "{1}"); - let version = env::var("CARGO_VERSION_MINOR").unwrap(); - assert_eq!(version, "{2}"); - let version = env::var("CARGO_VERSION_PATCH").unwrap(); - assert_eq!(version, "{3}"); - let version = env::var("RUSTC_VERSION").unwrap(); - assert_eq!(version, "{4}.{5}.{6}", "bad rust version"); + assert_eq!(version, "{1}.{2}.{3}", "bad rust version"); let version = env::var("RUSTC_VERSION_MAJOR").unwrap(); - assert_eq!(version, "{4}"); + assert_eq!(version, "{1}"); let version = env::var("RUSTC_VERSION_MINOR").unwrap(); - assert_eq!(version, "{5}"); + assert_eq!(version, "{2}"); let version = env::var("RUSTC_VERSION_PATCH").unwrap(); - assert_eq!(version, "{6}"); + assert_eq!(version, "{3}"); }} "#, p.root() @@ -150,9 +140,6 @@ fn custom_build_env_vars() { .join("debug") .join("build") .display(), - cargo_version.major, - cargo_version.minor, - cargo_version.patch, rustc_version.major, rustc_version.minor, rustc_version.patch, From fb0d41fcc559e295f1bd7b18504e84047a50de41 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Tue, 29 Jun 2021 12:08:50 -0700 Subject: [PATCH 11/19] Adopt CARGO_ENCODED_RUSTFLAGS --- .../compiler/build_context/target_info.rs | 10 +++++- src/cargo/core/compiler/custom_build.rs | 6 +++- .../src/reference/environment-variables.md | 16 ++++++--- tests/testsuite/build_script.rs | 34 +++++++++++++++++-- 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 8aff294bb7a..c27a119535e 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -548,6 +548,7 @@ fn output_err_info(cmd: &ProcessBuilder, stdout: &str, stderr: &str) -> String { /// /// The locations are: /// +/// - the `CARGO_ENCODED_RUSTFLAGS` environment variable /// - the `RUSTFLAGS` environment variable /// /// then if this was not found @@ -595,7 +596,14 @@ fn env_args( return Ok(Vec::new()); } - // First try RUSTFLAGS from the environment + // First try CARG_ENCODED_RUSTFLAGS from the environment. + // Prefer this over RUSTFLAGS since it's less prone to encoding errors. + if let Ok(a) = env::var(format!("CARGO_ENCODED_{}", name)) { + let args = a.split('\x1f').map(str::to_string); + return Ok(args.collect()); + } + + // Then try RUSTFLAGS from the environment if let Ok(a) = env::var(name) { let args = a .split(' ') diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index aed838bb0a8..53f532d52f7 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -255,7 +255,11 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { } else { cmd.env_remove("RUSTC_WRAPPER"); } - cmd.env("RUSTFLAGS", bcx.rustflags_args(unit).join(" ")); + cmd.env( + "CARGO_ENCODED_RUSTFLAGS", + bcx.rustflags_args(unit).join("\x1f"), + ); + cmd.env_remove("RUSTFLAGS"); let version = &bcx.rustc().version; cmd.env( "RUSTC_VERSION", diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index 373612db231..2fb77c31c72 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -35,11 +35,17 @@ system: * `RUSTDOCFLAGS` — A space-separated list of custom flags to pass to all `rustdoc` invocations that Cargo performs. In contrast with [`cargo rustdoc`], this is useful for passing a flag to *all* `rustdoc` instances. See - [`build.rustdocflags`] for some more ways to set flags. + [`build.rustdocflags`] for some more ways to set flags. This string is + split by whitespace; for a more robust encoding of multiple arguments, + set `CARGO_ENCODED_RUSTDOCFLAGS` instead with arguments separated by + `0x1f` (ASCII Unit Separator). * `RUSTFLAGS` — A space-separated list of custom flags to pass to all compiler invocations that Cargo performs. In contrast with [`cargo rustc`], this is useful for passing a flag to *all* compiler instances. See - [`build.rustflags`] for some more ways to set flags. + [`build.rustflags`] for some more ways to set flags. This string is + split by whitespace; for a more robust encoding of multiple arguments, + set `CARGO_ENCODED_RUSTFLAGS` instead with arguments separated by + `0x1f` (ASCII Unit Separator). * `CARGO_INCREMENTAL` — If this is set to 1 then Cargo will force [incremental compilation] to be enabled for the current compilation, and when set to 0 it will force disabling it. If this env var isn't present then cargo's defaults @@ -341,8 +347,10 @@ let out_dir = env::var("OUT_DIR").unwrap(); changed by editing `.cargo/config.toml`; see the documentation about [cargo configuration][cargo-config] for more information. -* `RUSTFLAGS` — the `RUSTFLAGS` that Cargo invokes `rustc` with. - See [`build.rustflags`]. +* `CARGO_ENCODED_RUSTFLAGS` — extra flags that Cargo invokes `rustc` + with, separated by a `0x1f` character + (ASCII Unit Separator). See + [`build.rustflags`]. * `CARGO_PKG_` - The package information variables, with the same names and values as are [provided during crate building][variables set for crates]. * `RUSTC_VERSION` - The version of rustc used by the cargo that invokes the build script. Its constituent parts are also diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 52c246a4756..9cbc807ec3a 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -122,7 +122,8 @@ fn custom_build_env_vars() { assert!(env::var("RUSTC_LINKER").is_err()); - let rustflags = env::var("RUSTFLAGS").unwrap(); + assert!(env::var("RUSTFLAGS").is_err()); + let rustflags = env::var("CARGO_ENCODED_RUSTFLAGS").unwrap(); assert_eq!(rustflags, ""); let version = env::var("RUSTC_VERSION").unwrap(); @@ -173,11 +174,12 @@ fn custom_build_env_var_rustflags() { fn main() {{ // Static assertion that exactly one of the cfg paths is always taken. + assert!(env::var("RUSTFLAGS").is_err()); let x; #[cfg(special)] - {{ assert_eq!(env::var("RUSTFLAGS").unwrap(), "{}"); x = String::new(); }} + {{ assert_eq!(env::var("CARGO_ENCODED_RUSTFLAGS").unwrap(), "{}"); x = String::new(); }} #[cfg(notspecial)] - {{ assert_eq!(env::var("RUSTFLAGS").unwrap(), "{}"); x = String::new(); }} + {{ assert_eq!(env::var("CARGO_ENCODED_RUSTFLAGS").unwrap(), "{}"); x = String::new(); }} let _ = x; }} "#, @@ -193,6 +195,32 @@ fn custom_build_env_var_rustflags() { p.cargo("check").env("RUSTFLAGS", rustflags_alt).run(); } +#[cargo_test] +fn custom_build_env_var_rustflags_escape() { + let p = project() + .file( + ".cargo/config", + r#" + [build] + rustflags = ["-Clink-arg=-add_empty_section text foobar", "--cfg=foo"] + "#, + ) + .file( + "build.rs", + r#" + use std::env; + + fn main() {{ + assert_eq!(env::var("CARGO_ENCODED_RUSTFLAGS").unwrap(), "-Clink-arg=-add_empty_section text foobar\x1f--cfg=foo"); + }} + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check").run(); +} + #[cargo_test] fn custom_build_env_var_rustc_wrapper() { let wrapper = tools::echo_wrapper(); From fa7c5b196f01edc339715c0412747892d3ee7334 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Tue, 29 Jun 2021 12:26:50 -0700 Subject: [PATCH 12/19] Use a more standard linker flag --- tests/testsuite/build_script.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 9cbc807ec3a..56533075eaa 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -196,13 +196,16 @@ fn custom_build_env_var_rustflags() { } #[cargo_test] -fn custom_build_env_var_rustflags_escape() { +fn custom_build_env_var_encoded_rustflags() { + // NOTE: We use "-Clink-arg=-B nope" here rather than, say, "-A missing_docs", since for the + // latter it won't matter if the whitespace accidentally gets split, as rustc will do the right + // thing either way. let p = project() .file( ".cargo/config", r#" [build] - rustflags = ["-Clink-arg=-add_empty_section text foobar", "--cfg=foo"] + rustflags = ["-Clink-arg=-B nope", "--cfg=foo"] "#, ) .file( @@ -211,7 +214,7 @@ fn custom_build_env_var_rustflags_escape() { use std::env; fn main() {{ - assert_eq!(env::var("CARGO_ENCODED_RUSTFLAGS").unwrap(), "-Clink-arg=-add_empty_section text foobar\x1f--cfg=foo"); + assert_eq!(env::var("CARGO_ENCODED_RUSTFLAGS").unwrap(), "-Clink-arg=-B nope\x1f--cfg=foo"); }} "#, ) From a01c5ddd708ab5ede3935b0e078fe37b19055893 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Tue, 29 Jun 2021 13:53:03 -0700 Subject: [PATCH 13/19] Ignore empty rustflags --- src/cargo/core/compiler/build_context/target_info.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index c27a119535e..551d4996812 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -599,7 +599,10 @@ fn env_args( // First try CARG_ENCODED_RUSTFLAGS from the environment. // Prefer this over RUSTFLAGS since it's less prone to encoding errors. if let Ok(a) = env::var(format!("CARGO_ENCODED_{}", name)) { - let args = a.split('\x1f').map(str::to_string); + let args = a + .split('\x1f') + .filter(|s| !s.is_empty()) + .map(str::to_string); return Ok(args.collect()); } From 8199f8582b556de2cb250f65eeb03200329143e5 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Tue, 29 Jun 2021 19:52:00 -0400 Subject: [PATCH 14/19] Update src/cargo/core/compiler/build_context/target_info.rs Co-authored-by: Josh Stone --- src/cargo/core/compiler/build_context/target_info.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index 551d4996812..c2708b8c00b 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -596,7 +596,7 @@ fn env_args( return Ok(Vec::new()); } - // First try CARG_ENCODED_RUSTFLAGS from the environment. + // First try CARGO_ENCODED_RUSTFLAGS from the environment. // Prefer this over RUSTFLAGS since it's less prone to encoding errors. if let Ok(a) = env::var(format!("CARGO_ENCODED_{}", name)) { let args = a From f927d2a7668d59eeb5579f2178e407f9b7ce6cfb Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Tue, 29 Jun 2021 17:01:36 -0700 Subject: [PATCH 15/19] Don't filter empty arguments with encoded rustflags --- src/cargo/core/compiler/build_context/target_info.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/cargo/core/compiler/build_context/target_info.rs b/src/cargo/core/compiler/build_context/target_info.rs index c2708b8c00b..5d1259b5233 100644 --- a/src/cargo/core/compiler/build_context/target_info.rs +++ b/src/cargo/core/compiler/build_context/target_info.rs @@ -599,11 +599,10 @@ fn env_args( // First try CARGO_ENCODED_RUSTFLAGS from the environment. // Prefer this over RUSTFLAGS since it's less prone to encoding errors. if let Ok(a) = env::var(format!("CARGO_ENCODED_{}", name)) { - let args = a - .split('\x1f') - .filter(|s| !s.is_empty()) - .map(str::to_string); - return Ok(args.collect()); + if a.is_empty() { + return Ok(Vec::new()); + } + return Ok(a.split('\x1f').map(str::to_string).collect()); } // Then try RUSTFLAGS from the environment From d6b4a062743384468e2e6fc6b388f1fb9e9f430d Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Tue, 6 Jul 2021 09:25:03 -0700 Subject: [PATCH 16/19] Also set RUSTC_WORKSPACE_WRAPPER for build.rs --- src/cargo/core/compiler/custom_build.rs | 6 +++++ .../src/reference/environment-variables.md | 3 +++ tests/testsuite/build_script.rs | 27 +++++++++++++++++++ 3 files changed, 36 insertions(+) diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 53f532d52f7..91416789734 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -255,6 +255,12 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { } else { cmd.env_remove("RUSTC_WRAPPER"); } + cmd.env_remove("RUSTC_WORKSPACE_WRAPPER"); + if cx.bcx.ws.is_member(&unit.pkg) { + if let Some(wrapper) = bcx.rustc().workspace_wrapper.as_ref() { + cmd.env("RUSTC_WORKSPACE_WRAPPER", wrapper); + } + } cmd.env( "CARGO_ENCODED_RUSTFLAGS", bcx.rustflags_args(unit).join("\x1f"), diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index 2fb77c31c72..a16e182ee54 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -342,6 +342,9 @@ let out_dir = env::var("OUT_DIR").unwrap(); use it as well. * `RUSTC_WRAPPER` — the `rustc` wrapper, if any, that Cargo is using. See [`build.rustc-wrapper`]. +* `RUSTC_WORKSPACE_WRAPPER` — the `rustc` wrapper, if any, that Cargo is + using for workspace members. See + [`build.rustc-workspace-wrapper`]. * `RUSTC_LINKER` — The path to the linker binary that Cargo has resolved to use for the current target, if specified. The linker can be changed by editing `.cargo/config.toml`; see the documentation diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 56533075eaa..e035579a5b8 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -119,6 +119,7 @@ fn custom_build_env_vars() { assert_eq!(rustdoc, "rustdoc"); assert!(env::var("RUSTC_WRAPPER").is_err()); + assert!(env::var("RUSTC_WORKSPACE_WRAPPER").is_err()); assert!(env::var("RUSTC_LINKER").is_err()); @@ -250,6 +251,32 @@ fn custom_build_env_var_rustc_wrapper() { .run(); } +#[cargo_test] +fn custom_build_env_var_rustc_workspace_wrapper() { + let wrapper = tools::echo_wrapper(); + let p = project() + .file( + "build.rs", + r#" + use std::env; + + fn main() {{ + assert_eq!( + env::var("RUSTC_WORKSPACE_WRAPPER").unwrap(), + env::var("CARGO_RUSTC_WORKSPACE_WRAPPER_CHECK").unwrap() + ); + }} + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check") + .env("CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER", &wrapper) + .env("CARGO_RUSTC_WORKSPACE_WRAPPER_CHECK", &wrapper) + .run(); +} + #[cargo_test] fn custom_build_env_var_rustc_linker() { if cross_compile::disabled() { From d0c751bc8fb87c6789388e5ab09c5f4b7d06013c Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Mon, 12 Jul 2021 09:34:39 -0700 Subject: [PATCH 17/19] Test when RUSTC_WORKSPACE_WRAPPER is not set --- tests/testsuite/build_script.rs | 44 +++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index e035579a5b8..4bcdc6ba226 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -254,6 +254,8 @@ fn custom_build_env_var_rustc_wrapper() { #[cargo_test] fn custom_build_env_var_rustc_workspace_wrapper() { let wrapper = tools::echo_wrapper(); + + // Workspace wrapper should be set for any crate we're operating directly on. let p = project() .file( "build.rs", @@ -275,6 +277,48 @@ fn custom_build_env_var_rustc_workspace_wrapper() { .env("CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER", &wrapper) .env("CARGO_RUSTC_WORKSPACE_WRAPPER_CHECK", &wrapper) .run(); + + // But should not be set for a crate from the registry, as then it's not in a workspace. + Package::new("bar", "0.1.0") + .file( + "Cargo.toml", + r#" + [package] + name = "bar" + version = "0.1.0" + links = "a" + "#, + ) + .file( + "build.rs", + r#" + use std::env; + + fn main() {{ + assert!(env::var("RUSTC_WORKSPACE_WRAPPER").is_err()); + }} + "#, + ) + .file("src/lib.rs", "") + .publish(); + let p = project() + .file( + "Cargo.toml", + r#" + [package] + name = "foo" + version = "0.1.0" + + [dependencies] + bar = "0.1" + "#, + ) + .file("src/lib.rs", "") + .build(); + + p.cargo("check") + .env("CARGO_BUILD_RUSTC_WORKSPACE_WRAPPER", &wrapper) + .run(); } #[cargo_test] From 931326619b80d33c299a45cb231fb2af94e902b4 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Wed, 14 Jul 2021 10:25:22 -0700 Subject: [PATCH 18/19] RUSTC_VERSION != CARGO_VERSION --- src/doc/src/reference/environment-variables.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index a16e182ee54..b237e9615dc 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -357,7 +357,7 @@ let out_dir = env::var("OUT_DIR").unwrap(); * `CARGO_PKG_` - The package information variables, with the same names and values as are [provided during crate building][variables set for crates]. * `RUSTC_VERSION` - The version of rustc used by the cargo that invokes the build script. Its constituent parts are also - available as `CARGO_VERSION_MAJOR`, `_MINOR`, and + available as `RUSTC_VERSION_MAJOR`, `_MINOR`, and `_PATCH`. [unix-like platforms]: ../../reference/conditional-compilation.html#unix-and-windows From 1cbce4705131b6d3a18afcaa6a7b18ddad540ea4 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Thu, 15 Jul 2021 17:52:33 -0700 Subject: [PATCH 19/19] Remove RUSTC_VERSION envvar --- crates/cargo-test-support/src/lib.rs | 8 -------- src/cargo/core/compiler/custom_build.rs | 8 -------- src/doc/src/reference/environment-variables.md | 4 ---- tests/testsuite/build_script.rs | 17 +---------------- 4 files changed, 1 insertion(+), 36 deletions(-) diff --git a/crates/cargo-test-support/src/lib.rs b/crates/cargo-test-support/src/lib.rs index e07b8d404cf..992446f7fc8 100644 --- a/crates/cargo-test-support/src/lib.rs +++ b/crates/cargo-test-support/src/lib.rs @@ -1041,14 +1041,6 @@ pub fn is_nightly() -> bool { && (vv.contains("-nightly") || vv.contains("-dev")) } -pub fn rustc_release() -> &'static str { - RUSTC_INFO - .verbose_version - .lines() - .find_map(|line| line.strip_prefix("release: ")) - .expect("verbose version has release: field") -} - pub fn process>(t: T) -> ProcessBuilder { _process(t.as_ref()) } diff --git a/src/cargo/core/compiler/custom_build.rs b/src/cargo/core/compiler/custom_build.rs index 91416789734..6bbc042d09f 100644 --- a/src/cargo/core/compiler/custom_build.rs +++ b/src/cargo/core/compiler/custom_build.rs @@ -266,14 +266,6 @@ fn build_work(cx: &mut Context<'_, '_>, unit: &Unit) -> CargoResult { bcx.rustflags_args(unit).join("\x1f"), ); cmd.env_remove("RUSTFLAGS"); - let version = &bcx.rustc().version; - cmd.env( - "RUSTC_VERSION", - format!("{}.{}.{}", version.major, version.minor, version.patch), - ); - cmd.env("RUSTC_VERSION_MAJOR", version.major.to_string()); - cmd.env("RUSTC_VERSION_MINOR", version.minor.to_string()); - cmd.env("RUSTC_VERSION_PATCH", version.patch.to_string()); // Gather the set of native dependencies that this package has along with // some other variables to close over. diff --git a/src/doc/src/reference/environment-variables.md b/src/doc/src/reference/environment-variables.md index b237e9615dc..e3cca01b6f2 100644 --- a/src/doc/src/reference/environment-variables.md +++ b/src/doc/src/reference/environment-variables.md @@ -355,10 +355,6 @@ let out_dir = env::var("OUT_DIR").unwrap(); (ASCII Unit Separator). See [`build.rustflags`]. * `CARGO_PKG_` - The package information variables, with the same names and values as are [provided during crate building][variables set for crates]. -* `RUSTC_VERSION` - The version of rustc used by the cargo that invokes - the build script. Its constituent parts are also - available as `RUSTC_VERSION_MAJOR`, `_MINOR`, and - `_PATCH`. [unix-like platforms]: ../../reference/conditional-compilation.html#unix-and-windows [windows-like platforms]: ../../reference/conditional-compilation.html#unix-and-windows diff --git a/tests/testsuite/build_script.rs b/tests/testsuite/build_script.rs index 4bcdc6ba226..22b9e29400f 100644 --- a/tests/testsuite/build_script.rs +++ b/tests/testsuite/build_script.rs @@ -5,9 +5,7 @@ use cargo_test_support::paths::CargoPathExt; use cargo_test_support::registry::Package; use cargo_test_support::tools; use cargo_test_support::{basic_manifest, cross_compile, is_coarse_mtime, project}; -use cargo_test_support::{ - rustc_host, rustc_release, sleep_ms, slow_cpu_multiplier, symlink_supported, -}; +use cargo_test_support::{rustc_host, sleep_ms, slow_cpu_multiplier, symlink_supported}; use cargo_util::paths::remove_dir_all; use std::env; use std::fs; @@ -82,7 +80,6 @@ fn custom_build_env_vars() { ) .file("bar/src/lib.rs", "pub fn hello() {}"); - let rustc_version = semver::Version::parse(rustc_release()).unwrap(); let file_content = format!( r#" use std::env; @@ -126,15 +123,6 @@ fn custom_build_env_vars() { assert!(env::var("RUSTFLAGS").is_err()); let rustflags = env::var("CARGO_ENCODED_RUSTFLAGS").unwrap(); assert_eq!(rustflags, ""); - - let version = env::var("RUSTC_VERSION").unwrap(); - assert_eq!(version, "{1}.{2}.{3}", "bad rust version"); - let version = env::var("RUSTC_VERSION_MAJOR").unwrap(); - assert_eq!(version, "{1}"); - let version = env::var("RUSTC_VERSION_MINOR").unwrap(); - assert_eq!(version, "{2}"); - let version = env::var("RUSTC_VERSION_PATCH").unwrap(); - assert_eq!(version, "{3}"); }} "#, p.root() @@ -142,9 +130,6 @@ fn custom_build_env_vars() { .join("debug") .join("build") .display(), - rustc_version.major, - rustc_version.minor, - rustc_version.patch, ); let p = p.file("bar/build.rs", &file_content).build();