Swift/C++ interoperability: SWIFT_PRIVATE_ATTR compilation error on Ubuntu

Hi There :wave:

I'm trying to tame Swift and C++ interoperability with CMake.

On macOS, everything works fine, but I have an issue on Ubuntu:

[3/4] /usr/bin/clang++-15  -I/home/runner/work/eat-swift-from-cpp/eat-swift-from-cpp/build/include -std=gnu++17 -MD -MT CMakeFiles/cpp_ex.dir/main.cc.o -MF CMakeFiles/cpp_ex.dir/main.cc.o.d -o CMakeFiles/cpp_ex.dir/main.cc.o -c /home/runner/work/eat-swift-from-cpp/eat-swift-from-cpp/main.cc
make: *** [Makefile:16: build] Error 1
FAILED: CMakeFiles/cpp_ex.dir/main.cc.o 
/usr/bin/clang++-15  -I/home/runner/work/eat-swift-from-cpp/eat-swift-from-cpp/build/include -std=gnu++17 -MD -MT CMakeFiles/cpp_ex.dir/main.cc.o -MF CMakeFiles/cpp_ex.dir/main.cc.o.d -o CMakeFiles/cpp_ex.dir/main.cc.o -c /home/runner/work/eat-swift-from-cpp/eat-swift-from-cpp/main.cc
In file included from /home/runner/work/eat-swift-from-cpp/eat-swift-from-cpp/main.cc:1:
/home/runner/work/eat-swift-from-cpp/eat-swift-from-cpp/build/include/swift-lib.h:323:17: error: expected '{'
namespace swift SWIFT_PRIVATE_ATTR {
                ^
/home/runner/work/eat-swift-from-cpp/eat-swift-from-cpp/build/include/swift-lib.h:323:17: error: a type specifier is required for all declarations
/home/runner/work/eat-swift-from-cpp/eat-swift-from-cpp/build/include/swift-lib.h:325:1: error: expected expression
namespace _impl {
^
/home/runner/work/eat-swift-from-cpp/eat-swift-from-cpp/build/include/swift-lib.h:542:2: error: expected ';' after top level declarator
} // namespace swift
 ^
 ;
4 errors generated.

It seems that on Ubuntu, clang is unhappy with the generated header file :confused:

Clang: 15.0.7
Swift: 5.9.2
OS: Ubuntu 22.04.4

I have a reproducible example of GH action: ci: install swift via swift-actions/setup-swift@v2 路 tony-go/eat-swift-from-cpp@8da6b98 路 GitHub

I also have a working example for macOS: ci: install swift via swift-actions/setup-swift@v2 路 tony-go/eat-swift-from-cpp@8da6b98 路 GitHub

I tried to make the compiler and Swift version match on both OSes, but the error still persists.

I open a pull request here: ci: add linux by tony-go 路 Pull Request #1 路 tony-go/eat-swift-from-cpp 路 GitHub

Could you please try building with the Clang compiler that is included in the Swift toolchain 鈥 would the same issue reproduce there?

I am experiencing a similar error on Rhel 9.

Thanks, I'll try :)