Skip to content

generator/linux: Use swiftResourcesPath to find framework headers #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ extension SwiftSDKGenerator {
try await generator.removeRecursively(at: sdkUsrLibPath.appending("python3.10"))

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

for (pathWithinPackage, pathWithinSwiftSDK) in [
("swift/linux", pathsConfiguration.toolchainDirPath.appending("usr/lib/swift")),
("swift_static/linux", pathsConfiguration.toolchainDirPath.appending("usr/lib/swift_static")),
("swift_static/shims", pathsConfiguration.toolchainDirPath.appending("usr/lib/swift_static")),
("swift/dispatch", sdkDirPath.appending("usr/include")),
("swift/os", sdkDirPath.appending("usr/include")),
("swift/CoreFoundation", sdkDirPath.appending("usr/include")),
("lib/swift", sdkDirPath.appending("usr/lib")),
("lib/swift_static", sdkDirPath.appending("usr/lib")),
("lib/clang", sdkDirPath.appending("usr/lib")),
("include", sdkDirPath.appending("usr")),
] {
try await rsync(from: distributionPath.appending(pathWithinPackage), to: pathWithinSwiftSDK)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,44 +48,6 @@ extension SwiftSDKGenerator {
}
}

func fixGlibcModuleMap(at path: FilePath, hostTriple: Triple) throws {
logGenerationStep("Fixing absolute paths in `glibc.modulemap`...")

guard doesFileExist(at: path) else {
throw GeneratorError.fileDoesNotExist(path)
}

let privateIncludesPath = path.removingLastComponent().appending("private_includes")
try removeRecursively(at: privateIncludesPath)
try createDirectoryIfNeeded(at: privateIncludesPath)

let regex = Regex {
#/\n( *header )"\/+usr\/include\//#
Capture {
Optionally {
hostTriple.arch!.linuxConventionName
"-linux-gnu"
}
}
#/([^\"]+)\"/#
}

var moduleMap = try String(data: readFile(at: path), encoding: .utf8)!
try moduleMap.replace(regex) {
let (_, headerKeyword, _, headerPath) = $0.output

let newHeaderRelativePath = headerPath.replacing("/", with: "_")
try writeFile(
at: privateIncludesPath.appending(String(newHeaderRelativePath)),
Data("#include <linux/uuid.h>\n".utf8)
)

return #"\#n\#(headerKeyword) "private_includes/\#(newHeaderRelativePath)""#
}

try writeFile(at: path, Data(moduleMap.utf8))
}

func symlinkClangHeaders() throws {
try self.createSymlink(
at: self.pathsConfiguration.toolchainDirPath.appending("usr/lib/swift_static/clang"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ extension SwiftSDKGenerator {
try await inTemporaryDirectory { fs, tmpDir in
try await fs.unpack(file: targetSwiftPackagePath, into: tmpDir)
try await fs.copyTargetSwift(
from: tmpDir.appending(relativePathToRoot).appending("usr/lib"), sdkDirPath: sdkDirPath
from: tmpDir.appending(relativePathToRoot).appending("usr"), sdkDirPath: sdkDirPath
)
}
}
Expand Down
22 changes: 14 additions & 8 deletions Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ public struct LinuxRecipe: SwiftSDKRecipe {
toolset.librarian = Toolset.ToolProperties(path: "llvm-ar")
}

public func applyPlatformOptions(
metadata: inout SwiftSDKMetadataV4.TripleProperties,
paths: PathsConfiguration,
targetTriple: Triple
) {
var relativeSDKDir = self.sdkDirPath(paths: paths)
guard relativeSDKDir.removePrefix(paths.swiftSDKRootPath) else {
fatalError("The SDK directory path must be a subdirectory of the Swift SDK root path.")
}
metadata.swiftResourcesPath = relativeSDKDir.appending("usr/lib/swift").string
metadata.swiftStaticResourcesPath = relativeSDKDir.appending("usr/lib/swift_static").string
}

public var defaultArtifactID: String {
"""
\(self.versionsConfiguration.swiftVersion)_\(self.linuxDistribution.name.rawValue)_\(
Expand Down Expand Up @@ -211,7 +224,7 @@ public struct LinuxRecipe: SwiftSDKRecipe {
)
case let .localPackage(filePath):
try await generator.copyTargetSwift(
from: filePath.appending("usr/lib"), sdkDirPath: sdkDirPath
from: filePath.appending("usr"), sdkDirPath: sdkDirPath
)
case .remoteTarball:
try await generator.unpackTargetSwiftPackage(
Expand All @@ -225,13 +238,6 @@ public struct LinuxRecipe: SwiftSDKRecipe {

try await generator.fixAbsoluteSymlinks(sdkDirPath: sdkDirPath)

let targetCPU = generator.targetTriple.arch!
try await generator.fixGlibcModuleMap(
at: generator.pathsConfiguration.toolchainDirPath
.appending("/usr/lib/swift/linux/\(targetCPU.linuxConventionName)/glibc.modulemap"),
hostTriple: self.mainHostTriple
)

if self.versionsConfiguration.swiftVersion.hasPrefix("5.9") ||
self.versionsConfiguration.swiftVersion .hasPrefix("5.10") {
try await generator.symlinkClangHeaders()
Expand Down
14 changes: 0 additions & 14 deletions Tests/SwiftSDKGeneratorTests/EndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,6 @@ func skipSlow() throws {
)
}

// Skip known failing tests unless an environment variable is set
func skipBroken(_ message: String) throws {
try XCTSkipUnless(
ProcessInfo.processInfo.environment.keys.contains("SWIFT_SDK_GENERATOR_RUN_BROKEN_TESTS"),
"Skipping broken test because SWIFT_SDK_GENERATOR_RUN_BROKEN_TESTS is not set: \(message)"
)
}

func buildTestcase(_ logger: Logger, testcase: String, bundleName: String, tempDir: URL) async throws {
let testPackageURL = tempDir.appendingPathComponent("swift-sdk-generator-test")
let testPackageDir = FilePath(testPackageURL.path)
Expand Down Expand Up @@ -318,25 +310,21 @@ final class Swift60_UbuntuEndToEndTests: XCTestCase {
)

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

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

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

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

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

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