Skip to content

Commit 652207c

Browse files
committed
Remove curl dependency and use built-in AsyncHTTPClient instead
1 parent b918c7d commit 652207c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Sources/SwiftlyCore/Commands.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,6 @@ extension SystemCommand.DsclCommand.ReadCommand: Output {
9393
}
9494
}
9595

96-
// Create or operate on universal files
97-
// See lipo(1) for details
9896
extension SystemCommand {
9997
// Create or operate on universal files
10098
// See lipo(1) for details

Tools/build-swiftly-release/BuildSwiftlyRelease.swift

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ArgumentParser
2+
import AsyncHTTPClient
23
import Foundation
34
import SwiftlyCore
45
import SystemPackage
@@ -142,9 +143,6 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
142143
}
143144

144145
func buildLinuxRelease() async throws {
145-
// TODO: turn these into checks that the system meets the criteria for being capable of using the toolchain + checking for packages, not tools
146-
let curl = try await self.assertTool("curl", message: "Please install curl with `yum install curl`")
147-
148146
try await self.checkGitRepoStatus()
149147

150148
// Start with a fresh SwiftPM package
@@ -162,7 +160,20 @@ struct BuildSwiftlyRelease: AsyncParsableCommand {
162160
try? FileManager.default.createDirectory(atPath: pkgConfigPath, withIntermediateDirectories: true)
163161

164162
try? FileManager.default.removeItem(atPath: libArchivePath)
165-
try currentPlatform.runProgram(curl, "-L", "-o", "\(buildCheckoutsDir + "/libarchive-\(libArchiveVersion).tar.gz")", "--remote-name", "--location", "https://github.com/libarchive/libarchive/releases/download/v\(libArchiveVersion)/libarchive-\(libArchiveVersion).tar.gz")
163+
164+
// Download libarchive
165+
let libarchiveRequest = HTTPClientRequest(url: "https://github.com/libarchive/libarchive/releases/download/v\(libArchiveVersion)/libarchive-\(libArchiveVersion).tar.gz")
166+
let libarchiveResponse = try await HTTPClient.shared.execute(libarchiveRequest, timeout: .seconds(60))
167+
guard libarchiveResponse.status == .ok else {
168+
throw Error(message: "Download failed with status: \(libarchiveResponse.status)")
169+
}
170+
let buf = try await libarchiveResponse.body.collect(upTo: 20 * 1024 * 1024)
171+
guard let contents = buf.getBytes(at: 0, length: buf.readableBytes) else {
172+
throw Error(message: "Unable to read all of the bytes")
173+
}
174+
let data = Data(contents)
175+
try data.write(to: FilePath(buildCheckoutsDir + "/libarchive-\(libArchiveVersion).tar.gz"))
176+
166177
let libArchiveTarShaActual = try await sys.sha256sum(files: FilePath("\(buildCheckoutsDir)/libarchive-\(libArchiveVersion).tar.gz")).output(currentPlatform)
167178
guard let libArchiveTarShaActual, libArchiveTarShaActual.starts(with: libArchiveTarSha) else {
168179
let shaActual = libArchiveTarShaActual ?? "none"

0 commit comments

Comments
 (0)