Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize --env-set option #119926

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1827,7 +1827,7 @@ pub fn rustc_optgroups() -> Vec<RustcOptGroup> {
"Remap source names in all output (compiler messages and output files)",
"FROM=TO",
),
opt::multi("", "env-set", "Inject an environment variable", "VAR=VALUE"),
opt::multi_s("", "env-set", "Inject an environment variable", "VAR=VALUE"),
]);
opts
}
Expand Down
31 changes: 31 additions & 0 deletions src/doc/rustc/src/command-line-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -504,3 +504,34 @@ an empty option. The file can use Unix or Windows style line endings, and must b
encoded as UTF-8.

[the JSON chapter]: json.md

<a id="option-env-set"></a>
## `env-set`: inject an environment variable

This option flag allows specification of environment variables at compile time for the
`env!` and `option_env!` macros and `tracked_env::var` function from the `proc_macro`
crate.

This information will be stored in the dep-info files. For more information about
dep-info files, take a look [here](https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-file\
s).

When retrieving an environment variable, the value specified by `--env-set` will take
precedence. For example, if you want have `PATH=env` in your environment and pass:

```bash
rustc --env-set PATH=env
```

Then you will have:

```rust,no_run
assert_eq!(env!("PATH"), "env");
```

Crates will be fully re-compiled if `--env-set` arguments are changed.

Please note that on Windows, environment variables are case insensitive but case
preserving whereas `rustc`'s environment variables are case sensitive. For example,
having `Path` in your environment (case insensitive) is different than using
`rustc --env-set Path=...` (case sensitive).
45 changes: 0 additions & 45 deletions src/doc/unstable-book/src/compiler-flags/env-set.md

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/extenv/extenv-env-overload.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// run-pass
// rustc-env:MY_VAR=tadam
// compile-flags: --env-set MY_VAR=123abc -Zunstable-options
// compile-flags: --env-set MY_VAR=123abc

// This test ensures that variables provided with `--env` take precedence over
// variables from environment.
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/extenv/extenv-env.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// compile-flags: --env-set FOO=123abc -Zunstable-options
// compile-flags: --env-set FOO=123abc
// run-pass
fn main() {
assert_eq!(env!("FOO"), "123abc");
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/feature-gates/env-flag.rs

This file was deleted.

2 changes: 0 additions & 2 deletions tests/ui/feature-gates/env-flag.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion tests/ui/proc-macro/env.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// aux-build:env.rs
// run-pass
// rustc-env: THE_CONST=1
// compile-flags: -Zunstable-options --env-set THE_CONST=12 --env-set ANOTHER=4
// compile-flags: --env-set THE_CONST=12 --env-set ANOTHER=4

#![crate_name = "foo"]

Expand Down
Loading