Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wasm interpreter doesn't allow for wasi to be enabled from CWasm3 #17

Open
gossmer opened this issue Sep 11, 2022 · 1 comment
Open

Comments

@gossmer
Copy link

gossmer commented Sep 11, 2022

Add the "m3_LinkWASI(module)" to the module when loading a new module. ie.

public init(stackSize: UInt32, module bytes: [UInt8]) throws {
    id = nextInstanceIdentifier
    idPointer = makeRawPointer(for: id)

    guard let environment = m3_NewEnvironment() else {
        throw WasmInterpreterError.couldNotLoadEnvironment
    }

    guard let runtime = m3_NewRuntime(environment, stackSize, idPointer) else {
        throw WasmInterpreterError.couldNotLoadRuntime
    }

    var mod: IM3Module?
    try WasmInterpreter.check(m3_ParseModule(environment, &mod, bytes, UInt32(bytes.count)))
    guard let module = mod else { throw WasmInterpreterError.couldNotParseModule }
    try WasmInterpreter.check(m3_LoadModule(runtime, module))

// New code:
// this must be after the m3_LoadModule
try WasmInterpreter.check(m3_LinkWASI(module))
// end
self.environment = environment
self.runtime = runtime
moduleAndBytes = (module, bytes)
}

@gossmer
Copy link
Author

gossmer commented Sep 11, 2022

You also need to add into the package.swift

            cSettings: [.define("APPLICATION_EXTENSION_API_ONLY", to: "YES"),
                        .define("__wasi__", to: "YES"),
                        .define("d_m3HasWASI", to: "YES"),
            ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant