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

Add support for Musl libc #4779

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Add support for Musl libc #4779

wants to merge 4 commits into from

Conversation

MaxDesiatov
Copy link
Contributor

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.

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.
@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

CoreFoundation/Base.subproj/CoreFoundation_Prefix.h Outdated Show resolved Hide resolved
CoreFoundation/Base.subproj/CoreFoundation_Prefix.h Outdated Show resolved Hide resolved
Copy link
Contributor

@finagolfin finagolfin left a 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.

@MaxDesiatov
Copy link
Contributor Author

@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__)
Copy link
Contributor

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.

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

1 similar comment
@MaxDesiatov
Copy link
Contributor Author

@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__)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

@MaxDesiatov
Copy link
Contributor Author

@swift-ci test windows

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.

4 participants