Skip to content

Commit efdf1dd

Browse files
committed
fix: apply --no-default-config for all macOS Clang compilation
The stale clang++.cfg issue affects not just std module precompile but also regular compilation via ninja. flags.cppm now applies the same --no-default-config + correct -isystem + xcrun --sysroot fix for all macOS Clang compilation, bypassing the cfg's stale paths.
1 parent 45dec7f commit efdf1dd

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/build/flags.cppm

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,24 @@ CompileFlags compute_flags(const BuildPlan& plan) {
8888
include_flags += " -I" + escape_path(abs);
8989
}
9090

91-
// Sysroot
91+
// Sysroot + config override for macOS.
92+
// On macOS, xlings LLVM's clang++.cfg contains hardcoded --sysroot and
93+
// -isystem paths from the original install location. When the package is
94+
// copied to mcpp's sandbox, these paths become stale. We pass
95+
// --no-default-config to ignore the cfg and provide correct paths.
9296
std::string sysroot_flag;
93-
if (!plan.toolchain.sysroot.empty()) {
97+
bool is_macos_clang = mcpp::toolchain::is_clang(plan.toolchain)
98+
&& (plan.toolchain.targetTriple.find("apple") != std::string::npos
99+
|| plan.toolchain.targetTriple.find("darwin") != std::string::npos);
100+
if (is_macos_clang) {
101+
auto llvmRoot = plan.toolchain.binaryPath.parent_path().parent_path();
102+
auto libcxxInclude = llvmRoot / "include" / "c++" / "v1";
103+
sysroot_flag = " --no-default-config";
104+
sysroot_flag += " -isystem" + escape_path(libcxxInclude);
105+
if (auto sdk = mcpp::platform::macos::sdk_path())
106+
sysroot_flag += " --sysroot=" + escape_path(*sdk);
107+
f.sysroot = sysroot_flag;
108+
} else if (!plan.toolchain.sysroot.empty()) {
94109
sysroot_flag = " --sysroot=" + escape_path(plan.toolchain.sysroot);
95110
f.sysroot = sysroot_flag;
96111
}

0 commit comments

Comments
 (0)