Skip to content

Commit 2eb076c

Browse files
committed
feat: capability-driven ABI enforcement
A dependency may declare an abi:<x> capability (e.g. compat.glfw -> abi:glibc). prepare_build now verifies the resolved toolchain's ABI satisfies every such requirement and fails fast with an actionable message on mismatch — turning a cryptic deep musl build error (libXdmcp arc4random_buf) into an upfront capability error. Enforces/diagnoses; abi-driven reselection (toolchain is resolved before the dep graph) is a resolution-ordering follow-up.
1 parent 0d537f6 commit 2eb076c

1 file changed

Lines changed: 26 additions & 0 deletions

File tree

src/cli.cppm

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3131,6 +3131,32 @@ prepare_build(bool print_fingerprint,
31313131
}
31323132
}
31333133

3134+
// Capability-driven ABI enforcement: if any dependency declares an
3135+
// `abi:<x>` capability, the resolved toolchain must satisfy it. (Toolchain
3136+
// is resolved before the dep graph, so this enforces/diagnoses rather than
3137+
// reselects — abi-driven reselection is a resolution-ordering follow-up.)
3138+
{
3139+
const std::string tcAbi =
3140+
ctx.tc.targetTriple.find("musl") != std::string::npos ? "musl"
3141+
: ctx.tc.stdlibId == "libc++" ? "libc++"
3142+
: ctx.tc.compiler == mcpp::toolchain::CompilerId::MSVC ? "msvc"
3143+
: "glibc";
3144+
for (auto& cap : ctx.plan.runtimeCapabilities) {
3145+
if (cap.rfind("abi:", 0) != 0) continue;
3146+
std::string need = cap.substr(4);
3147+
if (need == tcAbi) continue;
3148+
std::string provider;
3149+
for (auto& [c, p] : ctx.plan.runtimeProviders)
3150+
if (c == cap) { provider = p; break; }
3151+
return std::unexpected(std::format(
3152+
"ABI mismatch: dependency '{}' requires abi={} but the resolved "
3153+
"toolchain '{}' is abi={}.\n"
3154+
" fix: `mcpp toolchain default <{}-compatible>` "
3155+
"(e.g. gcc@16.1.0 for glibc), or set [toolchain] in mcpp.toml.",
3156+
provider.empty() ? "?" : provider, need, ctx.tc.label(), tcAbi, need));
3157+
}
3158+
}
3159+
31343160
return ctx;
31353161
}
31363162

0 commit comments

Comments
 (0)