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

Update SwiftPM branch to 5.8 and fix build errors #395

Merged
merged 8 commits into from
May 4, 2023
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
24 changes: 12 additions & 12 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -105,25 +105,25 @@
"repositoryURL": "https://github.com/apple/swift-crypto.git",
"state": {
"branch": null,
"revision": "ddb07e896a2a8af79512543b1c7eb9797f8898a5",
"version": "1.1.7"
"revision": "75ec60b8b4cc0f085c3ac414f3dca5625fa3588e",
"version": "2.2.4"
}
},
{
"package": "swift-driver",
"repositoryURL": "https://github.com/apple/swift-driver.git",
"state": {
"branch": "release/5.7",
"revision": "719426df790661020de657bf38beb2a8b1de5ad3",
"branch": "release/5.8",
"revision": "7cfe0c0b6e6297efe88a3ce34e6138ee7eda969e",
"version": null
}
},
{
"package": "llbuild",
"repositoryURL": "https://github.com/apple/swift-llbuild.git",
"state": {
"branch": "release/5.7",
"revision": "564424db5fdb62dcb5d863bdf7212500ef03a87b",
"branch": "release/5.8",
"revision": "dccfc2e127a34b89a849407594cf2d604b598ba9",
"version": null
}
},
Expand Down Expand Up @@ -203,8 +203,8 @@
"package": "SwiftPM",
"repositoryURL": "https://github.com/apple/swift-package-manager.git",
"state": {
"branch": "release/5.7",
"revision": "63c14b84dc12c943a9d4c102648b7617d8b92f67",
"branch": "release/5.8",
"revision": "fe383ccb099ff65ca1403137e7383aedaf99af87",
"version": null
}
},
Expand All @@ -221,8 +221,8 @@
"package": "swift-tools-support-core",
"repositoryURL": "https://github.com/apple/swift-tools-support-core.git",
"state": {
"branch": "release/5.7",
"revision": "184eba382f6abbb362ffc02942d790ff35019ad4",
"branch": "release/5.8",
"revision": "ac4871e01ef338cb95b5d28328cab0ec1dfae935",
"version": null
}
},
Expand Down Expand Up @@ -258,8 +258,8 @@
"repositoryURL": "https://github.com/jpsim/Yams.git",
"state": {
"branch": null,
"revision": "9ff1cc9327586db4e0c8f46f064b6a82ec1566fa",
"version": "4.0.6"
"revision": "f47ba4838c30dbd59998a4e4c87ab620ff959e8a",
"version": "5.0.5"
}
}
]
Expand Down
6 changes: 3 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ let package = Package(
.package(
name: "SwiftPM",
url: "https://github.com/apple/swift-package-manager.git",
.branch("release/5.7")
.branch("release/5.8")
),
.package(
url: "https://github.com/apple/swift-tools-support-core.git",
.branch("release/5.7")
.branch("release/5.8")
),
.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"),
.package(url: "https://github.com/apple/swift-crypto.git", from: "2.2.0"),
.package(url: "https://github.com/JohnSundell/Splash.git", from: "0.16.0"),
.package(
url: "https://github.com/swiftwasm/WasmTransformer",
Expand Down
23 changes: 13 additions & 10 deletions Sources/CartonCLI/Commands/Bundle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ struct Bundle: AsyncParsableCommand {
@Option(
name: .long,
help: """
Which optimizations to apply to the .wasm binary output.
Available values: \(
Which optimizations to apply to the .wasm binary output.
Available values: \(
WasmOptimizations.allCases.map(\.rawValue).joined(separator: ", ")
)
"""
)
"""
)
var wasmOptimizations: WasmOptimizations = .size

Expand Down Expand Up @@ -122,7 +122,9 @@ struct Bundle: AsyncParsableCommand {
terminal.write("Bundle generation finished successfully\n", inColor: .green, bold: true)
}

func optimize(_ inputPath: AbsolutePath, outputPath: AbsolutePath, terminal: InteractiveWriter) async throws {
func optimize(_ inputPath: AbsolutePath, outputPath: AbsolutePath, terminal: InteractiveWriter)
async throws
{
var wasmOptArgs = ["wasm-opt", "-Os", inputPath.pathString, "-o", outputPath.pathString]
if debugInfo {
wasmOptArgs.append("--debuginfo")
Expand Down Expand Up @@ -156,7 +158,7 @@ struct Bundle: AsyncParsableCommand {
try localFileSystem.move(from: wasmOutputFilePath, to: mainModulePath)

// Copy the bundle entrypoint, point to the binary, and give it a cachebuster name.
let (_, _, entrypointPath) = dependency.paths(on: localFileSystem)
let (_, _, entrypointPath) = try dependency.paths(on: localFileSystem)
let entrypoint = try ByteString(
encodingAsUTF8: localFileSystem.readFileContents(entrypointPath)
.description
Expand All @@ -173,10 +175,11 @@ struct Bundle: AsyncParsableCommand {

try localFileSystem.writeFileContents(
AbsolutePath(bundleDirectory, "index.html"),
bytes: ByteString(encodingAsUTF8: HTML.indexPage(
customContent: HTML.readCustomIndexPage(at: customIndexPage, on: localFileSystem),
entrypointName: entrypointName
))
bytes: ByteString(
encodingAsUTF8: HTML.indexPage(
customContent: HTML.readCustomIndexPage(at: customIndexPage, on: localFileSystem),
entrypointName: entrypointName
))
)

let manifest = try toolchain.manifest.get()
Expand Down
4 changes: 3 additions & 1 deletion Sources/CartonCLI/Commands/Dev.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ struct Dev: AsyncParsableCommand {
verbose: verbose,
port: port,
host: host,
customIndexPath: customIndexPage.map { AbsolutePath($0, relativeTo: localFileSystem.currentWorkingDirectory!) },
customIndexPath: customIndexPage.map {
try AbsolutePath(validating: $0, relativeTo: localFileSystem.currentWorkingDirectory!)
},
// swiftlint:disable:next force_try
manifest: try! toolchain.manifest.get(),
product: build.product,
Expand Down
19 changes: 11 additions & 8 deletions Sources/CartonCLI/Commands/Init.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ struct Init: AsyncParsableCommand {
subcommands: [ListTemplates.self]
)

@Option(name: .long,
help: "The template to base the project on.",
transform: { Templates(rawValue: $0.lowercased()) })
@Option(
name: .long,
help: "The template to base the project on.",
transform: { Templates(rawValue: $0.lowercased()) })
var template: Templates?

@Option(name: .long,
help: "The name of the project") var name: String?
@Option(
name: .long,
help: "The name of the project") var name: String?

func run() async throws {
let terminal = InteractiveWriter.stdout
Expand All @@ -50,9 +52,10 @@ struct Init: AsyncParsableCommand {
terminal.write(" in ")
terminal.write("\(name)\n", inColor: .cyan)

guard let packagePath = self.name == nil ?
localFileSystem.currentWorkingDirectory :
AbsolutePath(name, relativeTo: currentDir)
guard
let packagePath = try self.name == nil
? localFileSystem.currentWorkingDirectory
: AbsolutePath(validating: name, relativeTo: currentDir)
else {
terminal.write("Path to project could be created.\n", inColor: .red)
return
Expand Down
7 changes: 4 additions & 3 deletions Sources/CartonCLI/Commands/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
import ArgumentParser

struct BuildOptions: ParsableArguments {
@Option(name: .customLong("Xswiftc", withSingleDash: true),
parsing: .unconditionalSingleValue,
help: "Pass flag through to all Swift compiler invocations")
@Option(
name: .customLong("Xswiftc", withSingleDash: true),
parsing: .unconditionalSingleValue,
help: "Pass flag through to all Swift compiler invocations")
var swiftCompilerFlags: [String] = []

init() {}
Expand Down
7 changes: 4 additions & 3 deletions Sources/CartonCLI/Commands/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ import TSCBasic

/// Proxy swift-package command to locally pinned toolchain version.
struct Package: AsyncParsableCommand {
static let configuration = CommandConfiguration(abstract: """
Perform operations on Swift packages.
""")
static let configuration = CommandConfiguration(
abstract: """
Perform operations on Swift packages.
""")

@Argument(wrappedValue: [], parsing: .remaining)
var arguments: [String]
Expand Down
13 changes: 7 additions & 6 deletions Sources/CartonCLI/Commands/SDK/Local.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ import SwiftToolchain
import TSCBasic

struct Local: ParsableCommand {
static let configuration = CommandConfiguration(abstract: """
Prints SDK version used for the current project or saves it \
in the `.swift-version` file if a version is passed as an argument.
""")
static let configuration = CommandConfiguration(
abstract: """
Prints SDK version used for the current project or saves it \
in the `.swift-version` file if a version is passed as an argument.
""")

@Argument() var version: String?

func run() throws {
let terminal = InteractiveWriter.stdout
let toolchainSystem = ToolchainSystem(fileSystem: localFileSystem)
let toolchainSystem = try ToolchainSystem(fileSystem: localFileSystem)

if let version = version {
let versions = try toolchainSystem.fetchAllSwiftVersions()
if versions.contains(version) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/CartonCLI/Commands/SDK/Versions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct Versions: ParsableCommand {
func run() throws {
let terminal = InteractiveWriter.stdout

let toolchainSystem = ToolchainSystem(fileSystem: localFileSystem)
let toolchainSystem = try ToolchainSystem(fileSystem: localFileSystem)
let versions = try toolchainSystem.fetchAllSwiftVersions()
let localVersion = try toolchainSystem.fetchLocalSwiftVersion()
if versions.count > 0 {
Expand Down
8 changes: 5 additions & 3 deletions Sources/CartonCLI/Commands/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct Test: AsyncParsableCommand {
private var environment = Environment.wasmer

/// It is implemented as a separate flag instead of a `--environment` variant because `--environment`
/// is designed to accept specific browser names in the future like `--environment firefox`.
/// is designed to accept specific browser names in the future like `--environment firefox`.
/// Then `--headless` should be able to be used with `defaultBrowser` and other browser values.
@Flag(help: "When running browser tests, run the browser in headless mode")
var headless: Bool = false
Expand Down Expand Up @@ -83,7 +83,8 @@ struct Test: AsyncParsableCommand {

func validate() throws {
if headless && environment != .defaultBrowser {
throw TestError(description: "The `--headless` flag can be applied only for browser environments")
throw TestError(
description: "The `--headless` flag can be applied only for browser environments")
}
}

Expand All @@ -92,7 +93,8 @@ struct Test: AsyncParsableCommand {
let toolchain = try await Toolchain(localFileSystem, terminal)
let bundlePath: AbsolutePath
if let preBundlePath = self.prebuiltTestBundlePath {
bundlePath = AbsolutePath(preBundlePath, relativeTo: localFileSystem.currentWorkingDirectory!)
bundlePath = try AbsolutePath(
validating: preBundlePath, relativeTo: localFileSystem.currentWorkingDirectory!)
guard localFileSystem.exists(bundlePath) else {
terminal.write(
"No prebuilt binary found at \(bundlePath)\n",
Expand Down
25 changes: 14 additions & 11 deletions Sources/CartonCLI/Commands/TestRunners/BrowserTestRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ enum BrowserTestRunnerError: Error, CustomStringConvertible {
case let .invalidRemoteURL(url): return "Invalid remote URL: \(url)"
case .failedToFindWebDriver:
return """
Failed to find WebDriver executable or remote URL to a running driver process.
Please make sure that you are satisfied with one of the followings (in order of priority)
1. Set `WEBDRIVER_REMOTE_URL` with the address of remote WebDriver like `WEBDRIVER_REMOTE_URL=http://localhost:9515`.
2. Set `WEBDRIVER_PATH` with the path to your WebDriver executable.
3. `chromedriver`, `geckodriver`, `safaridriver`, or `msedgedriver` has been installed in `PATH`
"""
Failed to find WebDriver executable or remote URL to a running driver process.
Please make sure that you are satisfied with one of the followings (in order of priority)
1. Set `WEBDRIVER_REMOTE_URL` with the address of remote WebDriver like `WEBDRIVER_REMOTE_URL=http://localhost:9515`.
2. Set `WEBDRIVER_PATH` with the path to your WebDriver executable.
3. `chromedriver`, `geckodriver`, `safaridriver`, or `msedgedriver` has been installed in `PATH`
"""
}
}
}
Expand Down Expand Up @@ -72,7 +72,7 @@ struct BrowserTestRunner: TestRunner {
httpClient = HTTPClient(eventLoopGroupProvider: .shared(eventLoopGroup))
}

