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
[android] add a module map for Android NDK #72161
base: main
Are you sure you want to change the base?
Conversation
CC: @etcwilde |
e3902b6
to
01acb56
Compare
@swift-ci please test |
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.
Seems mostly reasonable, what is the plan for selecting a given API level to build against?
Oh nice, I had a similar pull I had been trying for both Glibc and Bionic, #66665, but this pull appears more specific to Bionic, which is good. Have you tried this pull with the C++ Interop tests on Android? Because they don't work with the current |
Yeah, this allows me to compile Swift code with C++ interop enabled, and use libc++ from the NDK as well in Swift :) |
OK, they were mostly working before the latest NDK 26, but NDK 26 broke many of them. You were using NDK 26? How were you running those tests, in an emulator? Because the community Android CI doesn't run those executable tests, so I run them natively in the Termux app. |
I didn't run the C++ interop tests on device yet unfortunately. What kind of issues did you see with NDK 26? That's something we will need for sure, but we don't have a good test setup yet. |
good question, we didn't discuss that yet. let me figure that out. |
This seems to be currently behaving as desired - the module triple strips the API level. This allows us to build the SDK against an API level that we want to support (I am currently leaning towards 28). When the client code is built, it can build against a higher API level and still work with the single SDK build. The API level encoded version of the triple would be used by the driver for the linker driver. |
API level in the triple seems reasonable. That is in alignment with clang, IIRC. |
The same error I mentioned to you more than a year ago, except dozens of C++ Interop executable tests that passed with NDK 25 now fail to compile with that |
I see. That error should go away with the updated module map, since I am able to successfully build and import the uchar module from the NDK now. |
@swift-ci please test |
@ian-twilightcoder I updated the module map to prefer split modules, how does it look now. |
1050e59
to
c7f9a66
Compare
@swift-ci please test |
@swift-ci please test source compatibility |
Now |
@finagolfin I was able to run more tests now with the regular Linux android setup, without going through termux. I can see that the test you were asking about passes, and I don't see any modularization errors for Unfortunately I'm not yet able to run the android linux C++ interop executable tests, but I get an improvement as compared to the baseline with respect to more android C++ interop tests now. I will merge this in, and then will continue on iterating on the remaining C++ interop test failures then so we can get them to be fully passing on a regular linux android setup. |
This was with the version of this pull from last week or the commit you just pushed a couple hours ago?
Unlikely, what about the 44 newly failing tests I mentioned, because they're still trying to use
A majority of the C++ Interop tests are executable, so you will not get a good idea of their status on Android without building them.
Hold off on merging, as until a couple hours ago, this pull was still failing to compile swift-corelibs-foundation, which just uses regular C interop. I will try building the Swift toolchain natively on Android with these two compiler pulls, that should be a good smoke test of this new Android overlay. Give me till next week to try that. If you have any more changes to these Android pulls you want to add, now would be the time to add them, else I will have to start over with my testing once you add them. |
this was when building with the latest changes.
Good call, let me check on them. |
Before building again, I went ahead and diffed the list of headers included for the
Were these choices all intentionally made and why? |
To check if this pull is working when cross-compiling for Android, I downloaded the latest linux toolchain build you kicked off, checked out the compiler source to the same commits, then ran this command to check the Swift Interop tests that don't require special tools like
I did find that most of the non-executable Interop tests worked, including I then tried that I finally tried building swift-corelibs-foundation natively on Android with the latest version of this pull and it now builds successfully. However, I'm now seeing |
@finagolfin re: tests. Thanks for highlighting the
Thanks for checking! I'll check these tests as well.
I'll get back to you to about the headers later today. |
Re: swift-corelibs-foundation tests. I have pushed some test fixes to the corresponding PR here: apple/swift-corelibs-foundation@69cfa27 I can now build the swift-corelibs-foundation tests for Android. |
d604f05
to
7c799cc
Compare
Re: swift-core-libs foundation. I updated the tests like I mentioned above. Could you please take another look. Re: module map question:
They're intentionally not in the module map, but it's a good idea to add them back to the header files themselves. I added them back to 'SwiftAndroidNDK.h' and 'SwiftBionic.h'
That's not an intentional replacement,
Good call, they should be there. I added them to the 'SwiftAndroidNDK.h'. All these changes are in the latest commit. Is there anything else that you think is missing before this change can be merged? |
@swift-ci please test |
@swift-ci please test source compatibility |
stdlib/public/Platform/SwiftBionic.h
Outdated
#include <stdarg.h> | ||
#include <stdbool.h> | ||
#include <stddef.h> | ||
#include <tgmath.h> |
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.
These are not part of Bionic though, are they usually required by the Bionic headers?
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, I dropped them!
@swift-ci please test |
@swift-ci please test source compatibility |
I'm kicking off a compiler validation suite run natively on Android now, will let you know by tonight.
Huh, those tests built fine for me without those imports, I will apply your new commit and re-test.
What about Give me a couple days to build and test the Swift toolchain natively on Android with your latest commits and I will let you know what I find. |
Alright, ran the compiler validation suite with the latest version of these two pulls of yours: looks like your import additions to the tests fixed 20 of the 44 failing tests I mentioned earlier. Another dozen are C++ interop tests that pass with the The rest are probably like the
I will look into those other validation suite regressions and get back to you tomorrow. In the meantime, let me know about that last |
This commit doesn't install them yet, they will be installed and a whole Android NDK module will be built in a follow-up commit This module map covers the Bionic C standard library and other Posix headers used in the Android NDK
78b38cd
to
7fa3a41
Compare
@finagolfin thanks!
That was indeed one I missed, thanks! Added it to the module map and the header.
Thanks, I updated this test case too and included it in the sibling PR: #72634 . Also addressed your comments there related to other changed tests. |
@swift-ci please test |
I updated to the latest version of these two pulls and ran the compiler validation suite again, got the same results. I didn't get to much else though, like going through all the failing tests, will do that this weekend and let you know by Monday. |
Thanks, sounds good! |
Could you also list the failing tests you saw? |
Sure, two tests fail because of the issue I raised in #73445, as a result of the frontend patch I showed there: As mentioned, 11 C++ Interop tests that passed natively on Android with the
Since only the last two are executable tests, do the first nine all pass for you when cross-compiling from linux in host-test mode with these pulls? I will look into whether Termux is modifying those Bionic headers in some way that gets them to fail with your new Android module. The remaining eight executable tests I just fixed and submitted as a pull against #72634, hyp#1. |
I'm unable to reproduce these two failures, they pass when testing for android on a regular linux setup setup (cross-compiled stdlib being tested with toolchain built with all changes + extra tools built locally). I'm not sure I fully understand that issue since it appears to be also Termux-specific but why is there still the Glibc dependency in that case?
Thanks! I tested each individually and they're passing on a regular linux setup (cross-compiled stdlib being tested with toolchain built with all changes + extra tools built locally). Using ndk-r26d. The cyclic dependency error is #72161 (comment) right?
Thank you, I will add them to the second PR. @finagolfin Do you think I can merge these changes now? The remaining failures appear to be Termux-specific if I understand correctly. I just ordered a device and it will arrive in two days, so I will setup execution tests and will be able to fix the Termux interop failures as well. Fwiw I think that the interop cyclic dependency error on Termux is fixable for sure, so I will be able to fix it once I have the device setup. |
Yes, it only happens because I'm modifying the trunk frontend as shown there, won't happen otherwise. The issue is the stdlib has As stated in that issue, that is an unrelated edge case on all platforms that this Android pull simply uncovered when building natively, so don't worry about it. I will see about fixing that separately.
Yep, I'll look into those C++ interop issues in Termux later, since you're not seeing them with the NDK.
Great, you will need extra Termux-specific patches to build the Swift toolchain. I've been meaning to document that on my Android SDK github repo, will do so now that you want to try it.
The Swift compiler validation suite appears to be in good shape with your pulls, but I'm still seeing those 47 foundation tests regressing with your latest patches. Give me a day or two to look into those, probably not hard to fix. The good news is that I've been running the tests for other parts of the toolchain with your pulls, and no regressions in the tests for libdispatch, XCTest, and llbuild so far, after modifying them to |
This module map covers the Bionic C standard library and other Posix headers used in the Android NDK