
Compiling Rust to Web Assembly - grey-area
https://medium.com/@chicoxyzzy/compiling-rust-to-webassembly-guide-411066a69fde#.x4y184tj6
======
marcosscriven
I wasn't a fan of having to compile the dev branch of both emscripten itself,
and clang, each time I wanted to try the latest (hence the 'wait 2 hours' in
the blog)

I thus asked about providing a Docker image - the person that handles the
builds and the SDKs says that nightly builds are on the way:
[https://github.com/kripken/emscripten/issues/4682#issuecomme...](https://github.com/kripken/emscripten/issues/4682#issuecomment-260159020)

~~~
brianshaler
I read the guide and came here looking to see if there was a docker image. I
just don't want to blindly pipe-sh on my host machine (would need to review
what rustup is doing first). On top of that, 'wait 2 hours' is not something I
want to do when I want to kick the tires on a Hello World.

This is a great example of docker-for-dev. Don't bother setting up the
specific versions of compilers and then worry about clean-up afterward.

The guide should be 2 lines: docker pull, then docker run.

------
sunng
Here is an example that using Rust-native library for web development:
[https://github.com/tcr/rust-todomvc](https://github.com/tcr/rust-todomvc)

Also I forked it to use handlebars: [https://github.com/sunng87/rust-
todomvc](https://github.com/sunng87/rust-todomvc)

Using asmjs, the compiled js file is about 20MB and can be slow in browser.
While wasm32 one is just ~500KB.

~~~
k__
Can wasm be chunked up and loaded on demand via AJAX, like JS?

------
tps5
Nice guide.

I did this over the holidays just to see it in action. It was a pain to get
the emscripten sdk installed (especially on a slow connection) but it's quite
cool to see it in action.

There's also a asm.js target which you can add like this:

$ rustup target add asmjs-unknown-emscripten

I'm not sure about browser support for asm.js but recent versions of node
support it.

~~~
marcoperaza
Every browser supports asm.js, since it's just a subset of standard JS. Some
browsers do optimize it, though.
[https://en.wikipedia.org/wiki/Asm.js#Implementations](https://en.wikipedia.org/wiki/Asm.js#Implementations)

------
rafinha
Is there a way to debug apps compiled to Web assembly? (Like a gdb.js :D ) I
suppose using standard dev tools won't be useful.

~~~
empath75
[https://github.com/WebAssembly/design/blob/master/TextFormat...](https://github.com/WebAssembly/design/blob/master/TextFormat.md)

------
kibwen
This is great, I've actually never seen the steps to compiling WASM laid out
before.

What all does the Emscripten SDK provide?

~~~
hackcasual
An HTML shell that can handle resource loading, plus a bunch of JS methods for
providing IO to WebAssembly. In the future it will be possible to do something
like [https://github.com/brson/mir2wasm](https://github.com/brson/mir2wasm) to
go directly from LLVM to WASM (though IO functionality will need to be
supplied separately).

------
rl3
What's the binary size like compared to C/C++?

I've read the overhead of Rust's standard library is about 100kB. Not sure if
putting it through the Emscripten toolchain changes that significantly.

~~~
steveklabnik
In general, [https://lifthrasiir.github.io/rustlog/why-is-a-rust-
executab...](https://lifthrasiir.github.io/rustlog/why-is-a-rust-executable-
large.html)

For this specifically, I made some numbers when it first landed:
[https://www.reddit.com/r/rust/comments/575pp6/compiling_to_t...](https://www.reddit.com/r/rust/comments/575pp6/compiling_to_the_web_with_rust_and_emscripten/d8pkki0/?context=1)

Regardless, this is in a "oh my god it works" state, not a super serious best-
we-can-do state. My understanding is that it's larger than it has to be at the
moment. We'll get there.

~~~
rl3
> _-rw-r--r-- 1 steve steve 159K Oct 12 20:00 sup.wasm_

It's looking pretty good already. Thanks for the reply.

------
ponytech
Has anyone heard of python compiled to Web Assembly ?

~~~
k__
As far as I know, if you don't want to add a runtime, you can only compile
languages that compile to native code to Web Assembly. C, C++, D, Rust, Nim,
etc.

So it's more for low level lanuages to make performance easier on the Web, not
for replacing JavaScript in general.

~~~
dan00
But don't need D und Nim a runtime for their garbage collection?

~~~
k__
Good point. Maybe it's small?

I mean Nim already allows compilation to JavaScript.

------
microo8
Still waiting for an article named 'Compiling Go to Web Assembly'
[https://imgflip.com/s/meme/Ill-Just-Wait-
Here.jpg](https://imgflip.com/s/meme/Ill-Just-Wait-Here.jpg)

------
adamnemecek
Three rust articles on the front page? Not complaining, it definitely seems
like the popularity has really jumped up in the last three months.

~~~
lacampbell
TBH it's getting a bit much at this point. The rust advocates here (not sure
if they're paid or just fanboys) _really_ need to tone it down. The hyperbole,
and the constant "rust solves this unrelated problem, and has no flaws!" is
beginning to grate.

I've coded in it a bit and it seems like cool language, they get a lot right
and have some new and interesting ideas. But it's not a panacea (or indeed
"salvation" as one recent blog post put it) for everything wrong in software.
We don't need to all immediately re-write everything we do rust. Not
everything new needs to be written in rust. And your re-writes of programs
that have already been written in other languages and work well aren't that
compelling.

If you like rust, then write some _new_ , interesting and useful software in
the language, where what language it's written in isn't the main selling
point. For example, I love the look of this
[http://nickel.rs/](http://nickel.rs/).

TL;DR - the corrosive nature of rust advocates on HN is starting to eat away
at my patience, and I am tired of having to galvanize against them and their
absurd claims.

~~~
benjismith
I enjoy reading about rust.

I don't know the language (yet), but I've been keeping my eye on it for a few
years, and I think it's going to be fantastic once it stabilizes and gets
improved tooling.

I especially welcome the possibility of using a safe language like rust for
web development, instead of writing more dreadful javascript...

~~~
Manishearth
Note that Rust is stable now. IDE tooling and stuff isn't there yet (soon?!),
and there are other reasons why you may not use Rust, but it is stable.

After 1.0 the Rust releases have been stable, with the stability checked
against the entire ecosystem on crates.io. [https://blog.rust-
lang.org/2014/10/30/Stability.html](https://blog.rust-
lang.org/2014/10/30/Stability.html)

