-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[cxx-interop] Use VFS to inject modulemap into libstdc++ installation #58843
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
bfe466b
to
9a17417
Compare
@swift-ci please smoke test |
@rintaro this is largely based on your commit back from 2016 that never got merged (rintaro@1dc920b). |
This is a requirement for #58699. |
9a17417
to
ff6b4c4
Compare
@swift-ci please smoke test |
Thank you for resurrecting this idea :) |
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.
Looks good to me. Thanks, Egor. Ship it when you feel ready!
@@ -1,79 +1,79 @@ | |||
#include <algorithm> |
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.
Why did these have to change? Is it ever going to be a problem for users if they use angle brackets in their includes?
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.
It'll work fine with angle brackets as well. I just wanted to make it more clear that both the modulemap & the header are now located in the same directory as the stdlib headers, so there's no need to use angle brackets.
Previously the modulemap for the C++ stdlib on Linux was provided via `-fmodule-map-file=` Clang argument pointing to the modulemap file within the Swift toolchain. The modulemap file could not reference the stdlib headers directly, since the exact stdlib include directory varies across Linux versions (it generally looks like `/usr/include/c++/{gcc_version}`). So the modulemap file instead referenced a local header, which `#include <>`-ed the stdlib headers, relying on Clang include resolution. Unfortunately this did not work properly in the presence of another C++ module which included the stdlib headers: sometimes decls from the stdlib were hijacked by the other module, and were not treated as a part of the stdlib by Clang. This caused compile errors in Swift. This change uses LLVM VFS to inject the modulemap file into the libstdc++ directory. The modulemap file is now able to reference the stdlib headers directly, which fixes the issue. Credits to Rintaro Ishizaki for proposing a similar idea for SwiftGlibc back in 2016.
Previously this header was sometimes getting hijacked by the first header to include it. This caused Swift compiler failures on Linux when using any LLVM header that uses `assert`. Now `cassert` is referenced directly from a modulemap, which fixes the issue.
ff6b4c4
to
20650ea
Compare
@swift-ci please smoke test |
Hi @egorzhdan, Can you fix the line
SmallVector without a on stack storage template parameter causes a compile failure on some linux configurations: https://ci.swift.org/view/Dashboard/job/oss-swift-package-centos-7/480/ |
cxxStdlibDirs.push_back(Path(iter->path())); | ||
} | ||
|
||
SmallVector<std::pair<std::string, std::string>> result; |
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.
^ Here
@egorzhdan |
Previously the modulemap for the C++ stdlib on Linux was provided via
-fmodule-map-file=
Clang argument pointing to the modulemap file within the Swift toolchain. The modulemap file could not reference the stdlib headers directly, since the exact stdlib include directory varies across Linux versions (it generally looks like/usr/include/c++/{gcc_version}
). So the modulemap file instead referenced a local header, which#include <>
-ed the stdlib headers, relying on Clang include resolution.Unfortunately this did not work properly in the presence of another C++ module which included the stdlib headers: sometimes decls from the stdlib were hijacked by the other module, and were not treated as a part of the stdlib by Clang. This caused compile errors in Swift.
This change uses LLVM VFS to inject the modulemap file into the libstdc++ directory. The modulemap file is now able to reference the stdlib headers directly, which fixes the issue.
Credits to Rintaro Ishizaki for proposing a similar idea for SwiftGlibc back in 2016.