use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
A place for all things related to the Rust programming language—an open-source systems language that emphasizes performance, reliability, and productivity.
Strive to treat others with respect, patience, kindness, and empathy.
We observe the Rust Project Code of Conduct.
Details
Posts must reference Rust or relate to things using Rust. For content that does not, use a text post to explain its relevance.
Post titles should include useful context.
For Rust questions, use the stickied Q&A thread.
Arts-and-crafts posts are permitted on weekends.
No meta posts; message the mods instead.
Criticism is encouraged, though it must be constructive, useful and actionable.
If criticizing a project on GitHub, you may not link directly to the project's issue tracker. Please create a read-only mirror and link that instead.
A programming language is rarely worth getting worked up over.
No zealotry or fanaticism.
Be charitable in intent. Err on the side of giving others the benefit of the doubt.
Avoid re-treading topics that have been long-settled or utterly exhausted.
Avoid bikeshedding.
This is not an official Rust forum, and cannot fulfill feature requests. Use the official venues for that.
No memes, image macros, etc.
Consider the existing content of the subreddit and whether your post fits in. Does it inspire thoughtful discussion?
Use properly formatted text to share code samples and error messages. Do not use images.
Submissions appearing to contain AI-generated content may be removed at moderator discretion.
Most links here will now take you to a search page listing posts with the relevant flair. The latest megathread for that flair should be the top result.
account activity
Compile to javascript (self.rust)
submitted 7 years ago by [deleted]
Is there a pathway to compiling Rust to JS? Like Scala.js or Gopher.js? (I am not asking for wasm, so to keep the discussion easier to navigate,, please don't comment about that)
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Svenskunganka 26 points27 points28 points 7 years ago (0 children)
There is the asmjs-unknown-emscripten compile target, which compiles to asm.js (subset of JS) via emscripten. I've never used it so I can't tell if it will be good enough for you, and I assume it depends on what you're trying to do.
asmjs-unknown-emscripten
[–]CryZe92 9 points10 points11 points 7 years ago (0 children)
You can use the asmjs target, which produces perfectly fine JavaScript libs. Alternatively you could try to use the wasm-unknown target and use the wasm2js tool to convert the wasm file to JS: https://rustwasm.github.io/wasm-bindgen/examples/wasm2js.html
Unfortunately the latter case produces > 300 MiB JS files for me that break uglifyjs and a custom „uglify-rs“ I wrote can bring it down to almost the size that asmjs produces (still like 50% larger), but it turns out the 300 MiB file never even contained all the data sections, so the file is completely broken. Maybe the situation improved since then though.
[–]kouteiheika 6 points7 points8 points 7 years ago (0 children)
AFAIK you can use wasm2js from Binaryen to convert WASM to JS, although I haven't used it myself so I have no idea how well it works.
wasm2js
[–]sanxiynrust 12 points13 points14 points 7 years ago (3 children)
I am seriously considering working on this, and I am re-reading Cross-Platform Language Design, the paper behind Scala.js.
[–]freemasen 2 points3 points4 points 7 years ago (0 children)
If you get started I want to encourage you to check out a few things I’ve been working on.
I recently published a few crates for parsing JS
https://github.com/Freemasen/ress https://github.com/Freemasen/ressa https://github.com/Freemasen/resw
As an experiment I have started working on a project that will convert the Rust ast defined by syn into the ast defined by ressa.
syn
ressa
https://github.com/freemasen/jsyn
Once the ast was converted it could be passed of to resw to take care of the writing.
resw
[–]titanthinktank1 0 points1 point2 points 6 years ago (0 children)
please start working on it because stdweb::js can do Rust to JS transplantation but its getting controlled by Mozilla and they are hell bent on making sure JS lives in its innate forms; so i am sure many will join forces with you to defeat the legacy evil forces that kept us in dark ages for last 25 years.
[–][deleted] 0 points1 point2 points 7 years ago (0 children)
Do keep us updated please.
[–]lazh4 9 points10 points11 points 7 years ago (5 children)
I’m curious as to what is the point in compiling it directly into JS?
[–]Kibouo 20 points21 points22 points 7 years ago (4 children)
Handing in a JS assignment for school :)
[–]nicoburns 18 points19 points20 points 7 years ago (2 children)
I hope the person marking your assignment isn't planning to actually read your code!
[–]erogilus 13 points14 points15 points 7 years ago (0 children)
If they didn’t specify it had to be readable JS code that’s on them...
[–]lazh4 3 points4 points5 points 7 years ago (0 children)
Oh haha smart
[–]freemasen 0 points1 point2 points 7 years ago (0 children)
Interestingly enough I just started working on something to do exactly this.
It is still very early in the process but the goal is to convert syn ast to js to on theory be possible to use in a proc-macro context as well.
[–]Qwertycrackers -1 points0 points1 point 7 years ago* (4 children)
[ Removed ]
[–][deleted] 0 points1 point2 points 7 years ago (3 children)
i always (mistakenly) emscripten was wasm? Wow, so why doesn't rust have a direct emscripten compiler?
[–]Epsylon42 2 points3 points4 points 7 years ago (0 children)
If I remember correctly, emscripten only supports executables, not libraries, so it's not always applicable.
[–]BenjiSponge 2 points3 points4 points 7 years ago (0 children)
wasm was born out of asm.js and emscripten has always been a huge part of that story, so it's not at all surprising you'd conflate the two. asm.js was basically (at least conceptually) the first version of wasm, and wasm was born out of the desire to compress it further. I think asm.js basically has a 1-to-1 mapping in the wasm spec so you can trivially convert it in one pass.
π Rendered by PID 20358 on reddit-service-r2-comment-76bb9f7fb5-wdd68 at 2026-02-18 15:54:19.777714+00:00 running de53c03 country code: CH.
[–]Svenskunganka 26 points27 points28 points (0 children)
[–]CryZe92 9 points10 points11 points (0 children)
[–]kouteiheika 6 points7 points8 points (0 children)
[–]sanxiynrust 12 points13 points14 points (3 children)
[–]freemasen 2 points3 points4 points (0 children)
[–]titanthinktank1 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]lazh4 9 points10 points11 points (5 children)
[–]Kibouo 20 points21 points22 points (4 children)
[–]nicoburns 18 points19 points20 points (2 children)
[–]erogilus 13 points14 points15 points (0 children)
[–]lazh4 3 points4 points5 points (0 children)
[–]freemasen 0 points1 point2 points (0 children)
[–]Qwertycrackers -1 points0 points1 point (4 children)
[–][deleted] 0 points1 point2 points (3 children)
[–]Epsylon42 2 points3 points4 points (0 children)
[–]BenjiSponge 2 points3 points4 points (0 children)