C++ Interop on Linux: <swift/bridging> header not found unless adding SDK search path manually

Hi all,

When using .interoperabilityMode(.Cxx) on Linux, the compiler still can’t find the <swift/bridging> header in a .hpp file, even though it works fine on macOS.

The only workaround I’ve found is adding the SDK include path manually, e.g.:

.unsafeFlags(["-I", "/path/to/toolchain/usr/include/"])

This works for small demos but causes header issues in larger projects.

Full repro steps and code are in the GitHub issue:

:backhand_index_pointing_right: swiftlang/swift#83626

Expected:

Linux build should work the same as macOS without manual include paths.

Has anyone else seen this? Is there a known fix?

I worked around this on my end by simply copying the header into my Cxx target and using it from there. But, it’s really dumb that it doesn’t work out of the box on Linux.

1 Like

I guess the solution might be that we need to add /path/to/toolchain/usr/include/ into clang's default search path on Linux.

This is a SwiftPM issue. I’ll move the Github issue over.

1 Like

It’s now 'swift/bridging' file not found on Linux SDK · Issue #9010 · swiftlang/swift-package-manager · GitHub

SwiftPM should be able to add this path automatically.

2 Likes

Work around it by using the same pattern as WebKit did.