Swift 6 Toolchain + Static Linux SDK Build Issue

I am experiencing a build issue with the swift-6.0-RELEASE toolchain + Static Linux SDK, but only when Xcode 16.0.0 is the selected version of Xcode.

If I select Xcode 15.4.0, for example, then the build "works" up to the point of this known issue: Missing required module '_FoundationCollections' when building with the Static Linux SDK · Issue #420 · apple/swift-collections · GitHub

Here are the highlights:

  • The swift-6.0-RELEASE toolchain and corresponding Static Linux SDK are installed (Swift.org - Install Swift).
  • The TOOLCHAINS environment is set to the swift-6.0-RELEASE toolchain.
  • The app builds using --swift-sdk, e.g. aarch64-swift-linux-musl.

Regarding the application's Package.swift manifest:

  • A project that pulls in Vapor/ SwiftNIO dependencies generates this error (there is a transitive dependency on swift-collections).
  • A project that just pulls in swift-collections generates this error.
  • A project that doesn't have any dependencies doesn't generate this error.
  • A project that pulls in a dependency without a transitive dependency on swift-collections doesn't generate this error.

Perhaps the known swift-collections issue is also causing this same issue??

And... here's a script that sets up the toolchain and kicks off a build.

#!/bin/zsh

set -e

# Valid values:
# - aarch64-swift-linux-musl
# - x86_64-swift-linux-musl
SWIFT_SDK=$1

SWIFT_TOOLCHAIN_NAME="swift-6.0-RELEASE"
SWIFT_TOOLCHAIN_PATH="/Library/Developer/Toolchains/$SWIFT_TOOLCHAIN_NAME.xctoolchain"

export TOOLCHAINS=$(plutil -extract CFBundleIdentifier raw $SWIFT_TOOLCHAIN_PATH/Info.plist)

echo "*****"
echo "***** Swift Toolchain"
echo "*****   Name: $SWIFT_TOOLCHAIN_NAME"
echo "*****   Path: $SWIFT_TOOLCHAIN_PATH"
echo "*****     ID: $TOOLCHAINS"
echo "*****    SDK: $SWIFT_SDK"
echo "*****    SPM: $(swift package --version)"
echo "*****  Xcode: $(xcode-select -p)"
echo "*****"

swift build -c release --swift-sdk $SWIFT_SDK

And here's the script execution showing the error:

$ ./build-swift-custom-toolchain.sh aarch64-swift-linux-musl

*****
***** Swift Toolchain
*****   Name: swift-6.0-RELEASE
*****   Path: /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain
*****     ID: org.swift.600202409101a
*****    SDK: aarch64-swift-linux-musl
*****    SPM: Swift Package Manager - Swift 6.0.0-dev
*****  Xcode: /Applications/Xcode16.0.0.app/Contents/Developer
*****

error: 'vapor': Invalid manifest (compiled with: ["/Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/bin/swiftc", "-vfsoverlay", "/var/folders/9z/n8vjtvf54b13j4vw4zm64k880000gp/T/TemporaryDirectory.NophSp/vfs.yaml", "-L", "/Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-lPackageDescription", "-Xlinker", "-rpath", "-Xlinker", "/Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-target", "arm64-apple-macosx13.0", "-I", "/Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/macosx/testing", "-L", "/Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/macosx/testing", "-plugin-path", "/Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/host/plugins/testing", "-sdk", "/Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk", "-F", "/Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks", "-I", "/Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-L", "/Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib", "-swift-version", "5", "-I", "/Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/pm/ManifestAPI", "-sdk", "/Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk", "-package-description-version", "5.9.0", "/Users/someuser/Developer/Temp/demo/.build/checkouts/vapor/Package@swift-5.9.swift", "-o", "/var/folders/9z/n8vjtvf54b13j4vw4zm64k880000gp/T/TemporaryDirectory.TPf6ZQ/vapor-manifest"])
error: compile command failed due to signal 6 (use -v to see invocation)
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/someuser/Developer/Temp/demo/.build/checkouts/vapor/Package@swift-5.9.swift -target arm64-apple-macosx13.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.0.sdk -I /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/macosx/testing -I /Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -I /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/pm/ManifestAPI -F /Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -vfsoverlay /var/folders/9z/n8vjtvf54b13j4vw4zm64k880000gp/T/TemporaryDirectory.NophSp/vfs.yaml -swift-version 5 -package-description-version 5.9.0 -empty-abi-descriptor -plugin-path /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/host/plugins/testing -resource-dir /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift -module-name main -plugin-path /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain/usr/local/lib/swift/host/plugins -target-sdk-version 15.0 -target-sdk-name macosx15.0 -external-plugin-path /Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode16.0.0.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -o /var/folders/9z/n8vjtvf54b13j4vw4zm64k880000gp/T/TemporaryDirectory.SSez9H/Package@swift-5.9-1.o
1.	Apple Swift version 6.0 (swift-6.0-RELEASE)
2.	Compiling with effective version 5.10
3.	While evaluating request ExecuteSILPipelineRequest(Run pipelines { Mandatory Diagnostic Passes + Enabling Optimization Passes } on SIL for Darwin)
4.	While running pass #2548 SILModuleTransform "MandatorySILLinker".
5.	While deserializing SIL function "$s6Darwin14POSIXErrorCodeO8rawValueACSgs5Int32V_tcfC"
6.	*** DESERIALIZATION FAILURE ***
*** If any module named here was modified in the SDK, please delete the ***
*** new swiftmodule files from the SDK and keep only swiftinterfaces.   ***
module '_errno', builder version '6.0(6.0)/Apple Swift version 6.0 (swift-6.0-RELEASE)', built from swiftinterface, resilient, loaded from '/var/folders/9z/n8vjtvf54b13j4vw4zm64k880000gp/C/clang/ModuleCache/_errno-2S3LNEQ44W3KQ.swiftmodule'
SILFunction type mismatch for '$s6Darwin14POSIXErrorCodeO8rawValueACSgs5Int32V_tcfC': '$@convention(method) (Int32, @thin POSIXErrorCode.Type) -> Optional<POSIXErrorCode>' != '$@convention(method) (Int32, @thin POSIXErrorCode.Type) -> Optional<POSIXErrorCode>'

