-
Notifications
You must be signed in to change notification settings - Fork 19
Compile Rust to JavaScript with emscripten #33
Comments
It should be as "easy" as creating an intermediary library in JS for all runtime dependencies (libuv, etc.) like this. I say easy in the sense that I don't think you'll have to do much magic to get it working, just a lot of work to get the runtime wrapped with JS functionality. |
Hi, I will like to work on this. Are there any docs that I should consult before starting? I have looked at https://github.com/kripken/emscripten/wiki and http://mozakai.blogspot.sg/2012/03/howto-port-cc-library-to-javascript.html. Also, I've tried to compile it with emcc but I'm getting some errors. Should I post them to the emscripten mailing list? |
You will need to look into how the runtime works, what sort of memory requirements it needs and how those memory requirements would best be wrapped in Javascript. Assuming the error you get is something about braces, then I get that too. And yeah, I would post it to the mailing list, along with the bitcode file ( |
@jsyeo by reading the emscripten docs you are a step ahead of me. You are fortunate that emscripten's author (@kripken / azakai) is on the Mozilla research team (and sits next to me) so you can feel free to bug him extensively. For things that you suspect are emscripten bugs, the best place to post them is the emscripten bug tracker on github, otherwise the emscripten mailing list is appropriate. #emscripten on irc.mozilla.org is a good place to ask questions too (as well as #rust). |
Any update on this? I have tried with the following programs and they work fine. #[start]
fn main(_:int, _: **u8) -> int { 0 } #[start]
fn main(_: int, _: **u8) -> int {
unsafe {
std::libc::puts(0 as *i8);
}
0
} |
I'd imagine with the work towards runtime-less rust this should be much easier to implement now. And by working, do you mean those programs compile fine in Emscripten? |
Yes, they do compile and run fine. |
@mrordinaire I'd be very interested to see a blog post or other writeup about how you compiled Rust with emscripten. I've never heard of anybody doing that. The ultimate goal of this task would be to make emscripten a first-class platform in Rust so that you could e.g. |
@brson Yes, I will make a writeup of this when I can find the time (it's right in the middle of exams here on my side). About emscripten being a first class platform, how will |
@mrordinaire rustc would probably need to take an argument specifically to provide the path to the emscripten toolchain, similar to our |
Still a great project. Should be pretty easy these days since the libs are very modular now. |
Is there any progress with this? Do we need to modify Rust itself to make this work? I was thinking the same, some sort of "Try Rust", as documentation is great but still no "user friendly" |
See existing progress at http://www.reddit.com/r/rust/comments/20nnkk/rust_and_emscripten_a_small_success/ |
Awesome! So sad that the |
@Arcnor I just put a status update about how I think to proceed over on the main Rust issue tracker. You are very welcome to take a stab at it. |
@brson Just was looking at it, thank you very much :D. I'm still a super newbie at Rust, and that's why I was looking at some "to the web" version, to help or document my journey. If I get any of your steps done, I'll comment in that issue. Thanks! |
It looks like rust-lang/rfcs#604 is the most recent place for info about this |
It would be nice to be able to run Rust code in the browser, particularly so we can create a 'try rust' website. We would like to do this using the emscripten LLVM-to-JavaScript compiler. The best approach is not exactly clear, but will probably entail porting more C++ runtime code to Rust and creating some sort of platform abstraction layer.
See also: 2235
The text was updated successfully, but these errors were encountered: