Wasmer: compiler passes: are wat files compiled?

I just got the basic example of 'add_one' at https://crates.io/crates/wasmer working.

One thing that confuses me from that page is the mention of multiple compiler passes:

Compilers (mutually exclusive):

  • singlepass : it will use wasmer-compiler-singlepass as the default compiler (ideal for blockchains ).
  • cranelift : it will use wasmer-compiler-cranelift as the default compiler (ideal for development ).
  • llvm : it will use wasmer-compiler-llvm as the default compiler (ideal for production ).

Here is why this is confusing to me.

  1. If we are compiling from Rust to wasm, the wasmer compiler is not used right? because we use whatever the host systems' cargo --target=wasm32-unknown-unknown ends up using.

  2. If this "compiler" is not referring to Rust -> wasm, what is it referring to? "wat -> wasm" ist just assembling right? (Are we running compiler optimization passes on wat -> wasm? That seems unlikely).

Thus, my question: wasmer has 3 options for compiler: singlepass, cranelft, llvm. Under what conditions is the wasmer compiler pass actually used ?

A wasm file can't just be directly executed by the cpu, it needs to be further compiled and that's what wasmer does.

1 Like

Ah, to put it another way, the "singlepass / cranelift / llvm" layer is responsible for, among other things, *.wasm -> x86_64 machine code ?

Pretty much yes. Of course it will generate x86_64 machine code only on x86_64 platforms.

1 Like