-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Allow C targets to import the compatibility header generated for Swift libraries #8736
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
The module map generated for the compatibility header was marked as `requires objc`. This triggers an error when importing it from a C source file. This declaration is superfluous, the compatibility header is already printed in a way where the Objective-C code is protected behind a language check. C clients can safely import the current compatibility header even if it may not see any content. Let's lift this restriction. It isn't currently necessary and we're adding C content to the compatibility header with the official support for `@cdecl` that is independent of Objective-C.
…tory Emit the generated compatibility header and module map in a new `include` directory under the temporary build directory of Swift libraries. This directory can then be used as a header search path for the dependent clang targets. This replaces the previous header search strategy that used only the generated module map. This was incompatible with C source files and classic non-module textual includes. The use of a header search path should support both module imports via the module map as well as includes of the compatibility header.
@swift-ci Please test |
@swift-ci Please test macOS |
@swift-ci Please test |
@swift-ci Please test Windows |
@swift-ci Please test |
Also lift the macOS restriction now that swiftpm emits the compatibility header on other platforms.
e788fa1
to
c2d9f40
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
Is someone available to review this change? |
@jakepetroules do you think we need a similar change in swift-build? It appears to print the |
I think so, yeah, at least for the |
Address two issues preventing a C source file to import the generated compatibility header:
Don't mark the module map generated for the compatibility header as
requires objc
. This triggers an error when importing it from a C source file. The compatibility header is already printed in a way where the Objective-C code is protected behind a language check. C clients can safely import it even if they may not see any content. Plus we're adding C content to the compatibility header with the official support for@cdecl
that is independent of Objective-C.Emit the generated compatibility header and module map in a new
include
directory under the temporary build directory of each Swift library. This directory is then used as a header search path for the dependent clang targets.This replaces the previous strategy that relied only the generated module map to resolve imports. It was incompatible with C source files and non-modular textual includes. The use of a header search path preserves the support for module imports via the same module map and supports textual includes of the compatibility header.
Fixes #7257.
Follow up to #8695.