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"] |
On CPU archs other than x86,
std_detectrelies on thelibcfeature for runtime feature detection. Without thelibcfeature, the following code initalizescache::Initializerwith 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
To ensture correct feature detection, the necessary feature (such as
libcordefault) should be explicitly enabled here:edit/.cargo/release.toml
Line 23 in c34bdb0