Top Related Projects
A fast and secure runtime for WebAssembly
🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten
Emscripten: An LLVM-to-WebAssembly Compiler
A TypeScript-like language for WebAssembly.
Facilitating high-level interactions between Wasm modules and JavaScript
WebAssembly Micro Runtime (WAMR)
Quick Overview
WASI (WebAssembly System Interface) is a standardized interface for WebAssembly modules to interact with system resources. It aims to provide a portable and secure way for WebAssembly programs to access system-level functionality across different environments, including browsers, servers, and embedded devices.
Pros
- Enhances WebAssembly's portability by providing a consistent system interface across platforms
- Improves security by offering a capability-based security model for system access
- Enables WebAssembly to be used in a wider range of applications, including server-side and edge computing
- Facilitates the development of language-agnostic, platform-independent applications
Cons
- Still in development, with some features and APIs not yet fully implemented or standardized
- Limited support in some environments, as adoption is ongoing
- May require additional tooling or runtime support for full functionality
- Learning curve for developers unfamiliar with WebAssembly or capability-based security models
Getting Started
To get started with WASI, you'll need a WASI-compatible WebAssembly runtime and toolchain. Here's a basic example using the wasmtime
runtime:
-
Install
wasmtime
: Follow the instructions at https://wasmtime.dev/ -
Create a simple C program that uses WASI:
#include <stdio.h>
int main() {
printf("Hello from WASI!\n");
return 0;
}
- Compile the program to WebAssembly using a WASI-enabled compiler (e.g., Clang):
clang --target=wasm32-wasi -o hello.wasm hello.c
- Run the WebAssembly module using
wasmtime
:
wasmtime hello.wasm
This should output: "Hello from WASI!"
For more advanced usage and API documentation, refer to the WASI specification and your chosen runtime's documentation.
Competitor Comparisons
A fast and secure runtime for WebAssembly
Pros of Wasmtime
- Comprehensive runtime implementation with a focus on performance and security
- Extensive language support, including Rust, C, and Python bindings
- Active development and frequent updates from the Bytecode Alliance
Cons of Wasmtime
- More complex setup and configuration compared to WASI
- Larger codebase and potentially steeper learning curve for newcomers
Code Comparison
WASI (specification example):
__wasi_errno_t __wasi_proc_exit(
__wasi_exitcode_t rval
) __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("proc_exit")
));
Wasmtime (Rust usage example):
use wasmtime::*;
let engine = Engine::default();
let module = Module::from_file(&engine, "example.wasm")?;
let store = Store::new(&engine, ());
let instance = Instance::new(&store, &module, &[])?;
Summary
WASI focuses on defining a standardized system interface for WebAssembly, while Wasmtime provides a full runtime implementation. WASI offers a more streamlined approach to WebAssembly system integration, whereas Wasmtime provides a feature-rich environment with broader language support and active development. The choice between them depends on specific project requirements and the desired level of control over the WebAssembly runtime environment.
🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten
Pros of Wasmer
- More comprehensive runtime environment with additional features
- Supports multiple backends (LLVM, Cranelift, Singlepass)
- Offers a standalone CLI tool for running WebAssembly modules
Cons of Wasmer
- Larger project scope may lead to increased complexity
- Potentially slower adoption of new WebAssembly standards
- May have higher resource requirements due to additional features
Code Comparison
WASI example:
#include <stdio.h>
int main() {
printf("Hello, WASI!\n");
return 0;
}
Wasmer example:
use wasmer::{imports, Instance, Module, Store};
use wasmer_wasi::WasiState;
fn main() -> anyhow::Result<()> {
let module = Module::from_file(&store, "hello_world.wasm")?;
let instance = Instance::new(&module, &imports! {})?;
// ... (additional setup and execution code)
}
While WASI focuses on defining a standardized system interface for WebAssembly, Wasmer provides a more feature-rich runtime environment. WASI aims for broad compatibility and standardization, whereas Wasmer offers additional tools and flexibility for running and managing WebAssembly modules. The code examples illustrate the difference in approach, with WASI providing a simpler C-based interface and Wasmer offering a more comprehensive Rust-based API for module management and execution.
Emscripten: An LLVM-to-WebAssembly Compiler
Pros of Emscripten
- Mature ecosystem with extensive documentation and community support
- Supports compiling a wide range of C/C++ libraries to WebAssembly
- Provides a complete toolchain for web development with WebAssembly
Cons of Emscripten
- More complex setup and usage compared to WASI
- Focuses primarily on web-based applications, limiting its use in other environments
- Can produce larger output files due to additional runtime components
Code Comparison
Emscripten:
#include <emscripten.h>
#include <stdio.h>
int main() {
printf("Hello, Emscripten!\n");
return 0;
}
WASI:
#include <stdio.h>
int main() {
printf("Hello, WASI!\n");
return 0;
}
The main difference in the code examples is that Emscripten requires the inclusion of the emscripten.h
header, while WASI uses standard C libraries without additional headers. This showcases Emscripten's focus on web-specific features, whereas WASI aims for a more general-purpose, system-level approach to WebAssembly outside the browser context.
A TypeScript-like language for WebAssembly.
Pros of AssemblyScript
- Familiar TypeScript-like syntax, making it easier for JavaScript developers to adopt
- Compiles directly to WebAssembly, offering a streamlined development process
- Includes a standard library with common data structures and utilities
Cons of AssemblyScript
- Limited ecosystem compared to WASI's broader support and standardization efforts
- May not be suitable for all use cases that WASI aims to address, such as system-level interactions
Code Comparison
AssemblyScript:
export function add(a: i32, b: i32): i32 {
return a + b;
}
WASI (using C for illustration):
#include <stdio.h>
int main() {
printf("Hello from WASI!\n");
return 0;
}
Key Differences
- AssemblyScript focuses on providing a TypeScript-like language for WebAssembly development
- WASI aims to standardize system interfaces for WebAssembly, enabling broader application scenarios
- AssemblyScript is more oriented towards application-level development, while WASI addresses system-level interactions
Use Cases
- AssemblyScript: Web applications, performance-critical browser-based computations
- WASI: Server-side applications, containerized environments, edge computing
Facilitating high-level interactions between Wasm modules and JavaScript
Pros of wasm-bindgen
- Specifically designed for Rust-to-WebAssembly interoperability
- Provides high-level abstractions for working with JavaScript types and APIs
- Offers automatic generation of JavaScript glue code for seamless integration
Cons of wasm-bindgen
- Limited to Rust and JavaScript/WebAssembly ecosystem
- May introduce additional overhead due to abstraction layers
- Requires learning a specific set of macros and conventions
Code Comparison
WASI example:
#include <stdio.h>
int main() {
printf("Hello from WASI!\n");
return 0;
}
wasm-bindgen example:
use wasm_bindgen::prelude::*;
#[wasm_bindgen]
pub fn greet(name: &str) -> String {
format!("Hello, {}!", name)
}
Summary
WASI focuses on providing a standardized system interface for WebAssembly, enabling portability across different environments. It's language-agnostic and aims to create a consistent runtime for WebAssembly modules.
wasm-bindgen, on the other hand, is specifically tailored for Rust-to-WebAssembly development, offering tight integration with JavaScript and web APIs. It simplifies the process of creating WebAssembly modules from Rust code and interacting with them from JavaScript.
While WASI provides a broader, more general-purpose solution, wasm-bindgen offers a more specialized and streamlined experience for Rust developers targeting web platforms.
WebAssembly Micro Runtime (WAMR)
Pros of wasm-micro-runtime
- Lightweight and efficient, suitable for resource-constrained devices
- Supports multiple architectures and platforms
- Includes a comprehensive set of tools and libraries for WebAssembly development
Cons of wasm-micro-runtime
- Limited WASI support compared to the WASI repository
- May have fewer standardization efforts and community involvement
- Potentially less focus on broader ecosystem compatibility
Code Comparison
WASI example:
#include <stdio.h>
#include <wasi/api.h>
int main() {
printf("Hello from WASI!\n");
return 0;
}
wasm-micro-runtime example:
#include <stdio.h>
#include "wasm_export.h"
int main() {
printf("Hello from WAMR!\n");
return 0;
}
The code examples show similar basic usage, but WASI focuses on standardized system interfaces, while wasm-micro-runtime provides a more specialized runtime environment. WASI aims to create a unified interface for WebAssembly modules across different platforms, whereas wasm-micro-runtime offers a complete runtime solution with additional features for embedded systems and IoT devices.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
WebAssembly System Interface
The WebAssembly System Interface (WASI) is a set of APIs for WASI being developed for eventual standardization by the WASI Subgroup, which is a subgroup of the WebAssembly Community Group.
WASI started with launching what is now called Preview 1, an API using the witx IDL, and it is now widely used. Its major influences are POSIX and CloudABI.
WASI Preview 2 is now in development, which is a modular collection of APIs defined with the Wit IDL, and it incorporates many of the lessons learned from Preview 1, including adding support for a wider range of source languages, modularity, a more expressive type system, virtualizability, and more.
Find the APIs
Development of each API happens in its own repo, which you can access from the proposals list.
This repo is for general discussion, as well as documenting how we work and high-level goals.
Propose a new API
If you would like to create a new proposal, get started with our Contributing guide.
All new API proposals should use the new format and the new repo structure that is shown in the proposal template.
See the Wit in WASI document for more information about using Wit for WASI proposals.
WASI High Level Goals
(In the spirit of WebAssembly's High-Level Goals.)
- Define a set of portable, modular, runtime-independent, and WebAssembly-native APIs which can be used by WebAssembly code to interact with the outside world. These APIs preserve the essential sandboxed nature of WebAssembly through a Capability-based API design.
- Specify and implement incrementally. Start with a Minimum Viable Product (MVP), then adding additional features, prioritized by feedback and experience.
- Supplement API designs with documentation and tests, and, when feasible, reference implementations which can be shared between wasm engines.
- Make a great platform:
- Work with WebAssembly tool and library authors to help them provide WASI support for their users.
- When being WebAssembly-native means the platform isn't directly compatible with existing applications written for other platforms, design to enable compatibility to be provided by tools and libraries.
- Allow the overall API to evolve over time; to make changes to API modules that have been standardized, build implementations of them using libraries on top of new API modules to provide compatibility.
WASI Design Principles
Capability-based security
WASI is designed with capability-based security principles, using the facilities provided by the Wasm component model. All access to external resources is provided by capabilities.
There are two kinds of capabilities:
-
Handles, defined in the component-model type system, dynamically identify and provide access to resources. They are unforgeable, meaning there's no way for an instance to acquire access to a handle other than to have another instance explicitly pass one to it.
-
Link-time capabilities, which are functions which require no handle arguments, are used sparingly, in situations where it's not necessary to identify more than one instance of a resource at runtime. Link-time capabilities are interposable, so they are still refusable in a capability-based security sense.
WASI has no ambient authorities, meaning that there are no global namespaces at runtime, and no global functions at link time.
Note that this is a different sense of "capability" than Linux capabilities or the withdrawn POSIX capabilities, which are per-process rather than per-resource.
Interposition
Interposition in the context of WASI interfaces is the ability for a Webassembly instance to implement a given WASI interface, and for a consumer WebAssembly instance to be able to use this implementation transparently. This can be used to adapt or attenuate the functionality of a WASI API without changing the code using it.
Component model interfaces always support link-time interposition. While WASI APIs are often implemented in hosts, they can also be implemented in Wasm, which may itself be a wrapper around the host. This may be used to implement attenuation, providing filtered access to the underlying host-provided functionality.
Interposition is sometimes referred to as "virtualization", however we use "interposition" here because the word "virtualization" has several related meanings.
Compatibility
Compatibility with existing applications and libraries, as well as existing host platforms, is important, but will sometimes be in conflict with overall API cleanliness, safety, performance, or portability. Where practical, WASI seeks to keep the WASI API itself free of compatibility concerns, and provides compatibility through libraries, such as WASI libc, and tools. This way, applications which don't require compatibility for compatibility's sake aren't burdened by it.
Portability
Portability is important to WASI, however the meaning of portability will be specific to each API.
WASI's modular nature means that engines don't need to implement every API in WASI, so we don't need to exclude APIs just because some host environments can't implement them. We prefer APIs which can run across a wide variety of engines when feasible, but we'll ultimately decide whether something is "portable enough" on an API-by-API basis.
Modularity
WASI will include many interfaces that are not appropriate for every host environment, so WASI uses the component model's worlds mechanism to allow specific sets of APIs to be described which meet the needs of different environments.
Top Related Projects
A fast and secure runtime for WebAssembly
🚀 The leading Wasm Runtime supporting WASIX, WASI and Emscripten
Emscripten: An LLVM-to-WebAssembly Compiler
A TypeScript-like language for WebAssembly.
Facilitating high-level interactions between Wasm modules and JavaScript
WebAssembly Micro Runtime (WAMR)
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot