New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Rust work with emscripten #604

Closed
steveklabnik opened this Issue Jan 21, 2015 · 21 comments

Comments

Projects
None yet
@steveklabnik
Member

steveklabnik commented Jan 21, 2015

Issue by brson
Wednesday Apr 18, 2012 at 20:44 GMT

For earlier discussion, see rust-lang/rust#2235

This issue was labelled with: A-an-interesting-project, A-build, A-runtime, E-hard, I-wishlist in the Rust repository


I've spent some time poking at this problem and rustc now generates code that emscripten can translate, but the compiled javascript fails when it hits a runtime function. The next step is to start building the runtime using emcc as the compiler. Stub out all the things that don't build behind EMSCRIPTEN ifdefs.

Emscripten is adding a way to treat inline assembly as javascript, so all the parts of the runtime that don't build with emscripten can be implemented inline with javascript.

Alternately, we could reimplement the runtime piecemeal in javascript and not bother compiling it from C++ at all. This approach isn't recommended.

@aidanhs

This comment has been minimized.

Show comment
Hide comment
@antonkulaga

This comment has been minimized.

Show comment
Hide comment
@antonkulaga

antonkulaga Aug 12, 2015

This feature looks very promising. I wonder, is the expecting performance going to be better than with native (handwritten) Javascript?

antonkulaga commented Aug 12, 2015

This feature looks very promising. I wonder, is the expecting performance going to be better than with native (handwritten) Javascript?

@withoutboats

This comment has been minimized.

Show comment
Hide comment
@withoutboats

withoutboats Aug 12, 2015

Contributor

@antonkulaga it should perform much better in a browser that supports asm.js - tests show asm.js is within about a factor of 2 of native performance.

Contributor

withoutboats commented Aug 12, 2015

@antonkulaga it should perform much better in a browser that supports asm.js - tests show asm.js is within about a factor of 2 of native performance.

@DiamondLovesYou

This comment has been minimized.

Show comment
Hide comment
@chpio

This comment has been minimized.

Show comment
Hide comment
@chpio

chpio Aug 26, 2015

it's not working any more: AerialX/cargo-build#2

chpio commented Aug 26, 2015

it's not working any more: AerialX/cargo-build#2

@chpio

This comment has been minimized.

Show comment
Hide comment
@chpio

chpio commented Aug 27, 2015

Bountysource

@tomaka

This comment has been minimized.

Show comment
Hide comment
@tomaka

tomaka Aug 27, 2015

@t128 The next step is basically rust-lang/rust#26505

tomaka commented Aug 27, 2015

@t128 The next step is basically rust-lang/rust#26505

@bennyn

This comment has been minimized.

Show comment
Hide comment
@bennyn

bennyn Sep 15, 2015

@tomaka rust-lang/rust#26505 is closed. So how good are chances to see a working Rust -> JavaScript transpiler? Has anyone made progress?

bennyn commented Sep 15, 2015

@tomaka rust-lang/rust#26505 is closed. So how good are chances to see a working Rust -> JavaScript transpiler? Has anyone made progress?

@ticki

This comment has been minimized.

Show comment
Hide comment
@ticki

ticki Sep 15, 2015

Contributor

This is not exactly a Rust -> JavaScript transpiler, but there is bilalhusain/dust, which is a language which is very similar to Rust (but as it's JS, it doesn't have all the fancy memory mangement of rust, it uses a gc). I'm not sure if that's relevant.

Also why make a transpiler, instead of getting it to work with emscripten?

Contributor

ticki commented Sep 15, 2015

This is not exactly a Rust -> JavaScript transpiler, but there is bilalhusain/dust, which is a language which is very similar to Rust (but as it's JS, it doesn't have all the fancy memory mangement of rust, it uses a gc). I'm not sure if that's relevant.

Also why make a transpiler, instead of getting it to work with emscripten?

@tomaka

This comment has been minimized.

Show comment
Hide comment
@tomaka

tomaka Sep 15, 2015

@bennyn The previous PR has been closed in favor of rust-lang/rust#28355

tomaka commented Sep 15, 2015

@bennyn The previous PR has been closed in favor of rust-lang/rust#28355

@tomaka

This comment has been minimized.

Show comment
Hide comment
@tomaka

tomaka Sep 15, 2015

To give a summary (hopefully I don't say anything wrong):

  • rust-lang/rust#27937 is the first step to compile rust with emscripten's llvm fork (which currently produces errors because this fork can't compile for x86, arm, etc.).
  • rust-lang/rust#28355 handles the fact that binaries aren't really binaries and the fact that some LLVM intrinsics aren't available.

After these two PRs we probably need to tweak the lists of build targets, then compiling a program with #![no_std] should probably work.

Then the stdlib probably needs some tweaks, although in don't know at which degree.

tomaka commented Sep 15, 2015

To give a summary (hopefully I don't say anything wrong):

  • rust-lang/rust#27937 is the first step to compile rust with emscripten's llvm fork (which currently produces errors because this fork can't compile for x86, arm, etc.).
  • rust-lang/rust#28355 handles the fact that binaries aren't really binaries and the fact that some LLVM intrinsics aren't available.

After these two PRs we probably need to tweak the lists of build targets, then compiling a program with #![no_std] should probably work.

Then the stdlib probably needs some tweaks, although in don't know at which degree.

@bnjbvr

This comment has been minimized.

Show comment
Hide comment
@bnjbvr

bnjbvr Sep 15, 2015

Just wanted to give a notice here: with WebAssembly being implemented as a pure LLVM backend in the future, compiling from Rust to WebAssembly should prove ridiculously easy, and as WebAssembly has JS polyfills, running it in browsers will be easy too.

bnjbvr commented Sep 15, 2015

Just wanted to give a notice here: with WebAssembly being implemented as a pure LLVM backend in the future, compiling from Rust to WebAssembly should prove ridiculously easy, and as WebAssembly has JS polyfills, running it in browsers will be easy too.

@DiamondLovesYou

This comment has been minimized.

Show comment
Hide comment
@DiamondLovesYou

DiamondLovesYou Sep 15, 2015

@tomaka I have other inbound PRs that address all of those issues. Plus this PR: rust-lang/rust#27937 . Also don't forget about the work I still have to do in pnacl-llvm.

DiamondLovesYou commented Sep 15, 2015

@tomaka I have other inbound PRs that address all of those issues. Plus this PR: rust-lang/rust#27937 . Also don't forget about the work I still have to do in pnacl-llvm.

@tomaka

This comment has been minimized.

Show comment
Hide comment
@tomaka

tomaka Dec 6, 2015

This branch by @brson is a work in progress that adds support for emscripten to rustc.

I tried it and it works great for the moment (I managed to run glium's teapot example with WebGL with some changes in the stdlib and in glutin and glium), although @brson said that things weren't getting compiled properly in release mode (I didn't try release mode).

tomaka commented Dec 6, 2015

This branch by @brson is a work in progress that adds support for emscripten to rustc.

I tried it and it works great for the moment (I managed to run glium's teapot example with WebGL with some changes in the stdlib and in glutin and glium), although @brson said that things weren't getting compiled properly in release mode (I didn't try release mode).

@tomaka

This comment has been minimized.

Show comment
Hide comment

tomaka commented Dec 18, 2015

@tomaka

This comment has been minimized.

Show comment
Hide comment
@slimsag

This comment has been minimized.

Show comment
Hide comment
@slimsag

slimsag Apr 9, 2016

Hope I'm not adding too much noise; could anyone tell me the current status of this issue?

I don't know enough to implement it myself, but have been eagerly following all PRs hoping I might one day find a set of commands that lets me compile a Rust program, with or without stdlib, to JS :)

slimsag commented Apr 9, 2016

Hope I'm not adding too much noise; could anyone tell me the current status of this issue?

I don't know enough to implement it myself, but have been eagerly following all PRs hoping I might one day find a set of commands that lets me compile a Rust program, with or without stdlib, to JS :)

@LaylConway

This comment has been minimized.

Show comment
Hide comment
@LaylConway

LaylConway Apr 29, 2016

What's currently still needed to bring emscripten support into the nightly builds? I'm having a hard time getting an overview of what the current blocking issues are for this.

LaylConway commented Apr 29, 2016

What's currently still needed to bring emscripten support into the nightly builds? I'm having a hard time getting an overview of what the current blocking issues are for this.

@tomaka

This comment has been minimized.

Show comment
Hide comment
@tomaka

tomaka Apr 29, 2016

@LaylConway

  • The biggest blocker is that Rust's build system would need to detect whether the local LLVM supports emscripten and conditionally enable it. But I think the plan now is to merge emscripten's LLVM and Rust's LLVM.
  • This PR contains some fixes on the Rust side and should be rebased and merged: rust-lang/rust#31623 The changes in the test runner were controversial, but they are not needed if you don't want to run Rust's tests suit.
  • Emscripten's exception handling code will result in the program stopping whenever a panic occurs. This should be fixed on the emscripten side (stub: kripken/emscripten#4104), but again it's not critical.

Other than that, most of the critical bugs have been fixed already and the rest of the fixes are in rust-lang/rust#31623.

tomaka commented Apr 29, 2016

@LaylConway

  • The biggest blocker is that Rust's build system would need to detect whether the local LLVM supports emscripten and conditionally enable it. But I think the plan now is to merge emscripten's LLVM and Rust's LLVM.
  • This PR contains some fixes on the Rust side and should be rebased and merged: rust-lang/rust#31623 The changes in the test runner were controversial, but they are not needed if you don't want to run Rust's tests suit.
  • Emscripten's exception handling code will result in the program stopping whenever a panic occurs. This should be fixed on the emscripten side (stub: kripken/emscripten#4104), but again it's not critical.

Other than that, most of the critical bugs have been fixed already and the rest of the fixes are in rust-lang/rust#31623.

@mbrubeck

This comment has been minimized.

Show comment
Hide comment
@mbrubeck

mbrubeck Sep 28, 2017

Contributor

This is done.

Contributor

mbrubeck commented Sep 28, 2017

This is done.

@mbrubeck mbrubeck closed this Sep 28, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment