Skip to content

Commit c7c8ff8

Browse files
committed
fix: payload probe falls back to the active home registry
probe_payload_paths found glibc/linux-headers only as compiler SIBLINGS. With an inherited (symlinked) compiler the binary resolves into its owner home, so sysroot payloads freshly installed into the ACTIVE home (first-run default path) were invisible -> std module precompile failed with stdlib.h not found (CI fresh-home e2e 29/31). Add paths::active_home_xpkgs()/find_home_tool() and consult them after sibling search: discovery = compiler siblings ∪ active home registry.
1 parent 81d84cf commit c7c8ff8

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

src/toolchain/probe.cppm

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,12 @@ std::optional<PayloadPaths>
303303
probe_payload_paths(const std::filesystem::path& compilerBin) {
304304
namespace paths = mcpp::xlings::paths;
305305

306-
// Find glibc xpkg (required).
306+
// Find glibc xpkg (required). Compiler siblings first; fall back to the
307+
// ACTIVE home registry — an inherited/symlinked compiler resolves into
308+
// its owner home, while the active home may own (or have just installed)
309+
// the sysroot payloads.
307310
auto glibc = paths::find_sibling_tool(compilerBin, "glibc");
311+
if (!glibc) glibc = paths::find_home_tool("glibc");
308312
if (!glibc) return std::nullopt;
309313

310314
// Glibc layout: <root>/include/ + <root>/lib64/ (or lib/).
@@ -322,8 +326,10 @@ probe_payload_paths(const std::filesystem::path& compilerBin) {
322326
pp.glibcInclude = glibcInclude;
323327
pp.glibcLib = glibcLib;
324328

325-
// Find linux kernel headers (optional — search across index prefixes).
329+
// Find linux kernel headers (optional — search across index prefixes,
330+
// then the active home registry).
326331
auto linuxHeaders = paths::find_sibling_package(compilerBin, "linux-headers");
332+
if (!linuxHeaders) linuxHeaders = paths::find_home_tool("linux-headers");
327333
if (linuxHeaders) {
328334
auto linuxInclude = *linuxHeaders / "include";
329335
if (std::filesystem::exists(linuxInclude / "linux" / "limits.h"))

src/xlings.cppm

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ namespace paths {
8282
find_sibling_package(const std::filesystem::path& compilerBin,
8383
std::string_view packageName);
8484

85+
// xpkgs root of the ACTIVE mcpp home ($MCPP_HOME or ~/.mcpp). Payload
86+
// discovery consults this in addition to compiler siblings: an
87+
// inherited/symlinked compiler resolves into its owner home, while the
88+
// active home may own (or have just installed) the sysroot payloads.
89+
std::optional<std::filesystem::path> active_home_xpkgs();
90+
91+
// Like find_sibling_tool, but anchored at the active home's xpkgs.
92+
std::optional<std::filesystem::path> find_home_tool(std::string_view tool);
93+
8594
// index data root: env.home / "data"
8695
std::filesystem::path index_data(const Env& env);
8796

@@ -519,6 +528,35 @@ find_sibling_tool(const std::filesystem::path& compilerBin,
519528
return std::nullopt;
520529
}
521530

531+
std::optional<std::filesystem::path> active_home_xpkgs() {
532+
std::filesystem::path home;
533+
if (const char* h = std::getenv("MCPP_HOME"); h && *h) {
534+
home = h;
535+
} else if (const char* u = std::getenv("HOME"); u && *u) {
536+
home = std::filesystem::path(u) / ".mcpp";
537+
} else {
538+
return std::nullopt;
539+
}
540+
auto xpkgs = home / "registry" / "data" / "xpkgs";
541+
std::error_code ec;
542+
if (!std::filesystem::exists(xpkgs, ec)) return std::nullopt;
543+
return xpkgs;
544+
}
545+
546+
std::optional<std::filesystem::path> find_home_tool(std::string_view tool) {
547+
auto xpkgs = active_home_xpkgs();
548+
if (!xpkgs) return std::nullopt;
549+
550+
auto root = *xpkgs / std::format("xim-x-{}", tool);
551+
std::error_code ec;
552+
if (!std::filesystem::exists(root, ec)) return std::nullopt;
553+
554+
for (auto& v : std::filesystem::directory_iterator(root, ec)) {
555+
if (v.is_directory(ec)) return v.path();
556+
}
557+
return std::nullopt;
558+
}
559+
522560
std::optional<std::filesystem::path>
523561
find_sibling_binary(const std::filesystem::path& compilerBin,
524562
std::string_view tool,

0 commit comments

Comments
 (0)