Use Cargo's target information when possible
rustc's target triples generally only have a vague resemblance to each other and to the information needed by cc. Let's instead prefer CARGO_CFG_* variables when available, since these contain the information directly from the compiler itself.
In the cases where it isn't available (i.e. when running outside of a build script), we fall back to parsing the target triple, but instead of doing it in an ad-hoc fashion with string manipulation, we do it in a more structured fashion up front.
Fixes https://github.com/rust-lang/cc-rs/issues/1219 (at least my main gripe with the current implementation).
Builds upon https://github.com/rust-lang/cc-rs/pull/1224.
I've now gone through my own FIXMEs, and opened PRs against rustc to fix the discrepancies I saw when trying to parse the target information.
- https://github.com/rust-lang/rust/issues/131172
- https://github.com/rust-lang/rust/issues/131165
- The
win7I didn't do, it's clearly a hack that they do intentionally. - https://github.com/rust-lang/rust/pull/131166
- https://github.com/rust-lang/rust/pull/131168
- https://github.com/rust-lang/rust/pull/131169
- https://github.com/rust-lang/rust/pull/131170
- https://github.com/rust-lang/rust/pull/131171
- armv[6|7]-unknown-freebsd seem to set
gnuexplicitly, so imma assume it's intentional. - https://github.com/rust-lang/rust/pull/131173
- https://github.com/rust-lang/rust/pull/131174
I've implemented the approach discussed in https://github.com/rust-lang/cc-rs/pull/1225#discussion_r1781935441 now.