Update Swift Package manifest to fix x86_64-swift-linux-musl build#377
Open
ilia3546 wants to merge 1 commit intoweichsel:developmentfrom
Open
Update Swift Package manifest to fix x86_64-swift-linux-musl build#377ilia3546 wants to merge 1 commit intoweichsel:developmentfrom
ilia3546 wants to merge 1 commit intoweichsel:developmentfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Updated the Swift Package manifest to use platform-conditional dependencies instead of compile-time
#if canImport(Compression)checks, fixing build issues on Linux platforms including x86_64-swift-linux-musl.Problem
The previous approach using
#if canImport(Compression)had a critical issue:Compile-time evaluation limitation:
canImport(Compression)is evaluated when Package.swift is compiled, not when the actual target is built. This created unreliablebehavior on Linux, especially with musl libc.
Implicit platform handling: The approach relied on compile-time checks rather than explicit platform declarations, preventing SPM from correctly handling
platform-specific dependencies.
Reproduction
To reproduce the issue, try building any SPM executable package with ZIPFoundation as a dependency:
The build would fail with the old manifest structure.
Solution
The new approach uses SPM's native
.when(platforms:)conditional dependency system:Explicit platform targeting: Clearly defines which platforms need CZLib (
[.linux, .openbsd]) vs. native Compression framework.Proper dependency resolution: SPM resolves dependencies correctly before compilation, knowing exactly what's needed for each platform.
Single unified target structure: One target definition with conditional dependencies instead of duplicated configurations.
Changes
#if canImport(Compression)conditional compilation_GNU_SOURCEconditionally for Linux platforms