Skip to content

target: recognize sh4 architecture in parse_arch()#1712

Merged
NobodyXu merged 1 commit intorust-lang:mainfrom
navhack-org:sh4-arch-add
Apr 30, 2026
Merged

target: recognize sh4 architecture in parse_arch()#1712
NobodyXu merged 1 commit intorust-lang:mainfrom
navhack-org:sh4-arch-add

Conversation

@jsloan-red-button
Copy link
Copy Markdown
Contributor

SH4 (SuperH) is a real Rust target tier 3 — both sh4-unknown-linux-gnu and sh4-unknown-redox are in upstream rustc as of 1.79+ — but parse_arch() doesn't recognise the sh4 prefix, so any C-touching crate compiled against an sh4-* target fails at config time:

error occurred in cc-rs: target `sh4-unknown-redox` had an unknown architecture

Adding the one-line arm here matches the existing convention for similar small soft-float architectures (mips, loongarch, riscv, bpf). SH4 has no architecture-specific compile-flag adjustments needed in cc-rs (no `-march` or similar), so normalising the arch name is sufficient.

Test plan

Tested via the navhack-org/RustXToolchain SH4 cross-compilation toolchain build (rust-src + LLVM-from-source with SuperH target enabled). End-to-end:

  • `x.py build --stage 1 library --target sh4-unknown-redox` succeeds without manual cargo-registry patches.
  • Resulting toolchain compiles `rustnav-broker` (a real downstream crate; SH4 ELF, 6.6 MB) end-to-end.

Without this arm, the bootstrap fails immediately during config-time target resolution with the error shown above. Historic mitigation in our build pipeline was to manually patch the cargo-registry copy of cc-rs's parser.rs after every fresh checkout — this PR retires that workaround.

Out of scope

No flag adjustments — SH4 is mostly a soft-float target (single-precision FPU only); the C compile flags from `gcc-sh4-*` are sufficient as-is. Any future SH4-specific tuning (e.g. `-m4-single-only`) can be added as a follow-up if needed.

SH4 (SuperH) is a Rust target tier 3 — sh4-unknown-linux-gnu and
sh4-unknown-redox both exist in upstream rustc as of 1.79+ — but
parse_arch() in cc-rs's target parser doesn't recognise the `sh4`
prefix, so any C-touching crate compiled against an sh4-* target
fails at config time:

    error occurred in cc-rs: target `sh4-unknown-redox` had an
    unknown architecture

Adding the one-line arm here matches the existing convention for
similar small soft-float architectures (mips, loongarch, riscv, bpf).
SH4 has no architecture-specific compile-flag adjustments needed in
cc-rs (no -march or similar), so just normalising the arch name is
sufficient.

Tested by building rustx-sh4 toolchain (rust-src + LLVM-from-source
with SuperH target) end-to-end against the resulting `cc` 1.2.28+sh4;
output is a working `rustnav-broker` SH4 ELF (6.6 MB) running on
sh4-unknown-redox.
Copy link
Copy Markdown
Contributor

@NobodyXu NobodyXu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you

@NobodyXu NobodyXu merged commit 18ed3dc into rust-lang:main Apr 30, 2026
79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants