C++ interoperability is broken (Windows platform)

Will Swift 6 on Windows embed a clang aligned with the Clang 17 release? There's alot of friction here for Windows users, since none of this is documented and most users will simply follow these docs, which at the time of writing - correlates to every C/C++ target failing to compile for users, which is not quite the out-of-the-box experience Swift provides on all other platforms.


As an additional note, Release (swift build -c release) builds, as well as Optimized (swift build -Xcc -Os) builds of C/C++ targets also break C++ interop on Windows.

Example output (slightly redacted to avoid printing too much noise in this comment) when compiling C/C++ targets with one of the aforementioned commands:

Function has token parameter but isn't an intrinsic
  call void @_GLOBAL__sub_I_tag.cpp.cold.1(token %0) #22, !dbg !4333
in function _GLOBAL__sub_I_tag.cpp
fatal error: error in backend: Broken function found, compilation aborted!
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.

...

1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'Function Pass Manager' on module 'C:\Users\furby\Wabi\MetaverseKit\Sources\Yaml\tag.cpp'.
4.      Running pass 'Module Verifier' on function '@_GLOBAL__sub_I_tag.cpp'
Exception Code: 0xE0000046
 #0 0x00007ffd7f2fc95a (C:\WINDOWS\System32\KERNELBASE.dll+0xcc95a)
 #1 0x00007ff78960316a (C:\Users\furby\AppData\Local\Programs\Swift\Toolchains\5.10.1+Asserts\usr\bin\clang.exe+0x16e316a)

...

clang: error: clang frontend command failed with exit code 70 (use -v to see invocation)
clang version 16.0.0
Target: x86_64-unknown-windows-msvc
Thread model: posix
InstalledDir: C:\Users\furby\AppData\Local\Programs\Swift\Toolchains\5.10.1+Asserts\usr\bin

...

As a final observation, with the following define present

cxxSettings: [
  .define("_ALLOW_COMPILER_AND_STL_VERSION_MISMATCH", .when(platforms: [.windows]))
]

with a single C++ target's header file including the following

// SomeCXXTarget.h
#include <version> // from stdlib

it errors with the following when attempting to import it into Swift:

// SomeApp.swift
import SomeCXXTarget
       ^~~~~~~~~~~~~
vcruntime.modulemap:696:10: error: module 'std.version' requires feature 'cplusplus20'

Note: I am using the following C/C++ language standards in my Package.swift manifest.

cLanguageStandard: .gnu17,
cxxLanguageStandard: .cxx17

Thanks!

1 Like