Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

xymus
Copy link
Contributor

@xymus xymus commented May 28, 2025

Address two issues preventing a C source file to import the generated compatibility header:

  1. 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.

  2. 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.

xymus added 2 commits May 27, 2025 15:28
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.
@xymus
Copy link
Contributor Author

xymus commented May 28, 2025

@swift-ci Please test

@xymus
Copy link
Contributor Author

xymus commented May 28, 2025

@swift-ci Please test macOS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to generate a static or dynamic Swift library called by C code
1 participant