Skip to content

Commit a6aa907

Browse files
committed
generator/linux: Use swiftResourcesPath to find framework headers
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 * This change fixes issue swiftlang#152. Compared to swiftlang#153, the end-to-end tests now pass for all supported Swift versions, distributions and architectures. | SDK | Hello World | Foundation | | ----------------------------------------- | ----------- | ---------- | | ubuntu_aarch64_5.9.2-RELEASE | ok | ok | | ubuntu_aarch64_5.9.2-RELEASE_with-docker | ok | ok | | ubuntu_aarch64_5.10.1-RELEASE | ok | ok | | ubuntu_aarch64_5.10.1-RELEASE_with-docker | ok | ok | | ubuntu_aarch64_6.0.2-RELEASE | ok | ok | | ubuntu_aarch64_6.0.2-RELEASE_with-docker | ok | ok | | | | | | ubuntu_x86_64_5.9.2-RELEASE | ok | ok | | ubuntu_x86_64_5.9.2-RELEASE_with-docker | ok | ok | | ubuntu_x86_64_5.10.1-RELEASE | ok | ok | | ubuntu_x86_64_5.10.1-RELEASE_with-docker | ok | ok | | ubuntu_x86_64_6.0.2-RELEASE | ok | ok | | ubuntu_x86_64_6.0.2-RELEASE_with-docker | ok | ok | | | | | | rhel_aarch64_5.9.2-RELEASE_with-docker | ok | ok | | rhel_aarch64_5.10.1-RELEASE_with-docker | ok | ok | | rhel_aarch64_6.0.2-RELEASE_with-docker | ok | ok | | | | | | rhel_x86_64_5.9.2-RELEASE_with-docker | ok | ok | | rhel_x86_64_5.10.1-RELEASE_with-docker | ok | ok | | rhel_x86_64_6.0.2-RELEASE_with-docker | ok | ok | FAIL1: cannot find /lib/ld-linux-aarch64.so.1 (swiftlang#147) FAIL2: missing required module '_FoundationCShims' (swiftlang#152) Fixes: swiftlang#152 Depends on: swiftlang#153, swiftlang#154
1 parent e690ad4 commit a6aa907

File tree

5 files changed

+20
-68
lines changed

5 files changed

+20
-68
lines changed

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ extension SwiftSDKGenerator {
9797
try await generator.removeRecursively(at: sdkUsrLibPath.appending("python3.10"))
9898

9999
try await generator.removeRecursively(at: sdkUsrLibPath.appending("ssl"))
100-
try await generator.copyTargetSwift(from: sdkUsrLibPath, sdkDirPath: sdkDirPath)
100+
try await generator.copyTargetSwift(from: sdkUsrPath, sdkDirPath: sdkDirPath)
101101
}
102102
}
103103
}
@@ -106,12 +106,10 @@ extension SwiftSDKGenerator {
106106
logGenerationStep("Copying Swift core libraries for the target triple into Swift SDK bundle...")
107107

108108
for (pathWithinPackage, pathWithinSwiftSDK) in [
109-
("swift/linux", pathsConfiguration.toolchainDirPath.appending("usr/lib/swift")),
110-
("swift_static/linux", pathsConfiguration.toolchainDirPath.appending("usr/lib/swift_static")),
111-
("swift_static/shims", pathsConfiguration.toolchainDirPath.appending("usr/lib/swift_static")),
112-
("swift/dispatch", sdkDirPath.appending("usr/include")),
113-
("swift/os", sdkDirPath.appending("usr/include")),
114-
("swift/CoreFoundation", sdkDirPath.appending("usr/include")),
109+
("lib/swift", sdkDirPath.appending("usr/lib")),
110+
("lib/swift_static", sdkDirPath.appending("usr/lib")),
111+
("lib/clang", sdkDirPath.appending("usr/lib")),
112+
("include", sdkDirPath.appending("usr")),
115113
] {
116114
try await rsync(from: distributionPath.appending(pathWithinPackage), to: pathWithinSwiftSDK)
117115
}

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Fixup.swift

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -48,44 +48,6 @@ extension SwiftSDKGenerator {
4848
}
4949
}
5050

