Skip to content

fix: remove subos sysroot override, use payload paths for toolchain sysroot#62

Open
Sunrisepeak wants to merge 4 commits into
mainfrom
fix/linux-sysroot-payload-first
Open

fix: remove subos sysroot override, use payload paths for toolchain sysroot#62
Sunrisepeak wants to merge 4 commits into
mainfrom
fix/linux-sysroot-payload-first

Conversation

@Sunrisepeak
Copy link
Copy Markdown
Member

Summary

  • Remove M5.5 logic that forced tc->sysroot to mcpp's subos (~/.mcpp/registry/subos/default), which lacks linux kernel headers (linux/limits.h) on user machines
  • Parse clang++.cfg for --sysroot= when -print-sysroot fails (Clang doesn't support it), so tc->sysroot reflects the payload's actual configuration
  • Generalize --no-default-config from macOS-only to all Clang toolchains with a cfg file (cfg paths become stale after mcpp copies the payload)

Root cause

Commit 063fb6f changed MCPP_HOME to ~/.mcpp/, where the subos skeleton exists but is incomplete (no linux/, asm/, asm-generic/ headers). M5.5 only checked exists(usr/include) and overwrote the toolchain's correct sysroot. CI never caught this because its subos is fully populated by xlings self install.

Design principle

mcpp uses xlings only as a package index + download tool. The toolchain sysroot comes from the payload itself (GCC -print-sysroot, Clang clang++.cfg), not from xlings subos.

Test plan

  • CI passes on Linux (GCC + LLVM std module precompilation)
  • CI passes on macOS (--no-default-config + xcrun SDK path)
  • CI passes on Windows (no sysroot involved, MSVC STL)

…ysroot (#62)

Remove M5.5 logic that forced tc->sysroot to mcpp's xlings subos
(~/.mcpp/registry/subos/default). The subos created by `xlings self init`
lacks linux kernel headers (linux/limits.h, asm/, asm-generic/), causing
std module precompilation to fail on user machines.

Root cause: commit 063fb6f changed MCPP_HOME to ~/.mcpp/, where the
subos exists but is incomplete. M5.5 only checked exists(usr/include)
and overwrote the toolchain's correct sysroot. CI never caught this
because its subos is fully populated by `xlings self install`.

Design principle: mcpp uses xlings only as a package index + download
tool. Sysroot comes from the toolchain payload itself, not from subos.

Changes:
- cli.cppm: delete M5.5 subos sysroot override entirely
- probe.cppm: parse clang++.cfg --sysroot= when -print-sysroot fails
  (Clang doesn't support -print-sysroot), so tc->sysroot reflects the
  payload's actual configuration
- stdmod.cppm: generalize --no-default-config from macOS-only to all
  Clang toolchains with a cfg file (cfg paths become stale after mcpp
  copies the payload to its sandbox)
- flags.cppm: sync the same --no-default-config logic for regular
  compilation flags
GCC bakes the build-time sysroot into the binary via --with-sysroot.
For xlings-built GCC this is a path like <buildhost>/.xlings/subos/default
that doesn't exist on the user's machine. When -print-sysroot returns
such a non-existent path ending in subos/default, remap it to the
equivalent sysroot relative to the compiler's own xpkgs directory.

This is payload-derived (from the compiler binary's location in the
registry), not a config-level dependency on subos.
When bypassing clang++.cfg with --no-default-config, we must provide
both libc++ include paths that the cfg originally supplied:
  -isystem <llvmRoot>/include/c++/v1
  -isystem <llvmRoot>/include/<triple>/c++/v1

The target-specific path contains __config_site which is required by
__config. Without it, std module precompilation fails with
'__config_site' file not found.
On Linux, clang++.cfg contains essential linker flags (-fuse-ld=lld,
--rtlib=compiler-rt, --unwindlib=libunwind). Using --no-default-config
strips these, causing "cannot find crtbeginS.o" link failures because
clang falls back to system GNU ld looking for GCC runtime objects.

On Linux, let the cfg apply normally. The cfg's --sysroot points to
the xlings subos which is valid and complete. Pass --sysroot explicitly
only when needed (to override a stale cfg value), leveraging the fact
that command-line --sysroot takes precedence over the cfg's value.

Keep --no-default-config for macOS only, where the cfg-baked paths
genuinely become stale (pointing to CommandLineTools SDK when Xcode
SDK is active).
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.

1 participant