Bytebox currently builds with Zig 0.11.x to avoid churn on zig master.
git clone --recurse-submodules https://github.com/rdunnington/bytebox.git
cd bytebox
zig build test # run the WebAssembly spec testsuite
# run the wasi testsuite
python3 test/wasi/wasi-testsuite/test-runner/wasi_test_runner.py -r test/wasi/bytebox_adapter.py -t ./test/wasi/wasi-testsuite/tests/assemblyscript/testsuite/ ./test/wasi/wasi-testsuite/tests/c/testsuite/ ./test/wasi/wasi-testsuite/tests/rust/testsuite/
You can use the standalone runtime to load and execute WebAssembly programs:
zig build run -- <file> [function] [function args]...
Or embed Bytebox in your own programs:
// build.zig
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
const exe = b.addExecutable("my_program", "src/main.zig");
exe.addPackage(std.build.Pkg{
.name = "bytebox",
.source = .{ .path = "bytebox/src/core.zig" }, // submodule in the root dir
});
exe.setTarget(b.standardTargetOptions(.{}));
exe.setBuildMode(b.standardReleaseOptions());
exe.install();
const run = exe.run();
const step = b.step("run", "runs my_program");
step.dependOn(&run.step);
}
// main.zig
const std = @import("std");
const bytebox = @import("bytebox");
pub fn main() !void {
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
var allocator: std.mem.Allocator = gpa.allocator();
var wasm_data: []u8 = try std.fs.cwd().readFileAlloc(allocator, "example.wasm", 1024 * 128);
defer allocator.free(wasm_data);
var module_definition = bytebox.ModuleDefinition.init(allocator, .{});
defer module_definition.deinit();
try module_definition.decode(wasm_data);
var module_instance = bytebox.ModuleInstance.init(&module_definition, allocator);
defer module_instance.deinit();
try module_instance.instantiate(.{});
}
Inter-language FFI is also supported. See src/bytebox.h
for an overview in C. To use bytebox as a static library, link with the built library in zig-out/lib/
. Note that Zig assumes a default stack size of 8MB, so you'll need to ensure the same in your program.
This project is still in the alpha stage.
Legend | Meaning |
---|---|
โ | Implemented |
โ | TODO |
๐ | Not planned/Removed from spec |
WebAssembly support:
Status | Feature |
---|---|
โ | WebAssembly 1.0 |
โ | Sign extension instructions |
โ | Non-trapping float-to-int conversion |
โ | Multiple values |
โ | Reference types |
โ | Table instructions |
โ | Multiple tables |
โ | Bulk memory and table instructions |
โ | Vector instructions |
WASI Preview 1 support:
Status | Feature |
---|---|
โ | args_get |
โ | args_sizes_get |
โ | environ_get |
โ | environ_sizes_get |
โ | clock_res_get |
โ | clock_time_get |
โ | fd_advise |
โ | fd_allocate |
โ | fd_close |
โ | fd_datasync |
โ | fd_fdstat_get |
โ | fd_fdstat_set_flags |
๐ | fd_fdstat_set_rights |
โ | fd_filestat_get |
โ | fd_filestat_set_size |
โ | fd_filestat_set_times |
โ | fd_pread |
โ | fd_prestat_get |
โ | fd_prestat_dir_name |
โ | fd_pwrite |
โ | fd_read |
โ | fd_readdir |
โ | fd_renumber |
โ | fd_seek |
โ | fd_sync |
โ | fd_tell |
โ | fd_write |
โ | path_create_directory |
โ | path_filestat_get |
โ | path_filestat_set_times |
โ | path_link |
โ | path_open |
โ | path_readlink |
โ | path_remove_directory |
โ | path_rename |
โ | path_symlink |
โ | path_unlink_file |
โ | poll_oneoff |
โ | proc_exit |
๐ | proc_raise |
โ | sched_yield |
โ | random_get |
โ | sock_accept |
โ | sock_recv |
โ | sock_send |
โ | sock_shutdown |
These tasks must be completed to enter alpha:
- API ergonomics pass
- Documentation
- General TODO/code cleanup
- Crash hardening/fuzzing
To enter beta:
- No breaking API changes after this point
- Performance competitive with other well-known interpreters (e.g. micro-wasm-runtime, wasm3)
To have a 1.0 release:
- Tested with a wide variety of wasm programs
- Successfully used in other beta-quality projects