-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[build] Allow cross-compiling build-script products for non-Darwin hosts too #36917
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
utils/swift_build_support/swift_build_support/products/product.py
Outdated
Show resolved
Hide resolved
for cross_compile_host in self.args.cross_compile_hosts: | ||
helper_cmd += [cross_compile_host] | ||
if host_target == self.args.host_target: | ||
for cross_compile_host in self.args.cross_compile_hosts: |
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.
No need for a loop here if we change the SPM bootstrap flag to --cross-compile-host
.
Updated this pull to generate a SPM configuration file to cross-compile for Android, which matches the latest version of my pull to cross-compile SPM with itself, swiftlang/swift-package-manager#3403. I'm able to use these two pulls with the latest official trunk snapshot build of the Swift toolchain to cross-compile SPM for Android. @shahmishal, can you review or recommend someone who might? |
utils/swift_build_support/swift_build_support/products/swiftpm.py
Outdated
Show resolved
Hide resolved
utils/swift_build_support/swift_build_support/products/product.py
Outdated
Show resolved
Hide resolved
ad6a515
to
af829b1
Compare
Rebased and ran this through the Python linter, then tweaked it to pass that. I used to merely dislike Python and its mandatory indentation, now I hate it and its linter: it's a cruel joke. @varungandhi-apple, would you run the CI on this? |
@swift-ci test |
Build failed |
Mac CI failure is unrelated, Win CI appears to have been broken then. |
Rebased and made an ARM change that I had missed when generating the JSON file. |
Rebased, added support for cross-compiling swift-driver too, and added a check to use an existing SPM JSON file if it was written previously. I just submitted the required patch to use this with swift-driver in swiftlang/swift-driver#743. |
utils/swift_build_support/swift_build_support/products/swiftdriver.py
Outdated
Show resolved
Hide resolved
@swift-ci test |
Rebased and added a new commit with the prefix flag for swift-driver. I also made two changes that will make this pull work in more scenarios. There are three primary scenarios it needs to handle:
Since 2. wasn't tested, I had made some mistakes in that scenario, which I call out in comments below. |
utils/swift_build_support/swift_build_support/products/product.py
Outdated
Show resolved
Hide resolved
utils/swift_build_support/swift_build_support/products/swiftpm.py
Outdated
Show resolved
Hide resolved
@drexin, since you're up, let's see if this still passes the CI. |
@swift-ci test |
@neonichu, since this pull primarily adds a way to cross-compile SPM for non-Darwin platforms, mind reviewing? We should probably also run it through the CI again since it's been more than a month since it passed the CI and was ready for review, I've gone ahead and rebased. |
@swift-ci please smoke test |
@buttaface I'm not really familiar with any of the build scripts in the Swift repo, so not the right person to review. |
@gottesmm, would you review? |
Rebased and added support for cross-compiling sourcekit-lsp too, as I said I would when I opened this pull more than seven months ago. I used this pull and the sourcekit-lsp change to successfully cross-compile the last trunk source snapshot of the toolchain before the break for Android. |
@shahmishal, can we get this in before the 5.6 branch? It's been ready for more than two months now and @gottesmm told me he'd like to get it in, but he was busy a month ago. |
@edymtt Can you help review this change? |
@swift-ci test |
Windows CI failure is single unrelated concurrency test. |
@edymtt, do you think we can get this in? |
I think @gottesmm is reviewing it now. |
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 really good. A few quick questions. I am fine with you answering them after we merge since if the tests pass I am ok with that later explanation.
@@ -669,7 +673,13 @@ def execute(self): | |||
# | |||
# This just maintains current behavior. | |||
if index > last_impl_index: | |||
self._execute(pipeline, [self.args.host_target]) | |||
non_darwin_cross_compile_hostnames = [ |
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.
@buttaface can you add a comment here (or fix up the comment above) explaining that we support it for non-darwin platforms. I am fine with a follow on commit fixing the comment.
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.
Will do.
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 simply removed the comments above, since it is no longer true. Darwin platforms were already cross-compiling in a different way, and this change adds support for non-Darwin platforms.
toolchain_path = swiftpm.SwiftPM.get_install_destdir(args, | ||
host_target, | ||
product.build_dir) | ||
toolchain_path = product.host_install_destdir(host_target) |
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 fine with this if the tests pass (which it looks like they did).
resource_path=resource_dir) | ||
] | ||
|
||
if action == 'install' and product.product_name() == "sourcekitlsp": |
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.
Shouldn't this also be guarded by the not is_darwin_host since you are trying to not effect the Darwin path?
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.
While most of these changes only affect non-Darwin and are guarded by such checks, there are a few changes that are applied generally, ie for Darwin too, which I called out separately in my notes for the first commit and the second commit:
Also, add a native_toolchain_path() method, that uses a prebuilt toolchain if available, and pass an install prefix in to swift-driver and sourcekit-lsp.
This was needed because non-Darwin uses a different install prefix for cross-compilation hosts, so I submitted pulls for those products' build scripts to accept an install prefix or actually start using the prefix passed in, which this pull now passes in for all platforms.
These configuration changes that affect Darwin too appear to be working fine.
if args.verbose_build: | ||
helper_cmd.append('--verbose') | ||
|
||
if action == 'install': | ||
helper_cmd += [ | ||
'--prefix', install_destdir + args.install_prefix |
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.
Same as my earlier question about --prefix. I just want to understand what the effect is.
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.
Same answer as indexstoredb above.
…sts too To that end, move the --cross-compile-deps-path flag from build-script-impl to a publicly documented build-script flag and use it for build-script products' library dependencies too. Generate a SPM destination JSON file that can be used both for cross-compiling these build-script products and by users for their own Swift packages. Also, add a native_toolchain_path() method, that uses a prebuilt toolchain if available, and pass an install prefix in to swift-driver and sourcekit-lsp.
…e new host_install_destdir()
@MaxDesiatov, would you test and merge? |
@swift-ci please smoke test |
If CI passes, I hesitate to merge since there were changes requested by one of the reviews that I don't know if they were fully addressed. I'd prefer one of the reviewers or code owners to merge. |
@DougGregor haven't they since built an ok toolchain? Can you remove your block? |
I looked above and it seems that Doug's issue was dealt with explicitly here: #36917 (comment). I am going to override the change request just so we can get this moving. |
Responded to and dealt with here: #36917 (comment)
To that end, move the
--cross-compile-deps-path
flag from build-script-impl to a publicly documented build-script flag and use it for build-script products' library dependencies too. Generate a SPM destination JSON file that can be used both for cross-compiling these build-script products and by users for their own Swift packages.Also, add a
native_toolchain_path()
method, that uses a prebuilt toolchain if available, and pass an install prefix in toswift-driver
andsourcekit-lsp
.I use this patch to cross-compile SPM from linux to Android, along with the since-merged #33724 and swiftlang/swift-package-manager#3403.
@shahmishal, since you added support for cross-compiling SPM from macOS x86_64 to arm64, maybe you could review this? I kept this separate from your macOS config, but one additional change that could be made is to rename the SPM bootstrap script's
--cross-compile-hosts
flag to--cross-compile-host
and only ever pass in one host at a time. That'll work because I only pass in one cross-compilation host at a time for these non-Darwin hosts, and you only support cross-compiling for a single Mac host, ie macOS arm64.Once this in,Iwill look into extendinghave also extended it to cross-compile sourcekit-lsp,which I have never cross-compiled.