Best path to compile Rust to SWF for use with Adobe AIR

I'm exploring the idea of compiling Rust to ActionScript bytecode and wrap it into a SWF. I can either:

  • create a target for rustup and manipulate the IR (don't know how to yet) or
  • compile Rust to LLVM bitcode as explained here and manipulate it.

What of these ways are easier? Also, how would I implement the low-level API that Rust uses?

If manipulating LLVM bitcode is easier, is there a full crate for manipulating it? I looked at API docs from but it seems incomplete (like, where is the opcodes enum?).

Likely, going through LLVM IR will be substantially easier. (Still a lot of work, though.) LLVM IR has good parsing support in a number of languages and is itself language-agnostic. On the other hand, if you were to add a new target to the Rust compiler itself, you'd need to build the compiler from source (which in itself is non-trivial), understand its internals, and also make sure to not emit erroneous low-level code when mapping its high-level constructs.

Inkwell is preferable these days. Pretty much no LLVM wrapper crate will give you complete coverage, because the LLVM API is huge, and some of it isn't even exposed via C (only C++, with which Rust can't interact without manually-written glue code).

I guess there is none. LLVM IR is not that simple. Natively (in LLVM's own C++ implementation), each instruction is its own subclass, with substantial behavior and data. It's not just an enum.

I don't understand what this means.

1 Like

I see... it seems LLVM bitcode is much more complex than a WebAssembly module. So I could consider Wasm to Abc, maybe... rather than developing a new target myself.

I mean, panic!("message"); will result in some system API call. How can I discover which system API is called and how it works?

There are existing WASM to SWF compilers.

You don't need to discover it; it's known. You need precisely the standard library and some intrinsics specific to Rust's LLVM fork. (Which is exactly what is documented in the Stack Overflow post you linked to.)

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.