Wasm-pack: Support for wasm32-wasi target?

Created on 23 May 2019  路  17Comments  路  Source: rustwasm/wasm-pack

Does wasm-pack support building for the new wasm32-wasi target instead of wasm32-unknown-unknown?

I have a project configured to use wasm-pack for wasm32-unknown-unknown, would like to switch to wasm32-wasi, wondering if I have to change the build tool, or if this is not supported and if there is a possibility it may in the future.

I tried wasm-pack build --target wasm32-wasi but this option specifies something else:

    -t, --target <target>        Sets the target environment. [possible values: browser, nodejs, web, no-modules]
                                 [default: browser]

Couldn't find any mention of "wasi" in this repository.

Background: https://github.com/CraneStation/wasmtime/blob/master/docs/WASI-intro.md

feature request needs discussion

Most helpful comment

Just allowing to somehow set target to WASI would be already good. Right now playing with porting some libraries to WASM via wasm-pack, but running into runtime panics due to unimplemented syscalls, which would be solved by passing WASI as a target.

All 17 comments

We don't support wasi yet.

It isn't totally clear what wasm-pack should do with wasi yet. (Not saying it is particularly difficult to figure out, we just haven't discussed it too much yet).

Just allowing to somehow set target to WASI would be already good. Right now playing with porting some libraries to WASM via wasm-pack, but running into runtime panics due to unimplemented syscalls, which would be solved by passing WASI as a target.

@yurydelendik Looks like the linked issue has been resolved since.

True. While underline tools are fixed, the wasm-pack code checks and operates only with 'wasm32-unknown-unknown' target.

Yeah, and seems like at this point it would be a fairly simple fix to allow other targets.

This would be a very useful feature.

I was hoping to use use clap command line parser in a Node.js app. clap heavily depends on os_str_bytes which does not support wasm32-unknown-unknown, but does support wasm32-wasi. clap compiles under wasm32-wasi. My app compiles under wasm32-wasi, but the rest of the stuff that wasm-pack does, I'm not sure how to handle.

Looking at https://nodejs.org/api/wasi.html, I probably need to upgrade my Node.js version and call wasi.start instead.

I think this needs to be added to wasm-bindgen first before it can be added to wasm-pack.

I came across just now https://github.com/bytecodealliance/cargo-wasi and I'm not sure if I should use that directly instead for wasi projects in rust. Can some code be shared to add support to wasm-pack?

@Pauan

I think this needs to be added to wasm-bindgen first before it can be added to wasm-pack.

Does wasm-bindgen differentiate or, indeed, even know, which target Wasm was built with? I think it should already work with wasm32-wasi built Wasm files like with the unknown ones.

IIUC the issue is only in wasm-pack because it passes the --target to cargo build, and that target is currently hardcoded to wasm32-unknown-unknown.

@RReverser For WASI it is necessary to pass in the WASI functions, but wasm-bindgen doesn't do this, therefore wasm32-wasi won't work.

And there could be some other assumptions that wasm-bindgen makes about wasm32-unknown-unknown, but you'll need to talk to @alexcrichton about that.

For WASI it is necessary to pass in the WASI functions, but wasm-bindgen doesn't do this, therefore wasm32-wasi won't work.

Ah yeah, that's a good point, these imports would have to be propagated via JS wrapper.

Perhaps wasmer-js could be used to handle the WASI functions.

It seems this may need supported in wasm-bindgen first since wasm-pack calls it to build and test projects. Idk if wasm-bindgen will want to add wasmer-js to polyfill the WASI syscalls or not, so if not, maybe that's something wasm-pack could do once wasm-bindgen supports building for wasm32-wasi.

There is no need to commit to any specific implementation for WASI syscalls, the JS wrapper would simply need to propagate the imports and let Webpack config or whatever handle them by mapping to a real implementation.

As of https://github.com/rust-lang/rust/pull/79998, in order to fix the use-case of linking C code (which passes structs by value) with Rust code, the wasm32-wasi target now has an ABI incompatibility with wam_bindgen (when passing structs by value). Thus, to make this happen someone would likely need to adopt https://github.com/rust-lang/rust-bindgen/pull/1952 and make the wasm_bindgen support the clang WASM ABI.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rpjohnst picture rpjohnst  路  5Comments

rbtcollins picture rbtcollins  路  3Comments

turboladen picture turboladen  路  4Comments

marcoscaceres picture marcoscaceres  路  3Comments

pablosichert picture pablosichert  路  4Comments