wamr-zig
kassane/wamr-zig
Apache-2.0
Zig bindings from WebAssembly Micro Runtime (WAMR)
0001
5
embedded, wamr, wasm, webassembly, zig-package
build.zig.zon build.zig
View on Github Updated: 6:18:47 PM Sun Sep 08 2024Size: 484KBCreated: 12:31:25 PM Sat Aug 31 2024
Dependencies:
WAMR
zig fetch --save git+https://github.com/kassane/wamr-zig
Copy to clipboard
WAMR-zig
Overview
Based on WAMR Rust SDK. It is the wrapper of wasm_export.h but with Zig style.
Requirements
Core concepts
- Runtime. It is the environment that hosts all the wasm modules. Each process has one runtime instance.
- Module. It is the compiled .wasm or .aot. It can be loaded into runtime and instantiated into instance.
- Instance. It is the running instance of a module. It can be used to call export functions.
- Function. It is the exported function.
WASI concepts
- WASIArgs. It is used to configure the WASI environment.
- pre-open. All files and directories in the list will be opened before the .wasm or .aot loaded.
- allowed address. All ip addresses in the allowed address list will be allowed to connect with a socket.
- allowed DNS.
How to use
- New project
# Create directory
$ mkdir project-name
$ cd project-name
$ zig init
# Add dependency in zon file
$ zig fetch --save=wamr-zig git+https://github.com/wamr-zig/wamr-zig
Add in build.zig
const std = @import("std");
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});
const wamr_zig = b.dependency("wamr-zig", .{
.target = target,
.optimize = optimize,
});
// your project
[exe|lib].root_module.addImport("wamr", wamr_zig.module("wamr"));
}