Skip to content

[Bug]: Swift Package Manager fails to bundle libswiftCompatibilitySpan.dylib on macOS 26 #417

@Bairum

Description

@Bairum

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

  1. Create or clone a Swift Package with an executable target for macOS
  2. Build using swift build from the command line
  3. 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.app

Additional 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:

  1. Bundle the library: Copy libswiftCompatibilitySpan.dylib to the build output directory alongside the executable when building for macOS, similar to how other Swift runtime libraries are handled.

  2. 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).

  3. Static linking: Consider statically linking the compatibility span code for macOS targets where appropriate.

References

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions