Skip to content

Commit 5df2325

Browse files
CLI: Update command descriptions and add hidden options
1 parent a4ad494 commit 5df2325

File tree

4 files changed

+57
-12
lines changed

4 files changed

+57
-12
lines changed

Sources/CLI/CLI.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import ArgumentParser
44
struct CLI: ParsableCommand {
55
static let configuration = CommandConfiguration(
66
commandName: "wasmkit",
7-
abstract: "WebAssembly Runtime written in Swift.",
7+
abstract: "WasmKit WebAssembly Runtime",
88
version: "0.0.8",
99
subcommands: [Run.self, Explore.self]
1010
)

Sources/CLI/Commands/Explore.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@ import SystemPackage
33
@_spi(OnlyForCLI) import WasmKit
44

55
struct Explore: ParsableCommand {
6+
7+
static let configuration = CommandConfiguration(
8+
abstract: "Explore the compiled functions of a WebAssembly module",
9+
discussion: """
10+
This command will parse a WebAssembly module and dump the compiled functions.
11+
""",
12+
// This command is just for debugging purposes, so it should be hidden by default
13+
shouldDisplay: false
14+
)
15+
616
@Argument
717
var path: String
818

Sources/CLI/Commands/Run.swift

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,17 @@ import os.signpost
77
#endif
88

99
struct Run: ParsableCommand {
10-
@Flag
10+
static let configuration = CommandConfiguration(
11+
abstract: "Run a WebAssembly module",
12+
discussion: """
13+
This command will parse a WebAssembly module and run it.
14+
"""
15+
)
16+
17+
@Flag(
18+
name: .shortAndLong,
19+
help: "Enable verbose logging"
20+
)
1121
var verbose = false
1222

1323
@Option(
@@ -47,14 +57,41 @@ struct Run: ParsableCommand {
4757
@Option(name: .customLong("dir"), help: "Grant access to the given host directory")
4858
var directories: [String] = []
4959

50-
enum ThreadingModel: String, ExpressibleByArgument {
60+
enum ThreadingModel: String, ExpressibleByArgument, CaseIterable {
5161
case direct
5262
case token
63+
64+
func resolve() -> EngineConfiguration.ThreadingModel {
65+
switch self {
66+
case .direct: return .direct
67+
case .token: return .token
68+
}
69+
}
5370
}
5471

5572
@Option(help: ArgumentHelp("The execution threading model to use", visibility: .hidden))
5673
var threadingModel: ThreadingModel?
5774

75+
enum CompilationMode: String, ExpressibleByArgument, CaseIterable {
76+
case eager
77+
case lazy
78+
79+
func resolve() -> EngineConfiguration.CompilationMode {
80+
switch self {
81+
case .eager: return .eager
82+
case .lazy: return .lazy
83+
}
84+
}
85+
}
86+
87+
@Option(
88+
help: ArgumentHelp(
89+
"The compilation mode to use for WebAssembly modules",
90+
valueName: "mode", visibility: .hidden
91+
)
92+
)
93+
var compilationMode: CompilationMode?
94+
5895
@Option(
5996
help: ArgumentHelp(
6097
"The size of the interpreter stack in bytes",
@@ -151,13 +188,11 @@ struct Run: ParsableCommand {
151188
}
152189

153190
private func deriveRuntimeConfiguration() -> EngineConfiguration {
154-
let threadingModel: EngineConfiguration.ThreadingModel?
155-
switch self.threadingModel {
156-
case .direct: threadingModel = .direct
157-
case .token: threadingModel = .token
158-
case nil: threadingModel = nil
159-
}
160-
return EngineConfiguration(threadingModel: threadingModel, stackSize: self.stackSize)
191+
return EngineConfiguration(
192+
threadingModel: threadingModel?.resolve(),
193+
compilationMode: compilationMode?.resolve(),
194+
stackSize: self.stackSize
195+
)
161196
}
162197

163198
func instantiateWASI(module: Module, interceptor: EngineInterceptor?) throws -> () throws -> Void {

Sources/WasmKit/Engine.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ public struct EngineConfiguration {
8989
/// - Parameter threadingModel: The threading model to use for the virtual
9090
/// machine interpreter. If `nil`, the default threading model for the
9191
/// current platform will be used.
92-
public init(threadingModel: ThreadingModel? = nil, compilationMode: CompilationMode = .lazy, stackSize: Int? = nil) {
92+
public init(threadingModel: ThreadingModel? = nil, compilationMode: CompilationMode? = nil, stackSize: Int? = nil) {
9393
self.threadingModel = threadingModel ?? .defaultForCurrentPlatform
94-
self.compilationMode = compilationMode
94+
self.compilationMode = compilationMode ?? .lazy
9595
self.stackSize = stackSize ?? (1 << 19)
9696
}
9797
}

0 commit comments

Comments
 (0)