Wasmer WebAssembly Runtime

repository·main·Indexed 12 days ago

https://github.com/wasmerio/wasmer

A high-performance, secure WebAssembly runtime for Desktop, Cloud, Edge, and Browser environments. Supports WASI and WASIX out of the box and provides SDKs for embedding in languages including Rust, C/C++, C#, Python, JavaScript, Go, PHP, Ruby, Java, Elixir, and D. Features pluggable compilers such as wasmer-compiler-singlepass, wasmer-compiler-cranelift, and wasmer-compiler-llvm.

Tokens
119.5K
Snippets
373
Records
593
Agent score
96%

What's inside Wasmer

  1. Overview of wai-bindgen-wasmer

    main

    wai-bindgen-wasmer is a runtime utility crate designed for Wasmer host WAI (WebAssembly Interface) bindings. These bindings are generated by the wai-bindgen-gen-wasmer tool.

    It is specifically intended to be used within the Wasmer ecosystem to support WAI bindings, which are being expanded to include wasix_http_client bindings and will eventually cover all WASI and WASIX syscalls.

  2. Overview of wasmer-sdk

    main

    The wasmer-sdk crate provides high-level wrappers for interacting with the Wasmer ecosystem. It is designed to simplify common developer workflows, specifically for:

    • Building and publishing packages: Streamlining the creation and distribution of WebAssembly packages.
    • Deploying apps: Facilitating the deployment of applications within the Wasmer environment.
  3. Overview of `wasmer-types` library

    main

    wasmer-types is a library that provides the core types and traits required to use WebAssembly across different environments. It serves as the foundational type system for the Wasmer ecosystem.

    Key capabilities include:

    • Unit Management: Defines units such as Pages and Bytes.
    • Wasm Types and Values: Provides representations for standard WebAssembly types like I32, I64, F32, F64, V128, as well as reference types like ExternRef and FuncRef. It also includes ExternType, FunctionType, and value conversion utilities.
    • Native Interop: The native module contains traits and implementations for handling WebAssembly types that have a direct representation on the host machine.
    • Memory Access: The memory_view API allows for reading and writing to memories by interpreting raw bytes as specific types (e.g., i8, i16, i32, etc.).
    • Indexing: The indexes module contains all possible WebAssembly module indexes for various types.
    • Initialization: Provides initializers for setting up tables, data, and other Wasm structures.
    • Feature Control: The features module allows you to enable or disable specific WebAssembly features within the Wasmer runtime.
  4. Overview of wasmer-backend-api

    main
    The wasmer-backend-api is a GraphQL API client designed for interacting with the Wasmer backend. It is built using the cynic crate, which provides tight integration between Rust and GraphQL types, reducing boilerplate compared to other GraphQL client libraries.
  5. Access Wasmer documentation and resources

    main

    Wasmer provides several documentation sources depending on your needs:

  6. Cache WebAssembly modules with `wasmer-cache`

    main

    The wasmer-cache crate provides mechanisms to cache compiled WebAssembly modules (wasmer::Module). By caching these modules, you can avoid the overhead of re-compilation on subsequent uses of the same module.

    Core Abstractions

    • Cache trait: A generic interface for storing and loading compiled WebAssembly modules.
    • FileSystemCache: A concrete implementation of the Cache trait that persists modules to the local file system.
    • Hash: Used to generate unique keys for WebAssembly binaries to identify them within the cache.
    use wasmer::{DeserializeError, Module, SerializeError};
    use wasmer_cache::{Cache, FileSystemCache, Hash};
    
    fn store_module(module: &Module, bytes: &[u8]) -> Result<(), SerializeError> {
        // Create a new file system cache.
        let mut fs_cache = FileSystemCache::new("some/directory/goes/here")?;
    
        // Compute a key for a given WebAssembly binary
        let hash = Hash::generate(bytes);
    
        // Store a module into the cache given a key
        fs_cache.store(hash, module.clone())?;
    
        Ok
    }
  7. Identify core Wasmer crates for development

    main

    Depending on your needs, you will interface with different crates in the Wasmer ecosystem:

    • wasmer: The core runtime API used by most developers.
    • wasmer-wasi: Wasmer's implementation of the WebAssembly System Interface (WASI).
    • wasmer-emscripten: Wasmer's Emscripten implementation.
    • wasmer-compiler: Used for implementing custom compilers if you require fine-grained control.
    • wasmer-engine: Used for implementing custom engines if you require fine-grained control.
  8. What is the Wasmer WASM shell (wasmer.sh)?

    main

    The Wasmer WASM shell (wasmer.sh) is a browser-based operating system designed for the WebAssembly community to assemble and build micro-applications. It provides a simulated environment with the following capabilities:

    • File System: Includes a MemFS file system with various mount points.
    • I/O Support: Full support for stdin, stdout, stderr, and tty, including piping and TTY functionality.
    • Process Isolation: Each process has its own private file system space.
    • Concurrency: Fully multi-threaded execution.
    • Command Support: Supports basic bash commands and a wide range of coreutils.
  9. Understand WASM Journal Functionality

    main

    Wasmer supports journals for the state of a WASM process. A journal is a linear history of events that occurred during execution. Replaying these events brings the process to a discrete and deterministic state.

    Key capabilities include:

    • Persistence: Persist changes made to the temporary file system.
    • Snapshots: Save and store snapshots of the running process (including memory and thread stacks).
    • Manipulation: Journal files can be concatenated, compacted, or filtered to modify the resulting discrete state.
    • Durability: Journals are maintained consistently to ensure system failures do not corrupt the history.
  10. Understanding the role of wasmer-vm

    main

    The wasmer-vm crate is the low-level foundation of the Wasmer runtime. It implements the core WebAssembly (Wasm) VM runtime library and supports the Wasm ABI used by Wasmer.

    It provides essential low-level components including:

    • instance management
    • memory handling
    • probestack functionality
    • signature registry
    • trap mechanisms
    • table management
    • VMContext and libcalls

    Note for users: It is highly unlikely that you will need to use wasmer-vm directly. Instead, you should use the high-level wasmer crate, which embeds these low-level types into a more ergonomic and user-friendly API.