Skip to content

Overwritten [env] paths are not relative to .cargo/config.toml's parent, when using config-includes #16954

Description

@thomasw04

Problem

When including a config file that defines a relative path [env] variable, the including config's definition takes precedence over the included one. However, the base of that relative path seems to be incorrectly calculated.

Steps

# inc/inc.toml
[env]
MY_ENV = { value = "outer", relative = true }

# foo/.cargo/config.toml
include = ["../../inc/inc.toml"]

[env]
MY_ENV = { value = "inner", relative = true }

# foo/build.rs
fn main() {
  panic!("{}", std::env::var("MY_ENV").unwrap());
}

When running cargo +1.93.1 build, it prints foo/inner (as an absolute path to wherever foo is).
When running cargo +1.94.0 build, it prints foo/.cargo/../../inner (as an absolute path to wherever foo is).
(The behaviour of 1.95.0 is similar to 1.94.0)

Interestingly, when changing to:

# foo/.cargo/config.toml
include = ["../../inc.toml"]

cargo +1.94.0 build, prints foo/.cargo/../inner
(The behaviour of 1.95.0 is similar to 1.94.0)

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.95.0 (f2d3ce0bd 2026-03-21)
release: 1.95.0
commit-hash: f2d3ce0bd7f24a49f8f72d9000448f8838c4e850
commit-date: 2026-03-21
host: x86_64-unknown-linux-gnu
libgit2: 1.9.2 (sys:0.20.4 vendored)
libcurl: 8.15.0-DEV (sys:0.4.83+curl-8.15.0 vendored ssl:OpenSSL/3.5.4)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Ubuntu 24.4.0 (noble) [64-bit]

cargo 1.94.0 (85eff7c80 2026-01-15)
release: 1.94.0
commit-hash: 85eff7c80277b57f78b11e28d14154ab12fcf643
commit-date: 2026-01-15
host: x86_64-unknown-linux-gnu
libgit2: 1.9.2 (sys:0.20.3 vendored)
libcurl: 8.17.0-DEV (sys:0.4.84+curl-8.17.0 vendored ssl:OpenSSL/3.5.4)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Ubuntu 24.4.0 (noble) [64-bit]

cargo 1.93.1 (083ac5135 2025-12-15)
release: 1.93.1
commit-hash: 083ac5135f967fd9dc906ab057a2315861c7a80d
commit-date: 2025-12-15
host: x86_64-unknown-linux-gnu
libgit2: 1.9.1 (sys:0.20.2 vendored)
libcurl: 8.15.0-DEV (sys:0.4.83+curl-8.15.0 vendored ssl:OpenSSL/3.5.4)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Ubuntu 24.4.0 (noble) [64-bit]

Metadata

Metadata

Assignees

Labels

A-config-includeArea: `include` config keyA-configurationArea: cargo config files and env varsC-bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions