-
Notifications
You must be signed in to change notification settings - Fork 129
Add support for Musl libc #133
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
Conversation
Since Musl is sufficiently different from Glibc (see https://wiki.musl-libc.org/functional-differences-from-glibc.html), it requires a different import, which now should be applied to files that have `import Glibc` in them.
|
|
||
| #if !os(Windows) | ||
| #if canImport(Musl) | ||
| internal var _O_ACCMODE: CInt { 03|O_SEARCH } |
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.
Copied verbatim from the header since ClangImport doesn't support C macros that expand to expressions.
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.
Yuck. The original 03 is in octal. It so happens that 038 and 0310 have the same value, but that's pretty horrid. I think I would prefer that if we're doing to write this in Swift code, we explicitly write 0o03 or 0x03 rather than just 03, because the latter looks like octal if you're used to C family languages, but in Swift it is in fact decimal with a leading zero.
|
@swift-ci test |
| #if os(macOS) || os(iOS) || os(watchOS) || os(tvOS) | ||
| import Darwin | ||
| #elseif os(Linux) || os(FreeBSD) || os(OpenBSD) || os(Android) | ||
| #elseif canImport(Glibc) |
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.
This is a big switch from using the OS name to using a sort of capability. Would it make sense to move this to after the #elseif os(Windows) branch?
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.
We should do the same in the other files where there's a sequence of if-os and if-canImport.
|
@swift-ci test |
| #elseif canImport(Glibc) | ||
| import Glibc | ||
| #elseif canImport(Musl) | ||
| import CSystem |
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.
in other spots it is imported with @_implementationOnly, also, do we need this in the Glibc case as well?
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.
Not sure about this one, I'd stick to how other imports are done in this file for consistency.
| @_implementationOnly import CSystem | ||
| import Glibc | ||
| #elseif canImport(Musl) | ||
| import CSystem |
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.
@_implementationOnly import CSystem?
| #elseif os(Windows) | ||
| import CSystem | ||
| import ucrt | ||
| #elseif canImport(Glibc) |
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.
much better!
|
@swift-ci test |
|
|
||
| #if !os(Windows) | ||
| #if canImport(Musl) | ||
| internal var _O_ACCMODE: CInt { 03|O_SEARCH } |
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.
Yuck. The original 03 is in octal. It so happens that 038 and 0310 have the same value, but that's pretty horrid. I think I would prefer that if we're doing to write this in Swift code, we explicitly write 0o03 or 0x03 rather than just 03, because the latter looks like octal if you're used to C family languages, but in Swift it is in fact decimal with a leading zero.
|
@swift-ci test |
Since Musl is sufficiently different from Glibc (see https://wiki.musl-libc.org/functional-differences-from-glibc.html), it requires a different import, which now should be applied to files that have
import Glibcin them.