Skip to content

Commit

Permalink
Improve documentation for --env-set option flag
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 18, 2024
1 parent 87c4695 commit b90ccde
Showing 1 changed file with 6 additions and 19 deletions.
25 changes: 6 additions & 19 deletions src/doc/rustc/src/command-line-arguments.md
Original file line number Diff line number Diff line change
Expand Up @@ -508,16 +508,16 @@ encoded as UTF-8.
<a id="option-env-set"></a>
## `env-set`: inject an environment variable

This option flag allows to specify environment variables value at compile time to be
used by `env!` and `option_env!` macros. It also impacts `tracked_env::var` function
from the `proc_macro` crate.
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 value, the one specified by `--env-set` will take
precedence. For example, if you want have `PATH=a` in your environment and pass:
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
Expand All @@ -529,20 +529,7 @@ Then you will have:
assert_eq!(env!("PATH"), "env");
```

It will trigger a new compilation if any of the `--env-set` argument value is different.
So if you first passed:

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

and then on next compilation:

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

`X` value is different (not set) so the code will be re-compiled.
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,
Expand Down

0 comments on commit b90ccde

Please sign in to comment.