wasm-pack
wasm-pack copied to clipboard
wasm and `no_std`
ISSUE
Overview
Hi, we're looking to start a wasm project and I'm wondering if no_std is required.
Background
I don't see anything about no_std in any of the documentation, which makes me think it's not a requirement. But that begs the question as to why the wasm projects that I've seen are no_std, including Substrate, as it's a very severe restriction.
Questions
What does wasm-pack do differently? And how does pulling in the standard library affect the output size (an important consideration for the browser).
A quick answer here would be fine but it should also be touched on in the documentation.
The rust compiler has support for using std for the wasm32-unknown-unknown target. (I'm not sure about the status of wasm32-wasi)
Sure, if you try to use std::fs or some other modules which are not implemented, you'll get errors, but using a subset of std is definitely supported. (for example, pub fn bar (s: String) -> String is a function that uses std::string::String and it works.)
For more advanced functionality, you might want to have a look at the official gloo project.
Thank you for the answer. Apparently, projects like Substrate avoid std because it bloats the final binary size - though I haven't been able to find hard numbers. I think this kind of information should be available and easy to find, so that devs starting a new project can make an informed decision.
Hey @mrcnski, you may want to take a look at this no_std guide for wasm32-*.
@jkomyno Thanks for the resource! Info like that should be incorporated into the docs. :)