Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/malcolmstill/zware
Zig WebAssembly Runtime Engine
https://github.com/malcolmstill/zware
wasm webassembly zig ziglang
Last synced: 30 days ago
JSON representation
Zig WebAssembly Runtime Engine
- Host: GitHub
- URL: https://github.com/malcolmstill/zware
- Owner: malcolmstill
- License: mit
- Created: 2021-02-01T04:27:54.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2024-06-15T13:59:58.000Z (5 months ago)
- Last Synced: 2024-10-01T03:21:18.587Z (about 1 month ago)
- Topics: wasm, webassembly, zig, ziglang
- Language: Zig
- Homepage:
- Size: 3.11 MB
- Stars: 285
- Watchers: 8
- Forks: 10
- Open Issues: 15
-
Metadata Files:
- Readme: README.md
- Contributing: docs/CONTRIBUTING.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-zig - zware
README
zware
Zig WebAssembly Runtime Engine## About
`zware` is a library for executing WebAssembly embedded in [Zig](https://ziglang.org) programs.
## Example
From `examples/fib`:
```zig
const std = @import("std");
const zware = @import("zware");
const Store = zware.Store;
const Module = zware.Module;
const Instance = zware.Instance;
const GeneralPurposeAllocator = std.heap.GeneralPurposeAllocator;
var gpa = GeneralPurposeAllocator(.{}){};pub fn main() !void {
defer _ = gpa.deinit();
const alloc = gpa.allocator();const bytes = @embedFile("fib.wasm");
var store = Store.init(alloc);
defer store.deinit();var module = Module.init(alloc, bytes);
defer module.deinit();
try module.decode();var instance = Instance.init(alloc, &store, module);
try instance.instantiate();
defer instance.deinit();const n = 39;
var in = [1]u64{n};
var out = [1]u64{0};try instance.invoke("fib", in[0..], out[0..], .{});
const result: i32 = @bitCast(@as(u32, @truncate(out[0])));
std.debug.print("fib({}) = {}\n", .{ n, result });
}
```## Requirements
### Compile-time
- Zig 0.12 (master)
### Run-time
- None, zig generates static binaries:
```bash
➜ zware git:(master) ✗ ldd fib
not a dynamic executable
```## Goals
- Embed WebAssembly programs in other zig programs
- Be fast enough to be useful## Status
- The project is very much alpha quality
- WebAssembly 2.0 supported (apart from the vector / SIMD support which is WIP)
- The WebAssembly official testsuite passes (not including SIMD tests)
- Partial WASI support## Running tests
Use `zig build --help` to see all the test targets, here's a summary of the important ones:
```sh
zig build test # Run all the tests (includes unittest and testsuite)
zig build unittest # Run the library unittests
zig build testsuite # Run all the testsuite tests
zig build test-NAME # Run the NAME testsuite test, i.e. test-type
```## Does it run doom?
Yes, [yes it does](https://github.com/malcolmstill/zware-doom)
https://github.com/malcolmstill/zware/assets/2567177/c9acdcb2-69e7-495f-b3f1-89cf6b807a43