51-
func fixGlibcModuleMap(at path: FilePath, hostTriple: Triple) throws {
52-
logGenerationStep("Fixing absolute paths in `glibc.modulemap`...")
53-
54-
guard doesFileExist(at: path) else {
55-
throw GeneratorError.fileDoesNotExist(path)
56-
}
57-
58-
let privateIncludesPath = path.removingLastComponent().appending("private_includes")
59-
try removeRecursively(at: privateIncludesPath)
60-
try createDirectoryIfNeeded(at: privateIncludesPath)
61-
62-
let regex = Regex {
63-
#/\n( *header )"\/+usr\/include\//#
64-
Capture {
65-
Optionally {
66-
hostTriple.arch!.linuxConventionName
67-
"-linux-gnu"
68-
}
69-
}
70-
#/([^\"]+)\"/#
71-
}
72-
73-
var moduleMap = try String(data: readFile(at: path), encoding: .utf8)!
74-
try moduleMap.replace(regex) {
75-
let (_, headerKeyword, _, headerPath) = $0.output
76-
77-
let newHeaderRelativePath = headerPath.replacing("/", with: "_")
78-
try writeFile(
79-
at: privateIncludesPath.appending(String(newHeaderRelativePath)),
80-
Data("#include <linux/uuid.h>\n".utf8)
81-
)
82-
83-
return #"\#n\#(headerKeyword) "private_includes/\#(newHeaderRelativePath)""#
84-
}
85-
86-
try writeFile(at: path, Data(moduleMap.utf8))
87-
}
88-
8951
func symlinkClangHeaders() throws {
9052
try self.createSymlink(
9153
at: self.pathsConfiguration.toolchainDirPath.appending("usr/lib/swift_static/clang"),

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Unpack.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ extension SwiftSDKGenerator {
8686
try await inTemporaryDirectory { fs, tmpDir in
8787
try await fs.unpack(file: targetSwiftPackagePath, into: tmpDir)
8888
try await fs.copyTargetSwift(
89-
from: tmpDir.appending(relativePathToRoot).appending("usr/lib"), sdkDirPath: sdkDirPath
89+
from: tmpDir.appending(relativePathToRoot).appending("usr"), sdkDirPath: sdkDirPath
9090
)
9191
}
9292
}

Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,19 @@ public struct LinuxRecipe: SwiftSDKRecipe {
122122
toolset.librarian = Toolset.ToolProperties(path: "llvm-ar")
123123
}
124124

125+
public func applyPlatformOptions(
126+
metadata: inout SwiftSDKMetadataV4.TripleProperties,
127+
paths: PathsConfiguration,
128+
targetTriple: Triple
129+
) {
130+
var relativeSDKDir = self.sdkDirPath(paths: paths)
131+
guard relativeSDKDir.removePrefix(paths.swiftSDKRootPath) else {
132+
fatalError("The SDK directory path must be a subdirectory of the Swift SDK root path.")
133+
}
134+
metadata.swiftResourcesPath = relativeSDKDir.appending("usr/lib/swift").string
135+
metadata.swiftStaticResourcesPath = relativeSDKDir.appending("usr/lib/swift_static").string
136+
}
137+
125138
public var defaultArtifactID: String {
126139
"""
127140
\(self.versionsConfiguration.swiftVersion)_\(self.linuxDistribution.name.rawValue)_\(
@@ -211,7 +224,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
211224
)
212225
case let .localPackage(filePath):
213226
try await generator.copyTargetSwift(
214-
from: filePath.appending("usr/lib"), sdkDirPath: sdkDirPath
227+
from: filePath.appending("usr"), sdkDirPath: sdkDirPath
215228
)
216229
case .remoteTarball:
217230
try await generator.unpackTargetSwiftPackage(
@@ -225,13 +238,6 @@ public struct LinuxRecipe: SwiftSDKRecipe {
225238

226239
try await generator.fixAbsoluteSymlinks(sdkDirPath: sdkDirPath)
227240

228-
let targetCPU = generator.targetTriple.arch!
229-
try await generator.fixGlibcModuleMap(
230-
at: generator.pathsConfiguration.toolchainDirPath
231-
.appending("/usr/lib/swift/linux/\(targetCPU.linuxConventionName)/glibc.modulemap"),
232-
hostTriple: self.mainHostTriple
233-
)
234-
235241
if self.versionsConfiguration.swiftVersion.hasPrefix("5.9") ||
236242
self.versionsConfiguration.swiftVersion .hasPrefix("5.10") {
237243
try await generator.symlinkClangHeaders()

Tests/SwiftSDKGeneratorTests/EndToEndTests.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,6 @@ func skipSlow() throws {
187187
)
188188
}
189189

190-
// Skip known failing tests unless an environment variable is set
191-
func skipBroken(_ message: String) throws {
192-
try XCTSkipUnless(
193-
ProcessInfo.processInfo.environment.keys.contains("SWIFT_SDK_GENERATOR_RUN_BROKEN_TESTS"),
194-
"Skipping broken test because SWIFT_SDK_GENERATOR_RUN_BROKEN_TESTS is not set: \(message)"
195-
)
196-
}
197-
198190
func buildTestcase(_ logger: Logger, testcase: String, bundleName: String, tempDir: URL) async throws {
199191
let testPackageURL = tempDir.appendingPathComponent("swift-sdk-generator-test")
200192
let testPackageDir = FilePath(testPackageURL.path)
@@ -318,25 +310,21 @@ final class Swift60_UbuntuEndToEndTests: XCTestCase {
318310
)
319311

320312
func testAarch64Direct() async throws {
321-
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/152")
322313
try skipSlow()
323314
try await buildTestcases(config: config.withArchitecture("aarch64"))
324315
}
325316

326317
func testX86_64Direct() async throws {
327-
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/152")
328318
try skipSlow()
329319
try await buildTestcases(config: config.withArchitecture("x86_64"))
330320
}
331321

332322
func testAarch64FromContainer() async throws {
333-
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/152")
334323
try skipSlow()
335324
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
336325
}
337326

338327
func testX86_64FromContainer() async throws {
339-
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/152")
340328
try skipSlow()
341329
try await buildTestcases(config: config.withArchitecture("x86_64").withDocker())
342330
}
@@ -389,13 +377,11 @@ final class Swift60_RHELEndToEndTests: XCTestCase {
389377
)
390378

391379
func testAarch64FromContainer() async throws {
392-
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/152")
393380
try skipSlow()
394381
try await buildTestcases(config: config.withArchitecture("aarch64").withDocker())
395382
}
396383

397384
func testX86_64FromContainer() async throws {
398-
try skipBroken("https://github.com/swiftlang/swift-sdk-generator/issues/152")
399385
try skipSlow()
400386
try await buildTestcases(config: config.withArchitecture("x86_64").withDocker())
401387
}

0 commit comments

Comments
 (0)