Skip to content

Commit 2efcfbc

Browse files
authored
NFC: make CLI commands reusable with new CLICommands module (#249)
Prerequisite for #248 to make existing CLI commands reused in both `wasmkit` and `wasmkit-llvm` executables.
1 parent 5544aa4 commit 2efcfbc

13 files changed

Lines changed: 117 additions & 68 deletions

File tree

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ jobs:
305305
curl -L https://github.com/Kitware/CMake/releases/download/v3.29.2/cmake-3.29.2-linux-x86_64.tar.gz | tar xz --strip-component 1 -C /usr/local/
306306
- run: cmake -G Ninja -B ./build
307307
- run: cmake --build ./build
308-
- run: ./build/bin/wasmkit-cli --version
308+
- run: ./build/bin/wasmkit --version
309309

310310
build-wasi:
311311
runs-on: ubuntu-24.04

CMakeLists.txt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,6 @@ add_compile_definitions(
5252

5353
include(FetchContent)
5454

55-
find_package(SwiftSystem CONFIG)
56-
if(NOT SwiftSystem_FOUND)
57-
message("-- Vending SwiftSystem")
58-
FetchContent_Declare(SwiftSystem
59-
GIT_REPOSITORY https://github.com/apple/swift-system
60-
GIT_TAG 1.5.0
61-
)
62-
FetchContent_MakeAvailable(SwiftSystem)
63-
endif()
64-
6555
option(WASMKIT_BUILD_CLI "Build wasmkit-cli" ON)
6656

6757
if(WASMKIT_BUILD_CLI)
@@ -77,6 +67,17 @@ if(WASMKIT_BUILD_CLI)
7767
endif()
7868
endif()
7969

70+
find_package(SwiftSystem CONFIG)
71+
if(NOT SwiftSystem_FOUND)
72+
message("-- Vending SwiftSystem")
73+
FetchContent_Declare(SwiftSystem
74+
GIT_REPOSITORY https://github.com/apple/swift-system
75+
GIT_TAG 1.5.0
76+
)
77+
FetchContent_MakeAvailable(SwiftSystem)
78+
endif()
79+
80+
8081
add_subdirectory(Sources)
8182
add_subdirectory(Tests)
8283
add_subdirectory(cmake/modules)

Package.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ let package = Package(
2222
targets: [
2323
.executableTarget(
2424
name: "CLI",
25+
dependencies: [
26+
"CLICommands"
27+
],
28+
exclude: ["CMakeLists.txt"]
29+
),
30+
31+
.target(
32+
name: "CLICommands",
2533
dependencies: [
2634
"WAT",
2735
"WasmKit",

Package@swift-6.1.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import class Foundation.ProcessInfo
66

77
let DarwinPlatforms: [Platform] = [.macOS, .iOS, .watchOS, .tvOS, .visionOS]
88

9-
let cliTarget = Target.executableTarget(
10-
name: "CLI",
9+
let cliCommandsTarget = Target.target(
10+
name: "CLICommands",
1111
dependencies: [
1212
"WAT",
1313
"WasmKit",
@@ -36,7 +36,12 @@ let package = Package(
3636
"WasmDebuggingSupport",
3737
],
3838
targets: [
39-
cliTarget,
39+
cliCommandsTarget,
40+
.executableTarget(
41+
name: "CLI",
42+
dependencies: ["CLICommands"],
43+
exclude: ["CMakeLists.txt"]
44+
),
4045
.target(
4146
name: "WasmKit",
4247
dependencies: [
@@ -193,7 +198,7 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
193198
),
194199
])
195200

196-
cliTarget.dependencies.append(contentsOf: [
201+
cliCommandsTarget.dependencies.append(contentsOf: [
197202
.product(name: "Logging", package: "swift-log", condition: .when(traits: ["WasmDebuggingSupport"])),
198203
.product(name: "NIOCore", package: "swift-nio", condition: .when(traits: ["WasmDebuggingSupport"])),
199204
.product(name: "NIOPosix", package: "swift-nio", condition: .when(traits: ["WasmDebuggingSupport"])),

Sources/CLI/CLI.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ArgumentParser
2+
import CLICommands
23

34
@main
45
struct CLI: AsyncParsableCommand {

Sources/CLI/CMakeLists.txt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
add_executable(wasmkit-cli
2-
Commands/Explore.swift
3-
Commands/Run.swift
4-
Commands/Wat2wasm.swift
1+
add_executable(wasmkit
52
CLI.swift
63
)
74

8-
target_link_wasmkit_libraries(wasmkit-cli PUBLIC
9-
ArgumentParser WAT WasmKitWASI)
5+
target_compile_options(wasmkit PRIVATE
6+
-package-name WasmKitPackage
7+
)
8+
9+
target_link_wasmkit_libraries(wasmkit PUBLIC
10+
CLICommands)
1011

11-
install(TARGETS wasmkit-cli
12+
install(TARGETS wasmkit
1213
RUNTIME DESTINATION bin)

Sources/CLI/Commands/Parse.swift

Lines changed: 0 additions & 20 deletions
This file was deleted.

Sources/CLICommands/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
add_wasmkit_library(CLICommands
2+
Explore.swift
3+
Run.swift
4+
Wat2wasm.swift
5+
)
6+
7+
target_link_wasmkit_libraries(CLICommands PUBLIC
8+
WAT WasmKitWASI)
9+
10+
add_dependencies(
11+
CLICommands
12+
13+
ArgumentParser
14+
)
15+
16+
target_link_libraries(CLICommands
17+
18+
PUBLIC
19+
ArgumentParser
20+
)
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import ArgumentParser
22
import SystemPackage
33
@_spi(OnlyForCLI) import WasmKit
44

5-
struct Explore: ParsableCommand {
5+
package struct Explore: ParsableCommand {
66

7-
static let configuration = CommandConfiguration(
7+
package static let configuration = CommandConfiguration(
88
abstract: "Explore the compiled functions of a WebAssembly module",
99
discussion: """
1010
This command will parse a WebAssembly module and dump the compiled functions.
@@ -22,7 +22,9 @@ struct Explore: ParsableCommand {
2222
}
2323
}
2424

25-
func run() throws {
25+
package init() {}
26+
27+
package func run() throws {
2628
let module = try parseWasm(filePath: FilePath(path))
2729
// Instruction dumping requires token threading model for now
2830
let configuration = EngineConfiguration(threadingModel: .token)

0 commit comments

Comments
 (0)