#environment variable passed to .cargo/config.toml has no effect

13 messages · Page 1 of 1 (latest)

frail flower
#

Because of a change in tooling, I now need to set an environment variable in .cargo/config.toml. My intent is to have invocations of cargo by rust-analyzer and the user themselves read and execute using this environment variable.

  • If this environment variable is not set, the program will not compile.
  • This environment variable is confirmed to function, as if I export it in a justfile or set it manually the program compiles. However, when rust-analyzer runs, it resets the variable to its default, empty value and runs without it.
  • I am relatively certain that cargo is reading from the config.toml file, as if I set other values or insert gibberish, cargo reacts accordingly
  • I have tried setting CARGO_ENCODED_RUSTFLAGS and RUSTFLAGS both with and without force being set and the variable does not get applied
  • I have also tried to set build.rustflags but this causes a parsing error.

I am on Windows 10, and this behavior is exhibited both in powershell and cmd.exe

#

Directory structure:

#

full text of the config.toml:

[env]
CARGO_ENCODED_RUSTFLAGS={value = "--cfg uuid_unstable", force = true}
stiff burrow
#

[env] probably does set the env var but doesn't affect compilation at this stage

frail flower
#

Here's the error the compiler emits:
```error: failed to run rustc to learn about target-specific information

Caused by:
process didn't exit successfully: rustc - --crate-name ___ --print=file-names "--cfg uuid_unstable" --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg (exit code: 1)
--- stderr
error: Unrecognized option: 'cfg uuid_unstable'

#

If I remove the leading --cfg in the config.toml the quotes seem to get escaped:

error: failed to run `rustc` to learn about target-specific information

Caused by:
  process didn't exit successfully: `rustc - --crate-name ___ --print=file-names uuid_unstable --crate-type bin --crate-type rlib --crate-type dylib --crate-type cdylib --crate-type staticlib --crate-type proc-macro --print=sysroot --print=split-debuginfo --print=crate-name --print=cfg` (exit code: 1)
  --- stderr
  error: multiple input filenames provided (first two filenames are `-` and `uuid_unstable`)
stiff burrow
frail flower