-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Does it make sense to support WASM? #858
Comments
I'd personally say "no" in the sense that wasm has no libc, and hence talking about a "c_int" doesn't even really have an answer. The only FFI types in wasm right now are i32/i64/f32/f64/u32/u64 (afaik), so at least for wasm I think those are the types you'd want to use. When there's perhaps a prevelant C compiler that can intermix with Rust code we could arbitrarily decide "that's the C ABI" and then just match that, but such a C compiler would likely want to be relatively standard... |
I understand your reasoning, but I also think this will make it really annoying for widely-applicable crates to be used in e.g. FFI, no-std, embedded, and wasm contexts. Is there a better solution for such types of crates? |
I agree yeah that we don't want things to be super painful, but I guess at this point I feel like it's too early to make decisions about wasm and libc. I'd sort of like to gather more data on this topic before adding something to this crate where it's insta-stable and we can basically never change it. |
Ok. I'll go ahead and close this; hopefully if anyone can provide that "more data" in whatever form, they can add it here! |
There is a C compiler that can intermix with Rust on wasm today. And it seems like for at least |
@sunfishcode oh sure yeah I think in theory it could work but for now w/ our bundling of the linker it may not work in practice... Also are we sure to have definitions for types like |
For an abundance of caution,
|
Today I ran into this issue. I tried to compile a program to wasm, but it was impossible because I am using EDIT: nvm, it seems that this has already been addressed by #861 |
Sorry for jumping into this old thread. The wasm32 support in llvm/clang is stable since version 8 (~1 year) - could this maybe help with adopting wasm32-unknown-unknown support in libc? I'd be interested to contribute if it's a possible way forward. |
By definition, |
It still has types though, and in many (most?) cases that's all you want - being able to define FFI for C functions to be able to use them from Rust in the same Wasm module. |
Is there any interest in revisiting this for types only for |
I would love if you could revisit this, since for a lot of use cases, this is the final missing link on providing great Rust apps with C dependencies to the web. Most of Rust echosystem for GUIs like egui and graphics libraries like wgpu target only In my use case for example, I am trying to build a FOSS USB peripherals device manager using Rust that can run "everywhere", including Linux on various CPU architectures and the web utilizing WebUSB. libusb supports as WebAssembly + WebUSB backend for some time now. It seems like the only remaining blocker is libc, which is used in rusb, a safe Rust wrapper for libusb. Also, this merged PR to Rust might be helpful, as described in this StackOverflow discussion. |
In the Omnibus, I recommend using libc to provide the basic types when doing FFI. Trying to do so with the newly-landed WASM support yields 70+ errors.
Should libc have the basic types defined for WASM but basically no functions?
The text was updated successfully, but these errors were encountered: