Any interest in making a WASM-to Rust transpiler?

There is an officially supported wasm-to-javascript compiler:

Aside from the rather large scope of writing such a transpilation target for Rust (Rustaceans who write compiler code for fun are not easily deterred by scope), is there anything else about the project that makes it seem infeasible or unappealing?

I’m just a little puzzled as to why no one has attempted a POC of this.

The prospective value proposition seems very appealing to me: Prototype 1-99% of your application in a rapid-iteration language. Incrementally convert critical paths and high-maintenance systems to Rust as the need arises.

And the list of languages we could transpile to Rust via WebAssembly would be very long, covering practically all mainstream languages.

The scope could also be narrowed by first targeting the WASM output of one specific language.

There is rewasm which is a wasm to rust _de_compiler. I’m not sure what the difference between decompilation and transpilation would be in this context.

(EDIT: Well, not quite rust, but it is pretty close).

2 Likes

I wrote one a long time ago. It successfully transpiled musl's libm, sqlite, some Java code, some Go code, lua (the library), ...

Interestingly this sometimes results in Rust code that takes like 15 minutes to compile for a simple Go hello world. And you can't blame LLVM for this one, because cargo check is just as slow (iirc it gets "stuck" in liveness checking or something).

1 Like

I don't see why you would need to "decompile" the WASM to convert critical paths to Rust while writing the rest of the app in another language. If you're writing an app, shouldn't you already have access to the source code and be able to link in Rust that way?

I don't see much use for something like this outside of reverse engineering applications/malware though.

The big problem in using a WASM-to-Rust transpiler is that it'd result in really low quality code. Compilers do a lot of work shuffling code around to be highly performant, and those sorts of optimisations tend to make code hard to follow. It'd also be quite unsafe.

Keep in mind it's also hard (or downright impossible) to reverse-engineer high-level concepts like a struct from machine-executable forms like WebAssembly or machine code.

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.