Skip to content

Commit 722cb0e

Browse files
committed
fix: don't use xcrun SDK as sysroot for xlings LLVM on macOS
Root cause: probe_sysroot() falls back to xcrun --show-sdk-path on macOS when the compiler doesn't report a sysroot via -print-sysroot. For xlings-installed LLVM 20.1.7, this sets --sysroot to the Xcode SDK path. Combined with -nostdinc++ from clang++.cfg, this breaks C runtime header resolution — macOS SDK headers reference internal macros (_CTYPE_A, etc.) that are only defined via default include paths which --sysroot overrides. Fix: remove the xcrun SDK fallback in probe_sysroot(). If the compiler itself doesn't report a sysroot, none should be used. The xcrun fallback was designed for Apple's system clang, not for standalone xlings LLVM which provides its own libc++ headers. Also revert the ci-macos.yml MCPP_HOME workaround — the real bug is fixed, no workaround needed.
1 parent b1b872d commit 722cb0e

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

.github/workflows/ci-macos.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ jobs:
1919
name: macOS ARM64 — xlings LLVM end-to-end
2020
runs-on: macos-15
2121
timeout-minutes: 30
22-
env:
23-
MCPP_HOME: /Users/runner/.mcpp
2422
steps:
2523
- uses: actions/checkout@v4
2624

@@ -287,12 +285,9 @@ jobs:
287285
288286
- name: Unit + integration tests via `mcpp test`
289287
run: |
290-
# Use freshly-built mcpp with the shared sandbox (MCPP_HOME set
291-
# via job-level env). MCPP_VENDORED_XLINGS ensures the sandbox
292-
# uses the pre-installed xlings binary.
288+
# Use freshly-built mcpp (has --mirror support)
293289
MCPP=$(find target -path "*/bin/mcpp" | head -1)
294290
MCPP=$(cd "$(dirname "$MCPP")" && pwd)/$(basename "$MCPP")
295-
export MCPP_VENDORED_XLINGS="$XLINGS_BIN"
296291
"$MCPP" self config --mirror GLOBAL
297292
"$MCPP" test
298293

src/toolchain/probe.cppm

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,17 @@ probe_sysroot(const std::filesystem::path& compilerBin,
262262
auto s = trim_line(*r);
263263
if (!s.empty() && std::filesystem::exists(s)) return s;
264264
}
265-
// macOS fallback: use xcrun to discover the SDK path
266-
if (auto sdk = mcpp::platform::macos::sdk_path())
267-
return *sdk;
265+
// macOS: do NOT fall back to xcrun SDK path for xlings-installed LLVM.
266+
// xlings LLVM uses -nostdinc++ (via clang++.cfg) to provide its own
267+
// libc++ headers. Combining --sysroot=<MacOSX.sdk> with -nostdinc++
268+
// breaks C runtime header resolution (_CTYPE_A, memcpy, errno etc.
269+
// become undeclared) because the SDK headers assume the C runtime
270+
// macros are available via default include paths, which --sysroot
271+
// overrides.
272+
//
273+
// If the compiler itself reports a sysroot (-print-sysroot), use it —
274+
// that's an explicit choice by the toolchain. But the xcrun SDK is
275+
// meant for Apple's system clang, not for standalone xlings LLVM.
268276
return {};
269277
}
270278

0 commit comments

Comments
 (0)