Skip to content

Commit daf152d

Browse files
Update SwiftPM library version to 5.7 (#381)
1 parent 734e333 commit daf152d

File tree

7 files changed

+84
-32
lines changed

7 files changed

+84
-32
lines changed

Package.resolved

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,17 @@
113113
"package": "swift-driver",
114114
"repositoryURL": "https://github.com/apple/swift-driver.git",
115115
"state": {
116-
"branch": "release/5.6",
117-
"revision": "9982f32f96a2e0e597d1b4a0af4a7e997dc471be",
116+
"branch": "release/5.7",
117+
"revision": "719426df790661020de657bf38beb2a8b1de5ad3",
118118
"version": null
119119
}
120120
},
121121
{
122122
"package": "llbuild",
123123
"repositoryURL": "https://github.com/apple/swift-llbuild.git",
124124
"state": {
125-
"branch": "release/5.6",
126-
"revision": "acd686530e56122d916acd49a166beb9198e9b87",
125+
"branch": "release/5.7",
126+
"revision": "564424db5fdb62dcb5d863bdf7212500ef03a87b",
127127
"version": null
128128
}
129129
},
@@ -203,17 +203,26 @@
203203
"package": "SwiftPM",
204204
"repositoryURL": "https://github.com/apple/swift-package-manager.git",
205205
"state": {
206-
"branch": "release/5.6",
207-
"revision": "55c1dc785b151cb51a54314ebc30a96d5cbaddf2",
206+
"branch": "release/5.7",
207+
"revision": "63c14b84dc12c943a9d4c102648b7617d8b92f67",
208208
"version": null
209209
}
210210
},
211+
{
212+
"package": "swift-system",
213+
"repositoryURL": "https://github.com/apple/swift-system.git",
214+
"state": {
215+
"branch": null,
216+
"revision": "836bc4557b74fe6d2660218d56e3ce96aff76574",
217+
"version": "1.1.1"
218+
}
219+
},
211220
{
212221
"package": "swift-tools-support-core",
213222
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
214223
"state": {
215-
"branch": "release/5.6",
216-
"revision": "f6c8048a76e280d0f14cc378b8b5c3cfb77c61fb",
224+
"branch": "release/5.7",
225+
"revision": "184eba382f6abbb362ffc02942d790ff35019ad4",
217226
"version": null
218227
}
219228
},

