Ciantic/rust-wasm-and-c

wishlist: Calling back from C to Rust

Opened this issue · 2 comments

I think it would be good for this example to also have an example in there in which C code calls functions defined in Rust again. Naïve attempts to do that (with an extern "C" function) result in Uncaught TypeError: Error resolving module specifier “env”. Relative module specifiers must start with “./”, “../” or “/”.` errors.

Once I get one to run, I'd be happy to PR it.


(And thanks for providing this example, it's a good starting point to explore C code in WASM, as long as one keeps a good eye on the caveats thread).

Oh sure, I'm bad maintainer of OS projects. But happy to commit pull request.

It's currently possible to build it for the wasm32-unknown-unknown target with calls from C to Rust and Rust to C. It needs Rust nightly with the --Z wasm_c_abi=spec they introduced in April. I put together a minimal example, and now I'm closing all the tabs that led me to it with this comment.