Skip to content

[android] Support building the host tools and with the static stdlib #34963

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 1 commit into from
Jan 11, 2021

Conversation

finagolfin
Copy link
Member

Some odds and ends I needed when cross-compiling the entire toolchain for Android. @drodriguez, @compnerd, and @drexin, I believe you are best qualified to review this.

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, this seems reasonable enough. If you want to remove the use of SWIFT_CONFIGURED_SDKS, I think that it might be valuable to ensure that we have removed it everywhere.

Copy link
Contributor

@drodriguez drodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this three unrelated changes? There seems to be the change to not use SWIFT_CONFIGURED_SDKS, which seems incomplete (per the previous comment). Then the change in the static-stdlib-args.lnk. And then the changes in the build-script-impl. Or are they necessary for each other?

I would recommend using independent PRs for each change. Easier to review, and easier to understand.

For the changes in build-script-impl you probably want to provide a "test plan". I don't think the standard workflows will exercise those code paths, so it is complicated to evaluate if they are correct without knowing what they intend to do.

@@ -1756,7 +1768,8 @@ for host in "${ALL_HOSTS[@]}"; do
)
fi

if [[ ! "${SKIP_BUILD_ANDROID}" ]]; then
if [[ ! "${SKIP_BUILD_ANDROID}" ]] ||
[[ $(is_cross_tools_host ${host}) && "${host}" == "android-"* ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this because if you don't skip building Android, the stdlib would also be built? Isn't there a cleaner or clearer way of doing this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, this is a minor addition to signify that the NDK can also be used to cross-compile the host tools and not just the Android stdlib, as SKIP_BUILD_ANDROID confusingly just means "don't build the Android stdlib." It fixes a bug I hit where I was only cross-compiling the host tools for Android and not the stdlib, which the unmodified version of this check would screw up.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that you are trying to cross-compile the tools. What I don't understand is that all these variables (if I remember correctly) are used during the compilation of the stdlib. Some host tools use Swift, and so they require a stdlib to be built, so I don't understand how the stdlib is both skipped, and used at the same time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe that any of the Swift host tools, like the Swift compiler or SourceKit, use any Swift yet, as I was building the host tools alone till earlier this year. A search for .swift files in the lib/ and tools/ directories only turns up anything in tools/swift-inspect, which I don't think is built by default.

@finagolfin
Copy link
Member Author

If you want to remove the use of SWIFT_CONFIGURED_SDKS, I think that it might be valuable to ensure that we have removed it everywhere.

This is the last use of SWIFT_CONFIGURED_SDKS to configure anything. Otherwise, it's only initialized in SwiftConfigureSDK.cmake and then used in other ways in three places:

  1. If a SWIFT_SDKS variable hasn't been passed in, through the build-script flag --stdlib-deployment-targets, or set, SWIFT_CONFIGURED_SDKS is used to initialize SWIFT_SDKS.
  2. Then, the CMake config immediately checks to make sure that SWIFT_SDKS is a subset of SWIFT_CONFIGURED_SDKS, ie that someone didn't pass in a SDK through --stdlib-deployment-targets that hasn't been configured.
  3. Finally, it runs that same subset check again in another part of the CMake config.

Other than the two uses in this pull that I'm changing, that's it: SWIFT_SDKS is used to configure actual build targets everywhere else in this codebase. Run a grep for SWIFT_CONFIGURED_SDKS and SWIFT_SDKS and look for yourself.

I am simply fixing this bug, where you pass in --stdlib-deployment-targets of say a single cross-compiled SDK and the outdated use of SWIFT_CONFIGURED_SDKS in this pull tries to configure the host SDK too and the CMake config dies, which I have hit when trying to cross-compile the Android stdlib alone.

@finagolfin
Copy link
Member Author

Is this three unrelated changes?

As mentioned in the OP, these are odds and ends I needed when building a full Swift toolchain for Android. Since this is so small, I'd rather just keep it all in one pull here.

For the changes in build-script-impl you probably want to provide a "test plan".

Since those involve building a Swift toolchain that will run natively on Android, I'm the only one currently using them and they're not currently tested by any CI.

Copy link
Contributor

@drodriguez drodriguez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About the unrelated changes: it is not the first time I ask you to split unrelated changes, and because the pull requests with unrelated changes keep coming, I am afraid it would not be the last. It is not a pet peeve of mine or anything, it is how the Contributing Code guidelines (https://swift.org/contributing/#contributing-code) describe it should be done. It makes everyone reviewing your code spend more time looking at the changes, trying to understand how the changes are supposed to be related. Splitting also benefits you: the change for static-stdlib-args.lnk haven't had any comment, but it is being hold back because the other changes that do not affect it.

About the testing plan: specially because they are not currently tested in CI, if someone wants to verify this changes are solving a problem, what can they do to verify that the code is correct. Besides solving the problem, it is also important to explain what the problem was, and how it was solved.

Finally, about the modifications in build-script-impl/build-script. As far as I understand those files were supposed to be used for CI, but they have been started to be used for day to day development. Adding specifics for other purposes only complicates those files even more (because most people do not have access to Termux and cannot check that their modifications to unbreak CI will not break Termux in the process). For specific systems/flavors packaging, it might be better to have an external set of scripts using the underlying CMake invocations (that's how the Windows packaging works, for example). Just my two cents.

@@ -1756,7 +1768,8 @@ for host in "${ALL_HOSTS[@]}"; do
)
fi

if [[ ! "${SKIP_BUILD_ANDROID}" ]]; then
if [[ ! "${SKIP_BUILD_ANDROID}" ]] ||
[[ $(is_cross_tools_host ${host}) && "${host}" == "android-"* ]]; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand that you are trying to cross-compile the tools. What I don't understand is that all these variables (if I remember correctly) are used during the compilation of the stdlib. Some host tools use Swift, and so they require a stdlib to be built, so I don't understand how the stdlib is both skipped, and used at the same time.

@drodriguez
Copy link
Contributor

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Dec 6, 2020

Build failed
Swift Test OS X Platform
Git Sha - 47d94da

@finagolfin
Copy link
Member Author

About the unrelated changes: it is not the first time I ask you to split unrelated changes

I have split off pulls on your recommendation in the past, even submitting one-line commits if they affect other OS platforms. In this case, there is a common theme: everything is scoped to Android. I understand that any increase in commit size takes longer to review, but this pull is so small that I'm fine with that.

if someone wants to verify this changes are solving a problem, what can they do to verify that the code is correct.

I'm not pulling these changes out of thin air, they are all currently used by my open-source patches to cross-compile the Swift toolchain for the OSS Termux app for Android.

Besides solving the problem, it is also important to explain what the problem was, and how it was solved.

On your prompting above, I've added additional comments that now explain everything.

about the modifications in build-script-impl/build-script. As far as I understand those files were supposed to be used for CI

I don't know that that was ever the case, new users who build this project are prompted to use those scripts for "day to day development" too.

Adding specifics for other purposes only complicates those files even more

Not if they're properly scoped, as these changes are, and these build scripts have long included support for niche platforms like Cygwin and Haiku that are not tested by any CI, and have bitrotted in the way you point out. I'm well aware that might happen for any Android-specific modifications too, and since I maintain the Termux package of the Swift toolchain, I will simply update those when necessary. It has not been a problem so far.

Thanks for running the CI, macOS failure when running sourcekit-lsp tests is unrelated to this pull.

@finagolfin
Copy link
Member Author

Could someone run the Mac CI again?

@drexin
Copy link
Contributor

drexin commented Dec 10, 2020

@swift-ci test macos

@finagolfin
Copy link
Member Author

Passed CI, ready to merge.

@finagolfin
Copy link
Member Author

Ping, this is ready to go.

@finagolfin
Copy link
Member Author

@drodriguez, ready to go?

@finagolfin
Copy link
Member Author

@varungandhi-apple, this has been ready for a couple weeks now, mind getting it in?

@varungandhi-apple
Copy link
Contributor

(Re-runnning CI since the last pass was over a week back)

@swift-ci please test

@finagolfin
Copy link
Member Author

Ping, a final CI run and this can be merged.

@drexin
Copy link
Contributor

drexin commented Jan 6, 2021

@swift-ci test

@swift-ci
Copy link
Contributor

swift-ci commented Jan 6, 2021

Build failed
Swift Test Linux Platform
Git Sha - 47d94da

@swift-ci
Copy link
Contributor

swift-ci commented Jan 6, 2021

Build failed
Swift Test OS X Platform
Git Sha - 47d94da

@finagolfin
Copy link
Member Author

CI is broken right now because of lldb issue.

@finagolfin
Copy link
Member Author

@varungandhi-apple, if the CI is not broken because of other pulls, could you retest this and merge?

@varungandhi-apple
Copy link
Contributor

@swift-ci test

@varungandhi-apple
Copy link
Contributor

@drodriguez is this okay to merge/are there changes that should be made? I skimmed through your comments and I'm not sure.

@drodriguez
Copy link
Contributor

I think I remember running this in my local Android CI, and didn't break anything (but that was more than a month ago). If it creates problem when merged, we can always revert and rework.

@varungandhi-apple varungandhi-apple merged commit c6490b2 into swiftlang:main Jan 11, 2021
@finagolfin finagolfin deleted the droid branch January 12, 2021 02:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants