Coder Social home page Coder Social logo

wasm-vm-bytebox's Introduction

Bytebox

Markdown Logo

Bytebox is a Webassembly VM.

Getting started

Requirements

Bytebox currently builds with Zig 0.11.x to avoid churn on zig master.

Run

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/

Usage

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.

Status

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
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

Roadmap

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

wasm-vm-bytebox's People

Contributors

rdunnington avatar deecellar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.