-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Add support for Musl libc #4779
base: main
Are you sure you want to change the base?
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.
@swift-ci test |
@swift-ci test |
@swift-ci test windows |
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.
Should work fine on Android and other platforms, but I agree with Saleem about shortening to defined(__GLIBC__)
in four of those C conditions.
@swift-ci test |
@@ -1675,7 +1675,7 @@ CFDictionaryRef __CFGetEnvironment() { | |||
extern char **environ; | |||
char **envp = environ; | |||
#elif TARGET_OS_LINUX | |||
#if !defined(environ) && !TARGET_OS_ANDROID | |||
#if !defined(environ) && !TARGET_OS_ANDROID && defined(__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.
Glibc isn't defined on Android, so you can remove the Android check.
@swift-ci test |
@swift-ci test windows |
1 similar comment
@swift-ci test windows |
@@ -562,7 +564,7 @@ CF_CROSS_PLATFORM_EXPORT int _CFOpenFile(const char *path, int opts); | |||
static inline int _direntNameLength(struct dirent *entry) { | |||
#ifdef _D_EXACT_NAMLEN // defined on Linux | |||
return _D_EXACT_NAMLEN(entry); | |||
#elif TARGET_OS_ANDROID | |||
#elif TARGET_OS_ANDROID || !defined(__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.
Won't this activate this line for the BSDs and all other libcs? No way to just enable this for Musl alone?
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.
Musl provides no macro we could reliably check for.
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.
Would it make sense to add one in this repo then, something like TARGET_LIBC_MUSL
using this SO answer? Because this is technically wrong: glibc uses the _D_EXACT_NAMLEN
branch above and has nothing to do with this condition.
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.
Couldn't we just write __linux__
instead? Android and Musl are both Linux, after all.
We could even do
#elif defined(__linux__) && !defined(_DIRENT_HAVE_D_NAMLEN)
which would then mean if Musl or Android added d_namlen
in the future, things would Just Work.
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 don't particularly like the attempts at detecting Musl in that Stack Overflow answer; Musl should probably define some macros of its own — it should ideally be possible to test not just for Musl but to check the Musl version 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.
Couldn't we just write
__linux__
instead?
That would work and be fine here, but I was trying to come up with a more general solution.
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 think the general solution is to get musl to add __MUSL__
(and ideally __MUSL_MINOR__
and __MUSL_PREREQ()
to go with it) in <features.h>
. I have a patch for that locally — I'll see if we can upstream it.
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.
Hmmm: https://www.openwall.com/lists/musl/2013/03/29/13 doesn't sound good.
@swift-ci test windows |
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.