Dart bindings to the WebAssembly System Interface.

Usage

This package allows Dart WebAssembly components (built with the wasm_tools package) to access WASI functionality like file systems, low-level networking as well as HTTP clients and servers.

Currently, this exposes the wasi:cli and wasi:http worlds.

To use this package, add it and wasm_tools to your dependencies:

dart pub add wasi dev:wasm_tools

WebAssembly components are defined against a "world" describing imports and exports. wasi:cli/command is one such world meant as a target for CLI programs. A simple Dart component for that world might look like this:

import 'dart:async';
import 'dart:convert';

import 'package:wasi/cli/command.dart';
import 'package:wasi/cli.dart';
import 'package:wasm_components/wasm_components.dart';

void main() {
  commandComponent((imports) => _Run(imports.cliStdout));
}

final class _Run(final Stdout stdout) implements Run {
  @override
  Future<Result<void, void>> run() async {
    await stdout.writeViaStream(data: .value(utf8.encode('Hello world!')));
    return const .ok(null);
  }
}

Compile this with dart run wasm_tools compile main.dart, and run it with wasmtime run main.wasm.

Libraries

cli
Interfaces and type definitions for wasi:cli.
cli/command
Define a component adhering to the wasi:cli/command world.
clocks
Interfaces and type definitions for wasi:clocks.
filesystem
Interfaces and type definitions for wasi:filesystem.
http
Interfaces and type definitions for wasi:http.
random
Interfaces and type definitions for wasi:cli.
sockets
Interfaces and type definitions for wasi:cli.