I can't get cargo / rustc to detect my avx instructions when using target-cpu=native.
Depending on how I invoke rustc I can sometimes see avx instructions, but I can't get target-cpu=native to activate the avx instructions unless I make a .cargo/config file.
Here's what I'm seeing:
RUSTFLAGS='-C target-cpu=native' rustc --print cfg
This generates a short list of features missing avx:
rustc -C target-cpu=native --print cfg
Generates a longer list of features: (includes avx which is supported on my cpu)
rustc --print target-features
Generates a LONG list of supported features:
The --print target-features is misleading, as I believe it includes all of the features that rustc could cross-compile, but includes things not supported by my cpu even though it says: "Features supported by rustc for this target:"
In the list, it describes items as either Support ___, or Enable ___. The Supported items are not supported by my cpu. Many of the things labeled Enable are also not supported according to
cat /proc/cpuinfo => avx, avx2 supported, avx512xxx - Not supported
--print target-features output:
avx10.1 - Support AVX10.1 up to 512-bit instruction.
avx10.2 - Support AVX10.2 up to 512-bit instruction.
avx2 - Enable AVX2 instructions.
avx512bf16 - Support bfloat16 floating point.
avx512bitalg - Enable AVX-512 Bit Algorithms.
Anyway, back to the issue at hand...
I've included environment flags:
RUSTFLAGS='-C target-cpu=native'
build.rs flags:
println!("cargo:rustc-env=RUSTFLAGS=-C target-cpu=native");
And Cargo.toml flags:
[profile.dev]
target-cpu = "native"
And still my attempts to use target-cpu=native to set the avx and avx2 features isn't working.
#[cfg(target_feature = "avx2")]
I'm pretty sure I could set the flags I need manually, but my project needs target-cpu=native to set the flags for me.
.cargo/config setup that works:
[target.x86_64-unknown-linux-gnu]
rustflags = ["-Ctarget-cpu=native"]
I'm convinced this is a real bug.
System is Linux Mint.
rustc 1.92.0-nightly (4082d6a3f 2025-09-27)
CPU: Intel(R) Core(TM) i9-10900K CPU