Switching the Xcode version to Xcode 15.4.0 seems to resolve the error above, but then fails with another known error regarding swift-collections: Missing required module '_FoundationCollections' when building with the Static Linux SDK · Issue #420 · apple/swift-collections · GitHub

$ ./build-swift-custom-toolchain.sh aarch64-swift-linux-musl

*****
***** Swift Toolchain
*****   Name: swift-6.0-RELEASE
*****   Path: /Library/Developer/Toolchains/swift-6.0-RELEASE.xctoolchain
*****     ID: org.swift.600202409101a
*****    SDK: aarch64-swift-linux-musl
*****    SPM: Swift Package Manager - Swift 6.0.0-dev
*****  Xcode: /Applications/Xcode15.4.0.app/Contents/Developer
*****

Building for production...
<unknown>:0: error: missing required module '_FoundationCollections'
<unknown>:0: error: missing required module '_FoundationCollections'
[119/891] Compiling dtls_method.cc

Given the explicit use of the Swift 6 OSS toolchain, I am not sure how/ why the selected Xcode version would come into play, but it appears to have an impact.

Also, I have been successfully using a beta version of the Swift 6 OSS toolchain for a few months (but I also had to set the Xcode version to 15.4.0... was never sure why).

Many thanks in advance.

The Xcode 16 problem is a separate issue and nothing to do with swift-collections.

It's happening because we've accidentally ended up with a Darwin module in the OSS Swift release (essentially, responsibility for the Darwin module has changed and it's now officially part of the OS rather than being part of Swift; we only want a single copy of it, which should now be the one from Xcode 16, but we're ending up with two, which means there are two Darwin.POSIXErrorCode types that are not equal, hence the error messages).

We're working on a fix and should have something available soon.

1 Like

Great! Thank you.

I'm having a different problem, but it really goes under this topic headline.

I followed the installation instructions as far as I can tell, but this is what I get if I try to build:

warning: multiple Swift SDKs match target triple `x86_64-swift-linux-musl` and host triple arm64-apple-macosx14.0, selected one at /Users/hacksaw/Library/org.swift.swiftpm/swift-sdks/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-09-17-a_static-linux-0.0.1.artifactbundle/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-09-17-a_static-linux-0.0.1/swift-linux-musl
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
/Users/hacksaw/src/swiftHTMLLinux/Sources/swiftHTMLLinux/main.swift:23:8: error: compiled module was created by a different version of the compiler ''; rebuild 'Foundation' and try again: /Users/hacksaw/Library/org.swift.swiftpm/swift-sdks/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-09-17-a_static-linux-0.0.1.artifactbundle/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-09-17-a_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/Foundation.swiftmodule/x86_64-swift-linux-musl.swiftmodule
 21 |
 22 |
 23 | import Foundation
swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0

Here's a newer try with nominally more aligned bundles:

21:43 $ swift build --swift-sdk x86_64-swift-linux-musl
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
/Users/hacksaw/src/swiftHTMLLinux/Sources/swiftHTMLLinux/main.swift:23:8: error: compiled module was created by a different version of the compiler ''; rebuild 'Foundation' and try again: /Users/hacksaw/Library/org.swift.swiftpm/swift-sdks/swift-6.0-RELEASE_static-linux-0.0.1.artifactbundle/swift-6.0-RELEASE_static-linux-0.0.1/swift-linux-musl/musl-1.2.5.sdk/x86_64/usr/lib/swift_static/linux-static/Foundation.swiftmodule/x86_64-swift-linux-musl.swiftmodule
 21 |
 22 |
 23 | import Foundation

Others have reported similar errors when cross-compiling from macOS: the reason is either that you are explicitly using the Xcode toolchain, which the static linux SDK doc says not to do, or you are using the OSS toolchain but the build is incorrectly picking up the installed Xcode toolchain instead, as originally reported by Bryan above.

The github issue that he linked has an explanation by Mishal of the two separate issues that people are hitting with the 6.0 static SDK: you are probably hitting the second one. Either install the latest 6.0 Sep. 17 OSS snapshot toolchain for macOS and static SDK and only use the Xcode versions specified there with it, or wait for both issues to be fixed in a likely forthcoming patch release.

2 Likes

Could have sworn I was using the OSS toolchain, but I'll look again. Thanks.

Okay, I tried being very explicit, and got to the FoundationCollectios problem. I'll wait and send pleasantly productive wishes to the team.

The 6.0.1 build works for me, thanks to the builders!