Skip to content
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

Use the new Android overlay and Bionic module from Swift 6 #2784

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

finagolfin
Copy link
Contributor

Motivation:

Get this repo building again for Android with the new overlay

Modifications:

  • Import the new module or overlay wherever Glibc is used
  • Keep this repo building with Swift 5 by duplicating some declarations

Result:

All the same tests keep passing on my Android CI, finagolfin/swift-android-sdk#158

I imported the smaller Bionic module where possible, and only used Android when files invoked C functions not in the new Bionic module, swiftlang/swift#72161.

let IFF_BROADCAST: CUnsignedInt = numericCast(Android.IFF_BROADCAST.rawValue)
let IFF_POINTOPOINT: CUnsignedInt = numericCast(Android.IFF_POINTOPOINT.rawValue)
let IFF_MULTICAST: CUnsignedInt = numericCast(Android.IFF_MULTICAST.rawValue)
#else
let IFF_BROADCAST: CUnsignedInt = numericCast(SwiftGlibc.IFF_BROADCAST.rawValue)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Swift 5 has canImport(Glibc) and SwiftGlibc on Android, while Swift 6 no longer uses those but has canImport(Bionic) and canImport(Android) instead. Both have os(Android).

To keep this code compiling for both Swift 5 and 6, I duplicated these C declarations. Whenever NIO stops supporting Swift 5, I will submit a pull to rip these out.

internal static let EPOLLIN: CUnsignedInt = numericCast(CNIOLinux.EPOLLIN)
internal static let EPOLLOUT: CUnsignedInt = numericCast(CNIOLinux.EPOLLOUT)
internal static let EPOLLERR: CUnsignedInt = numericCast(CNIOLinux.EPOLLERR)
internal static let EPOLLRDHUP: CUnsignedInt = numericCast(CNIOLinux.EPOLLRDHUP)
internal static let EPOLLHUP: CUnsignedInt = numericCast(CNIOLinux.EPOLLHUP)
#if canImport(Android)
internal static let EPOLLET: CUnsignedInt = 2147483648
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously, all these constants couldn't be automatically set by the ClangImporter from the C headers, but now only this one constant couldn't, because it's the only one that's a C macro.

Comment on lines 89 to +95
#if os(Android)
#if canImport(Android)
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't we just use the same conditionals as above? Instead of checking for the os we just check for canImport(Glibc) and canImport(Android)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The OS check works when building for Android on both Swift 5 and 6 and also includes the Android armv7 definitions on line 100 below. It cannot be replaced because then canImport(Glibc) would be true and entered into on linux too, and the #elseif os(Linux) on line 103 would be skipped on most linux distros that use glibc.

Copy link
Member

@FranzBusch FranzBusch left a comment

Choose a reason for hiding this comment

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

@finagolfin Thanks for the PR. Relatedly I have been wondering if we could setup GH action based Android testing in this repo in the long term?

I would interested to hear what your thoughts are and how we can make developing for Android as easy as installing a cross compilation SDK.

@finagolfin
Copy link
Contributor Author

Thanks for the quick review, a github action CI workflow for Android on this repo would be great. 😄

I plan to start distributing an Android SDK bundle, which would obsolete the additional local configuration required for my current Android SDK, and then look into putting together a custom github build action that any Swift package can use with that new SDK bundle for their own CI, finagolfin/swift-android-sdk#127.

If you would like, I can submit an Android CI workflow for this repo when that SDK bundle is ready. However, my daily Android CI already tests this repo and I quickly upstream most changes needed, so I'm fine with that cadence too. It really just depends if you want to know about Android breaks with every pull, and given that Android is not an officially supported platform, I'm fine with not imposing that additional requirement on NIO pull authors for now.

@FranzBusch
Copy link
Member

If you would like, I can submit an Android CI workflow for this repo when that SDK bundle is ready. However, my daily Android CI already tests this repo and I quickly upstream most changes needed, so I'm fine with that cadence too. It really just depends if you want to know about Android breaks with every pull, and given that Android is not an officially supported platform, I'm fine with not imposing that additional requirement on NIO pull authors for now.

In the fullness of time I would like to have Android support in all the repos as well. This would require a few things:

  • The cross compilation SDK bundle
  • Pitching Android as an officially supported language for Swift.

Once we tackle the latter we might be able to distribute this cross compilation bundle on swift.org which would unlock us testing this in our GitHub Actions.

@finagolfin
Copy link
Contributor Author

Pitching Android as an officially supported language for Swift

Already done and I think provisionally agreed to by the core team members I talked to. I will know for sure once I submit it as part of the official CI, which has only been delayed by me.

Once we tackle the latter we might be able to distribute this cross compilation bundle on swift.org which would unlock us testing this in our GitHub Actions.

Yes, once I'm distributing my own Android SDK bundle and then if and when Android becomes officially supported, distributing an official Android SDK bundle like the current official linux static SDK bundle would be the next step.

We can try setting up an Android CI action for this and other Swift repos then, let's see.

Motivation:

Get this repo building again for Android with the new overlay

Modifications:

- Import the new module or overlay wherever `Glibc` is used
- Keep this repo building with Swift 5 by duplicating some declarations

Result:

All the same tests keep passing on my Android CI, finagolfin/swift-android-sdk#158
@finagolfin
Copy link
Contributor Author

Rebased and fixed merge conflicts, anything holding up review here?

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.

None yet

2 participants