swiftwasm / WasmKit

WebAssembly Runtime written in Swift
https://swiftpackageindex.com/swiftwasm/WasmKit/main/documentation/wasmkit
MIT License
226 stars 8 forks source link

Host Globals aren't working #131

Closed cristian-5 closed 1 month ago

cristian-5 commented 1 month ago

Version 0.0.8

I tried to make a global so I can access it from the module but it appears the initializer of GlobalInstance is inaccessible. It might be because it's not marked as public and since it has a internal(set) member it's deduced to be internal. On a side-note, for this I needed to import both WasmParser and WasmTypes which I think it's a bit excessive.

let runtime = Runtime(hostModules: [ "env": HostModule(globals: [
    "myvalue": GlobalInstance(
        globalType: GlobalType(mutability: .constant, valueType: .f32),
        initialValue: Value.fromFloat32(5.5)
    )
]) ])
Screenshot 2024-10-01 at 10 56 37 AM

EDIT 1 - Circular Logic - version based on: 4aff9cc5d12649da1b92c72f125233509fd1feff

Everything is completely different in the actual code, in fact, it's still impossible to make a global because circular logic: Global needs to be initialized with Store which you can only get by first making a Runtime which asks for your HostModules in which you need to put your Globals. In other words, it's an infinite loop of dependecies.

Please help, I just need to import a global variable in my webassembly module 😭

kateinoigakukun commented 1 month ago

I'm working on API overhaul towards the next release. I think https://github.com/swiftwasm/WasmKit/pull/132 addressed this issue. Could you try with the latest main?

cristian-5 commented 1 month ago

It works perfectly now, you should probably make a tag 😄