Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CARGO_CFG_TARGET_HAS_ATOMIC{,_LOAD_STORE} are empty strings (with Rust nightly) #11789

Closed
vadorovsky opened this issue Mar 2, 2023 · 0 comments · Fixed by #11790
Closed

CARGO_CFG_TARGET_HAS_ATOMIC{,_LOAD_STORE} are empty strings (with Rust nightly) #11789

vadorovsky opened this issue Mar 2, 2023 · 0 comments · Fixed by #11790
Labels
C-bug Category: bug

Comments

@vadorovsky
Copy link
Contributor

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

  1. 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()
    );
}
  1. 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
@vadorovsky vadorovsky added the C-bug Category: bug label Mar 2, 2023
vadorovsky added a commit to vadorovsky/cargo that referenced this issue Mar 2, 2023
When a rustc cfg is defined both with and without value, the
environment variable should provide all the values. Before this change,
it ended up being empty.

Fixes: rust-lang#11789
vadorovsky added a commit to vadorovsky/cargo that referenced this issue Mar 3, 2023
When a rustc cfg is defined both with and without value, the
environment variable should provide all the values. Before this change,
it ended up being empty.

Fixes: rust-lang#11789
vadorovsky added a commit to vadorovsky/cargo that referenced this issue Mar 3, 2023
When a rustc cfg is defined both with and without value, the
environment variable should provide all the values. Before this change,
it ended up being empty.

Fixes: rust-lang#11789
vadorovsky added a commit to vadorovsky/cargo that referenced this issue Mar 3, 2023
When a rustc cfg is defined both with and without value, the
environment variable should provide all the values. Before this change,
it ended up being empty.

Fixes: rust-lang#11789
@rustbot rustbot added the beta-nominated Nominated to backport to the beta branch. label Mar 6, 2023
bors added a commit that referenced this issue Mar 6, 2023
Fix `CARGO_CFG_` vars for configs defined both with and without value

When a rustc cfg is defined both with and without value, the environment variable should provide all the values. Before this change, it ended up being empty.

Fixes: #11789
@arlosi arlosi removed the beta-nominated Nominated to backport to the beta branch. label Mar 6, 2023
@bors bors closed this as completed in ccd9915 Mar 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants