Skip to content
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

Add build setting for enabling C++ interoperability #6276

Merged
merged 1 commit into from
Mar 16, 2023

Conversation

egorzhdan
Copy link
Contributor

Motivation:

When importing C language dependencies, the Swift compiler internally runs Clang in C/Objective-C mode by default.
If some of the imported clang modules are actually written in C++, that causes build errors since C++ syntax might be invalid in C/Objective-C. To resolve that, Swift allows the user to explicitly enable C++/Objective-C++ language mode (along with the rest of the Swift/C++ interoperability logic) for clang via a compiler flag. The reason we cannot enable C++/Objective-C++ mode by default is because it changes the way some existing C/Objective-C APIs are imported: for instance, a library header might provide a different definition of a symbol under #ifdef __cplusplus.

The user should be able to enable Swift/C++ interoperability for a given Swift target without using unsafe flags.

Modifications:

This adds a build setting to the package manifest that enables Swift/C++ Interoperability for a given Swift target:

.interoperabilityMode(.Cxx, version: "swift-5.9")

The implementation relies on the new Swift driver flag for versioned C++ interop (see swiftlang/swift#64088).

@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@egorzhdan egorzhdan force-pushed the egorzhdan/cxx-interop-flag branch from 95da5dd to f4d960b Compare March 16, 2023 14:29
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

This adds a build setting to the package manifest that enables Swift/C++ Interoperability for a given Swift target:
```
.interoperabilityMode(.Cxx, version: "swift-5.9")
```

This relies on the new Swift driver flag for versioned C++ interop (see swiftlang/swift#64088).

rdar://106756067
@egorzhdan egorzhdan force-pushed the egorzhdan/cxx-interop-flag branch from f4d960b to f7b042c Compare March 16, 2023 15:50
@egorzhdan
Copy link
Contributor Author

@swift-ci please smoke test

@zoecarver zoecarver merged commit fe10910 into main Mar 16, 2023
@egorzhdan egorzhdan deleted the egorzhdan/cxx-interop-flag branch March 17, 2023 13:12
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.

4 participants