Open
Description
It's possible to set target compilation architecture via RUSTFLAGS="-C target-cpu=<arch>"
.
As far as I can tell, the C compiler is not made aware of this, so it won't be producing matching binaries. It affects performance and I suspect it may also affect correctness when it affects C calling convention (newer SSE registers are used).
So I think it'd be best if the cc
crate detected Rust's compilation target and automatically configured the C compiler to match (abstracting away compiler-specific flags and possibly cpu arch naming mismatches, so that build scripts don't have to reinvent this).
Activity
kornelski commentedon Dec 10, 2017
I've cross-referenced https://gcc.gnu.org/onlinedocs/gcc/x86-Options.html and
rustc --print target-cpus
Most of them match exactly. Below is the list of odd ones.
The extra options on GCC side can be ignored (they're mostly exotic/outdated and not fully supported anyway).
The extra options on LLVM side may need to be mapped to a closest equivalent.
march
lilith commentedon Dec 10, 2017
related: conan-io/conan#847
lilith commentedon Dec 10, 2017
I would suggest (since these have to be mapped and handled separately per ToolFamily), that you start with a minimal list and expand support as they are requested by other projects.
GCC 4.8 requires corei7-avx (rather than sandybridge) and core-avx2 (rather than haswell). I don't see gcc version detection, and I think those values are forward compatible.
Maybe we should start with a mapping table and add columns for MSVC, CLANG, and GCC. I would imagine that we'd have to target baseline versions and only enable advanced mappings if we know the compiler version.
lilith commentedon Dec 10, 2017
For this crate, what are the minimum supported versions of clang, gcc, and msvc?
gnzlbg commentedon Jun 27, 2019
The same applies to target-features.
nazar-pc commentedon Feb 26, 2024
I need this for WASM (
target-cpu=mvp
) in order to address paritytech/polkadot-sdk#3192 with LLVM 16+.rustc
's target spec #1249rustc
's default value forcrt-static
#1266-m
flags #1269