Skip to content

Commit 96cac0a

Browse files
authored
Unrolled build for rust-lang#119115
Rollup merge of rust-lang#119115 - GuillaumeGomez:env-docs, r=Nilstrieb Update documentation for `--env` compilation flag Part of rust-lang#80792. As mentioned in rust-lang#118830. It adds a mention to `tracked_env::var` and also clarifies what triggers a new compilation. r? `@Nilstrieb`
2 parents 8fca829 + 2679bca commit 96cac0a

File tree

1 file changed

+20
-1
lines changed
  • src/doc/unstable-book/src/compiler-flags

1 file changed

+20
-1
lines changed

src/doc/unstable-book/src/compiler-flags/env.md

+20-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ The tracking issue for this feature is: [#118372](https://github.com/rust-lang/r
55
------------------------
66

77
This option flag allows to specify environment variables value at compile time to be
8-
used by `env!` and `option_env!` macros.
8+
used by `env!` and `option_env!` macros. It also impacts `tracked_env::var` function
9+
from the `proc_macro` crate.
10+
11+
This information will be stored in the dep-info files. For more information about
12+
dep-info files, take a look [here](https://doc.rust-lang.org/cargo/guide/build-cache.html#dep-info-files).
913

1014
When retrieving an environment variable value, the one specified by `--env` will take
1115
precedence. For example, if you want have `PATH=a` in your environment and pass:
@@ -20,6 +24,21 @@ Then you will have:
2024
assert_eq!(env!("PATH"), "env");
2125
```
2226

27+
It will trigger a new compilation if any of the `--env` argument value is different.
28+
So if you first passed:
29+
30+
```bash
31+
--env A=B --env X=12
32+
```
33+
34+
and then on next compilation:
35+
36+
```bash
37+
--env A=B
38+
```
39+
40+
`X` value is different (not set) so the code will be re-compiled.
41+
2342
Please note that on Windows, environment variables are case insensitive but case
2443
preserving whereas `rustc`'s environment variables are case sensitive. For example,
2544
having `Path` in your environment (case insensitive) is different than using

0 commit comments

Comments
 (0)