wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

wasm and `no_std`

Open mrcnski opened this issue 3 years ago • 4 comments

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.

mrcnski avatar Mar 07 '22 17:03 mrcnski

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.

kartva avatar May 18 '22 07:05 kartva

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.

mrcnski avatar May 18 '22 14:05 mrcnski

Hey @mrcnski, you may want to take a look at this no_std guide for wasm32-*.

jkomyno avatar Aug 30 '23 21:08 jkomyno

@jkomyno Thanks for the resource! Info like that should be incorporated into the docs. :)

mrcnski avatar Aug 31 '23 08:08 mrcnski