Skip to content

Detect and report usage of environment variables at build time and run time. #44074

Closed
@joshtriplett

Description

@joshtriplett

(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-reproducibilityArea: Reproducible / deterministic buildsC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions