Skip to content

Commit 52c9da5

Browse files
committed
fix(toolchain): clang cfg gains the C-header axis (v0.0.84)
fixup_clang_cfg's regenerated cfg covered the link axis (-B/-L/loader/ rpath) but omitted the C library and kernel headers — a direct `clang hello.c` only worked when the HOST happened to ship /usr/include (silently non-hermetic; hard failure on header-less machines). The cfg now carries -isystem for the glibc payload headers and the linux-headers payload, ordered AFTER the libc++ block (its C-header wrappers reach libc via #include_next) — byte-consistent with what xim-pkgindex's llvm.lua install hook generates, so the two cfg writers can no longer diverge. The C driver cfg (clang.cfg) gets the headers directly; the C++ cfg gets them after the libc++ includes. Fixup rev bumped to hermetic-3 so existing payloads re-converge on their next build. Verified with host headers masked (--sysroot=<empty dir>): cfg-driven bare clang and clang++ both compile and run; negative control without the payload headers fails as expected. mcpp's own builds are unaffected (the link model has always supplied its own header flags).
1 parent 19e2070 commit 52c9da5

4 files changed

Lines changed: 46 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,22 @@
33
> 本文件追踪 `mcpp-community/mcpp` 公开仓的版本演进。
44
> 格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)
55
6-
## [0.0.83] — 2026-07-07
6+
## [0.0.84] — 2026-07-08
7+
8+
### 修复 / 完善
9+
10+
- **clang cfg 头文件轴补齐(供人类直接使用的完备性)**:`fixup_clang_cfg` 再生的
11+
cfg 此前只覆盖链接轴(`-B`/`-L`/loader/rpath),缺 C 库与内核头——裸
12+
`clang hello.c` 只有在宿主恰好装有 `/usr/include` 时才能编译(静默不 hermetic,
13+
无宿主头的机器直接失败)。现补上 `-isystem <glibc payload>/include`
14+
`-isystem <linux-headers payload>/include`,置于 libc++ 头块**之后**
15+
(保持 `#include_next` 链),与 xim-pkgindex 侧 `llvm.lua` 装机生成的 cfg
16+
内容一致——两个写手不再漂移。fixup rev 升至 `hermetic-3`,存量 payload 在
17+
下次构建时自动再收敛。已实测:宿主头被屏蔽(`--sysroot=<空目录>`)下,
18+
cfg 驱动的裸 `clang`/`clang++` 编译运行均成功。mcpp 自身构建不受影响
19+
(linkmodel 一直自带头轴)。
20+
21+
722

823
### 修复
924

mcpp.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mcpp"
3-
version = "0.0.83"
3+
version = "0.0.84"
44
description = "Modern C++ build & package management tool"
55
license = "Apache-2.0"
66
authors = ["mcpp-community"]

src/toolchain/fingerprint.cppm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import mcpp.toolchain.detect;
1818

1919
export namespace mcpp::toolchain {
2020

21-
inline constexpr std::string_view MCPP_VERSION = "0.0.83";
21+
inline constexpr std::string_view MCPP_VERSION = "0.0.84";
2222

2323
struct FingerprintInputs {
2424
Toolchain toolchain;

src/toolchain/post_install.cppm

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ export void fixup_clang_cfg(const std::filesystem::path& payloadRoot,
232232
}
233233
}
234234

235-
std::string common, cxxOnly;
235+
std::string common, cxxOnly, cHdr;
236236
auto cxxInclude = payloadRoot / "include" / "c++" / "v1";
237237
if constexpr (mcpp::platform::is_macos) {
238238
// macOS keeps its historical cfg semantics: the C library and the
@@ -256,6 +256,28 @@ export void fixup_clang_cfg(const std::filesystem::path& payloadRoot,
256256
}
257257
common += "-fuse-ld=lld\n--rtlib=compiler-rt\n--unwindlib=libunwind\n";
258258

259+
// HEADER axis (C and C++ drivers alike): the C library and kernel
260+
// headers come from the same payloads the link axis uses. Without
261+
// these, a direct `clang hello.c` only works when the HOST happens
262+
// to ship /usr/include — silently non-hermetic, broken on
263+
// header-less machines. For C++ they must come AFTER the libc++
264+
// block (its C-header wrappers reach libc via #include_next), so
265+
// they are collected separately and appended in order below —
266+
// byte-consistent with what llvm.lua's install hook generates.
267+
if (!glibcLibDir.empty()) {
268+
auto glibcInclude = glibcLibDir.parent_path() / "include";
269+
if (std::filesystem::exists(glibcInclude / "features.h"))
270+
cHdr += "-isystem " + glibcInclude.string() + "\n";
271+
constexpr std::string_view kLinuxLimits = "include/linux/limits.h";
272+
auto linuxHeaders = mcpp::xlings::paths::find_sibling_package(
273+
payloadRoot / "bin" / "clang++", "linux-headers", kLinuxLimits);
274+
if (!linuxHeaders)
275+
linuxHeaders = mcpp::xlings::paths::find_home_tool(
276+
"linux-headers", kLinuxLimits);
277+
if (linuxHeaders)
278+
cHdr += "-isystem " + (*linuxHeaders / "include").string() + "\n";
279+
}
280+
259281
if (std::filesystem::exists(cxxInclude)) {
260282
cxxOnly += "-nostdinc++\n-stdlib=libc++\n";
261283
cxxOnly += "-isystem " + cxxInclude.string() + "\n";
@@ -264,6 +286,9 @@ export void fixup_clang_cfg(const std::filesystem::path& payloadRoot,
264286
auto tripleInclude = payloadRoot / "include" / triple / "c++" / "v1";
265287
if (std::filesystem::exists(tripleInclude))
266288
cxxOnly += "-isystem " + tripleInclude.string() + "\n";
289+
}
290+
cxxOnly += cHdr;
291+
if (!triple.empty()) {
267292
auto tripleLib = payloadRoot / "lib" / triple;
268293
if (std::filesystem::exists(tripleLib)) {
269294
cxxOnly += "-L" + tripleLib.string() + "\n";
@@ -281,7 +306,7 @@ export void fixup_clang_cfg(const std::filesystem::path& payloadRoot,
281306
if (!name.ends_with(".cfg")) continue;
282307
const bool isCxx = name.find("++") != std::string::npos;
283308
std::ofstream os(it->path());
284-
os << common << (isCxx ? cxxOnly : std::string{});
309+
os << common << (isCxx ? cxxOnly : cHdr);
285310
}
286311
}
287312

@@ -376,7 +401,7 @@ void llvm_post_install_fixup(const mcpp::config::GlobalConfig& cfg,
376401
// runtime libs. Idempotent via a content-fingerprinted marker.
377402
//
378403
// Bump when the fixup logic changes so existing installs re-run it.
379-
constexpr std::string_view kFixupRev = "hermetic-2";
404+
constexpr std::string_view kFixupRev = "hermetic-3";
380405

381406
export void ensure_post_install_fixup(const mcpp::config::GlobalConfig& cfg,
382407
const std::filesystem::path& payloadRoot,

0 commit comments

Comments
 (0)