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

Load/run WASM created with wit-bindgen #5

Open
Manuthor opened this issue Jan 3, 2022 · 3 comments
Open

Load/run WASM created with wit-bindgen #5

Manuthor opened this issue Jan 3, 2022 · 3 comments

Comments

@Manuthor
Copy link

Manuthor commented Jan 3, 2022

Hello!

I am interested by loading in Java a WebAssembly created using the crate wit_bindgen. Actually I was looking for the Java bindings for this but I could not find any related project. As you probably already know, having this would allow to have a common WASM loaded by different languages (Python, Java, C, etc.).

I run your project wasmtime-java (and thanks for this) with a wit-bindgen generated WASM but I encounter 2 problems:

  • this first problem deals with the de/allocation functions: for wasmtime-java, the WASM file needs to have the 2 exported functions __alloc_bytes and __dealloc_bytes). Even this is not ideal, I temporarly added these functions (of course it would be better to use the existing wit-bindgen allocation functions)
  • the second problem occurs when function-signature (in WASM) looks like fn my_function(input: Vec<u8>) -> Vec<u8>. I cannot find a way to load the return value. I confirm that I can "see" the expected result in the WASM memory but I dont understand how to find the correct offset of this result in memory (and the related result size in bytes). The offset returned by the function call (which is correct) does not match the good offset of the result.

Could I ask your opinion about this?
Thanks!!

@bluejekyll
Copy link
Owner

Hi, thanks for the note. I'm excited that you're looking at the project. So far this is definitely not production ready. In terms of support for wit_bindgen, I think that would be great. I've been a little stuck on trying to figure out generic language support.

I'm definitely aware of some of the limitations of the current structure of this project. I think the __alloc_bytes and __dealloc_bytes are artifacts of how data is passed back and forth with wasm from the Java environment.

As to your issue with Vec parameters and returns, currently the project only supports limited C style arrays to be passed around. This example shows what is currently supported: https://github.com/bluejekyll/wasmtime-java/blob/main/tests/slices/src/lib.rs#L39-L43

Since I haven't played with wit_bindgen yet, I think that would be a great first step in trying to normalize some of these conventions? Is this something you might want to try and help contribute to?

@Manuthor
Copy link
Author

Manuthor commented Jan 4, 2022

Hi, thanks for your quick answer!
Well, I want to help so I created a branch feature/add_ref_return_value here where there is a way to build a wit-bindgen wasm module (nightly rustc only). Feel free to take it or not!
For the time being, I do not know how to load the return value of my function (which is a byte vector whose value can be found in WASM-memory). Maybe we can contact us through the bytecodealliance zulip chat.

@bluejekyll
Copy link
Owner

I’m not super active on the bytcodealliance Zulip, but I am on there. That would be a fine place for us to discuss things.

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

2 participants