Skip to content

[env] settings are not consistently applied to rustc invocations #12028

Closed
@main--

Description

@main--

Problem

The docs on the [env] section in the config file state:

The [env] section allows you to set additional environment variables for build scripts, rustc invocations, cargo run and cargo build.

Hence, I would expect these variables to be set whenever rustc is invoked. In practice, compiling a simple Hello World crate reveals that the compilation starts with a rustc invocation that does not have these environment variables set.

Steps

  1. Set an environment variable in the cargo config
  2. Expect it to consistently apply to all rustc invocations
  3. It doesn't

Possible Solution(s)

The environment variable should be consistently applied to all rustc invocations.

Notes

This problem is especially frustrating in conjunction with sccache (as rustc-wrapper). sccache can be configured via environment variables, which makes an [env] section in a config.toml an extremely attractive way for a project-specific caching setup. sccache launches a server process on its first invocation. Since the current behavior of cargo is to ignore environment variables for the first rustc invocation, sccache will at that point launch a server process that is missing the config (and instead defaults to caching on the local disk). Subsequent invocations would have the environment variables present, but since the sccache server is already running, they will be ignored. In essence, the only way to make this work is to wrap sccache in a shell script that explicitly sets the variables, rendering cargo's env feature entirely useless for this usecase.

Version

cargo 1.68.0 (115f34552 2023-02-26)
release: 1.68.0
commit-hash: 115f34552518a2f9b96d740192addbac1271e7e6
commit-date: 2023-02-26
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.16.0 vendored)
libcurl: 7.86.0-DEV (sys:0.4.59+curl-7.86.0 vendored ssl:OpenSSL/1.1.1q)
os: Arch Linux Rolling Release [64-bit]

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-acceptedStatus: Issue or feature is accepted, and has a team member available to help mentor or review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions