Skip to content

Commit

Permalink
Include as many target/product as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Jul 1, 2024
1 parent eb27bde commit d7bf655
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 28 deletions.
48 changes: 23 additions & 25 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@ let package = Package(
name: "WasmParser",
targets: ["WasmParser"]
),
.library(
name: "WIT", targets: ["WIT"]
),
.executable(
name: "wasmkit-cli",
targets: ["CLI"]
),
.library(name: "_CabiShims", targets: ["_CabiShims"]),
],
targets: [
.executableTarget(
Expand Down Expand Up @@ -59,6 +63,24 @@ let package = Package(
.product(name: "SystemPackage", package: "swift-system"),
]
),
.target(name: "WIT"),
.testTarget(name: "WITTests", dependencies: ["WIT"]),
.target(name: "WITOverlayGenerator", dependencies: ["WIT"]),
.target(name: "_CabiShims"),
.target(name: "WITExtractor"),
.testTarget(
name: "WITExtractorTests",
dependencies: ["WITExtractor", "WIT"]
),
.executableTarget(
name: "WITTool",
dependencies: [
"WIT",
"WITOverlayGenerator",
"WITExtractor",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
.testTarget(
name: "WasmKitTests",
dependencies: ["WasmKit"]
Expand Down Expand Up @@ -119,10 +141,6 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
name: "WASITests",
dependencies: ["WASI"]
),
.testTarget(
name: "WASITests",
dependencies: ["WASI"]
),
])
let targetDependenciesToAdd = [
"CLI": ["WasmKitWASI"],
Expand All @@ -136,19 +154,13 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
}
}

// Add WIT-related products and targets
// Add build tool plugins only for non-Windows platforms
package.products.append(contentsOf: [
.library(name: "WIT", targets: ["WIT"]),
.library(name: "_CabiShims", targets: ["_CabiShims"]),
.plugin(name: "WITOverlayPlugin", targets: ["WITOverlayPlugin"]),
.plugin(name: "WITExtractorPlugin", targets: ["WITExtractorPlugin"]),
])

package.targets.append(contentsOf: [
.target(name: "WIT"),
.testTarget(name: "WITTests", dependencies: ["WIT"]),
.target(name: "WITOverlayGenerator", dependencies: ["WIT"]),
.target(name: "_CabiShims"),
.plugin(name: "WITOverlayPlugin", capability: .buildTool(), dependencies: ["WITTool"]),
.plugin(name: "GenerateOverlayForTesting", capability: .buildTool(), dependencies: ["WITTool"]),
.testTarget(
Expand All @@ -157,11 +169,6 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
exclude: ["Fixtures", "Compiled", "Generated"],
plugins: [.plugin(name: "GenerateOverlayForTesting")]
),
.target(name: "WITExtractor"),
.testTarget(
name: "WITExtractorTests",
dependencies: ["WITExtractor", "WIT"]
),
.plugin(
name: "WITExtractorPlugin",
capability: .command(
Expand All @@ -174,14 +181,5 @@ if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
name: "WITExtractorPluginTests",
exclude: ["Fixtures"]
),
.executableTarget(
name: "WITTool",
dependencies: [
"WIT",
"WITOverlayGenerator",
"WITExtractor",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),
])
#endif
7 changes: 4 additions & 3 deletions Sources/CLI/Run/Run.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,14 @@ struct Run: ParsableCommand {
)
}
#else
// GuestTimeProfiler is not available without SystemExtras
func deriveInterceptor() throws -> (interceptor: RuntimeInterceptor, finalize: () -> Void)? {
nil
}
#endif

func instantiateWASI(module: Module, interceptor: RuntimeInterceptor?) throws -> () throws -> Void {
#if os(Windows)
fatalError("WASI is not supported on Windows")
#else
#if canImport(WasmKitWASI)
// Flatten environment variables into a dictionary (Respect the last value if a key is duplicated)
let environment = environment.reduce(into: [String: String]()) {
$0[$1.key] = $1.value
Expand All @@ -124,6 +123,8 @@ struct Run: ParsableCommand {
let exitCode = try wasi.start(moduleInstance, runtime: runtime)
throw ExitCode(Int32(exitCode))
}
#else
fatalError("WASI is not supported on this platform")
#endif
}

Expand Down
3 changes: 3 additions & 0 deletions Sources/WasmKit/ModuleParser.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import SystemPackage
import WasmParser
#if os(Windows)
import ucrt
#endif

/// Parse a given file as a WebAssembly binary format file
/// > Note: <https://webassembly.github.io/spec/core/binary/index.html>
Expand Down

0 comments on commit d7bf655

Please sign in to comment.