-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
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 |
export * | ||
} | ||
export * | ||
link "z" |
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.
One thing I noticed is that this line means that all libraries and executables built with this Android overlay are now newly linked against libz.so
, despite basically none of them needing it:
> llvm-readelf -d usr/lib/swift/android/libFoundation.so | ag NEEDED
0x0000000000000001 (NEEDED) Shared library: [libswiftDispatch.so]
0x0000000000000001 (NEEDED) Shared library: [libicuuc.so.74]
0x0000000000000001 (NEEDED) Shared library: [libicui18n.so.74]
0x0000000000000001 (NEEDED) Shared library: [libicudata.so.74]
0x0000000000000001 (NEEDED) Shared library: [libdispatch.so]
0x0000000000000001 (NEEDED) Shared library: [libBlocksRuntime.so]
0x0000000000000001 (NEEDED) Shared library: [libswiftAndroid.so]
0x0000000000000001 (NEEDED) Shared library: [libswiftCore.so]
0x0000000000000001 (NEEDED) Shared library: [libswift_Concurrency.so]
0x0000000000000001 (NEEDED) Shared library: [libswift_StringProcessing.so]
0x0000000000000001 (NEEDED) Shared library: [libswift_RegexParser.so]
0x0000000000000001 (NEEDED) Shared library: [libm.so]
0x0000000000000001 (NEEDED) Shared library: [libz.so.1]
0x0000000000000001 (NEEDED) Shared library: [liblog.so]
0x0000000000000001 (NEEDED) Shared library: [libdl.so]
0x0000000000000001 (NEEDED) Shared library: [libc.so]
What is the great need to add this to the Android overlay? Packages that need this can simply add a separate zlib modulemap.
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.
Hmm this is an interesting point. I suppose they don't really need to, but we would have to take out the zlib headers from the 'Android' module to avoid that. That seems reasonable to me, as users can just include 'zlib' module directly from Swift then. Let me try to see if I can take the zlib headers from the 'Android' module and rerun the tests.
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 removed the 'zlib' header inclusion, and updated the PR, so now zlib link dependency shouldn't be pulled in implicitly.
Looks like you made a mistake? This zlib link is still there in your latest push yesterday.
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.
Oh, I see now that you simply removed the header from the SwiftAndroid
module. I can confirm that this fixes this problem in my latest build.
@finagolfin , thanks for working on swift-corelibs-foundation crash, it looks like they now work on device. I am ready to do Termux testing this week, so would appreciate any pointers or patches that you think I need. Do you think we can move towards getting this merged in the meantime? I would like to land this sooner than later to have better chance of us landing in Swift 6 as well as we're time constrained there. |
Best if you hold off for a bit, as there was a regression in C++ interop a couple months ago when building the trunk Swift compiler in Termux with a prebuilt Swift compiler that uses the Once I know how that turns out, I'll let you know how best to build trunk Swift on Termux.
We're getting there, now that there are no more regressions in the non-Termux tests when building an Android SDK, but I think we should test it on some Swift packages first. For example, I intend to apply your Android overlay patches to my daily Android CI this week, then patch those Swift packages for your new overlay and cross-compile and run all their tests on the Android emulator. You can do the same testing with various Swift packages, since you're able to cross-compile an Android SDK with your Android overlay pulls. I'm building the March 1 trunk source snapshot of SwiftPM natively in Termux right now with your overlay pulls, after which I will run its tests. I think we can get these pulls tested well this week and clean them up, like the zlib issue I mentioned above, now that they're mostly working, but I doubt Swift 6 provides any time pressure. At most, we may have to push merging this to next week, but Swift 6 doesn't ship for four months. Since these two stdlib pulls do not affect any platform but Android and no existing user has complained about them on the forum, should be easy to review and get this into Swift 6 also. The foundation pull is the only one that modifies some common code for all platforms, so may take longer to review. |
sounds good.
Thanks. I will test some packages like https://github.com/thebrowsercompany/swift-firebase which we're planning to build for Android.
Thanks, let's plan to finalize everything for these PRs this week, and will update this PR with the 'zlib' change too. I will see if I can get someone to look at corelibs-foundation so that it will be ready to merge by next week too. Yes, Swift 6 doesn't ship for a few more month but it will be really hard to convince the project owners that this change should land in Swift 6 as the time passes, as they will ultimately be in charge of deciding whether this will be ok to get cherry-picked into Swift 6 or not, and they have a high bar for changes as time gets closer to the release. |
I doubt that will happen. Let's try to get this right, there is no deadline here.
Great, let me know when that's ready, so I can redo some testing with that change.
I know, having had such backport pulls refused in the past, but my understanding is that bar is lower for unofficial platforms like Android, understandably so. Let's just try to get it in when we are confident it's working well, which you can ascertain by building several packages with these patches and running their tests on Android, ie you can put more effort into testing to speed that up if you want. Of course, if you plan to take June off for summer vacation or something, that would be good to know ahead of time. 😉 I'm happy to report that the SwiftPM and Swift Syntax packages have no test regressions out of their thousands of tests each, when built natively in Termux with a March 1 trunk snapshot toolchain with your pulls applied. Next, I will try building a May trunk snapshot compiler with that modified March trunk snapshot toolchain, both natively in the Termux app for Android and by cross-compiling it from linux. Finally, I will apply these patches to my Android CI and run all those packages' tests, which will require porting those packages to your new overlay first. I think these changes are looking pretty good at this point, so let's clean up the remaining loose ends, finish testing, and aim to get the stdlib pulls in next week. About the foundation pull I can't say, as I don't like how we just slapped |
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
7fa3a41
to
dac0739
Compare
I removed the 'zlib' header inclusion, and updated the PR, so now zlib link dependency shouldn't be pulled in implicitly. I didn't see any issues with this. I did some more testing on a couple of packages, like https://github.com/thebrowsercompany/swift-firebase and SQLLite while building them for Android. I didn't run into any issues that are related to this change, albeit swift-firebase has other unrelated build issues for Android related to how we use C++ interoperability, but they're not caused by this change. So based on that additional testing it looks good still. Left an additional comment responding to your comment on #72634 as well, and incorporated your earlier PR against that branch into that PR as well. I would like to proceed with merging this by mid-week this upcoming week. |
This lets us declare constants in the Android platform module using the expected mode_t type
@finagolfin Like you suggested in https://github.com/apple/swift/pull/72634/files#r1615158860, I made the |
I now have these stdlib and foundation pulls running against trunk on my Android CI, finagolfin/swift-android-sdk#151, with all those Swift packages' tests passing on the Android x86_64 emulator once I got them ported over to use your new overlay. Any further iterations on these overlay pulls should be easy to check by simply updating that CI pull and running my Android CI again. Now that this new I'll leave final approval up to @ian-twilightcoder, as I know little about these module maps compared to him, but I don't have any objections to this current version, since it works well when building for Android and fixes C++ Interop tests that had been failing with NDK 26. |
@swift-ci please test |
@swift-ci please test source compatibility |
Planning to submit for 6.0 next? |
@finagolfin yep, will cherry-pick it this week. |
[android] add a module map for Android NDK
This module map covers the Bionic C standard library and other Posix headers used in the Android NDK