rust-lang / cc-rs

Rust library for build scripts to compile C/C++ code into a Rust library
https://docs.rs/cc
Apache License 2.0
1.81k stars 434 forks source link

Query rustc for clang target triples #994

Closed djkoloski closed 6 months ago

djkoloski commented 6 months ago

Right now, we pick the target triples to pass clang by defaulting to the first segment of the target triple and then manually fixing them up with a large set of branches. Is there a way we could query the target spec from rustc to get the LLVM target names? For example, by running:

$ rustc +nightly -Zunstable-options --print all-target-specs-json

We can obtain a JSON dump of all of the target configurations. Each target configuration contains an "llvm-target" field which we should be passing to clang. That's not stable right now, but maybe there's some other way to work with that?

NobodyXu commented 6 months ago

We can obtain a JSON dump of all of the target configurations. Each target configuration contains an "llvm-target" field which we should be passing to clang.

Maybe we could add pre-generate them, in the same way we generate windows syscall bindings (in dev-tools/generate-windows-sys-bindings)?

E.g. add a new non-publish-able crate in the workspace that query the rustc and generate a .rs file containing the mapping.