Trouble cross compiling with Swift 6.0

Hi,

I was trying to cross compile a web server based on SwiftNIO. I get the following error when trying to cross compile SwiftNIO by it's self. I have downloaded the command line tools update released today and restarted my computer after. Any suggestions how to update Dispatch?

swift build -c release --swift-sdk x86_64-swift-linux-musl
swift build --swift-sdk x86_64-swift-linux-musl

swift-nio/Sources/NIOCore/ByteBuffer-aux.swift:15:8: error: compiled module was created by a different version of the compiler ''; rebuild 'Dispatch' and try again: /Users/zane/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/x86_64/Dispatch.swiftmodule

MacOS 15.0 (24A335)
sdk checksum:
7984c2cf175bde52ba6ea1fcbe27fc4a148a6237c41c719209c9288ed3ceb652
swift:
swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2) Target: arm64-apple-macosx15.0

Thanks,
Zane

Update, having the same issue on different Mac. Can't seem to build the hello world example listed either.

test swift build --swift-sdk x86_64-swift-linux-musl
Building for debugging...
<unknown>:0: warning: libc not found for 'x86_64-swift-linux-musl'; C stdlib may be unavailable
<unknown>:0: warning: libc not found for 'x86_64-swift-linux-musl'; C stdlib may be unavailable
error: unableToFind(tool: "swift-autolink-extract")

I'm kinda new at this should this have been filed as an issue instead?

Thanks,
Zane

It looks like there's something seriously wrong with your install, if it cannot even find the C stdlib. Try removing any SDKs you have installed and just reinstalling the latest 6.0 SDK. If that still doesn't work, add the -v flag and copy-paste the full verbose output here.

Actually, Swift SDK for Static Linux cannot be used with Xcode toolchain. You need to install an Open Source toolchain from swift.org. Could you install Swift 6.0 OSS toolchain by following Swift.org - macOS Package Installer and try again?

1 Like

Yep, that was the problem. I assumed they were roughly the same and glossed over that step. Still a crash when compiling NIO but I will submit that stack trace as an issue.

Thank you so much, I appreciate the help.

I'm running into the same issue, even when specifying an OSS toolchain (just following the swift package init example):

swift build --toolchain /Library/Developer/Toolchains/swift-6.0.3-RELEASE.xctoolchain  --swift-sdk x86_64-swift-linux-musl
objc[33800]: Class _TtC19CompilerSwiftSyntax16BumpPtrAllocator is implemented in both /Library/Developer/Toolchains/swift-6.0.3-RELEASE.xctoolchain/usr/lib/swift/host/libSwiftSyntax.dylib (0x1053e5138) and /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftSyntax.dylib (0x103d52138). One of the two will be used. Which one is undefined.
objc[33800]: Class _TtC19CompilerSwiftSyntax23SourceLocationConverter is implemented in both /Library/Developer/Toolchains/swift-6.0.3-RELEASE.xctoolchain/usr/lib/swift/host/libSwiftSyntax.dylib (0x1053e5350) and /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftSyntax.dylib (0x103d52350). One of the two will be used. Which one is undefined.
objc[33800]: Class _TtCV19CompilerSwiftSyntax6Syntax4Info is implemented in both /Library/Developer/Toolchains/swift-6.0.3-RELEASE.xctoolchain/usr/lib/swift/host/libSwiftSyntax.dylib (0x1053e54b0) and /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftSyntax.dylib (0x103d524b0). One of the two will be used. Which one is undefined.
[…more of the same; truncated]
Building for debugging...
<unknown>:0: warning: libc not found for 'x86_64-swift-linux-musl'; C stdlib may be unavailable
<unknown>:0: warning: libc not found for 'x86_64-swift-linux-musl'; C stdlib may be unavailable
clang: warning: argument unused during compilation: '-pie' [-Wunused-command-line-argument]
[7/7] Linking graph-server-core
Build complete! (0.83s)

Looks like something might be trying to get swift build to still use the default Xcode toolchain?

I don't think you are, Build complete! means it built fine. :smiley: Those warnings may have been introduced recently and likely are spurious, as I see them on my Android CI too for builds that then work fine, which wouldn't be the case if the compiler genuinely couldn't find the libc.

1 Like

One thing you could try is to regenerate Dispatch by compiling it with your compiler then open a volume and make a temporary version where you splice your compiler replacing /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/x86_64/Dispatch.swiftmodule with the regenerated version. If that doesn’t work then reinstall the compiler and run checksums to validate the copy.

I suggest that you bring this up with someone who is on the Compiler Workgroup to help you work through this better.

Indeed it does work! I was running into some other issues building a particular library, but it turns out those issues were specific to that library instead of this toolchain.