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

Is wasm32_wasip1_threads Rust target supported? #253

Open
atilag opened this issue Oct 18, 2024 · 8 comments
Open

Is wasm32_wasip1_threads Rust target supported? #253

atilag opened this issue Oct 18, 2024 · 8 comments

Comments

@atilag
Copy link
Contributor

atilag commented Oct 18, 2024

Hey team!
I wanted to use a .wasm module that has been compiled from Rust, using the wasm32_wasip1_threads target but it looks like this target required some imports from the host that are not being satisfied when I try to instantiate a module like:

        engine = Engine()
        
        wasi_config = WasiConfig()
        wasi_config.inherit_stdout()

        store = Store(engine)
        store.set_wasi(wasi_config)

        with open( 'my_wasi_library.wasm', 'rb') as f:
            wasi_bytes = f.read()

        module = Module(engine, wasi_bytes)

        linker = Linker(engine)
        linker.define_wasi()

        instance = linker.instantiate(store, module) # This throws: wasmtime._error.WasmtimeError: unknown import: `env::memory` has not been defined

I would have expected the define_wasi() to prepare everything so the required imports are satisfied, but I guess this wasm32_wasip1_threads target might not be supported just yet?

Thank you very much!!

Awesome work, btw :)

@atilag
Copy link
Contributor Author

atilag commented Oct 19, 2024

Ok, I see. There's no support for shared memory just yet, right?

@alexcrichton
Copy link
Member

IIRC the C API has all the bits necessary for this, but yeah I don't think shared memory is bound yet. This library is notably not threadsafe yet though so you'll need to be careful to use things correctly lest you run into data races.

@atilag
Copy link
Contributor Author

atilag commented Oct 21, 2024

Yeah, I saw it!
I started to implement the bindings and added a ShareMemory class. So far it's not working due to a crash in the wasmtime runtime part while cloning the shared memory structure, but I have everything setup locally to apply patches there as well, so once I have something more or less working I'll PR.
Thanks Alex!

@atilag
Copy link
Contributor Author

atilag commented Oct 22, 2024

So, basically, I started implementing SharedMemory until I got here:
https://github.com/bytecodealliance/wasmtime/blob/a5412caa6c7845cfd068d5ed20006711762b660c/crates/c-api/src/extern.rs#L23
I'm not familiar at all with the codebase so after a few hours trying to implement this, I'm not feeling comfortable with my changes... I'll give a stab one more time, and see if I make progress but looks like the implementation of SharedMemory is far from trivial at this point.

@alexcrichton
Copy link
Member

Oh I'd recommend instead using wasmtime_* functions from this header if that works?

@thewtex
Copy link
Contributor

thewtex commented Jan 6, 2025

Hi @atilag @alexcrichton ,

Thank you so much for your work on this!

Is this issue addressed with #255 merged and released?

@alexcrichton
Copy link
Member

I think it should be good yeah, but I think it'd be best to test in a higher-level use case as well before closing perhaps

@thewtex
Copy link
Contributor

thewtex commented Jan 10, 2025

@alexcrichton @atilag I am looking to exercise with C++ wasi-sdk modules.

It seems that we need something like a wasmtime_linker_define_wasi_threads similar to wasmtime_linker_define_wasi that calls the wasi-threads add_to_linker and expose it here.

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

3 participants