Skip to content
Draft
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
201 changes: 201 additions & 0 deletions [email protected]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added separate Package.swift manifest to hide debugger support behind a trait for now, and traits aren't supported in 6.0.

Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
// swift-tools-version:6.1

import PackageDescription

import class Foundation.ProcessInfo

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

let package = Package(
name: "WasmKit",
platforms: [.macOS(.v14), .iOS(.v17)],
products: [
.executable(name: "wasmkit-cli", targets: ["CLI"]),
.library(name: "WasmKit", targets: ["WasmKit"]),
.library(name: "WasmKitWASI", targets: ["WasmKitWASI"]),
.library(name: "WASI", targets: ["WASI"]),
.library(name: "WasmParser", targets: ["WasmParser"]),
.library(name: "WAT", targets: ["WAT"]),
.library(name: "WIT", targets: ["WIT"]),
.library(name: "_CabiShims", targets: ["_CabiShims"]),
],
traits: [
.default(enabledTraits: []),
"WasmDebuggingSupport"
],
targets: [
.executableTarget(
name: "CLI",
dependencies: [
"WAT",
"WasmKit",
"WasmKitWASI",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "SystemPackage", package: "swift-system"),
],
exclude: ["CMakeLists.txt"]
),

.target(
name: "WasmKit",
dependencies: [
"_CWasmKit",
"WasmParser",
"WasmTypes",
"SystemExtras",
.product(name: "SystemPackage", package: "swift-system"),
],
exclude: ["CMakeLists.txt"]
),
.target(name: "_CWasmKit"),
.target(
name: "WasmKitFuzzing",
dependencies: ["WasmKit"],
path: "FuzzTesting/Sources/WasmKitFuzzing"
),
.testTarget(
name: "WasmKitTests",
dependencies: ["WasmKit", "WAT", "WasmKitFuzzing"],
exclude: ["ExtraSuite"]
),

.target(
name: "WAT",
dependencies: ["WasmParser"],
exclude: ["CMakeLists.txt"]
),
.testTarget(name: "WATTests", dependencies: ["WAT"]),

.target(
name: "WasmParser",
dependencies: [
"WasmTypes",
.product(name: "SystemPackage", package: "swift-system"),
],
exclude: ["CMakeLists.txt"]
),
.testTarget(name: "WasmParserTests", dependencies: ["WasmParser"]),

.target(name: "WasmTypes", exclude: ["CMakeLists.txt"]),

.target(
name: "WasmKitWASI",
dependencies: ["WasmKit", "WASI"],
exclude: ["CMakeLists.txt"]
),
.target(
name: "WASI",
dependencies: ["WasmTypes", "SystemExtras"],
exclude: ["CMakeLists.txt"]
),
.testTarget(name: "WASITests", dependencies: ["WASI", "WasmKitWASI"]),

.target(
name: "SystemExtras",
dependencies: [
.product(name: "SystemPackage", package: "swift-system")
],
exclude: ["CMakeLists.txt"],
swiftSettings: [
.define("SYSTEM_PACKAGE_DARWIN", .when(platforms: DarwinPlatforms))
]
),

.executableTarget(
name: "WITTool",
dependencies: [
"WIT",
"WITOverlayGenerator",
"WITExtractor",
.product(name: "ArgumentParser", package: "swift-argument-parser"),
]
),

.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"]),

.target(name: "GDBRemoteProtocol",
dependencies: [
.product(name: "Logging", package: "swift-log"),
.product(name: "NIOCore", package: "swift-nio"),
]
),
.testTarget(name: "GDBRemoteProtocolTests", dependencies: ["GDBRemoteProtocol"]),

.target(
name: "WasmKitGDBHandler",
dependencies: [
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "SystemPackage", package: "swift-system"),
"WasmKit",
"GDBRemoteProtocol",
],
),