Package.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ let package = Package(
2727
.package(
2828
name: "SwiftPM",
2929
url: "https://github.com/apple/swift-package-manager.git",
30-
.branch("release/5.6")
30+
.branch("release/5.7")
3131
),
3232
.package(
3333
url: "https://github.com/apple/swift-tools-support-core.git",
34-
.branch("release/5.6")
34+
.branch("release/5.7")
3535
),
3636
.package(url: "https://github.com/vapor/vapor.git", from: "4.57.1"),
3737
.package(url: "https://github.com/apple/swift-crypto.git", from: "1.1.0"),
@@ -81,6 +81,7 @@ let package = Package(
8181
dependencies: [
8282
.product(name: "AsyncHTTPClient", package: "async-http-client"),
8383
.product(name: "ArgumentParser", package: "swift-argument-parser"),
84+
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
8485
"Splash",
8586
"WasmTransformer",
8687
]

Sources/CartonCLI/Commands/Bundle.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ struct Bundle: AsyncParsableCommand {
146146
wasmOutputFilePath: AbsolutePath,
147147
buildDirectory: AbsolutePath,
148148
bundleDirectory: AbsolutePath,
149-
toolchain: Toolchain,
149+
toolchain: SwiftToolchain.Toolchain,
150150
product: ProductDescription
151151
) throws {
152152
// Rename the final binary to use a part of its hash to bust browsers and CDN caches.

Sources/SwiftToolchain/Manifest.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ import Workspace
2222
extension Manifest {
2323
static func from(path: AbsolutePath, swiftc: AbsolutePath, fileSystem: FileSystem, terminal: InteractiveWriter) async throws -> Manifest {
2424
terminal.write("\nParsing package manifest: ", inColor: .yellow)
25-
let toolchain = ToolchainConfiguration(swiftCompilerPath: swiftc)
25+
let destination = try Destination.hostDestination(swiftc.parentDirectory)
26+
let toolchain = try UserToolchain(destination: destination)
2627
let loader = ManifestLoader(toolchain: toolchain)
2728
let observability = ObservabilitySystem { _, diagnostic in
2829
terminal.write("\n\(diagnostic)")

Sources/SwiftToolchain/Toolchain.swift

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -351,30 +351,34 @@ public final class Toolchain {
351351
private func basicBuildArguments(flavor: BuildFlavor) -> [String] {
352352
var builderArguments = ["--triple", "wasm32-unknown-wasi"]
353353

354-
// Versions later than 5.3.x have test discovery enabled by default and the explicit flag
355-
// deprecated.
356-
if ["wasm-5.3.0-RELEASE", "wasm-5.3.1-RELEASE"].contains(version) {
357-
builderArguments.append("--enable-test-discovery")
358-
}
354+
if let wasmVersion = try? Version(swiftWasmVersion: version) {
355+
356+
// Versions later than 5.3.x have test discovery enabled by default and the explicit flag
357+
// deprecated.
358+
if wasmVersion.major == 5, wasmVersion.minor == 3 {
359+
builderArguments.append("--enable-test-discovery")
360+
}
359361

360-
// SwiftWasm 5.5 requires explicit linking arguments in certain configurations,
361-
// see https://github.com/swiftwasm/swift/issues/3891
362-
if version.starts(with: "wasm-5.5") {
363-
builderArguments.append(contentsOf: ["-Xlinker", "-licuuc", "-Xlinker", "-licui18n"])
364-
}
362+
// SwiftWasm 5.5 requires explicit linking arguments in certain configurations,
363+
// see https://github.com/swiftwasm/swift/issues/3891
364+
if wasmVersion.major == 5, wasmVersion.minor == 5 {
365+
builderArguments.append(contentsOf: ["-Xlinker", "-licuuc", "-Xlinker", "-licui18n"])
366+
}
365367

366-
// SwiftWasm 5.6 requires reactor model from updated wasi-libc when not building as a command
367-
// see https://github.com/WebAssembly/WASI/issues/13
368-
if version.starts(with: "wasm-5.6") && flavor.environment != .wasmer {
369-
builderArguments.append(contentsOf: [
370-
"-Xswiftc", "-Xclang-linker", "-Xswiftc", "-mexec-model=reactor",
371-
"-Xlinker", "--export=main",
372-
])
368+
// SwiftWasm 5.6 and up requires reactor model from updated wasi-libc when not building as a command
369+
// see https://github.com/WebAssembly/WASI/issues/13
370+
if wasmVersion >= Version(5, 6, 0) && flavor.environment != .wasmer {
371+
builderArguments.append(contentsOf: [
372+
"-Xswiftc", "-Xclang-linker", "-Xswiftc", "-mexec-model=reactor",
373+
"-Xlinker", "--export=main",
374+
])
375+
}
373376
}
374377

375378
builderArguments.append(contentsOf: flavor.swiftCompilerFlags.flatMap {
376379
["-Xswiftc", $0]
377380
})
381+
378382
return builderArguments
379383
}
380384

@@ -405,3 +409,22 @@ extension Result where Failure == Error {
405409
}
406410
}
407411
}
412+
413+
extension Version {
414+
/// Initialize a numeric version from a SwiftWasm Toolchain version string, e.g.:
415+
/// "wasm-5.3.1-RELEASE", "wasm-5.7-SNAPSHOT-2022-07-14-a",
416+
/// **discarding all identifiers**.
417+
/// Note: input toolchain name already has "swift-" prefix stripped.
418+
init(swiftWasmVersion: String) throws {
419+
let prefix = "wasm-"
420+
guard swiftWasmVersion.hasPrefix(prefix) else {
421+
throw ToolchainError.invalidVersion(version: swiftWasmVersion)
422+
}
423+
var swiftWasmVersion = swiftWasmVersion
424+
swiftWasmVersion.removeFirst(prefix.count)
425+
426+
let version = try Version(versionString: swiftWasmVersion, usesLenientParsing: true)
427+
// Strip prereleaseIdentifiers
428+
self.init(version.major, version.minor, version.patch)
429+
}
430+
}

Tests/CartonCommandTests/CommandTestHelper.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,8 @@ public extension XCTest {
325325
if expectedContains {
326326
XCTAssertTrue(
327327
finalString.contains(expected),
328-
"The final string \(finalString) does not contain \(expected)"
328+
"The final string \(finalString) does not contain \(expected)",
329+
file: file, line: line
329330
)
330331
} else {
331332
AssertEqualStringsIgnoringTrailingWhitespace(

Tests/CartonTests/CartonTests.swift

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@
1515
import CartonHelpers
1616
@testable import CartonKit
1717
import class Foundation.Bundle
18-
import SwiftToolchain
18+
@testable import SwiftToolchain
1919
import TSCBasic
20+
import TSCUtility
2021
import XCTest
2122

2223
final class CartonTests: XCTestCase {
2324
/// Returns path to the built products directory.
24-
var productsDirectory: URL {
25+
var productsDirectory: Foundation.URL {
2526
#if os(macOS)
2627
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
2728
return bundle.bundleURL.deletingLastPathComponent()
@@ -143,4 +144,20 @@ final class CartonTests: XCTestCase {
143144
nil
144145
)
145146
}
147+
148+
func testSwiftWasmVersionParsing() throws {
149+
let v5_6 = try Version(swiftWasmVersion: "wasm-5.6.0-RELEASE")
150+
XCTAssertEqual(v5_6.major, 5)
151+
XCTAssertEqual(v5_6.minor, 6)
152+
XCTAssertEqual(v5_6.patch, 0)
153+
XCTAssert(v5_6.prereleaseIdentifiers.isEmpty)
154+
XCTAssert(v5_6 >= Version(5, 6, 0))
155+
156+
let v5_7_snapshot = try Version(swiftWasmVersion: "wasm-5.7-SNAPSHOT-2022-07-14-a")
157+
XCTAssertEqual(v5_7_snapshot.major, 5)
158+
XCTAssertEqual(v5_7_snapshot.minor, 7)
159+
XCTAssertEqual(v5_7_snapshot.patch, 0)
160+
XCTAssert(v5_7_snapshot.prereleaseIdentifiers.isEmpty)
161+
XCTAssert(v5_7_snapshot >= Version(5, 6, 0))
162+
}
146163
}

0 commit comments

Comments
 (0)