Skip to content

Commit

Permalink
Add entrypoint for WASI reactor initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
kateinoigakukun committed Jan 10, 2025
1 parent cc7dac1 commit 34ae4c8
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Sources/WasmKitWASI/WASIBridgeToHost+WasmKit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import WasmKit
public typealias WASIBridgeToHost = WASI.WASIBridgeToHost

extension WASIBridgeToHost {

/// Register the WASI implementation to the given `imports`.
///
/// - Parameters:
/// - imports: The imports scope to register the WASI implementation.
/// - store: The store to create the host functions.
public func link(to imports: inout Imports, store: Store) {
for (moduleName, module) in wasiHostModules {
for (name, function) in module.functions {
Expand Down Expand Up @@ -35,6 +41,13 @@ extension WASIBridgeToHost {
}
}

/// Start a WASI application as a `command` instance.
///
/// See <https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md>
/// for more information about the WASI Preview 1 Application ABI.
///
/// - Parameter instance: The WASI application instance.
/// - Returns: The exit code returned by the WASI application.
public func start(_ instance: Instance) throws -> UInt32 {
do {
guard let start = instance.exports[function: "_start"] else {
Expand All @@ -47,6 +60,19 @@ extension WASIBridgeToHost {
return 0
}

/// Start a WASI application as a `reactor` instance.
///
/// See <https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md>
/// for more information about the WASI Preview 1 Application ABI.
///
/// - Parameter instance: The WASI application instance.
public func initialize(_ instance: Instance) throws {
if let initialize = instance.exports[function: "_initialize"] {
// Call the optional `_initialize` function.
_ = try initialize()
}
}

@available(*, deprecated, message: "Use `Engine`-based API instead")
public func start(_ instance: Instance, runtime: Runtime) throws -> UInt32 {
return try start(instance)
Expand Down

0 comments on commit 34ae4c8

Please sign in to comment.