Skip to content

Update SwiftPM library version to 5.7 #381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 25, 2022
Merged
Show file tree
Hide file tree
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
25 changes: 17 additions & 8 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,17 @@
"package": "swift-driver",
"repositoryURL": "https://github.com/apple/swift-driver.git",
"state": {
"branch": "release/5.6",
"revision": "9982f32f96a2e0e597d1b4a0af4a7e997dc471be",
"branch": "release/5.7",
"revision": "719426df790661020de657bf38beb2a8b1de5ad3",
"version": null
}
},
{
"package": "llbuild",
"repositoryURL": "https://github.com/apple/swift-llbuild.git",
"state": {
"branch": "release/5.6",
"revision": "acd686530e56122d916acd49a166beb9198e9b87",
"branch": "release/5.7",
"revision": "564424db5fdb62dcb5d863bdf7212500ef03a87b",
"version": null
}
},
Expand Down Expand Up @@ -203,17 +203,26 @@
"package": "SwiftPM",
"repositoryURL": "https://github.com/apple/swift-package-manager.git",
"state": {
"branch": "release/5.6",
"revision": "55c1dc785b151cb51a54314ebc30a96d5cbaddf2",
"branch": "release/5.7",
"revision": "63c14b84dc12c943a9d4c102648b7617d8b92f67",
"version": null
}
},
{
"package": "swift-system",
"repositoryURL": "https://github.com/apple/swift-system.git",
"state": {
"branch": null,
"revision": "836bc4557b74fe6d2660218d56e3ce96aff76574",
"version": "1.1.1"
}
},
{
"package": "swift-tools-support-core",
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
"state": {
"branch": "release/5.6",
"revision": "f6c8048a76e280d0f14cc378b8b5c3cfb77c61fb",
"branch": "release/5.7",
"revision": "184eba382f6abbb362ffc02942d790ff35019ad4",
"version": null
}
},
Expand Down
5 changes: 3 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ let package = Package(
.package(
name: "SwiftPM",
url: "https://github.com/apple/swift-package-manager.git",
.branch("release/5.6")
.branch("release/5.7")
),
.package(
url: "https://github.com/apple/swift-tools-support-core.git",
.branch("release/5.6")
.branch("release/5.7")
),
.package(url: "https://github.com/vapor/vapor.git", from: "4.57.1"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "1.1.0"),
Expand Down Expand Up @@ -81,6 +81,7 @@ let package = Package(
dependencies: [
.product(name: "AsyncHTTPClient", package: "async-http-client"),
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SwiftToolsSupport-auto", package: "swift-tools-support-core"),
"Splash",
"WasmTransformer",
]
Expand Down
2 changes: 1 addition & 1 deletion Sources/CartonCLI/Commands/Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ struct Bundle: AsyncParsableCommand {
wasmOutputFilePath: AbsolutePath,
buildDirectory: AbsolutePath,
bundleDirectory: AbsolutePath,
toolchain: Toolchain,
toolchain: SwiftToolchain.Toolchain,
product: ProductDescription
) throws {
// Rename the final binary to use a part of its hash to bust browsers and CDN caches.
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftToolchain/Manifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import Workspace
extension Manifest {
static func from(path: AbsolutePath, swiftc: AbsolutePath, fileSystem: FileSystem, terminal: InteractiveWriter) async throws -> Manifest {
terminal.write("\nParsing package manifest: ", inColor: .yellow)
let toolchain = ToolchainConfiguration(swiftCompilerPath: swiftc)
let destination = try Destination.hostDestination(swiftc.parentDirectory)
let toolchain = try UserToolchain(destination: destination)
let loader = ManifestLoader(toolchain: toolchain)
let observability = ObservabilitySystem { _, diagnostic in
terminal.write("\n\(diagnostic)")
Expand Down
57 changes: 40 additions & 17 deletions Sources/SwiftToolchain/Toolchain.swift
Original file line number Diff line number Diff line change
Expand Up @@ -351,30 +351,34 @@ public final class Toolchain {
private func basicBuildArguments(flavor: BuildFlavor) -> [String] {
var builderArguments = ["--triple", "wasm32-unknown-wasi"]

// Versions later than 5.3.x have test discovery enabled by default and the explicit flag
// deprecated.
if ["wasm-5.3.0-RELEASE", "wasm-5.3.1-RELEASE"].contains(version) {
builderArguments.append("--enable-test-discovery")
}
if let wasmVersion = try? Version(swiftWasmVersion: version) {

// Versions later than 5.3.x have test discovery enabled by default and the explicit flag
// deprecated.
if wasmVersion.major == 5, wasmVersion.minor == 3 {
builderArguments.append("--enable-test-discovery")
}

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

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

builderArguments.append(contentsOf: flavor.swiftCompilerFlags.flatMap {
["-Xswiftc", $0]
})

return builderArguments
}

Expand Down Expand Up @@ -405,3 +409,22 @@ extension Result where Failure == Error {
}
}
}

extension Version {
/// Initialize a numeric version from a SwiftWasm Toolchain version string, e.g.:
/// "wasm-5.3.1-RELEASE", "wasm-5.7-SNAPSHOT-2022-07-14-a",
/// **discarding all identifiers**.
/// Note: input toolchain name already has "swift-" prefix stripped.
init(swiftWasmVersion: String) throws {
let prefix = "wasm-"
guard swiftWasmVersion.hasPrefix(prefix) else {
throw ToolchainError.invalidVersion(version: swiftWasmVersion)
}
var swiftWasmVersion = swiftWasmVersion
swiftWasmVersion.removeFirst(prefix.count)

let version = try Version(versionString: swiftWasmVersion, usesLenientParsing: true)
// Strip prereleaseIdentifiers
self.init(version.major, version.minor, version.patch)
}
}
3 changes: 2 additions & 1 deletion Tests/CartonCommandTests/CommandTestHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,8 @@ public extension XCTest {
if expectedContains {
XCTAssertTrue(
finalString.contains(expected),
"The final string \(finalString) does not contain \(expected)"
"The final string \(finalString) does not contain \(expected)",
file: file, line: line
)
} else {
AssertEqualStringsIgnoringTrailingWhitespace(
Expand Down
21 changes: 19 additions & 2 deletions Tests/CartonTests/CartonTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@
import CartonHelpers
@testable import CartonKit
import class Foundation.Bundle
import SwiftToolchain
@testable import SwiftToolchain
import TSCBasic
import TSCUtility
import XCTest

final class CartonTests: XCTestCase {
/// Returns path to the built products directory.
var productsDirectory: URL {
var productsDirectory: Foundation.URL {
#if os(macOS)
for bundle in Bundle.allBundles where bundle.bundlePath.hasSuffix(".xctest") {
return bundle.bundleURL.deletingLastPathComponent()
Expand Down Expand Up @@ -143,4 +144,20 @@ final class CartonTests: XCTestCase {
nil
)
}

func testSwiftWasmVersionParsing() throws {
let v5_6 = try Version(swiftWasmVersion: "wasm-5.6.0-RELEASE")
XCTAssertEqual(v5_6.major, 5)
XCTAssertEqual(v5_6.minor, 6)
XCTAssertEqual(v5_6.patch, 0)
XCTAssert(v5_6.prereleaseIdentifiers.isEmpty)
XCTAssert(v5_6 >= Version(5, 6, 0))

let v5_7_snapshot = try Version(swiftWasmVersion: "wasm-5.7-SNAPSHOT-2022-07-14-a")
XCTAssertEqual(v5_7_snapshot.major, 5)
XCTAssertEqual(v5_7_snapshot.minor, 7)
XCTAssertEqual(v5_7_snapshot.patch, 0)
XCTAssert(v5_7_snapshot.prereleaseIdentifiers.isEmpty)
XCTAssert(v5_7_snapshot >= Version(5, 6, 0))
}
}