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

Support for Static Linux SDK Based on Musl Instead of Glibc #1058

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

AnneBlair
Copy link

Hello,

I am currently working on a project that requires the use of a static Linux SDK. We are opting to use Musl instead of Glibc due to its excellent support for static linking and its permissive licensing, which simplifies the distribution of statically linked executables.

To ensure compatibility with Musl, I suggest a modification in the conditional compilation statements for importing C libraries. Here is the current code:

#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(WinSDK)
import WinSDK
#endif

And here is the proposed change:

#if canImport(Darwin)
import Darwin
#elseif canImport(Glibc)
import Glibc
#elseif canImport(Musl)
import Musl
#elseif canImport(WinSDK)
import WinSDK
#endif

This change will allow the framework to dynamically check for the availability of Glibc or Musl, thus supporting environments built with Musl. This would greatly enhance the flexibility and usability of SwifterSwift in various Linux environments.

For further reference on static linking in Linux, you can visit the official Swift documentation:
Static Linux Getting Started.

Thank you for considering this enhancement.

@nathanfallet
Copy link
Collaborator

Any way to add tests so we are sure everything works with Musl too? (Maybe adding a workflow or something to cover this case)

@AnneBlair
Copy link
Author

Add Static Linux SDK Build Verification for Swift 6.0.2

While I have verified the build locally, I am not very familiar with the GitHub submission verification process. This pull request introduces a build verification process using the Static Linux SDK for Swift 6.0.2 on macOS environments. The key component used is the Static Linux SDK, which can be obtained from Swift.org. This ensures that our codebase remains compatible with Linux platforms using Musl as the standard library.

Setup Steps:

  1. Install the Static Linux SDK for Swift as described in the Swift Static Linux Getting Started Guide.

  2. List the available Swift SDKs using the command:

    swift SDK list
  3. Set the environment to use Swift 6.0.2:

    export PATH="/Library/Developer/Toolchains/swift-6.0.2-RELEASE.xctoolchain/usr/bin:$PATH"
  4. Verify the Swift version:

    swift --version

    Expected output:

    Apple Swift version 6.0.2 (swift-6.0.2-RELEASE)
    Target: x86_64-apple-macosx14.0
    
  5. Build the project using:

    swift build -v

This setup ensures that our Swift projects are correctly built using the specified Static Linux SDK, which is crucial for maintaining cross-platform compatibility.

@krzyzanowskim krzyzanowskim merged commit d4db480 into krzyzanowskim:main Dec 6, 2024
2 checks passed
@krzyzanowskim
Copy link
Owner

thank you!

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