-
-
Notifications
You must be signed in to change notification settings - Fork 56k
Description
Bug Report: Swift Package Manager fails to bundle libswiftCompatibilitySpan.dylib on macOS 26
Summary
Swift Package Manager (SPM) does not include libswiftCompatibilitySpan.dylib in build outputs when building macOS executables with Swift 6.2 on macOS 26. This causes binaries to crash immediately on launch with a dyld library loading error.
Environment
- macOS Version: macOS 26.1 (Build 25B78)
- Xcode Version: Xcode 26.0.1 (Build 17A400)
- Swift Version: Apple Swift version 6.2 (swiftlang-6.2.0.19.9 clang-1700.3.19.1)
- Target: arm64-apple-macosx26.0
- Command Line Tools: 26.2
Steps to Reproduce
- Create or clone a Swift Package with an executable target for macOS
- Build using
swift buildfrom the command line - Attempt to run the resulting binary from
.build/arm64-apple-macosx/debug/
Expected Behavior
The built executable should run successfully, with all required Swift runtime libraries either:
- Bundled alongside the executable, or
- Available in system library paths
Actual Behavior
The executable crashes immediately on launch with the following error:
dyld[PID]: Library not loaded: @rpath/libswiftCompatibilitySpan.dylib
Referenced from: <UUID> /path/to/.build/arm64-apple-macosx/debug/ExecutableName
Reason: tried: '/path/to/.build/arm64-apple-macosx/debug/libswiftCompatibilitySpan.dylib' (no such file),
'/path/to/.build/arm64-apple-macosx/debug/libswiftCompatibilitySpan.dylib' (no such file)
Abort trap: 6
Analysis
The binary is linked with @rpath/libswiftCompatibilitySpan.dylib, but SPM does not copy this library to the build output directory.
The library exists at:
/Library/Developer/CommandLineTools/usr/lib/swift-6.2/macosx/libswiftCompatibilitySpan.dylib
Running otool -L on the built binary shows:
@rpath/libswiftCompatibilitySpan.dylib (compatibility version 1.0.0, current version 6.2.0)
However, the rpath does not include the CommandLineTools path, and the library is not copied to the build directory.
Workaround
Manually copy the missing library to the build output or app bundle:
# For debug builds
cp /Library/Developer/CommandLineTools/usr/lib/swift-6.2/macosx/libswiftCompatibilitySpan.dylib \
.build/arm64-apple-macosx/debug/
# For app bundles
cp /Library/Developer/CommandLineTools/usr/lib/swift-6.2/macosx/libswiftCompatibilitySpan.dylib \
MyApp.app/Contents/MacOS/
# or
cp /Library/Developer/CommandLineTools/usr/lib/swift-6.2/macosx/libswiftCompatibilitySpan.dylib \
MyApp.app/Contents/Frameworks/
# Re-sign the app bundle after modification
codesign --force --deep --sign - MyApp.appAdditional Context
Related Issue: App Bundle Requirement
When running Swift executables that use certain macOS frameworks (e.g., UserNotifications), an additional crash occurs if the executable is not run from within a proper .app bundle:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',
reason: 'bundleProxyForCurrentProcess is nil: mainBundle.bundleURL file:///path/to/.build/arm64-apple-macosx/debug/'
This is separate from the library loading issue but compounds the problem for macOS app development with SPM.
Build Methods Tested
| Build Method | Library Issue | Bundle Issue |
|---|---|---|
swift build |
❌ Fails | ❌ Fails |
swift run |
❌ Fails | ❌ Fails |
xcodebuild -scheme X -destination "platform=macOS" |
❌ Fails | ❌ Fails |
| Xcode IDE (Run) | ❌ Fails | ❌ Fails |
| Custom packaging script + manual library copy | ✅ Works | ✅ Works |
Affected Frameworks/Features
The project triggering this bug uses:
- SwiftUI
- UserNotifications
- Sparkle (via SPM binary target)
- Various Apple system frameworks
Suggested Fix
Swift Package Manager should either:
-
Bundle the library: Copy
libswiftCompatibilitySpan.dylibto the build output directory alongside the executable when building for macOS, similar to how other Swift runtime libraries are handled. -
Fix the rpath: Ensure the executable's rpath includes the system location of the Swift compatibility libraries (
/Library/Developer/CommandLineTools/usr/lib/swift-6.2/macosx/or equivalent). -
Static linking: Consider statically linking the compatibility span code for macOS targets where appropriate.
References
- Swift Package Manager: https://github.com/apple/swift-package-manager
- Swift Forums (related discussions on SPM + macOS app bundles)
- Feedback Assistant: (file under Xcode / Swift / Swift Package Manager)
Reproduction Project
A minimal reproduction case can be created with:
// Package.swift
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "SPMLibraryBugDemo",
platforms: [.macOS(.v15)],
targets: [
.executableTarget(
name: "SPMLibraryBugDemo",
dependencies: []
),
]
)// Sources/SPMLibraryBugDemo/main.swift
import Foundation
print("Hello, World!")Build with swift build and attempt to run the output binary directly.
Filed: 2026-01-07
Severity: Major (blocks macOS app development with SPM on Swift 6.2 / macOS 26)