fix: normalize cfg attributes for three-part Rust triples - #213
Open
theGlenn wants to merge 1 commit into
Open
Conversation
`triple_to_cfg_attrs` read every triple positionally, but a 3-part triple is not positional: its third component may be an OS, a bare ABI, or an OS with the ABI glued onto it. It also passed most raw architecture tokens through as `target_arch`, which is not always what rustc reports. The most damaging case is 32-bit Android. `armv7-linux-androideabi` and `arm-linux-androideabi` resolved to `target_os = "androideabi"`, `target_family = ""`, and `target_arch = "armv7"`. Builds succeeded, but dependencies behind `cfg(unix)`, `cfg(target_os = "android")`, or `cfg(target_arch = "arm")` were silently dropped. - Parse non-positional Android EABI and bare-metal Arm triples. - Extend architecture normalization beyond the existing RISC-V handling. - Derive pointer width from the normalized architecture while preserving the raw spelling for endianness. - Match longer ABI names first so `eabihf` is not reduced to `eabi`. Add focused coverage using expected values from `rustc --print cfg --target <triple>`.
Member
|
Thanks for sending this up! It looks like a similar open PR but we had an unresolved question there #205 (comment) - wonder if you have thoughts on that bit? fyi @Geethree |
Author
|
Hey @dzbarsky. I finally had time to look at #205 and added my thoughts to the existing discussion. The PRs overlap on target identity, but they take different approaches.
Since #205’s versioning question is still unresolved, I think #213 can land independently. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hi @dzbarsky and team! Thanks again for reaching out to us and inviting us to upstream our Rust and LLVM patches. This is the first one.
Summary
eabihfis not reduced toeabi.triple_to_cfg_attrscurrently interpretsarmv7-linux-androideabiastarget_os = "androideabi"andtarget_arch = "armv7", with no Unix family oreabiABI. Dependencies gated bycfg(unix),cfg(target_os = "android"), orcfg(target_arch = "arm")are therefore omitted from 32-bit Android builds.The repository's
rules_rusttriple parser already mapsandroideabitoandroid. This change bringscfg_parser.bzlin line with that behavior and withrustc --print cfg.Validation
rustc --print cfg --target <triple>.bazel test //rs/private:cfg_parser_testspasses.bazel test //...passes (40/40 tests).