diff --git a/src/cargo/core/compiler/compilation.rs b/src/cargo/core/compiler/compilation.rs index 50f5945a8..40389e7ae 100644 --- a/src/cargo/core/compiler/compilation.rs +++ b/src/cargo/core/compiler/compilation.rs @@ -340,10 +340,12 @@ impl<'cfg> Compilation<'cfg> { .env("CARGO_PKG_AUTHORS", &pkg.authors().join(":")) .cwd(pkg.root()); - // Apply any environment variables from the config - for (key, value) in self.config.env_config()?.iter() { - if value.is_force() || cmd.get_env(&key).is_none() { - cmd.env(&key, value.resolve(&self.config)); + if self.config.cli_unstable().configurable_env { + // Apply any environment variables from the config + for (key, value) in self.config.env_config()?.iter() { + if value.is_force() || cmd.get_env(&key).is_none() { + cmd.env(&key, value.resolve(&self.config)); + } } } diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 494e33993..3b6c4e9d7 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -444,6 +444,7 @@ pub struct CliUnstable { pub weak_dep_features: bool, pub extra_link_arg: bool, pub credential_process: bool, + pub configurable_env: bool, } const STABILIZED_COMPILE_PROGRESS: &str = "The progress bar is now always \ @@ -598,6 +599,7 @@ impl CliUnstable { "doctest-xcompile" => self.doctest_xcompile = parse_empty(k, v)?, "panic-abort-tests" => self.panic_abort_tests = parse_empty(k, v)?, "jobserver-per-rustc" => self.jobserver_per_rustc = parse_empty(k, v)?, + "configurable-env" => self.configurable_env = parse_empty(k, v)?, "features" => { // For now this is still allowed (there are still some // unstable options like "compare"). This should be removed at diff --git a/tests/testsuite/cargo_env_config.rs b/tests/testsuite/cargo_env_config.rs index 874976b38..963455382 100644 --- a/tests/testsuite/cargo_env_config.rs +++ b/tests/testsuite/cargo_env_config.rs @@ -25,7 +25,8 @@ fn env_basic() { ) .build(); - p.cargo("run") + p.cargo("run -Zconfigurable-env") + .masquerade_as_nightly_cargo() .with_stdout_contains("compile-time:Hello") .with_stdout_contains("run-time:Hello") .run(); @@ -51,7 +52,8 @@ fn env_invalid() { ) .build(); - p.cargo("build") + p.cargo("build -Zconfigurable-env") + .masquerade_as_nightly_cargo() .with_status(101) .with_stderr_contains("[..]`env.ENV_TEST_BOOL` expected a string, but found a boolean") .run(); @@ -81,7 +83,8 @@ fn env_force() { ) .build(); - p.cargo("run") + p.cargo("run -Zconfigurable-env") + .masquerade_as_nightly_cargo() .env("ENV_TEST_FORCED", "from-env") .env("ENV_TEST_UNFORCED", "from-env") .with_stdout_contains("ENV_TEST_FORCED:from-config") @@ -117,5 +120,7 @@ fn env_relative() { ) .build(); - p.cargo("run").run(); + p.cargo("run -Zconfigurable-env") + .masquerade_as_nightly_cargo() + .run(); }