-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Glibc] Configure modulemap for target, not host #1679
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
2766687
to
b62940d
Compare
@swift-ci Please smoke test |
Hmm, looks like a legitimate failure when running the swift-package-manager tests on Linux. I'll check it out, thanks! Any comments on the overall approach would be very much appreciated!! 🙇 |
I haven't reviewed CMake code line-by-line, but this looks like the right direction to me. |
Excellent, thanks @gribozavr! That's reassuring. |
b62940d
to
b4ebbe7
Compare
@tkremenek @gribozavr Updated! The tests should now pass, if one of you could do me the favor of asking @swift-ci to please test. |
@swift-ci Please test |
Hmm, looks like some OS X errors this time. Strange, since this shouldn't affect OS X at all. I'll look into it more--thanks! |
b4ebbe7
to
826e0dc
Compare
Updated once again. I added a check such that This got all my tests passing on both OS X and Linux locally--fingers crossed it also works on CI! @gribozavr, is it alright that I left a FIXME in there? Also, an alternative approach would have been to modify the tests such that |
It would be best to keep the current extended coverage. |
Excellent. Well, this pull request has all the same test coverage, but can also handle the Android changes in #1442 -- whaddya think? Also, could you kick off a test? |
@swift-ci Please test |
CC @jrose-apple for Clang importer changes. |
Glibc.swift | ||
Misc.c | ||
Glibc.swift | ||
Misc.c |
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.
CMake code uses 4 spaces for indentation on continuation lines.
CMake changes LGTM modulo comments. |
llvm::SmallString<128>(searchPathOpts.RuntimeResourcePath); | ||
} | ||
if (!GlibcModuleMapPath.empty()) { | ||
if (triple.isOSFreeBSD()) { |
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.
Please use swift::getPlatformNameForTriple
instead of hardcoding names here.
826e0dc
to
83cefbf
Compare
@jrose-apple Thanks for the review!! I hope I've addressed all of your comments--I'm very new to C++, let alone llvm/ADT, so I can't be sure I did. 😅 |
e3ddc84
to
097c9be
Compare
@gribozavr All tests pass locally for me. Could you ask @swift-ci to test? Also, any additional feedback here? |
// a Swift compiler not built for Linux targets. | ||
if (llvm::sys::fs::exists(GlibcModuleMapPath)) { | ||
invocationArgStrs.insert(invocationArgStrs.end(), { | ||
(SmallString<128>("-fmodule-map-file=") + GlibcModuleMapPath).str(), |
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.
I think this is still going to go through std::string, but maybe that's all right. I forgot this is building up a vector of std::strings anyway. Let's go back to the Twine version.
Actually, you can simplify it a bit with push_back
. insert
is just a trick for adding multiple arguments at once.
invocationArgStrs.push_back(
(Twine("-fmodule-map-file=") + GlibcModuleMapPath).str());
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.
Thanks for the tips! Updated to use push_back()
and Twine
.
@swift-ci Please test |
The current Glibc CMakeLists.txt uses the host machine to determine which modulemap to use. The same modulemap can't be used for all platforms because headers are available in different locations on different platforms. Using the host machine to determine which modulemap to configure and place at a specific path in the resource dir is fine, so long as: 1. Only one Glibc is being compiled in a single CMake invocation. 2. The target machine needs the same modulemap as the host. swiftlang#1442 violates both of these assumptions: the Glibc module for both Linux and Android is compiled at the same time, and the Android target can't use the Linux modulemap. This commit instead uses the target(s) to determine which modulemap to use. The modulemap is configured and placed in an OS- and architecture-specific directory in the resource dir. The path to that modulemap is referenced by the ClangImporter (since it is no longer at a path that is automatically discovered as an implicit modulemap).
097c9be
to
04e1cd5
Compare
I wonder if amending the commit to use |
It's probably still running, but I guess GitHub can't report status for it. I'll trigger it again. |
@swift-ci Please test |
@jrose-apple @gribozavr Hooray, everything passed! Does this look good to merge? |
Importer changes look good to me. 👍 |
CMake LGTM! |
Well, if everything looks fine to everyone and the CI says it's alright, I guess I've got no choice but to merge this! 😁 Thanks again for the reviews! This will be a big help for #1442. |
[Glibc] Configure modulemap for target, not host
swift_install_in_component(stdlib | ||
FILES "${output_dir}/module.map" | ||
DESTINATION "lib/swift/glibc") | ||
swift_install_in_component(stdlib |
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 looks like we've got a problem: this shows up as part of the install component even when we're not building for Linux or FreeBSD. Maybe this just needs to go in the if
below? (Maybe everything needs to be guarded by that if
?)
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.
Good call, I believe I may have misinterpreted some of the comments in the pull request review. I could place an if("${SDK}" STREQUAL "LINUX" OR "${SDK}" STREQUAL "${FREEBSD}")
at the very beginning of the inner loop--does that sound right?
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.
Maybe. Why would "${FREEBSD}"
be a variable?
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.
I copy-pasted from five lines down, but you're absolutely right. I'll change that part, too. 😅
What's in this pull request?
The current Glibc CMakeLists.txt uses the host machine to determine which modulemap to use. The same modulemap can't be used for all platforms because headers are available in different locations on
different platforms.
Using the host machine to determine which modulemap to configure and place at a specific path in the resource dir is fine, so long as:
#1442 violates both of these assumptions: the Glibc module for both Linux and Android is compiled at the same time, and the Android target can't use the Linux modulemap.
This commit instead uses the target(s) to determine which modulemap to use. The modulemap is configured and placed in an OS- and architecture-specific directory in the resource dir. The path to that modulemap is referenced by the ClangImporter (since it is no longer at a path that is automatically discovered as an implicit modulemap).
#1442 will build upon the work here by adding an Android module map:
Resolved bug number: None
Before merging this pull request to apple/swift repository:
Triggering Swift CI
The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:
Smoke Testing
Validation Testing
Note: Only members of the Apple organization can trigger swift-ci.