Description
(As discussed with @wycats on IRC.)
Rustc should have an option to obtain a list, as part of building, of every environment variable that was requested via the env!
or option_env!
macros (tagged accordingly with "required" or "optional"), as well as providing a way to instrument intrinsics like env::var
called by build.rs
scripts. This will make it more feasible to detect (and lint about) the usage of environment variables only set by newer build bits (e.g. Cargo) without an appropriate versioned dependency; for instance, it'd be possible to say "you use the $CARGO_FOO
environment variable without a dependency on a version of Cargo that supplies $CARGO_FOO
. This would also help people doing reproducible builds to see what environment variables might affect a build.
This will never be perfect; it can't capture variables read from native code or from code that goes out of its way to bypass the normal mechanism (e.g. calling libc::getenv
.) However, this would still catch many common cases.