-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Swift doesn’t recognize Clang’s header on Windows #60534
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Swift doesn’t recognize Clang’s header on Windows #60534
Comments
I see this problem all the time if the Swift symlink to the clang headers isn't set up right. Is there a symlink |
@buttaface I believe that’s not the case on Windows. And it works after I add the symlink manually. cc @compnerd if we can teach the installer to set up the symlink? |
This is a SwiftPM side issue, not a swiftc issue. The fact that this builds correctly with CMake is proof of that. Building it locally, the problematic part of the repo for me is: https://github.com/apple/swift-atomics/blob/main/Sources/_AtomicsShims/include/_AtomicsShims.h#L63-L65. Changing the order of inclusion, I'm not a fan of - the MSVC headers should be preferred for Windows. |
MSVC The Clang header will fall back using |
I was talking about the toolchain, not SwiftPM or compiler. |
No, the clang header will not fallback to MSVC: https://github.com/apple/llvm-project/blob/next/clang/lib/Headers/stdatomic.h#L20-L22. I would say we should work out why it builds with CMake and not SPM and make SPM behave similar here. |
I'm surprised it works with CMake: I can't build anything that calls libc with the Swift compiler if that clang symlink is not there on linux or Android. @stevapple, does compiling the equivalent hello world to this simple file for Windows, ie
On linux with this file, I get this error after removing the clang symlink that the toolchain comes with:
|
I don’t think it can build with CMake based on an VS 2019 installation. There’s no SwiftPM can build it successfully with VS 2022 toolset — as long as the symlink is set up. I believe this is the correct behavior, identical to other platforms. |
For anyone running Swift 5.7 or older, |
Still a problem with Swift 6? If not, please close. |
Describe the bug
Clang provides some C headers as polyfills (or shims) and the Swift toolchain vendors it in
/usr/lib/clang/{clang_version}/include
. However, the Swift compiler doesn’t recognize these headers, so a module produced by the bundled Clang may not be consumed by Swift.Steps To Reproduce
Steps to reproduce the behavior:
https://github.com/apple/swift-atomics
;swift-atomics
;swift build
.Expected behavior
Since the
_AtomicsShims
target is successfully compiled, it should be consumable forAtomics
.Screenshots

Environment
Additional context
Although this can be worked around from the SwiftPM side, I believe resolving it with
swiftc
is a better choice.The text was updated successfully, but these errors were encountered: