Skip to content

build_support: add g++ cross-compilation wrappers for musl targets#3208

Open
benhillis wants to merge 2 commits intomicrosoft:mainfrom
benhillis:benhillis/add-musl-gxx-wrappers
Open

build_support: add g++ cross-compilation wrappers for musl targets#3208
benhillis wants to merge 2 commits intomicrosoft:mainfrom
benhillis:benhillis/add-musl-gxx-wrappers

Conversation

@benhillis
Copy link
Copy Markdown
Member

The existing cross-compilation setup only had C compiler wrappers
(*-underhill-musl-gcc). When cc-rs needed to compile .cxx files, it fell
back to using that gcc wrapper as the C++ compiler, which failed because:

  1. gcc doesn't search C++ standard library headers (<cassert>, <cstdint>, etc.)
  2. The musl-gcc.specs file uses -nostdinc, stripping all system include
    paths — so even g++ can't find its C++ headers unless they're explicitly
    added back via -isystem

This PR adds matching g++ wrappers for both x86_64 and aarch64 that invoke g++
with the same musl specs, plus -isystem flags pointing at the sysroot's C++
headers. The C++ header version directory is auto-detected via shell glob rather
than hardcoded.

Changes

  • build_support/underhill_cross/{x86_64,aarch64}-underhill-musl-g++ — new g++
    wrappers mirroring the existing gcc wrapper pattern
  • .cargo/config.toml — added CXX_* env vars for all 4 musl targets so
    cc-rs discovers the wrappers
  • shell.nix — added g++ symlinks alongside the existing gcc symlinks

@benhillis benhillis requested a review from a team as a code owner April 6, 2026 21:44
Copilot AI review requested due to automatic review settings April 6, 2026 21:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds C++-aware cross-compilation support for Underhill musl targets by introducing g++ wrapper scripts and wiring them into the build environment so cc-rs can compile .cxx sources against the musl sysroot.

Changes:

  • Add *-underhill-musl-g++ wrapper scripts that apply musl-gcc.specs and inject sysroot libstdc++ header include paths.
  • Configure Cargo environment variables (CXX_*) so cc-rs discovers the new wrappers for all Underhill musl targets.
  • Extend the Nix dev shell to provide *-linux-gnu-g++ symlinks alongside existing gcc symlinks for consistent wrapper resolution.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
shell.nix Adds g++ symlinks into the temporary wrapper dir so the new scripts can find prefixed compilers in nix shells.
build_support/underhill_cross/x86_64-underhill-musl-g++ New x86_64 musl g++ wrapper with sysroot C++ header auto-detection.
build_support/underhill_cross/aarch64-underhill-musl-g++ New aarch64 musl g++ wrapper with sysroot C++ header auto-detection.
.cargo/config.toml Adds CXX_* env entries for musl targets so cc-rs uses the new wrappers.

@smalis-msft
Copy link
Copy Markdown
Contributor

What C++ code are we compiling? Ideally we'd be reducing our non-Rust code, not adding more.

Ben Hillis and others added 2 commits April 7, 2026 20:53
The existing cross-compilation setup only had C compiler wrappers
(*-underhill-musl-gcc). When cc-rs needed to compile .cxx files, it fell
back to using that gcc wrapper as the C++ compiler, which failed because:

1. gcc doesn't search C++ standard library headers (<cassert>, etc.)
2. The musl-gcc.specs file uses -nostdinc, stripping all system include
   paths -- so even g++ can't find its C++ headers unless they're
   explicitly added back via -isystem

Add matching g++ wrappers for both x86_64 and aarch64 that invoke g++
with the same musl specs, plus -isystem flags pointing at the sysroot's
C++ headers. The C++ header version directory is auto-detected via shell
glob rather than hardcoded.

Also wire up the wrappers:
- Add CXX_* env vars to .cargo/config.toml so cc-rs discovers them
- Add g++ symlinks to shell.nix alongside the existing gcc symlinks

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Address review feedback:
- Validate that the sysroot env var is set, fail early with a clear error
- Use -d check on glob results to handle missing C++ headers gracefully
- Pass -isystem flags as properly quoted arguments instead of via an
  unquoted intermediate string to avoid accidental glob expansion

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@benhillis benhillis force-pushed the benhillis/add-musl-gxx-wrappers branch from 1b18dda to 599b0c8 Compare April 7, 2026 20:54
Copilot AI review requested due to automatic review settings April 7, 2026 20:54
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.

3 participants