Skip to content

Commit df46d2f

Browse files
Fix missing lib/ directory for Ubuntu Noble, remove unused components (#193)
Apparently I didn't test very well from PR #188, because when I went to use the Ubuntu Noble Swift SDK, I got this error: ``` error: link command failed with exit code 1 (use -v to see invocation) ld.lld: error: ~/.swiftpm/swift-sdks/6.0.3-RELEASE_ubuntu_noble_aarch64.artifactbundle/6.0.3-RELEASE_ubuntu_noble_aarch64/aarch64-unknown-linux-gnu/ubuntu-noble.sdk/usr/lib/aarch64-linux-gnu/libm.so:4: cannot find /lib/aarch64-linux-gnu/libm.so.6 inside ~/.swiftpm/swift-sdks/6.0.3-RELEASE_ubuntu_noble_aarch64/aarch64-unknown-linux-gnu/ubuntu-noble.sdk >>> GROUP ( /lib/aarch64-linux-gnu/libm.so.6 AS_NEEDED ( /lib/aarch64-linux-gnu/libmvec.so.1 ) ) >>> ^ clang: error: linker command failed with exit code 1 (use -v to see invocation) ld.lld: error: ~/.swiftpm/swift-sdks/6.0.3-RELEASE_ubuntu_noble_aarch64.artifactbundle/6.0.3-RELEASE_ubuntu_noble_aarch64/aarch64-unknown-linux-gnu/ubuntu-noble.sdk/usr/lib/aarch64-linux-gnu/libm.so:4: cannot find /lib/aarch64-linux-gnu/libm.so.6 inside /~/.swiftpm/swift-sdks/6.0.3-RELEASE_ubuntu_noble_aarch64.artifactbundle/6.0.3-RELEASE_ubuntu_noble_aarch64/aarch64-unknown-linux-gnu/ubuntu-noble.sdk >>> GROUP ( /lib/aarch64-linux-gnu/libm.so.6 AS_NEEDED ( /lib/aarch64-linux-gnu/libmvec.so.1 ) ) >>> ^ ``` Turns out, the packages for Ubuntu Noble do not come with a lib/ symlink included, so all I needed was to add a custom step to create that symlink from `ubuntu-noble.sdk/lib` -> `ubuntu-noble.sdk/usr/lib` and all is well. As a part of these changes, I also added a missing cleanup of the target toolchain to remove unused parts of the LinuxRecipe as is done for the [WebAssemblyRecipe](https://github.com/swiftlang/swift-sdk-generator/blob/a0ff972af294243ef9211534f7c9ba6f83672b82/Sources/SwiftSDKGenerator/SwiftSDKRecipes/WebAssemblyRecipe.swift#L120-L125). Doing this reduces the size of `ubuntu-noble.sdk` from 1GB to 721MB, when building the Swift SDK without docker. This can help for the end-to-end tests, and is nice to have for smaller Swift SDK distributions. Finally, I updated the EndToEndTests to provide `linuxDistributionVersion` and set the Swift60_Ubuntu tests to use "24.04" as a way to test this lib/ directory fix. This has me thinking we may want to think about end-to-end tests for each version of Ubuntu, like "20.04", "22.04", and "24.04", for each version of Swift.
1 parent b9d611f commit df46d2f

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Fixup.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ import SystemPackage
1616
import struct Foundation.Data
1717

1818
extension SwiftSDKGenerator {
19+
func createLibSymlink(sdkDirPath: FilePath) throws {
20+
let libPath = sdkDirPath.appending("lib")
21+
if !doesFileExist(at: libPath) {
22+
logger.info("Adding lib symlink to usr/lib...")
23+
try createSymlink(at: libPath, pointingTo: "usr/lib")
24+
}
25+
}
26+
1927
func fixAbsoluteSymlinks(sdkDirPath: FilePath) throws {
2028
logger.info("Fixing up absolute symlinks...")
2129

Sources/SwiftSDKGenerator/SwiftSDKRecipes/LinuxRecipe.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,15 @@ public struct LinuxRecipe: SwiftSDKRecipe {
294294
)
295295
}
296296

297+
logger.info("Removing unused toolchain components from target SDK...")
298+
try await generator.removeToolchainComponents(
299+
sdkDirPath,
300+
platforms: unusedTargetPlatforms,
301+
libraries: unusedHostLibraries,
302+
binaries: unusedHostBinaries
303+
)
304+
305+
try await generator.createLibSymlink(sdkDirPath: sdkDirPath)
297306
try await generator.fixAbsoluteSymlinks(sdkDirPath: sdkDirPath)
298307

299308
// Swift 6.1 and later do not throw warnings about the SDKSettings.json file missing,

Tests/SwiftSDKGeneratorTests/EndToEndTests.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,10 +151,11 @@ final class RepeatedBuildTests: XCTestCase {
151151
struct SDKConfiguration {
152152
var swiftVersion: String
153153
var linuxDistributionName: String
154+
var linuxDistributionVersion: String
154155
var architecture: String
155156
var withDocker: Bool
156157

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

159160
func withDocker(_ enabled: Bool = true) -> SDKConfiguration {
160161
var res = self
@@ -308,6 +309,7 @@ final class Swift59_UbuntuEndToEndTests: XCTestCase {
308309
let config = SDKConfiguration(
309310
swiftVersion: "5.9.2",
310311
linuxDistributionName: "ubuntu",
312+
linuxDistributionVersion: "22.04",
311313
architecture: "aarch64",
312314
withDocker: false
313315
)
@@ -337,6 +339,7 @@ final class Swift510_UbuntuEndToEndTests: XCTestCase {
337339
let config = SDKConfiguration(
338340
swiftVersion: "5.10.1",
339341
linuxDistributionName: "ubuntu",
342+
linuxDistributionVersion: "22.04",
340343
architecture: "aarch64",
341344
withDocker: false
342345
)
@@ -366,6 +369,7 @@ final class Swift60_UbuntuEndToEndTests: XCTestCase {
366369
let config = SDKConfiguration(
367370
swiftVersion: "6.0.3",
368371
linuxDistributionName: "ubuntu",
372+
linuxDistributionVersion: "24.04",
369373
architecture: "aarch64",
370374
withDocker: false
371375
)
@@ -395,6 +399,7 @@ final class Swift59_RHELEndToEndTests: XCTestCase {
395399
let config = SDKConfiguration(
396400
swiftVersion: "5.9.2",
397401
linuxDistributionName: "rhel",
402+
linuxDistributionVersion: "ubi9",
398403
architecture: "aarch64",
399404
withDocker: true // RHEL-based SDKs can only be built from containers
400405
)
@@ -414,6 +419,7 @@ final class Swift510_RHELEndToEndTests: XCTestCase {
414419
let config = SDKConfiguration(
415420
swiftVersion: "5.10.1",
416421
linuxDistributionName: "rhel",
422+
linuxDistributionVersion: "ubi9",
417423
architecture: "aarch64",
418424
withDocker: true // RHEL-based SDKs can only be built from containers
419425
)
@@ -433,6 +439,7 @@ final class Swift60_RHELEndToEndTests: XCTestCase {
433439
let config = SDKConfiguration(
434440
swiftVersion: "6.0.3",
435441
linuxDistributionName: "rhel",
442+
linuxDistributionVersion: "ubi9",
436443
architecture: "aarch64",
437444
withDocker: true // RHEL-based SDKs can only be built from containers
438445
)

0 commit comments

Comments
 (0)