Skip to content

Commit 0f8d0e8

Browse files
committed
fix: GCC sysroot fallback — remap stale build-time path to registry
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.
1 parent acc1a71 commit 0f8d0e8

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/toolchain/probe.cppm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,21 @@ probe_sysroot(const std::filesystem::path& compilerBin,
262262
if (r) {
263263
auto s = trim_line(*r);
264264
if (!s.empty() && std::filesystem::exists(s)) return s;
265+
266+
// GCC bakes the build-time sysroot into the binary. For xlings-built
267+
// GCC this is a path like <buildhost>/.xlings/subos/default that
268+
// doesn't exist on the user's machine. If the reported path ends
269+
// with subos/default, look for the equivalent sysroot relative to
270+
// the compiler's own xpkgs directory (payload-derived).
271+
if (!s.empty() && s.ends_with("subos/default")) {
272+
if (auto xpkgs = mcpp::xlings::paths::xpkgs_from_compiler(compilerBin)) {
273+
// xpkgs is <registry>/data/xpkgs → registry = xpkgs/../..
274+
auto registrySysroot = xpkgs->parent_path().parent_path()
275+
/ "subos" / "default";
276+
if (std::filesystem::exists(registrySysroot / "usr" / "include"))
277+
return registrySysroot;
278+
}
279+
}
265280
}
266281

267282
// 2. Parse the compiler driver config file (Clang .cfg).

0 commit comments

Comments
 (0)