typealias Disposer = () -> ()
typealias Disposer = () -> Void

func findAvailablePort() async throws -> SocketAddress {
let bootstrap = ServerBootstrap(group: eventLoopGroup)
Expand Down Expand Up @@ -118,8 +118,10 @@ struct BrowserTestRunner: TestRunner {
let driverCandidates = [
"chromedriver", "geckodriver", "safaridriver", "msedgedriver",
]
terminal.logLookup("- checking WebDriver executable in PATH: ", driverCandidates.joined(separator: ", "))
guard let found = driverCandidates.lazy.compactMap({ Process.findExecutable($0) }).first else {
terminal.logLookup(
"- checking WebDriver executable in PATH: ", driverCandidates.joined(separator: ", "))
guard let found = driverCandidates.lazy.compactMap({ Process.findExecutable($0) }).first
else {
return nil
}
return try await launchDriver(executablePath: found.pathString)
Expand Down Expand Up @@ -153,11 +155,12 @@ struct BrowserTestRunner: TestRunner {
.shared(eventLoopGroup)
)
let localURL = try await server.start()
var disposer: () async throws -> () = {}
var disposer: () async throws -> Void = {}
do {
if headless {
let (endpoint, clientDisposer) = try await selectWebDriver()
let client = try await WebDriverClient.newSession(endpoint: endpoint, httpClient: httpClient)
let client = try await WebDriverClient.newSession(
endpoint: endpoint, httpClient: httpClient)
disposer = {
try await client.closeSession()
clientDisposer()
Expand Down
8 changes: 5 additions & 3 deletions Sources/CartonCLI/Commands/TestRunners/NodeTestRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,20 @@ struct NodeTestRunner: TestRunner {
terminal.write("\nRunning the test bundle with Node.js:\n", inColor: .yellow)

try Constants.entrypoint.check(on: localFileSystem, terminal)
let (_, _, entrypointPath) = Constants.entrypoint.paths(on: localFileSystem)
let (_, _, entrypointPath) = try Constants.entrypoint.paths(on: localFileSystem)

// Allow Node.js to resolve modules from resource directories by making them relative to the entrypoint path.
let buildDirectory = testFilePath.parentDirectory
let staticDirectory = entrypointPath.parentDirectory

// Clean up existing symlinks before creating new ones.
for existingSymlink in try localFileSystem.resourcesDirectoryNames(relativeTo: staticDirectory) {
for existingSymlink in try localFileSystem.resourcesDirectoryNames(relativeTo: staticDirectory)
{
try localFileSystem.removeFileTree(staticDirectory.appending(component: existingSymlink))
}

let resourceDirectories = try localFileSystem.resourcesDirectoryNames(relativeTo: buildDirectory)
let resourceDirectories = try localFileSystem.resourcesDirectoryNames(
relativeTo: buildDirectory)

// Create new symlink for each resource directory.
for resourcesDirectoryName in resourceDirectories {
Expand Down
12 changes: 6 additions & 6 deletions Sources/CartonHelpers/Async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import ArgumentParser

public extension Sequence {
func asyncMap<T>(
extension Sequence {
public func asyncMap<T>(
_ transform: (Element) async throws -> T
) async rethrows -> [T] {
var values = [T]()
Expand All @@ -33,8 +33,8 @@ public protocol AsyncParsableCommand: ParsableCommand {
mutating func run() async throws
}

public extension AsyncParsableCommand {
mutating func run() throws {
extension AsyncParsableCommand {
public mutating func run() throws {
throw CleanExit.helpRequest(self)
}
}
Expand All @@ -43,8 +43,8 @@ public protocol AsyncMain {
associatedtype Command: ParsableCommand
}

public extension AsyncMain {
static func main() async {
extension AsyncMain {
public static func main() async {
do {
var command = try Command.parseAsRoot()
if var command = command as? AsyncParsableCommand {
Expand Down
Loading