Add (unstable) documentation for --env command line option · rust-lang/rust@dc2f77a (original) (raw)

File tree

1 file changed

lines changed

1 file changed

lines changed

Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
1 +# `env`
2 +
3 +The tracking issue for this feature is: [#118372](https://github.com/rust-lang/rust/issues/118372).
4 +
5 +------------------------
6 +
7 +This option flag allows to specify environment variables value at compile time to be
8 +used by `env!` and `option_env!` macros.
9 +
10 +When retrieving an environment variable value, the one specified by `--env` will take
11 +precedence. For example, if you want have `PATH=a` in your environment and pass:
12 +
13 +```bash
14 +rustc --env PATH=env
15 +```
16 +
17 +Then you will have:
18 +
19 +```rust,no_run
20 +assert_eq!(env!("PATH"), "env");
21 +```
22 +
23 +Please note that on Windows, environment variables are case insensitive but case
24 +preserving whereas `rustc`'s environment variables are case sensitive. For example,
25 +having `Path` in your environment (case insensitive) is different than using
26 +`rustc --env Path=...` (case sensitive).