-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Android API level needs to be visible in Swift #76671
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
Comments
@finagolfin @compnerd Could use your thoughts here. :) |
There's another option of mapping OS release to API level, but that isn't very precise either. The difference between the iOS and Android here is that the information is statically available for Android. IIRC the OS check on Darwin was static with |
See my "alternatives" section, yeah. |
It is possible. The macro For more information, see this guide and refer to the implementation details in android/versioning.h and time.h. |
We'd need some way for the underlying machinery of |
It's something Android porters like @drodriguez have talked about for years, but nobody got around to adding. Since Android usually builds with the API version in the build triple, it should be easy to pass in at compile time to Swift code, just as it is currently passed in by SwiftPM when compiling C/C++ code with clang and Swift's |
This is definitely something that would be nice to have. This is similar to the long standing feature request on Windows for availability support. I think that would allow us to surface both of these in the best way possible, but that isn't something that we can take on just right now with the other items that are outstanding. |
I think we would also want the PSG to chime in if we were ready to pursue a change here for any given platform. |
While I agree it would be very useful, we unfortunately don't have the bandwidth to tackle it anytime in the near future. |
Ok, for me personally, this is a nice to have feature but not a priority, so I'm sounding the community out to see who is willing to put the time in to implement and push this through. Just for completeness, pinging @ephemer and @mstokercricut to see if either of you have any input. |
Thanks for the ping. We would also like to see this, but it's not something we actively have a current use-case for. |
Yes, I think this is potentially something PSG is interested in. Personally I'd rather see |
I specifically suggested |
Alright, looks like this is just waiting on someone to pitch and implement it then. |
Motivation
In Android, new API is guarded by API level. For instance,
timespec_get()
was introduced with Android API level 29. API level can be determined by checking the value of__ANDROID_API__
defined in the system header<android/api-level.h>
.This value is not visible to Swift, meaning that code that is conditionally dependent on the availability of some API needs to check for it (and provide a fallback path!) in C or C++ rather than in Swift.
Proposed solution
I propose we teach the compiler, when targetting Android, to expose the API level similar to how the Swift language mode and compiler version are exposed:
Alternatives considered
#available(Android 29, *)
) would have a similar problem.Additional information
No response
The text was updated successfully, but these errors were encountered: