Convert Figma logo to code with AI

bytecodealliance logolucet

Lucet, the Sandboxing WebAssembly Compiler.

4,064
164
4,064
65

Top Related Projects

18,439

🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten

2,639

WebAssembly Virtual Machine

1,555

WebAssembly (Wasm) interpreter.

7,207

🚀 A fast WebAssembly interpreter and the most universal WASM runtime

Quick Overview

Lucet is a native WebAssembly compiler and runtime. It's designed to safely execute untrusted WebAssembly programs inside your application, with near-native speeds. Lucet is developed by the Bytecode Alliance to enable secure, high-performance execution of WebAssembly outside the browser.

Pros

  • High performance: Near-native execution speeds for WebAssembly modules
  • Security: Provides strong sandboxing for untrusted code execution
  • Low overhead: Minimal runtime overhead and fast instantiation times
  • Flexibility: Can be embedded in various host applications and languages

Cons

  • Limited ecosystem: Fewer tools and libraries compared to more established runtimes
  • Complexity: Requires understanding of WebAssembly and low-level concepts
  • Platform support: Primarily focused on Linux, with limited support for other platforms
  • Learning curve: May be challenging for developers new to WebAssembly concepts

Code Examples

  1. Compiling a WebAssembly module:
use lucet_runtime::{DlModule, Limits, MmapRegion, Region};

let module = DlModule::load("path/to/your/module.so")?;
let region = MmapRegion::create(1, &Limits::default())?;
let instance = region.instantiate(&module)?;
  1. Calling a WebAssembly function:
use lucet_runtime::Instance;

let result = instance
    .run("add", &[1.into(), 2.into()])?
    .returned()?;
println!("Result: {}", result);
  1. Setting up a custom host function:
use lucet_runtime::{InstanceHandle, Val};

fn host_function(
    _vmctx: &mut lucet_runtime::Vmctx,
    args: &[Val],
) -> Result<Vec<Val>, lucet_runtime::Error> {
    println!("Host function called with args: {:?}", args);
    Ok(vec![42.into()])
}

instance.register_callback("host_function", host_function)?;

Getting Started

To get started with Lucet, follow these steps:

  1. Install Rust and Cargo: https://www.rust-lang.org/tools/install
  2. Clone the Lucet repository:
    git clone https://github.com/bytecodealliance/lucet.git
    cd lucet
    
  3. Build Lucet:
    cargo build --release
    
  4. Run the tests:
    cargo test
    

For more detailed instructions and usage examples, refer to the Lucet documentation in the repository.

Competitor Comparisons

18,439

🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten

Pros of Wasmer

  • Supports multiple backends (LLVM, Cranelift, Singlepass)
  • More extensive language support (Python, PHP, Ruby, etc.)
  • Active development and larger community

Cons of Wasmer

  • Generally slower execution compared to Lucet
  • Higher memory usage for runtime and compiled modules
  • More complex setup and configuration

Code Comparison

Wasmer:

use wasmer::{Store, Module, Instance};

let module = Module::from_file(&store, "example.wasm")?;
let instance = Instance::new(&module, &imports)?;
let result = instance.exports.get_function("sum")?;

Lucet:

use lucet_runtime::{DlModule, Limits, Region};

let module = DlModule::load("example.so")?;
let region = Region::create(1, &Limits::default())?;
let instance = region.new_instance(module)?;
let result = instance.run("sum", &[])?;

Both Wasmer and Lucet provide WebAssembly runtimes, but they have different focuses and trade-offs. Wasmer aims for broader language and platform support, while Lucet prioritizes performance and security for server-side applications. The code examples demonstrate the slightly different approaches to loading and executing WebAssembly modules in each runtime.

2,639

WebAssembly Virtual Machine

Pros of WAVM

  • Supports a wider range of WebAssembly features, including SIMD and threading
  • Generally faster execution speed for complex WebAssembly modules
  • More actively maintained with frequent updates and improvements

Cons of WAVM

  • Larger runtime footprint and longer compilation times
  • Less focus on sandboxing and security features
  • More complex setup and integration process

