Skip to content

Commit dc2f77a

Browse files
committedDec 10, 2023
Add (unstable) documentation for --env command line option
1 parent d2b1f94 commit dc2f77a

File tree

1 file changed

+26
-0
lines changed
  • src/doc/unstable-book/src/compiler-flags

1 file changed

+26
-0
lines changed
 
Original file line numberDiff line numberDiff 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).

0 commit comments

Comments
 (0)
Please sign in to comment.