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

[cxx-interop] Fix two headers to be valid in C++ mode. #2895

Merged
merged 2 commits into from
Nov 20, 2020

Conversation

zoecarver
Copy link
Contributor

This is exported as a C header but in C++ mode ucal.h will expose templates that aren't valid. This will hopefully fix the Linux build for swiftlang/swift#32721.

@spevans
Copy link
Contributor

spevans commented Oct 9, 2020

@swift-ci test

@zoecarver
Copy link
Contributor Author

@swift-ci please test.

@zoecarver
Copy link
Contributor Author

I don't have commit access. Could someone review/merge this for me?

@zoecarver zoecarver changed the title [cxx-interop] Don't include unicode/ucal in C++ mode. [cxx-interop] Fix two headers to be valid in C++ mode. Oct 11, 2020
Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems legit to me, but as there's a way to test the toolchain PR with this without merging, I'll defer to the rest of the requested reviewers to merge it, unless it's urgent.

@zoecarver
Copy link
Contributor Author

zoecarver commented Oct 14, 2020

This seems legit to me, but as there's a way to test the toolchain PR with this without merging, I'll defer to the rest of the requested reviewers to merge it, unless it's urgent.

Not urgent. I'm just eager to get that other patch in 😁 I had forgotten that toolchain PR testing exists, thanks for running that. Anyway, I'm fine waiting for one of the reviewers to merge.

@zoecarver
Copy link
Contributor Author

Friendly ping.

@MaxDesiatov
Copy link
Contributor

@compnerd @millenomi would you have a moment to take a look, or would you mind if I merge this otherwise?

@compnerd
Copy link
Member

Hmm, where is CFCalendar_Internal.h used in a C++ context? I also have the same question for the CFForSwiftFoundationOnly.h header. I think we should make that more explicit in the commit message at the very least.

@zoecarver
Copy link
Contributor Author

Hmm, where is CFCalendar_Internal.h used in a C++ context? I also have the same question for the CFForSwiftFoundationOnly.h header.

When C++ interop is enabled, any time these are used it's in a C++ context. The same is true for Swift shims (we had to make similar fixes there a while back).

@zoecarver
Copy link
Contributor Author

In other words, it's used in C++ mode any time a Swift program imports CoreFoundation and has the flag -enable-cxx-interop.

I'll update the commit messages to clarify that this is needed to import these into programs that use the -enable-cxx-interop flag.

This is exported as a C header but in C++ mode ucal.h will expose
templates that aren't valid.

When a program uses the flag "-enable-cxx-interop" this library will be
imported in a C++ context so we can only have valid C++ code.
This C99 extensions is only valid in C.

When a program uses the flag "-enable-cxx-interop" this library will be
imported in a C++ context so we can only have valid C++ code.
@zoecarver zoecarver force-pushed the fix/skip-icu-in-cxx-mode branch from 380e732 to f82f4cb Compare October 26, 2020 23:27
@MaxDesiatov

This comment has been minimized.

@zoecarver
Copy link
Contributor Author

I've updated the commit message. @compnerd any other comments?

@MaxDesiatov

This comment has been minimized.

@zoecarver
Copy link
Contributor Author

@swift-ci please test Linux platform.

3 similar comments
@zoecarver
Copy link
Contributor Author

@swift-ci please test Linux platform.

@zoecarver
Copy link
Contributor Author

@swift-ci please test Linux platform.

@zoecarver
Copy link
Contributor Author

@swift-ci please test Linux platform.

@zoecarver
Copy link
Contributor Author

Friendly ping.

@zoecarver
Copy link
Contributor Author

@swift-ci please smoke test Windows platform.

@zoecarver
Copy link
Contributor Author

@swift-ci please test Windows platform.

2 similar comments
@zoecarver
Copy link
Contributor Author

@swift-ci please test Windows platform.

@zoecarver
Copy link
Contributor Author

@swift-ci please test Windows platform.

@zoecarver
Copy link
Contributor Author

@millenomi friendly ping. Any comments?

@millenomi
Copy link
Contributor

millenomi commented Nov 7, 2020

I'm a little slow here but I'm not sure I get the change for _Internal, which should not be imported outside of the CF build itself, which is in C mode and not C++. Okay on the ForSwift… because that ends up in the CF module, tho.

@@ -19,7 +19,7 @@
#include "CFDateComponents.h"
#include "CFDateInterval.h"

#if __has_include(<unicode/ucal.h>)
#if __has_include(<unicode/ucal.h>) && !defined(__cplusplus)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per comment: please explain here.

Copy link
Contributor Author

@zoecarver zoecarver Nov 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With C++ Interoperability enabled, all headers are imported as C++ headers. So they will all be imported in C++ mode. Even if they're not publically exposed. In other words, all headers in the CF module will be imported as C++ headers in a program that enables C++ interoperability.

You're right, I think ForSwift may be the only place this is causing issues. To be honest, I know next to nothing about core foundation so, maybe this isn't the correct fix. Feel free to suggest an alternative.

Anyway, does that answer your question? Would you also like me to put a comment in "CFCalendar_Internal.h" explaining this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@millenomi friendly ping. I'd really like to get this moving.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I missed your ping back.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries. I missed your comment the first time ;) Thanks!

@millenomi
Copy link
Contributor

@swift-ci please test and merge

@millenomi
Copy link
Contributor

In the interest of getting this going, I'm okay with the safety change on the internal header.

@zoecarver
Copy link
Contributor Author

In the interest of getting this going, I'm okay with the safety change on the internal header.

Great. If you'd like to keep discussing, I'm happy to. (And if we arrive at a better solution, I'm happy to implement it.)

@swift-ci swift-ci merged commit 7d521e4 into swiftlang:main Nov 20, 2020
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.

6 participants