Skip to content

Commit 21ab2b4

Browse files
authored
Support downloading toolchains for non-x86_64 architectures (#27)
Right now, this just means supporting ARM (aarch64).
1 parent 6d71826 commit 21ab2b4

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

Sources/Swiftly/Config.swift

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ public struct Config: Codable, Equatable {
2020
/// output and logging.
2121
/// For example, “Ubuntu 18.04” would be returned on Ubuntu 18.04.
2222
public let namePretty: String
23+
24+
/// The CPU architecture of the platform. If omitted, assumed to be x86_64.
25+
public let architecture: String?
2326
}
2427

2528
public var inUse: ToolchainVersion?

Sources/Swiftly/Install.swift

+13-4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,14 @@ struct Install: SwiftlyCommand {
7676
}
7777

7878
var url = "https://download.swift.org/"
79+
80+
var platformString = config.platform.name
81+
var platformFullString = config.platform.nameFull
82+
if let arch = config.platform.architecture {
83+
platformString += "-\(arch)"
84+
platformFullString += "-\(arch)"
85+
}
86+
7987
switch version {
8088
case let .stable(stableVersion):
8189
// Building URL path that looks like:
@@ -84,10 +92,11 @@ struct Install: SwiftlyCommand {
8492
if stableVersion.patch != 0 {
8593
versionString += ".\(stableVersion.patch)"
8694
}
95+
8796
url += "swift-\(versionString)-release/"
88-
url += "\(config.platform.name)/"
97+
url += "\(platformString)/"
8998
url += "swift-\(versionString)-RELEASE/"
90-
url += "swift-\(versionString)-RELEASE-\(config.platform.nameFull).\(Swiftly.currentPlatform.toolchainFileExtension)"
99+
url += "swift-\(versionString)-RELEASE-\(platformFullString).\(Swiftly.currentPlatform.toolchainFileExtension)"
91100
case let .snapshot(release):
92101
let snapshotString: String
93102
switch release.branch {
@@ -99,9 +108,9 @@ struct Install: SwiftlyCommand {
99108
snapshotString = "swift-DEVELOPMENT-SNAPSHOT"
100109
}
101110

102-
url += "\(config.platform.name)/"
111+
url += "\(platformString)/"
103112
url += "\(snapshotString)-\(release.date)-a/"
104-
url += "\(snapshotString)-\(release.date)-a-\(config.platform.nameFull).\(Swiftly.currentPlatform.toolchainFileExtension)"
113+
url += "\(snapshotString)-\(release.date)-a-\(platformFullString).\(Swiftly.currentPlatform.toolchainFileExtension)"
105114
}
106115

107116
let animation = PercentProgressAnimation(

Tests/SwiftlyTests/SwiftlyTests.swift

+2-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ class SwiftlyTests: XCTestCase {
8080
platform: Config.PlatformDefinition(
8181
name: try getEnv("SWIFTLY_PLATFORM_NAME"),
8282
nameFull: try getEnv("SWIFTLY_PLATFORM_NAME_FULL"),
83-
namePretty: try getEnv("SWIFTLY_PLATFORM_NAME_PRETTY")
83+
namePretty: try getEnv("SWIFTLY_PLATFORM_NAME_PRETTY"),
84+
architecture: try? getEnv("SWIFTLY_PLATFORM_ARCH")
8485
)
8586
)
8687
try config.save()

0 commit comments

Comments
 (0)