swift-collections: Missing required module '_FoundationCollections' when building with the Static Linux SDK
When building a Swift package using the September 11, 2024 Swift 6 toolchain and matching Static Linux SDK, compilation fails with error: missing required module '_FoundationCollections'
% xcrun --toolchain swift swift build --swift-sdk aarch64-swift-linux-musl
Building for debugging...
error: emit-module command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: missing required module '_FoundationCollections'
<unknown>:0: error: missing required module '_FoundationCollections'
System info
OS: macOS 14.6.1 Xcode: 16.0 public release, 16.0 release candidate, 15.4 Swift: Apple Swift version 6.0-dev (LLVM fc1036139c5e562, Swift 5bbf725fd958d34) Target: arm64-apple-macosx14.0 Static Linux SDK swift-6.0-DEVELOPMENT-SNAPSHOT-2024-09-11-a_static-linux-0.0.1
Package
Package.swift
// swift-tools-version: 6.0
import PackageDescription
let package = Package(
name: "FoundationTest",
targets: [
.executableTarget(name: "FoundationTest")
]
)
Sources/FoundationTest/FoundationTest.swift
import Foundation
@main
struct App {
static func main() async throws {
print("Hello World!")
}
}
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 27 (14 by maintainers)
Commits related to this issue
- Revert "github: Switch build to Swift 6.0 release" Linux static builds are broken in the release version: https://github.com/apple/swift-collections/issues/420 This reverts commit d574262ca25d10558e... — committed to remko/age-plugin-se by remko 2 years ago
- [Build] Use `SWIFT_SYSTEM_NAME` rather than just lowercasing. Lowercasing `CMAKE_SYSTEM_NAME` to find the name Swift uses for a platform is not guaranteed to work. Instead, use the `SWIFT_SYSTEM_NAM... — committed to al45tair/swift-collections by al45tair 2 years ago
- [Build] Use `SWIFT_SYSTEM_NAME` rather than just lowercasing. Lowercasing `CMAKE_SYSTEM_NAME` to find the name Swift uses for a platform is not guaranteed to work. Instead, use the `SWIFT_SYSTEM_NAM... — committed to al45tair/swift-collections by al45tair 2 years ago
- [Build] Use `SWIFT_SYSTEM_NAME` rather than just lowercasing. Lowercasing `CMAKE_SYSTEM_NAME` to find the name Swift uses for a platform is not guaranteed to work. Instead, use the `SWIFT_SYSTEM_NAM... — committed to al45tair/swift-collections by al45tair 2 years ago
Swift 6.0 Nightly should resolve this issue with temporary workaround in the build script.
error: missing required module '_FoundationCollections'We would like to hear feedback if this resolves the issue for you.
Toolchain: https://download.swift.org/swift-6.0-branch/xcode/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-09-17-a/swift-6.0-DEVELOPMENT-SNAPSHOT-2024-09-17-a-osx.pkg Static SDK: https://download.swift.org/swift-6.0-branch/static-sdk/swift-6.0-DEVELOPMENT-SNAPSHOT-[…]PSHOT-2024-09-17-a_static-linux-0.0.1.artifactbundle.tar.gz (b34ae1758ba66f2cd0d8c7e93b504df199905ddd69dabc7e6b686542b2c43547)
Note: We should not close this issue until the proper fix is merged into swift-collections repo.
Having said that I thought @etcwilde was working on it, I went looking. The problem is that
swift-collectionsis trying to work out the system name by lowercasing theCMAKE_SYSTEM_NAME, but that fails for the Static SDK for Linux because the system name there needs to belinux-static. The other Foundation components accept that via the CMake variableSWIFT_SYSTEM_NAME, which gets set by Swift when it’s doing the build, butswift-collectionsignores that.I’ll have some PRs up tomorrow my time to fix that and a couple of other things I found along the way.
Thank you. The temporary workaround in the 9/17 toolchain and static SDK appears to be working, the test code compiles successfully.
I can also confirm the 9.17 toolchain + Static Linux SDK appears to resolve the
_FoundationCollectionsbuild issue.I also wanted to mention that there appears to be another build issue with the Swift 6 toolchain (9.17 version) + SDK issue with SwiftNIO. That issue is reported here: https://github.com/apple/swift-nio/issues/2893
Many thanks!
The website issue should be resolved now, thanks for letting me know.
The warning is a known issue with the modulewrap program (rdar://115918181); it’s harmless, but annoying. (Update: I just raised a PR to get rid of it)
The missing
swift-autolink-extractis almost certainly, as you say, because they’re using the Xcode toolchain. Updating the documentation isn’t a bad idea, but let’s make sure everything works first.@al45tair should we move this issue over to the swift-collections repo if we need to make the CMake fix there?
cc @lorentey since this likely entails tagging a new swift-collections version for the toolchain build to pickup with CMake-only changes