The swift/bridging
header defines C/C++ annotations that are recognized and used by Swift's ClangImporter for interop. This header file currently ships with the toolchain in the <toolchain>/usr/include/
subdirectory, which is part of Clang's default search paths for Apple-built toolchains, but not for OSS toolchains distributed via Swiftly/swift.org.
To make this behavior consistent, I'd like to propose shipping this header file in a separate "Swift resource directory", which would consist of the following changes:
- (swiftlang/swift) move the installation destionation for the
swift/bridging
header from<toolchain>/usr/include/
to<toolchain>/usr/lib/swift/include
, which is the location of the Swift resource directory. - (swiftlang/llvm-project) add
<toolchain>/usr/lib/swift/include
to Clang's default search paths - (swiftlang/swift-installer-scripts) adjust package manifests to include the new resource directory.
The addition of this default search path to the OSS Swift toolchain's Clang will allow that toolchain to resolve #<swift/bridging>
without explicitly adding that search path to the build invocation.
Note, however, that this will not affect C/C++ compilers outside of the Swift toolchain. In particular, upstream Clang will still not be able to resolve #include <swift/bridging>
without adding an explicit search path (which is the status quo). Those toolchains will still be able to derive that directory relative to Swift-Clang’s own resource directory, i.e., $(swift/toolchain/clang -print-resource-dir)/../../swift/include
.
The motivation to behind moving the directory from <toolchain>/usr/include
to <toolchain>/usr/lib/swift/include
is to ship it alongside the rest of the toolchain-specific files. We already ship a number of header files in other subdirectories of <toolchain>/usr/lib/swift
to support the toolchain, and as well as Clang’s own resource directory under <toolchain>/usr/lib/clang/<version>/
.
I'd love to hear your thoughts and suggestions about this. Thank you!