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

Update documentation for --env compilation flag #119115

Merged
merged 2 commits into from
Dec 20, 2023
Merged
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
21 changes: 20 additions & 1 deletion src/doc/unstable-book/src/compiler-flags/env.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ The tracking issue for this feature is: [#118372](https://github.com/rust-lang/r
------------------------

This option flag allows to specify environment variables value at compile time to be
used by `env!` and `option_env!` macros.
used by `env!` and `option_env!` macros. It also impacts `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-files).

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

It will trigger a new compilation if any of the `--env` argument value is different.
So if you first passed:
GuillaumeGomez marked this conversation as resolved.
Show resolved Hide resolved

```bash
--env A=B --env X=12
```

and then on next compilation:

```bash
--env A=B
```

`X` value is different (not set) so the code will be re-compiled.

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
Expand Down
Loading