Skip to content

Commit 2ae9e21

Browse files
authored
generator/linux: Use swiftResourcesPath to find framework headers (#139)
Building with a Swift 6.0 SDK fails because the new `_FoundationCShims` framework headers can't be found: <unknown>:0: error: missing required module '_FoundationCShims' The necessary files are present in `$PLATFORM.sdk/usr/lib/swift`, but are not part of the list which is copied to `$PLATFORM.sdk/usr/include`. The Static Linux SDK and WASM SDK generator don't copy these files into /usr/include; instead they set the `swiftResourcesPath` and `swiftStaticResourcesPath` fields in `swift-sdk.json`, which causes the build system to look in those paths for framework headers. We can do the same for Linux SDKs, however we must stop copying the files to `/usr/include`, otherwise the build will fail because the framework header definitions are duplicated: error: redefinition of module 'DispatchIntrospection' 6 | } 7 | 8 | module DispatchIntrospection [system] [extern_c] { | `- error: redefinition of module 'DispatchIntrospection' 9 | header "introspection.h" 10 | export *
1 parent ea3e824 commit 2ae9e21

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ extension SwiftSDKGenerator {
101101
("swift/linux", pathsConfiguration.toolchainDirPath.appending("usr/lib/swift")),
102102
("swift_static/linux", pathsConfiguration.toolchainDirPath.appending("usr/lib/swift_static")),
103103
("swift_static/shims", pathsConfiguration.toolchainDirPath.appending("usr/lib/swift_static")),
104-
("swift/dispatch", sdkDirPath.appending("usr/include")),
105-
("swift/os", sdkDirPath.appending("usr/include")),
106-
("swift/CoreFoundation", sdkDirPath.appending("usr/include")),
107104
] {
108105
try await rsync(from: distributionPath.appending(pathWithinPackage), to: pathWithinSwiftSDK)
109106
}

Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ public struct LinuxRecipe: SwiftSDKRecipe {
115115
toolset.librarian = Toolset.ToolProperties(path: "llvm-ar")
116116
}
117117

118+
public func applyPlatformOptions(
119+
metadata: inout SwiftSDKMetadataV4.TripleProperties,
120+
paths: PathsConfiguration,
121+
targetTriple: Triple
122+
) {
123+
var relativeSDKDir = self.sdkDirPath(paths: paths)
124+
guard relativeSDKDir.removePrefix(paths.swiftSDKRootPath) else {
125+
fatalError("The SDK directory path must be a subdirectory of the Swift SDK root path.")
126+
}
127+
metadata.swiftResourcesPath = relativeSDKDir.appending("usr/lib/swift").string
128+
metadata.swiftStaticResourcesPath = relativeSDKDir.appending("usr/lib/swift_static").string
129+
}
130+
118131
public var defaultArtifactID: String {
119132
"""
120133
\(self.versionsConfiguration.swiftVersion)_\(self.linuxDistribution.name.rawValue)_\(

0 commit comments

Comments
 (0)