Skip to content

std_detect breaks when using build-std-features without the libc feature #553

@heiher

Description

@heiher

On CPU archs other than x86, std_detect relies on the libc feature for runtime feature detection. Without the libc feature, the following code initalizes cache::Initializer with a default value, which prevents accurate detection of CPU features:

https://github.com/rust-lang/stdarch/blob/5a7342fc16b208b1b16624e886937ed8509a6506/crates/std_detect/src/detect/mod.rs#L51-L56

        ...
    } else if #[cfg(all(any(target_os = "linux", target_os = "android"), feature = "libc"))] {
        #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
        #[path = "os/riscv.rs"]
        mod riscv;
        #[path = "os/linux/mod.rs"]
        mod os;
    } else ... {
        ...
    } else {
        #[path = "os/other.rs"]
        mod os;
    }

To ensture correct feature detection, the necessary feature (such as libc or default) should be explicitly enabled here:

build-std-features = ["panic_immediate_abort", "optimize_for_size"]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    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