Skip to content

Commit ca0425f

Browse files
committed
fix(toolchain): 固定的 host 工具链装不上时,回退到已经在本机可用的 target 工具链
`ci-aarch64-fresh-install` 在 aarch64 上构建 xlings 时死在: [error] download failed for xim:gcc@16.1.0: HTTP 404 error: host toolchain for build.mcpp ('gcc@16.1.0'): ... 链条是:图里有包带 build.mcpp ⇒ 需要 HOST 编译器 ⇒ 取 `[toolchain] default` ⇒ 那是 `gcc@16.1.0`,而 xim 的 gcc 声明 `archs = { "x86_64" }` ⇒ 404。 `[toolchain]` 的键是 OS,**没有 arch 这根轴**(#367),所以 aarch64 问的和 x86_64 问的是同一个包。结果是:凡是依赖图里出现 build.mcpp 的工程,在 aarch64 上就是死路。 但这台机器上**已经有**一个能用的编译器:当解析出的 target 与 host 只差 libc 环境(aarch64-linux-musl 跑在 aarch64 Linux 上),target 工具链就是本机原生的 —— 它在这里能跑,它产出的二进制在这里也能跑,拿它编译一个构建程序完全成立。 因此:固定的 host 工具链取不到时,若 arch 与 os 与 host 相同,就用 target 工具 链,并发一条命名双方的告警。成功路径一字未改;此前的死路变成一次可解释的降级。 #367 记录的仍是根因(host 工具链选择缺 arch 轴),这条只是让它不再是绝路。
1 parent c5cdcec commit ca0425f

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/build/prepare.cppm

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,34 @@ prepare_build(bool print_fingerprint,
18121812
mcpp::fetcher::InstallProgressHandler progress;
18131813
auto payload = fetcher.resolve_xpkg_path(pkg.target(), /*autoInstall=*/true, &progress);
18141814
if (!payload) {
1815+
// The pinned host toolchain is not obtainable here. Before giving
1816+
// up, ask whether we already HAVE a compiler that runs on this
1817+
// machine: when the resolved target differs from the host only in
1818+
// its libc environment (aarch64-linux-musl on an aarch64 Linux
1819+
// host), the target toolchain is native — it runs here and the
1820+
// binaries it produces run here — so it is a perfectly good
1821+
// compiler for a build program.
1822+
//
1823+
// Without this, a whole architecture is a dead end for any project
1824+
// whose graph contains a build.mcpp: `[toolchain]` is keyed by OS
1825+
// with no arch axis (#367), so `default = "gcc@16.1.0"` is what
1826+
// aarch64 asks for too, and that package declares
1827+
// `archs = { "x86_64" }` — the download 404s and the build stops.
1828+
// A toolchain that is already on disk and already correct should
1829+
// not be unusable because a second, redundant one is missing.
1830+
auto hostT = mcpp::toolchain::triple::host_triple();
1831+
auto tgtT = mcpp::toolchain::triple::parse(overrides.target_triple);
1832+
if (tgtT && tgtT->arch == hostT.arch && tgtT->os == hostT.os) {
1833+
mcpp::diag::warning("toolchain/host-fallback", std::format(
1834+
"the pinned host toolchain '{}' could not be provisioned "
1835+
"({}), so build.mcpp will be compiled with the target "
1836+
"toolchain instead — it is native here ({} vs host {}). "
1837+
"Pin a host toolchain that exists on this architecture to "
1838+
"silence this.",
1839+
*tcSpec, payload.error().message, tgtT->str(), hostT.str()));
1840+
hostTcCache = std::pair{explicit_compiler, *tc};
1841+
return *hostTcCache;
1842+
}
18151843
return std::unexpected(std::format(
18161844
"host toolchain for build.mcpp ('{}'): {}", *tcSpec,
18171845
payload.error().message));

0 commit comments

Comments
 (0)