Skip to content

Commit 429a65e

Browse files
committed
Move arch to a global variable
1 parent 92f54bd commit 429a65e

File tree

3 files changed

+11
-29
lines changed

3 files changed

+11
-29
lines changed

Sources/LinuxPlatform/Linux.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,7 @@ public struct Linux: Platform {
382382
}
383383

384384
public func getExecutableName() -> String {
385-
#if arch(x86_64)
386-
let arch = "x86_64"
387-
#elseif arch(arm64)
388-
let arch = "aarch64"
389-
#else
390-
fatalError("Unsupported processor architecture")
391-
#endif
385+
let arch = cpuArch
392386

393387
return "swiftly-\(arch)-unknown-linux-gnu"
394388
}

Sources/SwiftlyCore/HTTPClient.swift

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -295,17 +295,7 @@ public struct SwiftlyHTTPClient {
295295
limit: Int? = nil,
296296
filter: ((ToolchainVersion.StableRelease) -> Bool)? = nil
297297
) async throws -> [ToolchainVersion.StableRelease] {
298-
let arch = if a == nil {
299-
#if arch(x86_64)
300-
"x86_64"
301-
#elseif arch(arm64)
302-
"aarch64"
303-
#else
304-
#error("Unsupported processor architecture")
305-
#endif
306-
} else {
307-
a!
308-
}
298+
let arch = a ?? cpuArch
309299

310300
let url = "https://www.swift.org/api/v1/install/releases.json"
311301
let swiftOrgReleases: [SwiftOrgRelease] = try await self.getFromJSON(url: url, type: [SwiftOrgRelease].self)
@@ -359,17 +349,7 @@ public struct SwiftlyHTTPClient {
359349
limit: Int? = nil,
360350
filter: ((ToolchainVersion.Snapshot) -> Bool)? = nil
361351
) async throws -> [ToolchainVersion.Snapshot] {
362-
let arch = if a == nil {
363-
#if arch(x86_64)
364-
"x86_64"
365-
#elseif arch(arm64)
366-
"aarch64"
367-
#else
368-
#error("Unsupported processor architecture")
369-
#endif
370-
} else {
371-
a!
372-
}
352+
let arch = a ?? cpuArch
373353

374354
let platformName = if platform.name == PlatformDefinition.macOS.name {
375355
"macos"

Sources/SwiftlyCore/SwiftlyCore.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,11 @@ public func readLine(prompt: String) -> String? {
5151
}
5252
return provider.readLine()
5353
}
54+
55+
#if arch(x86_64)
56+
public let cpuArch = "x86_64"
57+
#elseif arch(arm64)
58+
public let cpuArch = "aarch64"
59+
#else
60+
#error("Unsupported processor architecture")
61+
#endif

0 commit comments

Comments
 (0)