Code Comparison

WAVM example:

#include "WAVM/Runtime/Runtime.h"
#include "WAVM/IR/Module.h"

WAVM::Runtime::ModuleRef compileModule(const std::vector<U8>& wasmBytes)
{
    return WAVM::Runtime::compileModule(wasmBytes);
}

Lucet example:

use lucet_runtime::{DlModule, Limits, MmapRegion, Region};

let region = MmapRegion::create(1, &Limits::default()).unwrap();
let module = DlModule::load("path/to/module.so").unwrap();
let instance = region.new_instance(module).unwrap();

Both WAVM and Lucet provide WebAssembly runtime environments, but they have different focuses and trade-offs. WAVM offers broader WebAssembly support and potentially faster execution for complex modules, while Lucet emphasizes sandboxing, security, and faster startup times. The choice between them depends on specific project requirements and priorities.

1,555

WebAssembly (Wasm) interpreter.

Pros of wasmi

  • Written in pure Rust, offering better portability and integration with Rust projects
  • Supports a wider range of WebAssembly features, including more recent proposals
  • Easier to use and integrate as an interpreter, with a simpler API

Cons of wasmi

  • Generally slower execution compared to Lucet's AOT compilation approach
  • Higher memory usage during runtime due to interpretation overhead
  • Less optimized for production environments with high-performance requirements

Code Comparison

wasmi example:

let module = Module::from_buffer(&wasm_binary)?;
let instance = ModuleInstance::new(&module, &ImportsBuilder::default())?;
let result = instance.invoke_export("add", &[RuntimeValue::I32(1), RuntimeValue::I32(2)], &mut NopExternals)?;

Lucet example:

let module = lucet_runtime::Module::load(&path)?;
let region = MmapRegion::create(1, &Limits::default())?;
let instance = region.new_instance(module)?;
let result = instance.run("add", &[1_i32.into(), 2_i32.into()])?;
7,207

🚀 A fast WebAssembly interpreter and the most universal WASM runtime

Pros of wasm3

  • Highly portable, runs on a wide range of platforms including microcontrollers
  • Lightweight and fast interpreter, suitable for embedded systems
  • Easy to integrate into existing projects

Cons of wasm3

  • Interpreter-based, generally slower than AOT compilation
  • Limited optimization capabilities compared to Lucet's AOT approach
  • May not be suitable for high-performance server-side applications

Code Comparison

wasm3:

m3_env env = m3_NewEnvironment ();
m3_runtime runtime = m3_NewRuntime (env, 64*1024, NULL);
m3_module module;
m3_LinkRawFunction (module, "env", "print", "v(i)", &print);

Lucet:

let module = DlModule::load("my_module.so")?;
let region = MmapRegion::create(1, &Limits::default())?;
let instance = region.new_instance(module)?;
instance.run("main", &[])?;

Summary

wasm3 is a lightweight, portable WebAssembly interpreter suitable for embedded systems and easy integration. Lucet, on the other hand, is an AOT compiler focused on high-performance server-side applications. wasm3 offers broader platform support but may sacrifice performance, while Lucet provides better optimization and speed but with more limited portability.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Lucet has reached End-of-life

Lucet has reached end-of-life, and maintence has ceased. All Lucet users should transition to Wasmtime.

In mid-2020, the Lucet team switched focus to working on the Wasmtime engine. We have added all of the features to Wasmtime which previously only Lucet had, such as ahead-of-time (AOT) compilation and a pooling userfaultfd-based memory allocator.

Lucet   Build Status

A Bytecode Alliance project

Lucet is a native WebAssembly compiler and runtime. It is designed to safely execute untrusted WebAssembly programs inside your application.

Check out our announcement post on the Fastly blog.

Lucet uses, and is developed in collaboration with, the Bytecode Alliance's Cranelift code generator. It powers Fastly's Compute@Edge platform.

asciicast

Lucet's documentation is available at https://bytecodealliance.github.io/lucet (sources).