Skip to content

Fix swift-corelibs-foundation for Musl compatibility #4876

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

Merged
merged 9 commits into from
Feb 27, 2024

Conversation

al45tair
Copy link
Contributor

@al45tair al45tair commented Feb 22, 2024

A few fixes are needed for swift-corelibs-foundation to make it work with Musl and the new fully-static Linux support I’m adding to Swift.

As with swift-corelibs-dispatch, we need a way to set the Swift libdir name that isn’t just lowercasing CMAKE_SYSTEM_NAME (because that won’t always work).

Musl doesn’t have strlcpy() or strlcat(), so we need to handle that (we should get CMake to look for these). It also doesn’t have __GLIBC_PREREQ (since it isn’t Glibc).

Another issue is that in order to support static linking, we need to make sure we’re linking with all the dependencies we need (we need to add libz, libcrypto and libssl in a couple of places, as well as libfts in the case of Musl. We also need to locate librt when we’re statically linking.

rdar://123381867

This lets us override the library subdir name when its derivation
isn't straightforwardly just the lower-case version of `CMAKE_SYSTEM_NAME`.

rdar://123381867
This is needed when we're statically linking, otherwise we can't
pull in Dispatch because we won't have RT::rt as a CMake target.

rdar://123381867
Musl doesn't have fts built-in; it's in a separate library, which
we need to add if we're going to use it.

rdar://123381867
@al45tair al45tair requested a review from MaxDesiatov February 22, 2024 10:50
@al45tair
Copy link
Contributor Author

@swift-ci Please test

@al45tair al45tair requested a review from iCharlesHu February 22, 2024 10:52
@al45tair
Copy link
Contributor Author

Hmmm. OK, looks like I need to tweak the auto linking stuff a bit.

@MaxDesiatov MaxDesiatov requested a review from parkera February 22, 2024 14:22
@parkera
Copy link
Contributor

parkera commented Feb 22, 2024

What do we do about ICU data when statically linking?

@al45tair
Copy link
Contributor Author

:-) Currently I just build it all into static libraries and link it.

For static linking, we need to list all the dependencies of libcurl
or libxml2 that we're using.  This differs from dynamic linking,
because in the latter case that information is in the shared objects,
which is not true in the statically linked case.

rdar://123381867
Use CMake to check for the existence of strlcpy(), strlcat() and
issetugid() before using them.

rdar://123381867
We might be using musl instead, which doesn't have __GLIBC_PREREQ as
it isn't Glibc.

rdar://123381867
This means we're in the same boat as for Android - we need to use
`strlen`.

rdar://123381867
This is mostly checking for and importing the `Musl` module and,
where necessary, using it instead of the `Glibc` module.

rdar://123381867
@al45tair
Copy link
Contributor Author

@swift-ci Please test

@MaxDesiatov
Copy link
Contributor

@swift-ci test windows

We need to include CheckSymbolExists on Windows as well as on Linux.

rdar://123381867
@al45tair
Copy link
Contributor Author

al45tair commented Feb 26, 2024

@swift-ci Please test Linux platform

@al45tair
Copy link
Contributor Author

@swift-ci Please test Windows platform

@al45tair
Copy link
Contributor Author

@swift-ci test windows

1 similar comment
@al45tair
Copy link
Contributor Author

@swift-ci test windows

@al45tair al45tair merged commit 5a1db79 into swiftlang:main Feb 27, 2024
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.

3 participants