Skip to content

Commit 134b46e

Browse files
committed
Install static sdk matching current swift version
Remove supported linux distribution check and deprecate command-line flag
1 parent 999f0e2 commit 134b46e

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

Tools/build-swiftly-release/BuildSwiftlyRelease.swift

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
import ArgumentParser
22
import Foundation
33

4+
public struct SwiftPlatform: Codable {
5+
public var name: String?
6+
public var checksum: String?
7+
}
8+
9+
public struct SwiftRelease: Codable {
10+
public var name: String?
11+
public var platforms: [SwiftPlatform]?
12+
}
13+
414
// These functions are cloned and adapted from SwiftlyCore until we can do better bootstrapping
515
public struct Error: LocalizedError {
616
public let message: String
@@ -128,10 +138,6 @@ public func getShell() async throws -> String {
128138
}
129139
#endif
130140

131-
public func isSupportedLinux(useRhelUbi9 _: Bool) -> Bool {
132-
true
133-
}
134-
135141
@main
136142
struct BuildSwiftlyRelease: AsyncParsableCommand {
137143
static let configuration = CommandConfiguration(
@@ -149,7 +155,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
149155
@Option(help: "Package identifier of macOS package")
150156
var identifier: String = "org.swift.swiftly"
151157
#elseif os(Linux)
152-
@Flag(name: .long, help: "Use RHEL UBI9 as the supported Linux to build a release instead of Amazon Linux 2")
158+
@Flag(name: .long, help: "Deprecated option since releases can be built on any swift supported Linux distribution.")
153159
var useRhelUbi9: Bool = false
154160
#endif
155161

@@ -249,13 +255,6 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
249255
}
250256

251257
func buildLinuxRelease() async throws {
252-
#if os(Linux)
253-
// Check system requirements
254-
guard isSupportedLinux(useRhelUbi9: self.useRhelUbi9) else {
255-
throw Error(message: "Linux releases must be made from specific distributions so that the binary can be used everyone else because it has the oldest version of glibc for maximum compatibility with other versions of Linux. Please try again with \(!self.useRhelUbi9 ? "Amazon Linux 2" : "RedHat UBI 9").")
256-
}
257-
#endif
258-
259258
// TODO: turn these into checks that the system meets the criteria for being capable of using the toolchain + checking for packages, not tools
260259
let curl = try await self.assertTool("curl", message: "Please install curl with `yum install curl`")
261260
let tar = try await self.assertTool("tar", message: "Please install tar with `yum install tar`")
@@ -294,17 +293,34 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
294293
let cwd = FileManager.default.currentDirectoryPath
295294
FileManager.default.changeCurrentDirectoryPath(libArchivePath)
296295

297-
let sdkName = "swift-6.0.3-RELEASE_static-linux-0.0.1"
296+
let swiftVerRegex: Regex<(Substring, Substring)> = try! Regex("Swift version (\\d+\\.\\d+\\.\\d+) ")
297+
let swiftVerOutput = (try await runProgramOutput(swift, "--version")) ?? ""
298+
guard let swiftVerMatch = try swiftVerRegex.firstMatch(in: swiftVerOutput) else {
299+
throw Error(message: "Unable to detect swift version")
300+
}
298301

299-
// FIXME: Adjust the URL and checksum to match the toolchain that is being used
302+
let swiftVersion = swiftVerMatch.output.1
303+
304+
let sdkName = "swift-\(swiftVersion)-RELEASE_static-linux-0.0.1"
300305

301306
#if arch(arm64)
302307
let arch = "aarch64"
303308
#else
304309
let arch = "x86_64"
305310
#endif
306311

307-
try runProgram(swift, "sdk", "install", "https://download.swift.org/swift-6.0.3-release/static-sdk/swift-6.0.3-RELEASE/swift-6.0.3-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz", "--checksum", "67f765e0030e661a7450f7e4877cfe008db4f57f177d5a08a6e26fd661cdd0bd")
312+
let swiftReleasesJson = (try await runProgramOutput(curl, "https://www.swift.org/api/v1/install/releases.json")) ?? "[]"
313+
let swiftReleases = try JSONDecoder().decode([SwiftRelease].self, from: swiftReleasesJson.data(using: .utf8)!)
314+
315+
guard let swiftRelease = swiftReleases.first(where: { ($0.name ?? "") == swiftVersion }) else {
316+
throw Error(message: "Unable to find swift release using swift.org API: \(swiftVersion)")
317+
}
318+
319+
guard let sdkPlatform = (swiftRelease.platforms ?? [SwiftPlatform]()).first(where: { ($0.name ?? "") == "Static SDK" }) else {
320+
throw Error(message: "Swift release \(swiftVersion) has no Static SDK offering")
321+
}
322+
323+
try runProgram(swift, "sdk", "install", "https://download.swift.org/swift-\(swiftVersion)-release/static-sdk/swift-\(swiftVersion)-RELEASE/swift-\(swiftVersion)-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz", "--checksum", sdkPlatform.checksum ?? "deadbeef")
308324

309325
var customEnv = ProcessInfo.processInfo.environment
310326
customEnv["CC"] = "\(cwd)/Tools/build-swiftly-release/musl-clang"

0 commit comments

Comments
 (0)