-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[CMake] Add broader support for cross-compiling the portions of the compiler that are written in Swift to non-Darwin Unix #71552
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The standard library must be built with the new compiler. Requiring the new stdlib to build the new compiler while also requiring the new compiler to build the stdlib will result in a situation where we can't build anything. I'm confused about how this is working for you at all given that changes landed literally yesterday that cause the stdlib to not build with the nightly toolchain compiler. You should be seeing something like this if you try:
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.
Let me step back a bit and explain what I'm doing here. This
CROSSCOMPILE
bootstrap mode is only invoked when cross-compiling the Swift compiler itself for a different platform, say you want to build the Swift compiler for linux AArch64 on a linux x86_64 host. As such, these dependencies have to be reordered as I laid out in the commit message.There are two ways to accomplish this, but the most likely is to first build the Swift compiler from source natively for the host, then turn around and cross-compile the exact same compiler source for another platform, using the freshly-built compiler to build the Swift portions of the cross-compiled compiler. That is what these reordered dependencies when cross-compiling the compiler are needed for.
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.
@etcwilde, let me add more detail on why this is needed. Previously, the Swift compiler was written purely in C++ and the CMake dependency order was to always build the Swift compiler first, then the Swift stdlib, especially because for a native host build, that freshly-built Swift compiler is used to build the native Swift stdlib. However, cross-compiling the Swift compiler and stdlib is also supported and in that case, the freshly-built native clang and Swift compilers still cross-compile the Swift compiler first, then cross-compile the Swift stdlib. No dependency re-ordering was needed, because which was cross-compiled first didn't matter.
However, now that significant portions of the Swift compiler are written in Swift, the order does matter. You have to cross-compile the Swift stdlib first, use that cross-compiled stdlib to cross-compile
SwiftCompilerSources/
andlib/ASTGen/
next, and only then can you link the cross-compiled Swift compiler. These CMake dependency changes make sure that re-ordering is done when cross-compiling the Swift stdlib and compiler.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 am aware of the Swift in the swift compiler. I am concerned about the abuse of CMake here (and I'm not blaming you, the whole build is bad). A given CMake invocation should only be building for one thing at a time. For cross-compiling, I would expect two CMake invocations. One to build your cross-compiling toolchain with the necessary SDKs enabled. Then, in a separate CMake invocation, use that just-built toolchain to cross compile the compiler and the SDKs that you plan on shipping.
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 know, I'm just making clear the implications of that change for cross-compiling.
So, technically, that is mostly how the
build-script
currently works. It invokes CMake for each Swift repo separately, like the compiler or foundation, to natively build them, collects all the build products in one native toolchain directory, then uses that freshly-built native toolchain to cross-compile each of those repos with multiple CMake invocations with different cross-compilation flags.The only difference from what you said is that rather than mixing cross-compiling the stdlib in with natively compiling initially, it does all the native compilation first, then cross-compiles for each cross-compilation non-Darwin platform separately.
I see no reason why your preference is better.
What specifically are you worried about in the CMake usage here? Swift does not use CMake's built-in Swift support when building the Swift compiler, because obviously that CMake support didn't exist when this Swift project started.