.executableTarget(
name: "wasmkit-gdb-tool",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.product(name: "Logging", package: "swift-log"),
.product(name: "NIOCore", package: "swift-nio"),
.product(name: "NIOPosix", package: "swift-nio"),
.product(name: "SystemPackage", package: "swift-system"),
"GDBRemoteProtocol",
"WasmKitGDBHandler",
]
),
],
)

if ProcessInfo.processInfo.environment["SWIFTCI_USE_LOCAL_DEPS"] == nil {
package.dependencies += [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.1"),
.package(url: "https://github.com/apple/swift-system", from: "1.5.0"),
.package(url: "https://github.com/apple/swift-nio", from: "2.86.2"),
.package(url: "https://github.com/apple/swift-log", from: "1.6.4"),
]
} else {
package.dependencies += [
.package(path: "../swift-argument-parser"),
.package(path: "../swift-system"),
.package(path: "../swift-nio"),
.package(path: "../swift-log"),
]
}

#if !os(Windows)
// Add build tool plugins only for non-Windows platforms
package.products.append(contentsOf: [
.plugin(name: "WITOverlayPlugin", targets: ["WITOverlayPlugin"]),
.plugin(name: "WITExtractorPlugin", targets: ["WITExtractorPlugin"]),
])

package.targets.append(contentsOf: [
.plugin(name: "WITOverlayPlugin", capability: .buildTool(), dependencies: ["WITTool"]),
.plugin(name: "GenerateOverlayForTesting", capability: .buildTool(), dependencies: ["WITTool"]),
.testTarget(
name: "WITOverlayGeneratorTests",
dependencies: ["WITOverlayGenerator", "WasmKit", "WasmKitWASI"],
exclude: ["Fixtures", "Compiled", "Generated", "EmbeddedSupport"],
plugins: [.plugin(name: "GenerateOverlayForTesting")]
),
.plugin(
name: "WITExtractorPlugin",
capability: .command(
intent: .custom(verb: "extract-wit", description: "Extract WIT definition from Swift module"),
permissions: []
),
dependencies: ["WITTool"]
),
.testTarget(
name: "WITExtractorPluginTests",
exclude: ["Fixtures"]
),
])
#endif
64 changes: 64 additions & 0 deletions Sources/GDBRemoteProtocol/GDBHostCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/// See GDB and LLDB remote protocol documentation for more details:
/// * https://sourceware.org/gdb/current/onlinedocs/gdb.html/General-Query-Packets.html
/// * https://lldb.llvm.org/resources/lldbgdbremote.html
package struct GDBHostCommand: Equatable {
package enum Kind: String, Equatable {
// Currently listed in the order that LLDB sends them in.
case startNoAckMode
case supportedFeatures
case isThreadSuffixSupported
case listThreadsInStopReply
case hostInfo
case vContSupportedActions
case isVAttachOrWaitSupported
case enableErrorStrings
case processInfo
case currentThreadID
case firstThreadInfo
case subsequentThreadInfo

case generalRegisters

package init?(rawValue: String) {
switch rawValue {
case "g":
self = .generalRegisters
case "QStartNoAckMode":
self = .startNoAckMode
case "qSupported":
self = .supportedFeatures
case "QThreadSuffixSupported":
self = .isThreadSuffixSupported
case "QListThreadsInStopReply":
self = .listThreadsInStopReply
case "qHostInfo":
self = .hostInfo
case "vCont?":
self = .vContSupportedActions
case "qVAttachOrWaitSupported":
self = .isVAttachOrWaitSupported
case "QEnableErrorStrings":
self = .enableErrorStrings
case "qProcessInfo":
self = .processInfo
case "qC":
self = .currentThreadID
case "qfThreadInfo":
self = .firstThreadInfo
case "qsThreadInfo":
self = .subsequentThreadInfo
default:
return nil
}
}
}

package let kind: Kind

package let arguments: String

package init(kind: Kind, arguments: String) {
self.kind = kind
self.arguments = arguments
}
}
Loading