Skip to content
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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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))
}
}