Skip to content

Cargo config reference should more clearly explain mapping complex keys to environment variable names #7610

@b-spencer

Description

@b-spencer

Problem

The cargo config reference page says this:

For each configuration key above of the form foo.bar the environment variable CARGO_FOO_BAR can also be used to define the value. For example the build.jobs key can also be defined by CARGO_BUILD_JOBS.

This is correct, and the simple example is useful. However, the transformation of non-alphanumeric characters is not documented and it isn't obvious how to map a more complex config parameter such as:

[target.aarch64-linux-android]
linker = "/some/linker"

to an environment variable. I tried many combinations unsuccessfully until I eventually found an old issue asking about the same problem:

I tried:

LD
LINKER
CARGO_BUILD_LINKER
CARGO_TARGET_i686-pc-windows-gnu_LINKER

But none had the same effect as a config file containing:

[target.i686-pc-windows-gnu]
linker = "c:/Rtools/mingw_32/bin/gcc"

Possible Solution(s)

I suggest expanding on the docs to give a complex example such as:

Replace any characters . or - in key names with _ and upper case the result. For example,

[target.aarch64-linux-android]
linker = "/some/linker"

can be set with the environment variable CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=/some/linker.

I hope this helps the next person who stumbles across the need to set these values via the environment.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions