#wasm-module #compiler #wasm-bytecode

no-std wasmer-compiler

Base compiler abstraction for Wasmer WebAssembly runtime

74 releases (41 stable)

5.0.1 Nov 6, 2024
4.4.0 Oct 4, 2024
4.3.5 Jul 16, 2024
4.2.6 Mar 4, 2024
1.0.0-alpha5 Nov 6, 2020

#1200 in WebAssembly

Download history 28446/week @ 2024-07-30 33685/week @ 2024-08-06 25141/week @ 2024-08-13 42138/week @ 2024-08-20 25464/week @ 2024-08-27 19043/week @ 2024-09-03 18443/week @ 2024-09-10 17201/week @ 2024-09-17 15184/week @ 2024-09-24 18076/week @ 2024-10-01 24307/week @ 2024-10-08 17978/week @ 2024-10-15 16794/week @ 2024-10-22 21689/week @ 2024-10-29 18771/week @ 2024-11-05 11527/week @ 2024-11-12

72,098 downloads per month
Used in 277 crates (21 directly)

MIT license

560KB
12K SLoC

wasmer-compiler Build Status Join Wasmer Slack MIT License

This crate is the base for Compiler implementations.

It performs the translation from a Wasm module into a basic ModuleInfo, but leaves the Wasm function bytecode translation to the compiler implementor.

Here are some of the Compilers provided by Wasmer:

How to create a compiler

To create a compiler, one needs to implement two traits:

  1. CompilerConfig, that configures and creates a new compiler,
  2. Compiler, the compiler itself that will compile a module.
/// The compiler configuration options.
pub trait CompilerConfig {
    /// Gets the custom compiler config
    fn compiler(&self) -> Box<dyn Compiler>;
}

/// An implementation of a compiler from parsed WebAssembly module to compiled native code.
pub trait Compiler {
    /// Compiles a parsed module.
    ///
    /// It returns the [`Compilation`] or a [`CompileError`].
    fn compile_module<'data, 'module>(
        &self,
        target: &Target,
        compile_info: &'module CompileModuleInfo,
        module_translation: &ModuleTranslationState,
        // The list of function bodies
        function_body_inputs: PrimaryMap<LocalFunctionIndex, FunctionBodyData<'data>>,
    ) -> Result<Compilation, CompileError>;
}

Acknowledgments

This project borrowed some of the code strucutre from the cranelift-wasm crate, however it's been adapted to not depend on any specific IR and be abstract of any compiler.

Please check Wasmer ATTRIBUTIONS to further see licenses and other attributions of the project.

Dependencies

~6–17MB
~235K SLoC