-
Notifications
You must be signed in to change notification settings - Fork 1.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
WASI support #3421
Comments
A library I was working with compiled and linked to a C library using the |
I guess this is one use-case: having WASI dependencies. But I would argue that this is really a bad workaround, C libraries can target Wasm without WASI or Emscripten just fine. If any WASI function is used it wouldn't work in the browser anyway without a compatibility shim. On the other hand I understand that the only Wasm target C/C++ libraries usually support is Emscripten, or WASI if they are more modern. As hacky as I described this above, it's a workaround many users could require. Though I've honestly no clue if you can use a WASI dependency successfully or not with |
Getting a WASI provider into the browser that covered the required system calls was trivial with https://github.com/bjorn3/browser_wasi_shim and required less than 10 LOC change to the bootstrap JS to make it send the required imports when instantiating the module, so this is no barrier. The third-party C dependency has no knowledge of wasm and used system calls which are available in the WASI shim; I do not understand the comment about it being a ‘bad workaround’ so would be interested to understand more where you are coming from in this regard. I am not paying attention to the wasm ecosystem to understand what is what, but as an outsider exploring the space for the first time, it looked like WASI being positioned as the standard ABI. Maybe that is just an wrong impression though? |
I agree, it's not a barrier.
So I'm searching for the "how it's supposed to be done". WASI isn't supported by the browser, that's why a shim is required. The "proper" way to do it is to compile to Wasm, not to WASI, which C/C++ is able to. Any C/C++ library not using any system calls will support the Wasm target (barring any complications with build systems 🤣), but as mentioned above, C/C++ libraries that do use system calls, don't commonly support targeting Wasm, but Emscripten. (I'm using the term "Wasm" here as in the bare target, without WASI or Emscripten.) I'm not against supporting WASI in The original plan for |
I understand what you were saying now, thank you for sharing. For what it is worth I don’t have much skin in the game at all here; I was just told by someone recently that the emscripten target for Rust did not work, took that claim at face value, saw that WASI was being developed under the WebAssembly group, and assumed this meant the ecosystem had agreed to move toward WASI as the universal ABI for runtimes that need system interface. I was able to hack wasm-bindgen into working with the wasi target within a day so it seems like it’s mostly there, but it is possible that I didn’t exercise the interface enough since I was only doing it as a proof of concept. Today I read some discussions in the WASI WG repo and have much more uncertainty as to whether there is actually a commitment to ensure first-class web platform support. Hopefully they are able to resolve that one way or the other since this is the sort of ambiguity that kills standards. Let me know if there is any other feedback I can provide. Thanks again! |
Not at all sure if its entirely related but as someone who actively uses the |
As the one who proposed #3233 and as the maintainer of a now-large-ish Rust/WASM web framework: I am fine with any solution that is an actual solution. At present, wasm-bindgen generates bindings that panic if called outside the browser. This is completely fine for me: it means that we can use types like However, in current For additional context see the following |
As @csnover mentioned, Since |
#3454 seems to be the initial progress toward WASI goal, so I'll leave the link here. |
I think in general Rust projects can add support for I generally don't think that WASI is entirely out of scope for Adding the WASI shim though is something that makes sense to me, because unlike Rust, C/C++ support for the browser is not "really" a thing (except through Emscripten). Rust libraries can use So the way forward here to me is:
It is obviously very convenient to just slap WASI support onto I hope this clarifies why I believe that the " |
Agreed, I was just trying to point out that WASI can run on the browser via polyfill libraries. The main benefit would be
Yeah, this is how the Rust web ecosystem is evolving right now. However, many crates won't work unless each of them implements a solution for wasm that bypasses
Yes, blocking the browser's main JS runtime should never happen. But since atomics are already available in wasm, access to system time and threads via
Yes, this would be a nice research to make. Thanks for the idea. |
Yes, but this can't be added to
I would argue that this is pretty crude and probably won't be accepted by Tokio. To properly add support for See https://github.com/WICG/scheduling-apis/blob/main/explainers/yield-and-continuation.md for proper yield functionality in JS, but even that I believe is not the way to move forward in Tokio. |
There was an opinion at the forum about this WASI support and ABI mismatch. |
I don't see an inherent reason why that function couldn't exist on |
I would expect it to be similar problem as for the WebAssembly support in the |
That's not really a "problem" as much as it's the "state of the art". The entire ecosystem works that way. At least until there's a separate |
To me, that looks like a 'problem' because unless a crate aims to support webassembly it doesn't work on the web at all. They have to write additional code or add additional feature to make it work on the web. With |
Please do, this is what we need to do here!
Actually you can just write: use web_time::Instant;
fn main() {
let now = Instant::now();
} ... which works correctly on all platforms.
This is the kind of stuff we do want to support. A linked library can be compiled to WASI to support C/C++ dependencies which can't use
I believe this is the crux of the problem here and I'm assuming where you were coming from this whole time. This is what we ought to discuss here. As far as I've experienced it, slapping WASI support on top will cause issues exactly for this reason. E.g. Tokio now has WASI support, but doesn't work in the browser. If Tokio wants to add browser support, they can't add it to @temeddix I encourage you to get into the specifics here. Which crates did you have problems with? What part of the ecosystem lacks browser support that you would like to see supported? How exactly could WASI support be applied to those crates to add browser support without creating target incompatibility? |
I will organize the list of crates that has issues on Also, I get the point that Some people do suggest deprecating |
This is true! It shows too: this is why we are having all these problems here!
I'm not a Rust maintainer/member, so you are asking the wrong person. But I doubt anything like that will be accepted by Rust. The reason why I'm not aware of any effort to standardize WASI in browsers, but if there would be, I think that might be an argument. But again, it has to differ somehow to But, to re-iterate: this is something you have to take up with the Rust team. |
I doubt
|
If Also, I'm wondering even if WASI component model is accepted someday, wouldn't Lastly, maybe If I have some consensus from |
If it does exist, I don't see why we shouldn't support it in
I'm not aware of any WASI component model, the component model proposal is a Wasm proposal, not a WASI one. So I would say no. I also wouldn't know why anybody would still continue to use WASI in the browser when the component model is available and presents itself as a working alternative.
I would vote for
Personally I would like to know first what this target is supposed to be exactly. But then sure, we can try to get some consensus here. FWIW, my assumption here is that Rust doesn't (and imo shouldn't) care about |
@daxpedda Can I today compile a Rust crate as
|
Yes and no. It should be theoretically possible, though I wouldn't be able to give you any pointers on it as I've never tried it myself, but practically you will very likely hit #3454. |
I don't think it's wasm-bindgen's job to provide a shim for WASI. WASI is way more than what could be execute in browser. I still think fixing wasm32-unknown-unknown is the better way to go. Adding yet another wasm target is only going to complicate things, I believe. I created #3674 to make releasing easier so we can get a release out of wasm-bindgen that supports C ABI |
IMHO, if a shim for WASI is provided for the browser, that would be done on This is being discussed on that side: |
I also want to point out that the component model standard states that it's currently being incrementally developed and stabilized as part of WASI Preview 2 |
Sorry, I want to give my 3 points.
Based on these three points, I hope that "--target wasm32-wasi" will be supported soon. thank u master , i hope you enjoyed everyday |
Totally agreed, especially on the point that many crates need Though the current status of |
@zhusjfaker could you elaborate? AFAIK neither would work in the browser. How exactly would |
This scene is really special, because in addition to the browser, in China there are a lot of NodeJs as a full-stack development, but the complex Crud scene, there are a lot of not only write Node-js using mysql there are also some people are using Rust c++ and other languages together to complete, and even in China there are a lot of cross-end development, try to add in the cell phone, such as iOS platforms The wasm3 project tries to use wasm's package volume to replace JS. If you only consider the browser environment, the limitations may be relatively small. |
I wasn't aware that NodeJS supports WASI natively, though I'm seeing that it is only experimental. It seems to me that this would be good justification to enable WASI support in
I still think it's out of scope for |
i got it thank you |
Sorry to revive a kind-of old thread, but I was wondering if this is a topic still in discussion. I've spoken with multiple developers who have expressed interest in integrating WASM/WASI into their server-side NodeJS applications to hand-off memory intensive tasks to other languages like Rust, while still keeping most of the development in NodeJS. For instance, I have a use case where I'm running an Express server that could use some integration with WASI for handling files directly on the file system (a use case that is possible with WASI but not with WASM); most of the developers in my team are familiar with NodeJS but not with Rust, but they would be open to have a single, critical module being written in Rust. Being able to use wasm-bindgen to glue both NodeJS and Rust would unlock a lot of options for backend-developers. The original plan in #1841 still makes sense to me (though I think a good first step would be to work towards supporting WASI with JavaScript, as the. scope is not as wide as in the original plan). If more help is needed to make it happen, I'm open to collaborate on it. |
You may be interested in jco, which is a polyfill for the wasm component model implemented in javascript. The wasm component model is used by wasip2. It has a shim for wasip1 support too. |
The original plan will not come into fruition without additional maintainers, its too big of a change for the resources available right now. |
I'd like this for tokio, mostly. Otherwise I'll have to use another approach I am available to contribute work with direction. |
web takeaway for the day: tokio doesn't support wasm32-unknown-unknown. will have to use wasm32-unknown-wasi, which tokio supports. i don't think wasm32-unknown-emscripten is going to help so: skip the wasm-pack and wasm-bindgen crates, which use wasm32-unknown-unknown see rustwasm/wasm-bindgen#3421 probably no big deal and other tools will work, this was just the first resource I tried
I outlined above why I believe using WASI for Web support in Tokio won't work as expected. Otherwise nothing changed really, see #3421 (comment). |
This issue will be used to collect discussions and issues about WASI support in
wasm-bindgen
.Generally speaking
wasm-bindgen
doesn't currently support WASI, but we should figure out if we want to support it (#3324) or disable it (#3233).The original plan, outlined here: #1841, now doesn't have the necessary developer support. But the motivation for it, the component model (previously interface types), isn't here yet either.
Input from stakeholders would help a lot!
The text was updated successfully, but these errors were encountered: