@@ -4,6 +4,12 @@ import WasmKit
4
4
public typealias WASIBridgeToHost = WASI . WASIBridgeToHost
5
5
6
6
extension WASIBridgeToHost {
7
+
8
+ /// Register the WASI implementation to the given `imports`.
9
+ ///
10
+ /// - Parameters:
11
+ /// - imports: The imports scope to register the WASI implementation.
12
+ /// - store: The store to create the host functions.
7
13
public func link( to imports: inout Imports , store: Store ) {
8
14
for (moduleName, module) in wasiHostModules {
9
15
for (name, function) in module. functions {
@@ -35,6 +41,13 @@ extension WASIBridgeToHost {
35
41
}
36
42
}
37
43
44
+ /// Start a WASI application as a `command` instance.
45
+ ///
46
+ /// See <https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md>
47
+ /// for more information about the WASI Preview 1 Application ABI.
48
+ ///
49
+ /// - Parameter instance: The WASI application instance.
50
+ /// - Returns: The exit code returned by the WASI application.
38
51
public func start( _ instance: Instance ) throws -> UInt32 {
39
52
do {
40
53
guard let start = instance. exports [ function: " _start " ] else {
@@ -47,6 +60,19 @@ extension WASIBridgeToHost {
47
60
return 0
48
61
}
49
62
63
+ /// Start a WASI application as a `reactor` instance.
64
+ ///
65
+ /// See <https://github.com/WebAssembly/WASI/blob/main/legacy/application-abi.md>
66
+ /// for more information about the WASI Preview 1 Application ABI.
67
+ ///
68
+ /// - Parameter instance: The WASI application instance.
69
+ public func initialize( _ instance: Instance ) throws {
70
+ if let initialize = instance. exports [ function: " _initialize " ] {
71
+ // Call the optional `_initialize` function.
72
+ _ = try initialize ( )
73
+ }
74
+ }
75
+
50
76
@available ( * , deprecated, message: " Use `Engine`-based API instead " )
51
77
public func start( _ instance: Instance , runtime: Runtime ) throws -> UInt32 {
52
78
return try start ( instance)
0 commit comments