Description
Problem
In the current Rust nightly, the cfg for atomics usually looks like:
❯ rustc +nightly --print cfg | grep target_has_atomic
target_has_atomic
target_has_atomic="16"
target_has_atomic="32"
target_has_atomic="64"
target_has_atomic="8"
target_has_atomic="ptr"
target_has_atomic_equal_alignment="16"
target_has_atomic_equal_alignment="32"
target_has_atomic_equal_alignment="64"
target_has_atomic_equal_alignment="8"
target_has_atomic_equal_alignment="ptr"
target_has_atomic_load_store
target_has_atomic_load_store="16"
target_has_atomic_load_store="32"
target_has_atomic_load_store="64"
target_has_atomic_load_store="8"
target_has_atomic_load_store="ptr"
The configs are defined both with values (e.g. target_has_atomic="16"
to indicate that the target supports atomics for 16 bit types) and without values (e.g. target_has_atomic
to indicate that the target supports atomics in general, for at least one type / size in bytes).
That change in rustc was made in this PR: rust-lang/rust#106856
However, that change made the CARGO_CFG_TARGET_HAS_ATOMIC{,_LOAD_STORE}
environment variables empty.
Steps
- Create a new Rust project with the following
build.rs
:
fn main() {
eprintln!(
"CARGO_CFG_TARGET_THREAD_LOCAL: {}",
std::env::var("CARGO_CFG_TARGET_THREAD_LOCAL").unwrap()
);
eprintln!(
"CARGO_CFG_TARGET_HAS_ATOMIC: {}",
std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC").unwrap()
);
eprintln!(
"CARGO_CFG_TARGET_HAS_ATOMIC_LOAD_STORE: {}",
std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC_LOAD_STORE").unwrap()
);
eprintln!(
"CARGO_CFG_TARGET_HAS_ATOMIC_EQUAL_ALIGNMENT: {}",
std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC_EQUAL_ALIGNMENT").unwrap()
);
}
- See the following output:
[rust-108201 0.1.0] CARGO_CFG_TARGET_THREAD_LOCAL:
[rust-108201 0.1.0] CARGO_CFG_TARGET_HAS_ATOMIC:
[rust-108201 0.1.0] CARGO_CFG_TARGET_HAS_ATOMIC_LOAD_STORE:
[rust-108201 0.1.0] CARGO_CFG_TARGET_HAS_ATOMIC_EQUAL_ALIGNMENT: 16,32,64,8,ptr
The expected, correct output would be rather:
[rust-108201 0.1.0] CARGO_CFG_TARGET_THREAD_LOCAL: 16,32,64,8,ptr
[rust-108201 0.1.0] CARGO_CFG_TARGET_HAS_ATOMIC: 16,32,64,8,ptr
[rust-108201 0.1.0] CARGO_CFG_TARGET_HAS_ATOMIC_LOAD_STORE: 16,32,64,8,ptr
[rust-108201 0.1.0] CARGO_CFG_TARGET_HAS_ATOMIC_EQUAL_ALIGNMENT: 16,32,64,8,ptr
Possible Solution(s)
When there is a cfg in Rustc which is defined both with and without value, I think we should keep the values as an environment variables.
For example, for the following cfg:
target_has_atomic
target_has_atomic="16"
target_has_atomic="32"
target_has_atomic="64"
target_has_atomic="8"
target_has_atomic="ptr"
Cargo should produce the following env variable:
CARGO_CFG_TARGET_HAS_ATOMIC: 16,32,64,8,ptr
Notes
No response
Version
cargo 1.67.1 (or current master) + rustc nightly