Skip to content

Commit d393e2f

Browse files
MaxDesiatovxtremekforevereuanh
authored
Merge main into release/6.2 (#214)
**Explanation**: This updates `release/6.2` branch of the generator used when building 6.2 Swift 6.2 toolchain with recent changes. Most notably: * Embedded Swift SDK for WASI within existing Swift SDK for WASI artifact bundles, thanks to swiftlang/swift-package-manager#8638 * Bump to Swift 5.9 in `// swift-tools-version` * Bump to generating with Swift 6.1 release tag by default (as opposed to 6.0 previously) * Support for Debian 11 and Debian 12 together with support for downloading and unpacking Debian packages as dependencies. * Additional test suite additions that cover these changes. **Scope**: Isolated to cross-compilation and only impacts existing Ubuntu toolchain job that generates Swift SDK for WASI. **Risk**: Low, most of the changes LoC-wise were incubated on the `main` branch for a month. **Testing**: Expanded test suite, corresponding toolchain builds are passing https://ci.swift.org/job/oss-swift-pr-test-crosscompile-wasm-ubuntu-20_04/ **Issue**: rdar://151475169 **Reviewers**: @kateinoigakukun @euanh --------- Co-authored-by: Jesse L. Zamora <[email protected]> Co-authored-by: Euan Harris <[email protected]>
1 parent 0158a41 commit d393e2f

23 files changed

+977
-286
lines changed

.swift-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"lineBreakBeforeControlFlowKeywords" : false,
1212
"lineBreakBeforeEachArgument" : true,
1313
"lineBreakBeforeEachGenericRequirement" : false,
14-
"lineLength" : 100,
14+
"lineLength" : 120,
1515
"maximumBlankLines" : 1,
1616
"multiElementCollectionTrailingCommas" : true,
1717
"noAssignmentInExpressions" : {

CONTRIBUTING.md

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,6 @@ We require that your commit messages match our template. The easiest way to do t
5858

5959
git config commit.template Utilities/git.commit.template
6060

61-
### Run `./Utilities/soundness.sh`
62-
63-
The scripts directory contains a [`soundness.sh` script](https://github.com/apple/swift-sdk-generator/blob/main/Utilities/soundness.sh)
64-
that enforces additional checks, like license headers and formatting style.
65-
66-
Please make sure to run `./Utilities/soundness.sh` before pushing a change upstream, otherwise it is likely the PR validation will fail
67-
on minor changes such as formatting issues.
68-
69-
For frequent contributors, we recommend adding the script as a [git pre-push hook](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks), which you can do via executing the following command in the project root directory:
70-
71-
```bash
72-
cat << EOF > .git/hooks/pre-push
73-
74-
if [[ -f "Utilities/soundness.sh" ]]; then
75-
Utilities/soundness.sh
76-
fi
77-
EOF
78-
```
79-
80-
Which makes the script execute, and only allow the `git push` to complete if the check has passed.
81-
82-
In the case of formatting issues, you can then `git add` the formatting changes, and attempt the push again.
83-
8461
## How to contribute your work
8562

86-
Please open a pull request at https://github.com/apple/swift-sdk-generator. Make sure the CI passes, and then wait for code review.
63+
Please open a pull request at https://github.com/apple/swift-sdk-generator. Make sure the CI passes, and then wait for code review.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 5.8
1+
// swift-tools-version: 5.9
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ The generator also allows cross-compiling between any Linux distributions offici
4747
| macOS (arm64) | ✅ macOS 13.0+ ||
4848
| macOS (x86_64) | ✅ macOS 13.0+[^1] ||
4949
| Ubuntu | ✅ 20.04+ | ✅ 20.04+ |
50-
| RHEL | ✅ Fedora 39[^2], UBI 9 | ✅ UBI 9 |
50+
| Debian | ✅ 11, 12[^2] | ✅ 11, 12[^2] |
51+
| RHEL | ✅ Fedora 39, UBI 9 | ✅ Fedora 39, UBI 9[^3] |
5152
| Amazon Linux 2 | ✅ Supported | ✅ Supported[^3] |
52-
| Debian 12 | ✅ Supported[^2] | ✅ Supported[^2][^3] |
5353

5454
[^1]: Since LLVM project doesn't provide pre-built binaries of `lld` for macOS on x86_64, it will be automatically built
5555
from sources by the generator, which will increase its run by at least 15 minutes on recent hardware. You will also
5656
need CMake and Ninja preinstalled (e.g. via `brew install cmake ninja`).
57-
[^2]: These distributions are only supported by Swift 5.10.1 and later as both host and target platforms.
57+
[^2]: Swift does not officially support Debian 11 or Debian 12 with Swift versions before 5.10.1. However, the Ubuntu 20.04/22.04 toolchains can be used with Debian 11 and 12 (respectively) since they are binary compatible.
5858
[^3]: These versions are technically supported but require custom commands and a Docker container to build the Swift SDK, as the generator will not download dependencies for these distributions automatically. See [issue #138](https://github.com/swiftlang/swift-sdk-generator/issues/138).
5959

6060
## How to use it

Sources/GeneratorCLI/GeneratorCLI.swift

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ extension GeneratorCLI {
114114
var swiftBranch: String? = nil
115115

116116
@Option(help: "Version of Swift to supply in the bundle.")
117-
var swiftVersion = "6.0.3-RELEASE"
117+
var swiftVersion = "6.1-RELEASE"
118118

119119
@Option(
120120
help: """
@@ -199,7 +199,8 @@ extension GeneratorCLI {
199199

200200
@Option(
201201
help: """
202-
Linux distribution to use if the target platform is Linux. Available options: `ubuntu`, `rhel`. Default is `ubuntu`.
202+
Linux distribution to use if the target platform is Linux.
203+
- Available options: `ubuntu`, `debian`, `rhel`. Default is `ubuntu`.
203204
""",
204205
transform: LinuxDistribution.Name.init(nameString:)
205206
)
@@ -208,8 +209,9 @@ extension GeneratorCLI {
208209
@Option(
209210
help: """
210211
Version of the Linux distribution used as a target platform.
211-
Available options for Ubuntu: `20.04`, `22.04` (default when `--linux-distribution-name` is `ubuntu`), `24.04`.
212-
Available options for RHEL: `ubi9` (default when `--linux-distribution-name` is `rhel`).
212+
- Available options for Ubuntu: `20.04`, `22.04` (default when `--distribution-name` is `ubuntu`), `24.04`.
213+
- Available options for Debian: `11`, `12` (default when `--distribution-name` is `debian`).
214+
- Available options for RHEL: `ubi9` (default when `--distribution-name` is `rhel`).
213215
"""
214216
)
215217
var linuxDistributionVersion: String?
@@ -239,6 +241,8 @@ extension GeneratorCLI {
239241
linuxDistributionDefaultVersion = "ubi9"
240242
case .ubuntu:
241243
linuxDistributionDefaultVersion = "22.04"
244+
case .debian:
245+
linuxDistributionDefaultVersion = "12"
242246
}
243247
let linuxDistributionVersion =
244248
self.linuxDistributionVersion ?? linuxDistributionDefaultVersion

Sources/Helpers/Vendor/QueryEngine/CacheKey.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,4 +182,3 @@ extension Array: CacheKey where Element == FilePath.Component {
182182
map(\.string).joined(separator: "\n").hash(with: &hashFunction)
183183
}
184184
}
185-

Sources/SwiftSDKGenerator/Artifacts/DownloadableArtifacts.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ struct DownloadableArtifacts: Sendable {
5454

5555
if hostTriple.os == .linux {
5656
// Amazon Linux 2 is chosen for its best compatibility with all Swift-supported Linux hosts
57-
let linuxArchSuffix =
57+
let hostArchSuffix =
5858
hostTriple.arch == .aarch64 ? "-\(Triple.Arch.aarch64.linuxConventionName)" : ""
5959
self.hostSwift = .init(
6060
remoteURL: versions.swiftDownloadURL(
61-
subdirectory: "amazonlinux2\(linuxArchSuffix)",
62-
platform: "amazonlinux2\(linuxArchSuffix)",
61+
subdirectory: "amazonlinux2\(hostArchSuffix)",
62+
platform: "amazonlinux2\(hostArchSuffix)",
6363
fileExtension: "tar.gz"
6464
),
6565
localPath: paths.artifactsCachePath
@@ -97,7 +97,9 @@ struct DownloadableArtifacts: Sendable {
9797
self.targetSwift = .init(
9898
remoteURL: versions.swiftDownloadURL(),
9999
localPath: paths.artifactsCachePath
100-
.appending("target_swift_\(versions.swiftVersion)_\(targetTriple.triple).tar.gz"),
100+
.appending(
101+
"target_swift_\(versions.swiftVersion)_\(versions.swiftPlatform)_\(targetTriple.archName).tar.gz"
102+
),
101103
isPrebuilt: true
102104
)
103105
}

Sources/SwiftSDKGenerator/Generator/SwiftSDKGenerator+Copy.swift

Lines changed: 32 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")
@@ -72,13 +82,26 @@ extension SwiftSDKGenerator {
7282
// architecture-specific directories:
7383
// https://wiki.ubuntu.com/MultiarchSpec
7484
// But not in all containers, so don't fail if it does not exist.
75-
if case .ubuntu = targetDistribution {
76-
subpaths += [("\(targetTriple.archName)-linux-gnu", false)]
85+
if targetDistribution.name == .ubuntu || targetDistribution.name == .debian {
86+
var archSubpath = "\(targetTriple.archName)-linux-gnu"
7787

78-
// Custom subpath for armv7
88+
// armv7 with Debian uses a custom subpath for armhf
7989
if targetTriple.archName == "armv7" {
80-
subpaths += [("arm-linux-gnueabihf", false)]
90+
archSubpath = "arm-linux-gnueabihf"
8191
}
92+
93+
// Copy /lib/<archSubpath> for Debian 11
94+
if case let .debian(debian) = targetDistribution, debian == .bullseye {
95+
try await generator.createDirectoryIfNeeded(at: sdkLibPath)
96+
try await generator.copyFromDockerContainer(
97+
id: containerID,
98+
from: FilePath("/lib").appending(archSubpath),
99+
to: sdkLibPath.appending(archSubpath),
100+
failIfNotExists: false
101+
)
102+
}
103+
104+
subpaths += [(archSubpath, false)]
82105
}
83106

84107
for (subpath, failIfNotExists) in subpaths {
@@ -89,7 +112,11 @@ extension SwiftSDKGenerator {
89112
failIfNotExists: failIfNotExists
90113
)
91114
}
92-
try await generator.createSymlink(at: sdkDirPath.appending("lib"), pointingTo: "usr/lib")
115+
116+
// Symlink if we do not have a /lib directory in the SDK
117+
if await !generator.doesFileExist(at: sdkLibPath) {
118+
try await generator.createSymlink(at: sdkLibPath, pointingTo: "usr/lib")
119+
}
93120

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

0 commit comments

Comments
 (0)