Skip to content

After #106856, CARGO_CFG_TARGET_HAS_ATOMIC{,_LOAD_STORE} become empty strings #108201

Closed
@taiki-e

Description

@taiki-e

Code

I ran cargo build -vv with this code:

# Cargo.toml
[package]
name = "repro"
version = "0.1.0"
edition = "2021"
// build.rs
fn main() {
    dbg!(std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC").ok());
    dbg!(std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC_LOAD_STORE").ok());
    dbg!(std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC_EQUAL_ALIGNMENT").ok());
}

I expected to see this happen:

[repro 0.1.0] [build.rs:2] std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC").ok() = Some(
[repro 0.1.0]     "128,16,32,64,8,ptr",
[repro 0.1.0] )
[repro 0.1.0] [build.rs:3] std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC_LOAD_STORE").ok() = Some(
[repro 0.1.0]     "128,16,32,64,8,ptr",
[repro 0.1.0] )
[repro 0.1.0] [build.rs:4] std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC_EQUAL_ALIGNMENT").ok() = Some(
[repro 0.1.0]     "128,16,32,64,8,ptr",
[repro 0.1.0] )

Instead, this happened:

[repro 0.1.0] [build.rs:2] std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC").ok() = Some(
[repro 0.1.0]     "",
[repro 0.1.0] )
[repro 0.1.0] [build.rs:3] std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC_LOAD_STORE").ok() = Some(
[repro 0.1.0]     "",
[repro 0.1.0] )
[repro 0.1.0] [build.rs:4] std::env::var("CARGO_CFG_TARGET_HAS_ATOMIC_EQUAL_ALIGNMENT").ok() = Some(
[repro 0.1.0]     "128,16,32,64,8,ptr",
[repro 0.1.0] )

It seems that cfg(target_has_atomic{,_load_store}) without value that is added in #106856 is overriding cfg(target_has_atomic{,_load_store}) with value.

This environment variable still seems to be rarely used in the ecosystem, but profiler_builtins uses it.

if env::var_os("CARGO_CFG_TARGET_HAS_ATOMIC")

Mentioning @vadorovsky who authored #106856

Version it worked on

It most recently worked on: nightly-2023-01-27

$ rustc +nightly-2023-01-27 --print cfg | grep target_has_atomic
target_has_atomic="128"
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="128"
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="128"
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"

Version with regression

nightly-2023-01-28
rustc --version --verbose:

rustc 1.69.0-nightly (ef982929c 2023-01-27)
binary: rustc
commit-hash: ef982929c0b653436a6ea6892a2a839fba7c8b57
commit-date: 2023-01-27
host: aarch64-apple-darwin
release: 1.69.0-nightly
LLVM version: 15.0.7
$ rustc +nightly-2023-01-28 --print cfg | grep target_has_atomic
target_has_atomic
target_has_atomic="128"
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="128"
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="128"
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"

@rustbot modify labels: +regression-from-stable-to-nightly -regression-untriaged

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.T-cargoRelevant to the cargo team, which will review and decide on the PR/issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions