Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions Tools/build-swiftly-release/BuildSwiftlyRelease.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
try await sys.tar(.directory(buildCheckoutsDir)).extract(.compressed, .archive(buildCheckoutsDir / "libarchive-\(libArchiveVersion).tar.gz")).runEcho()

let cwd = fs.cwd
FileManager.default.changeCurrentDirectoryPath(libArchivePath.string)
_ = FileManager.default.changeCurrentDirectoryPath(libArchivePath.string)

let swiftVerRegex: Regex<(Substring, Substring)> = try! Regex("Swift version (\\d+\\.\\d+\\.?\\d*) ")

Expand Down Expand Up @@ -205,12 +205,35 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
throw Error(message: "Swift release \(swiftVersion) has no Static SDK offering")
}

try await sys.swift().sdk().install(.checksum(sdkPlatform.checksum ?? "deadbeef"), bundle_path_or_url: "https://download.swift.org/swift-\(swiftVersion)-release/static-sdk/swift-\(swiftVersion)-RELEASE/swift-\(swiftVersion)-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz").runEcho()
// Download and extract SDK into the build checkouts directory
let sdkRequest = HTTPClientRequest(url: "https://download.swift.org/swift-\(swiftVersion)-release/static-sdk/swift-\(swiftVersion)-RELEASE/swift-\(swiftVersion)-RELEASE_static-linux-0.0.1.artifactbundle.tar.gz")
let sdkResponse = try await httpExecutor.httpClient.execute(sdkRequest, timeout: .seconds(60))
guard sdkResponse.status == .ok else {
throw Error(message: "Download failed with status: \(sdkResponse.status)")
}

try await NIOFileSystem.FileSystem.shared.withFileHandle(forWritingAt: buildCheckoutsDir / "static-linux-sdk.tar.gz", options: .newFile(replaceExisting: true)) { fileHandle in
var pos: Int64 = 0

for try await buffer in sdkResponse.body {
pos += try await fileHandle.write(contentsOf: buffer, toAbsoluteOffset: pos)
}
}

guard let sdkShaActual = try await sys.sha256sum(files: buildCheckoutsDir / "static-linux-sdk.tar.gz").output(limit: 1024) else { throw Error(message: "Unable to calculate sha256sum of static-linux-sdk.tar.gz") }
guard sdkShaActual.starts(with: sdkPlatform.checksum ?? "beefdead") else {
throw Error(message: "The static linux sdk tar.gz file sha256sum is \(sdkShaActual), but expected \(sdkPlatform.checksum ?? "none")")
}

let sdkDir = fs.mktemp()
try await fs.mkdir(atPath: sdkDir)

try await sys.tar(.directory(sdkDir)).extract(.compressed, .archive(buildCheckoutsDir / "static-linux-sdk.tar.gz")).runEcho()

var customEnv: Environment = .inherit
customEnv = customEnv.updating([
"CC": "\(cwd)/Tools/build-swiftly-release/musl-clang",
"MUSL_PREFIX": "\(fs.home / ".swiftpm/swift-sdks/\(sdkName).artifactbundle/\(sdkName)/swift-linux-musl/musl-1.2.5.sdk/\(arch)/usr")",
"MUSL_PREFIX": "\(sdkDir / "\(sdkName).artifactbundle/\(sdkName)/swift-linux-musl/musl-1.2.5.sdk/\(arch)/usr")",
])

let configCmd = Configuration(
Expand Down Expand Up @@ -252,9 +275,9 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {

try await sys.make().install().runEcho()

FileManager.default.changeCurrentDirectoryPath(cwd.string)
_ = FileManager.default.changeCurrentDirectoryPath(cwd.string)

try await sys.swift().build(.swift_sdk("\(arch)-swift-linux-musl"), .product("swiftly"), .pkg_config_path(pkgConfigPath / "lib/pkgconfig"), .static_swift_stdlib, .configuration("release")).runEcho()
try await sys.swift().build(.swift_sdks_path(sdkDir.string), .swift_sdk("\(arch)-swift-linux-musl"), .arch(arch), .product("swiftly"), .pkg_config_path(pkgConfigPath / "lib/pkgconfig"), .configuration("release")).runEcho()

let releaseDir = cwd / ".build/release"

Expand All @@ -263,11 +286,7 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {

try await self.collectLicenses(releaseDir)

#if arch(arm64)
let releaseArchive = releaseDir / "swiftly-\(version)-aarch64.tar.gz"
#else
let releaseArchive = releaseDir / "swiftly-\(version)-x86_64.tar.gz"
#endif
let releaseArchive = releaseDir / "swiftly-\(version)-\(arch).tar.gz"

try await sys.tar(.directory(releaseDir)).create(.compressed, .archive(releaseArchive), files: ["swiftly", "LICENSE.txt"]).runEcho()

Expand All @@ -276,19 +295,15 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
if self.test {
let debugDir = cwd / ".build/debug"

#if arch(arm64)
let testArchive = debugDir / "test-swiftly-linux-aarch64.tar.gz"
#else
let testArchive = debugDir / "test-swiftly-linux-x86_64.tar.gz"
#endif
let testArchive = debugDir / "test-swiftly-linux-\(arch).tar.gz"

try await sys.swift().build(.swift_sdk("\(arch)-swift-linux-musl"), .product("test-swiftly"), .pkg_config_path(pkgConfigPath / "lib/pkgconfig"), .static_swift_stdlib, .configuration("debug")).runEcho()
try await sys.swift().build(.swift_sdks_path(sdkDir.string), .swift_sdk("\(arch)-swift-linux-musl"), .arch(arch), .product("test-swiftly"), .pkg_config_path(pkgConfigPath / "lib/pkgconfig"), .configuration("debug")).runEcho()
try await sys.tar(.directory(debugDir)).create(.compressed, .archive(testArchive), files: ["test-swiftly"]).runEcho()

print(testArchive)
}

try await sys.swift().sdk().remove(sdk_id_or_bundle_name: sdkName).runEcho()
try await fs.remove(atPath: sdkDir)
}

func buildMacOSRelease(cert: String?, identifier: String) async throws {
Expand Down