Skip to content

Commit 144b407

Browse files
Copy /lib and /lib64 for Debian 11 containers
- This is required since Debian 11 has a different layout than other Ubuntu/Debian versions.
1 parent 9bf533b commit 144b407

File tree

1 file changed

+31
-5
lines changed

1 file changed

+31
-5
lines changed

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ extension SwiftSDKGenerator {
2222
logger.info("Launching a container to extract the Swift SDK for the target triple...")
2323
try await withDockerContainer(fromImage: baseDockerImage) { containerID in
2424
try await inTemporaryDirectory { generator, _ in
25+
let sdkLibPath = sdkDirPath.appending("lib")
2526
let sdkUsrPath = sdkDirPath.appending("usr")
2627
try await generator.createDirectoryIfNeeded(at: sdkUsrPath)
2728
try await generator.copyFromDockerContainer(
@@ -60,6 +61,15 @@ extension SwiftSDKGenerator {
6061
to: sdkUsrLib64Path
6162
)
6263
try await createSymlink(at: sdkDirPath.appending("lib64"), pointingTo: "./usr/lib64")
64+
} else if case let containerLib64 = FilePath("/lib64"),
65+
try await generator.doesPathExist(containerLib64, inContainer: containerID)
66+
{
67+
let sdkLib64Path = sdkDirPath.appending("lib64")
68+
try await generator.copyFromDockerContainer(
69+
id: containerID,
70+
from: containerLib64,
71+
to: sdkLib64Path
72+
)
6373
}
6474

6575
let sdkUsrLibPath = sdkUsrPath.appending("lib")
@@ -73,12 +83,24 @@ extension SwiftSDKGenerator {
7383
// https://wiki.ubuntu.com/MultiarchSpec
7484
// But not in all containers, so don't fail if it does not exist.
7585
if targetDistribution.name == .ubuntu || targetDistribution.name == .debian {
76-
subpaths += [("\(targetTriple.archName)-linux-gnu", false)]
86+
let archSubpath =
87+
switch targetTriple.archName {
88+
case "armv7": "arm-linux-gnueabihf"
89+
default: "\(targetTriple.archName)-linux-gnu"
90+
}
7791

78-
// Custom subpath for armv7
79-
if targetTriple.archName == "armv7" {
80-
subpaths += [("arm-linux-gnueabihf", false)]
92+
// Copy /lib/<archSubpath> for Debian 11
93+
if case let .debian(debian) = targetDistribution, debian == .bullseye {
94+
try await generator.createDirectoryIfNeeded(at: sdkLibPath)
95+
try await generator.copyFromDockerContainer(
96+
id: containerID,
97+
from: FilePath("/lib").appending(archSubpath),
98+
to: sdkLibPath.appending(archSubpath),
99+
failIfNotExists: false
100+
)
81101
}
102+
103+
subpaths += [(archSubpath, false)]
82104
}
83105

84106
for (subpath, failIfNotExists) in subpaths {
@@ -89,7 +111,11 @@ extension SwiftSDKGenerator {
89111
failIfNotExists: failIfNotExists
90112
)
91113
}
92-
try await generator.createSymlink(at: sdkDirPath.appending("lib"), pointingTo: "usr/lib")
114+
115+
// Symlink if we do not have a /lib directory in the SDK
116+
if await !generator.doesFileExist(at: sdkLibPath) {
117+
try await generator.createSymlink(at: sdkLibPath, pointingTo: "usr/lib")
118+
}
93119

94120
// Look for 32-bit libraries to remove from RHEL-based distros
95121
// These are not needed, and the amazonlinux2 x86_64 symlinks are messed up

0 commit comments

Comments
 (0)