rust-lang-nursery / portability-wg

Coordination repository of the portability Working Group (WG)
42 stars 3 forks source link

Coordinate with WebAssembly WG #10

Open jethrogb opened 6 years ago

jethrogb commented 6 years ago

Lots of issues touch both WebAssembly and general portability. Reference this issue in the WebAssembly WG issue tracker to create a link to the portability WG.

mgattozzi commented 6 years ago

A few things based off what we've seen from the wasm WG is that we have three distinct use cases:

1) wasm that's called as part of JS or calls into it 2) Pure wasm on the web 3) wasm run not in a web browser

This and just how the binary is structured leads to some problems. We did talk a lot in this issue about what we can assume with the host environment but we're unsure right now what the best course is. This makes using libstd kind of possible maybe depending on the route taken but we have no satisfactory answer right now.

Pauan commented 6 years ago

Portability with wasm is more than just about wasm itself, it also has to do with the executing environment.

The two biggest executing environments are the browser and Node.js, and both environments have completely different APIs and behavior.

And it's not just the APIs either: the way that WebAssembly modules are loaded is different in the browser and Node.js. The way that libraries are created is different. The package managers are different. The tools are different. They really are completely separate in many deep ways.

So we actually have these use cases:

  1. Wasm library/application that wants to use JavaScript APIs that exist in the browser and Node.js.

  2. Wasm library/application that wants to use Node.js APIs.

  3. Wasm library/application that wants to use browser APIs (e.g. DOM).

  4. Wasm library/application that wants to use non-JavaScript APIs (there are already multiple wasm environments which don't include JavaScript at all, e.g. they are built on top of C++, C#, etc.)

  5. Wasm library that wants to be embedded within a larger JavaScript application.

  6. Wasm library that wants to be embedded within a larger Node.js application.

  7. Wasm library that wants to be embedded within a larger browser application.

  8. Wasm library that wants to be embedded within a larger non-JavaScript application (e.g. a wasm plugin embedded within a game engine, similar to what Lua is used for right now).

Essentially, we need to be able to differentiate (at a minimum) between Node.js APIs, browser APIs, general JavaScript APIs, and non-JavaScript APIs.

And the situation is complicated even further because there are things like Electron which allows for an application to use both Node.js and browser APIs at the same time. So it needs to be flexible enough to accommodate things like that.

mgattozzi commented 6 years ago

Thanks for the clarification @Pauan!

Ericson2314 commented 6 years ago

Yikes. Does the standard just talk about the no-API case?

mgattozzi commented 6 years ago

No WebAssembly only defines the JS and Web APIs as well as the core functionality. A lot of the good stuff that will improve this probably won't be for some time. The standard made it so that we can have a Minimum Viable Product release, but it's pretty spartan in what it is capable of. We might be blocked on this for some time unfortunately.

Ericson2314 commented 6 years ago

@mgattozzi Actually I see that page as great news. The layering of the space gives / will give us a nice hierarchy of platforms. Since it looks like no web-assembly APIs are standardized at this moment, we'd probably want something user-definable, like the portability lint working over Cargo features, as a stop gap.

mgattozzi commented 6 years ago

Yeah! I'm more saying it's whatever we define right now and not something defined in the standard, which is fine, but if there is one eventually it'll break possibly the work we've done which isn't as good.

Ericson2314 commented 6 years ago

Agreed, which is why I don't want to define any non-standard cfg tokens in the compiler. By using features, some library takes the fall :D.

Pauan commented 6 years ago

Right now the only standard way to interop with the executing environment is to use wasm import/export, and when doing so you can only import/export these types. In other words:

Beyond that, nothing else is currently standardized. In other words, no standard APIs, no API conventions, no type conversions, nothing at all.

There is work being done on creating standardized WebAssembly bindings for JavaScript and the browser APIs, but it will be quite some time before it's standardized. And it will be even more time before Node.js APIs are standardized (if they are ever standardized).

So it's up to us (Rust programmers and library authors) to decide on the APIs, and how to squeeze Rust types into the restricted wasm types, etc. There is ongoing work on that, with wasm-bindgen and stdweb, but I think those are outside the scope of the Portability WG.

So something like Cargo features sounds great. That should also handle things like Electron which allow both browser and Node.js APIs (the programmer would just use the Node.js and browser features at the same time).

jethrogb commented 6 years ago

Relevant article https://hacks.mozilla.org/2018/03/making-webassembly-better-for-rust-for-all-languages/

Ericson2314 commented 6 years ago

Alright, standard FFI. Yeah, that should definitely be done with Cargo features. Heck, even post stabilization it's always best to bake fewer things in the compiler.