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

Inform dep-info users about used environment variables #40364

Closed
alexcrichton opened this issue Mar 8, 2017 · 2 comments · Fixed by #71858
Closed

Inform dep-info users about used environment variables #40364

alexcrichton opened this issue Mar 8, 2017 · 2 comments · Fixed by #71858
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR.

Comments

@alexcrichton
Copy link
Member

It'd be great for caching servers like sccache if the compiler could inform them about used environment variables for the compilation through macros like env! and option_env!. I'm not precisely sure what the format would look like, but via some means would be great!

@luser
Copy link
Contributor

luser commented Mar 8, 2017

I don't have any great ideas, but if we could get this out of the compiler in the same invocation where we get dep-info that would be ideal. Whether it goes to a separate file or is mixed into the dep-info somehow is not particularly important to me.

@alexcrichton
Copy link
Member Author

Right now foo.d (the output of dep-info) is makefile syntax (intentionally). We could perhaps consider just throwing in something like:

# env-dep: FOO
# env-dep: BAR
foo.d: ...

a.rs:
b.rs:

A bit of a hack, but could get the job done.

@Mark-Simulacrum Mark-Simulacrum added the A-incr-comp Area: Incremental compilation label May 27, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 27, 2017
@alexcrichton alexcrichton removed the A-incr-comp Area: Incremental compilation label Sep 1, 2017
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue Jun 25, 2020
Print environment variables accessed by rustc as special comments into depinfo files

So cargo (and perhaps others tools) can use them for linting (at least) or for actually rebuilding crates on env var changes.

---
I've recently observed one more forgotten environment variable in a build script rust-lang@8a77d1c and thought it would be nice to provide the list of accessed variables to cargo automatically as a part of depinfo.

Unsurprisingly, I wasn't the first who had this idea - cc rust-lang#70517 rust-lang#40364 rust-lang#44074.

Also, there are dozens of uses of `(option_)env!` in rustc repo and, like, half of them are not registered in build scripts.

---
Description:
- depinfo files are extended with special comments containing info about environment variables accessed during compilation.
- Comment format for environment variables with successfully retrieved value: `# env-dep:KEY=VALUE`.
- Comment format for environment variables without successfully retrieved value: `# env-dep:KEY` (can happen with `option_env!`).
- `KEY` and `VALUE` are minimally escaped (`\n`, `\r`, `\\`) so they don't break makefile comments and can be unescaped by anything that can unescape standard `escape_default` and friends.

FCP report: rust-lang#71858 (comment)

Closes rust-lang#70517
Closes rust-lang#40364
Closes rust-lang#44074
A new issue in the cargo repo will be needed to track the cargo side of this feature.

r? @ehuss
@bors bors closed this as completed in 1033351 Jun 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR.
Projects
None yet
3 participants