-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Open
swiftlang/swift-installer-scripts
#198Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Description
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:
- Clone
https://github.com/apple/swift-atomics
; - Change directory to
swift-atomics
; - Run
swift build
.
Expected behavior
Since the _AtomicsShims
target is successfully compiled, it should be consumable for Atomics
.
Environment
- OS: Windows Server 2019 Datacenter (1809)
- Swift version: 5.6.2
- Visual Studio: Community 2019, 16.11.18
Additional context
Although this can be worked around from the SwiftPM side, I believe resolving it with swiftc
is a better choice.
lin72h
Metadata
Metadata
Assignees
Labels
bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Activity
finagolfin commentedon Aug 13, 2022
I see this problem all the time if the Swift symlink to the clang headers isn't set up right. Is there a symlink
usr\lib\swift\clang
that points at the clang headers you noted? If not, it will not find them.stevapple commentedon Aug 13, 2022
@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?
[-]Swift doesn’t recognize Clang’s header[/-][+]Swift doesn’t recognize Clang’s header on Windows[/+]Atomics
on Windows #60543compnerd commentedon Aug 17, 2022
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.
stevapple commentedon Aug 17, 2022
MSVC
stdatomics.h
doesn't support C so far. It’s even missing in VS 2019.The Clang header will fall back using
#include_next
if system header is available, but the MSVC one cannot be used at this point.stevapple commentedon Aug 17, 2022
I was talking about the toolchain, not SwiftPM or compiler.
/usr/lib/swift/clang
symlink is set up on both Linux and macOS, I don’t think Windows should make a difference here.compnerd commentedon Aug 17, 2022
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.
finagolfin commentedon Aug 18, 2022
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
import CRT
or whatever, work if you remove that clang symlink?On linux with this file, I get this error after removing the clang symlink that the toolchain comes with:
stevapple commentedon Aug 19, 2022
I don’t think it can build with CMake based on an VS 2019 installation. There’s no
stdatomics.h
provided by MSVC.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.
\usr\lib\swift\clang
swiftlang/swift-installer-scripts#144stevapple commentedon Sep 22, 2022
For anyone running Swift 5.7 or older,
set TOOLCHAIN_ROOT=C:\Library\Developer\Toolchains\unknown-Asserts-development.xctoolchain
and runmklink /D %TOOLCHAIN_ROOT%\usr\lib\swift\clang ..\clang\<clang_version>
with an elevated (Administrator) command prompt to work around the problem. Hopefully we can solve this by Swift 5.7.1.finagolfin commentedon Jan 16, 2025
Still a problem with Swift 6? If not, please close.