Skip to content

Commit

Permalink
Merge branch 'main' into swiftlang#116-support-debian-distributions
Browse files Browse the repository at this point in the history
  • Loading branch information
xtremekforever committed Mar 4, 2025
2 parents f52aa21 + df46d2f commit 8e0ffcf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ import SystemPackage
import struct Foundation.Data

extension SwiftSDKGenerator {
func createLibSymlink(sdkDirPath: FilePath) throws {
let libPath = sdkDirPath.appending("lib")
if !doesFileExist(at: libPath) {
logger.info("Adding lib symlink to usr/lib...")
try createSymlink(at: libPath, pointingTo: "usr/lib")
}
}

func fixAbsoluteSymlinks(sdkDirPath: FilePath) throws {
logger.info("Fixing up absolute symlinks...")

Expand Down
14 changes: 14 additions & 0 deletions Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ public struct LinuxRecipe: SwiftSDKRecipe {
} else {
swiftCompilerOptions.append("-use-ld=lld")

// 32-bit architectures require libatomic
if let arch = targetTriple.arch, arch.is32Bit {
swiftCompilerOptions.append("-latomic")
}

if self.hostSwiftSource != .preinstalled {
toolset.linker = Toolset.ToolProperties(path: "ld.lld")
}
Expand Down Expand Up @@ -289,6 +294,15 @@ public struct LinuxRecipe: SwiftSDKRecipe {
)
}

logger.info("Removing unused toolchain components from target SDK...")
try await generator.removeToolchainComponents(
sdkDirPath,
platforms: unusedTargetPlatforms,
libraries: unusedHostLibraries,
binaries: unusedHostBinaries
)

try await generator.createLibSymlink(sdkDirPath: sdkDirPath)
try await generator.fixAbsoluteSymlinks(sdkDirPath: sdkDirPath)

// Swift 6.1 and later do not throw warnings about the SDKSettings.json file missing,
Expand Down
9 changes: 8 additions & 1 deletion Tests/SwiftSDKGeneratorTests/EndToEndTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ final class RepeatedBuildTests: XCTestCase {
struct SDKConfiguration {
var swiftVersion: String
var linuxDistributionName: String
var linuxDistributionVersion: String
var architecture: String
var withDocker: Bool

var bundleName: String { "\(linuxDistributionName)_\(architecture)_\(swiftVersion)-RELEASE\(withDocker ? "_with-docker" : "")" }
var bundleName: String { "\(linuxDistributionName)_\(linuxDistributionVersion)_\(architecture)_\(swiftVersion)-RELEASE\(withDocker ? "_with-docker" : "")" }

func withDocker(_ enabled: Bool = true) -> SDKConfiguration {
var res = self
Expand Down Expand Up @@ -308,6 +309,7 @@ final class Swift59_UbuntuEndToEndTests: XCTestCase {
let config = SDKConfiguration(
swiftVersion: "5.9.2",
linuxDistributionName: "ubuntu",
linuxDistributionVersion: "22.04",
architecture: "aarch64",
withDocker: false
)
Expand Down Expand Up @@ -337,6 +339,7 @@ final class Swift510_UbuntuEndToEndTests: XCTestCase {
let config = SDKConfiguration(
swiftVersion: "5.10.1",
linuxDistributionName: "ubuntu",
linuxDistributionVersion: "22.04",
architecture: "aarch64",
withDocker: false
)
Expand Down Expand Up @@ -366,6 +369,7 @@ final class Swift60_UbuntuEndToEndTests: XCTestCase {
let config = SDKConfiguration(
swiftVersion: "6.0.3",
linuxDistributionName: "ubuntu",
linuxDistributionVersion: "24.04",
architecture: "aarch64",
withDocker: false
)
Expand Down Expand Up @@ -395,6 +399,7 @@ final class Swift59_RHELEndToEndTests: XCTestCase {
let config = SDKConfiguration(
swiftVersion: "5.9.2",
linuxDistributionName: "rhel",
linuxDistributionVersion: "ubi9",
architecture: "aarch64",
withDocker: true // RHEL-based SDKs can only be built from containers
)
Expand All @@ -414,6 +419,7 @@ final class Swift510_RHELEndToEndTests: XCTestCase {
let config = SDKConfiguration(
swiftVersion: "5.10.1",
linuxDistributionName: "rhel",
linuxDistributionVersion: "ubi9",
architecture: "aarch64",
withDocker: true // RHEL-based SDKs can only be built from containers
)
Expand All @@ -433,6 +439,7 @@ final class Swift60_RHELEndToEndTests: XCTestCase {
let config = SDKConfiguration(
swiftVersion: "6.0.3",
linuxDistributionName: "rhel",
linuxDistributionVersion: "ubi9",
architecture: "aarch64",
withDocker: true // RHEL-based SDKs can only be built from containers
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ final class LinuxRecipeTests: XCTestCase {
let testCases = [
(
swiftVersion: "5.9.2",
targetTriple: Triple("x86_64-unknown-linux-gnu"),
expectedSwiftCompilerOptions: [
"-Xlinker", "-R/usr/lib/swift/linux/",
"-Xclang-linker", "--ld-path=ld.lld"
Expand All @@ -53,19 +54,30 @@ final class LinuxRecipeTests: XCTestCase {
),
(
swiftVersion: "6.0.2",
targetTriple: Triple("aarch64-unknown-linux-gnu"),
expectedSwiftCompilerOptions: [
"-Xlinker", "-R/usr/lib/swift/linux/",
"-use-ld=lld"
],
expectedLinkerPath: "ld.lld"
),
(
swiftVersion: "6.0.3",
targetTriple: Triple("armv7-unknown-linux-gnueabihf"),
expectedSwiftCompilerOptions: [
"-Xlinker", "-R/usr/lib/swift/linux/",
"-use-ld=lld",
"-latomic"
],
expectedLinkerPath: "ld.lld"
)
]

for testCase in testCases {
let recipe = try self.createRecipe(swiftVersion: testCase.swiftVersion)
var toolset = Toolset(rootPath: nil)
recipe.applyPlatformOptions(
toolset: &toolset, targetTriple: Triple("aarch64-unknown-linux-gnu")
toolset: &toolset, targetTriple: testCase.targetTriple
)
XCTAssertEqual(toolset.swiftCompiler?.extraCLIOptions, testCase.expectedSwiftCompilerOptions)
XCTAssertEqual(toolset.linker?.path, testCase.expectedLinkerPath)
Expand Down

0 comments on commit 8e0ffcf

Please sign in to comment.