From d7bf655419a2d7c7e6ecc58505ecce8a0a3bef15 Mon Sep 17 00:00:00 2001 From: Yuta Saito Date: Mon, 1 Jul 2024 23:43:06 +0900 Subject: [PATCH] Include as many target/product as possible --- Package.swift | 48 ++++++++++++++---------------- Sources/CLI/Run/Run.swift | 7 +++-- Sources/WasmKit/ModuleParser.swift | 3 ++ 3 files changed, 30 insertions(+), 28 deletions(-) diff --git a/Package.swift b/Package.swift index 8b86fe98..3907e35e 100644 --- a/Package.swift +++ b/Package.swift @@ -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( @@ -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"] @@ -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"], @@ -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( @@ -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( @@ -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 diff --git a/Sources/CLI/Run/Run.swift b/Sources/CLI/Run/Run.swift index dc0ca6fb..54bbeddb 100644 --- a/Sources/CLI/Run/Run.swift +++ b/Sources/CLI/Run/Run.swift @@ -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 @@ -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 } diff --git a/Sources/WasmKit/ModuleParser.swift b/Sources/WasmKit/ModuleParser.swift index 26834de7..d6119883 100644 --- a/Sources/WasmKit/ModuleParser.swift +++ b/Sources/WasmKit/ModuleParser.swift @@ -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: