fix(sdk): patch Clang resource headers for Xcode 26+ compatibility on Linux#215
Open
reklis wants to merge 1 commit into
Open
fix(sdk): patch Clang resource headers for Xcode 26+ compatibility on Linux#215reklis wants to merge 1 commit into
reklis wants to merge 1 commit into
Conversation
Apple's bundled Clang resource headers (arm_neon.h, x86 intrinsics, etc.) in Xcode's toolchain are auto-generated to match the version of Clang that built them. On Linux the host Clang (e.g. from swiftly) does the actual C compilation against this SDK, so Apple's intrinsics use __builtin_neon_* signatures upstream Clang doesn't recognise — failing with "incompatible constant for this __builtin_neon function" the moment anything imports `simd/base.h` (CoreMedia, simd, etc.). After installDeveloper, replace the SDK's clang resource includes — both `swift/clang/include` and `clang/<ver>/include` — with the host Clang's matching headers so they line up with the compiler. Safe because Apple frameworks are precompiled binaries that don't go through these headers, and intrinsic names lower to fixed ARM64/x86 hardware ISA regardless of which Clang emits them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
arm_neon.h, x86 intrinsics, etc.) with the host Clang's matching headers at the end ofxtool sdk install.error: incompatible constant for this __builtin_neon functionthe moment any source pulls in<simd/base.h>(transitively viasimd,CoreMedia, etc.).Background
Apple's Clang resource headers are auto-generated to match Apple's Clang fork. On Linux, the host Clang (e.g. from swiftly) is the one that actually compiles C/Objective-C sources during cross-build. Apple's intrinsic headers expand to
__builtin_neon_*calls whose constant-argument signatures don't line up with upstream Clang's, so every NEON intrinsic in the header fails the constant-validity check.This is a structural mismatch — even pinning to a stable Xcode (e.g. Xcode 26.3) doesn't help, because Apple's Clang is patched ahead of upstream LLVM. With Xcode 26.2 SDK + swiftly Swift 6.3.0 (Clang 21), every Swift source in the build produces ~2 MB of identical
arm_neon.herrors before SwiftPM bails withtoo many errors emitted.Related:
llvm/llvm-project#158312documents the same class of mismatch (NDK Clang vs upstream Clang). May also be relevant toxtool-org/xtool#214(different symptom — Apple-only LLVM flag-aarch64-use-tbi— but same family of "Apple toolchain assets ↔ upstream toolchain").Approach
After
installDeveloperfinishes, locate the host Clang's resource directory viaclang -print-resource-dirand replace:Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/clang/include/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/<version>/include/(every versioned subdir)with the host Clang's
include/contents.Why this is safe
.tbd/.dylib— that link via stable ABI. They were already compiled by Apple's Clang and never go through these headers again at app build time.arm_neon.his a superset of Apple's (~74k lines vs ~70k), so substituting up rarely loses intrinsics.If a future Xcode SDK uses an Apple-only intrinsic that upstream Clang doesn't have, this surfaces at build time as a normal "unknown intrinsic" error, not as a silent runtime failure.
Verified
Manual repro on Linux (Ubuntu 24.04, swiftly Swift 6.3.0 → Clang 21) with Xcode 26.3 → iPhoneOS 26.2 SDK:
swift build --swift-sdk arm64-apple-iosfails immediately with NEONincompatible constanterrors flooding from every source file.SDKBuilder: build progresses through the full Swift source compilation pass.Test plan
xtool sdk install <Xcode26.x.xip>on Linux completes and prints[Patching Clang resource headers]import simd,import CoreMedia) builds forarm64-apple-ioswithout__builtin_neonerrorsxtool sdk installstill works thereAlternatives considered
darwin-tools-linux-llvm: would be most exact, but Apple Clang is closed-source patches on top of LLVM and shipping a Linux build would mean independently tracking Apple's NEON/intrinsic additions. Not practical for this fix.-Xcc -resource-dir <host-path>intoolset.json: would work but bakes the host path into the SDK at install time, breaking if the user later changes Clang versions. Substituting at install time keeps the bundle self-contained.🤖 Generated with Claude Code