-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Import libstdc++ as a Clang module #41953
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
Conversation
0ed5bec
to
1adbc40
Compare
@swift-ci please smoke test |
bfc86e0
to
4f5ad83
Compare
e8b7d5e
to
1172138
Compare
This patch depends on #42222 being merged first. Apologies for spamming this PR with git rebases, the test failure wasn't reproducible for me locally. |
1172138
to
1e7489c
Compare
@swift-ci please smoke test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you Egor. This looks great (as usual).
@swift-ci please smoke test Windows |
1e7489c
to
003aea6
Compare
@swift-ci please smoke test |
@swift-ci please smoke test Windows |
This change adds a module map for libstdc++, which allows it to be properly imported into Swift as a module. The module map is installed into `usr/lib/swift/linux/{arch}` similarly to `glibc.modulemap`, and is passed to Clang as `-fmodule-map-file`. That means it is now possible to import std directly from Swift on Linux, when C++ interop is enabled. The module map currently declares a single `std` module without splitting the headers into submodules. This is going to change in the near future. rdar://87654514
003aea6
to
a3e9143
Compare
@swift-ci please smoke test |
@swift-ci please smoke test Windows |
@egorzhdan, I cross-compile the trunk toolchain for Android occasionally, and this pull broke cross-compiling the libswift portion of the compiler, because the Android NDK has a C++ modulemap (for some reason, this works fine when natively building the Apr. 21 trunk snapshot on my Android phone). I then disabled the new C++ modulemap portion of this pull for Android, and it cross-compiles and works fine. Is that what you recommend for such platforms that have a C++ modulemap of their own, or is there something else I should do instead? |
@buttaface oh this is interesting. Looks like Swift on Android uses libc++, but when cross-compiling, it uses libstdc++? I'm not familiar with Android, sorry about that. In general, I think the best approach is to always use the system-wide default C++ standard library. If the default stdlib is libc++, which already has a modulemap, then the logic in this PR should not be used. |
Thanks for the quick response.
No, Android always uses libc++, and the Android C++ module map exists in both the cross-compilation and native build environments. I took a closer look at the build commands and the only difference is that cross-compiling this libswift file specifies the If that Swift file can be built without the
I haven't tried removing it when natively building, but given my above finding that the native build never used your new module map and what you said about libc++ not needing it, removing that line seems like the solution. |
This change adds a module map for libstdc++, which allows it to be properly imported into Swift as a module. The module map is installed into
usr/lib/swift/linux/{arch}
similarly toglibc.modulemap
, and is passed to Clang as-fmodule-map-file
.That means it is now possible to import std directly from Swift on Linux, when C++ interop is enabled.
The module map currently declares a single
std
module without splitting the headers into submodules. This is going to change in the near future.rdar://87654514