cc-rs icon indicating copy to clipboard operation
cc-rs copied to clipboard

Use Cargo's target information when possible

Open madsmtm opened this issue 1 year ago • 2 comments

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.

madsmtm avatar Sep 30 '24 23:09 madsmtm

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 win7 I 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 gnu explicitly, so imma assume it's intentional.
  • https://github.com/rust-lang/rust/pull/131173
  • https://github.com/rust-lang/rust/pull/131174

madsmtm avatar Oct 02 '24 19:10 madsmtm

I've implemented the approach discussed in https://github.com/rust-lang/cc-rs/pull/1225#discussion_r1781935441 now.

madsmtm avatar Oct 08 '24 21:10 madsmtm