Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dev/jit-debugging.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ wrap in a minimal ELF, and disassemble with LLVM objdump.
```zig
// Add temporarily in Compiler.finalize(), after @memcpy:
if (condition) { // e.g. self.reg_count == 11
const file = std.fs.cwd().createFile("/tmp/jit_dump.bin", .{}) catch null;
const file = std.Io.Dir.cwd().createFile("/tmp/jit_dump.bin", .{}) catch null;
if (file) |f| { defer f.close(); f.writeAll(src_bytes) catch {}; }
}
```
Expand Down
10 changes: 4 additions & 6 deletions bench/fib_bench.zig
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
const std = @import("std");
const types = @import("zwasm");

pub fn main() !void {
var gpa: std.heap.GeneralPurposeAllocator(.{}) = .init;
defer _ = gpa.deinit();
const allocator = gpa.allocator();
pub fn main(init: std.process.Init) !void {
const allocator = init.gpa;

// Parse optional argument for N
var n: u64 = 35;
Expand Down Expand Up @@ -35,8 +33,8 @@ pub fn main() !void {
try stdout.flush();
}

fn readFile(allocator: std.mem.Allocator, path: []const u8) ![]const u8 {
const file = try std.fs.cwd().openFile(path, .{});
fn readFile(allocator: std.mem.Allocator, io: std.Io, path: []const u8) ![]const u8 {
const file = try std.Io.Dir.cwd().openFile(".", io, path);
defer file.close();
const stat = try file.stat();
const data = try allocator.alloc(u8, stat.size);
Expand Down
19 changes: 19 additions & 0 deletions build.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
test
+- run test 398 pass, 3 skip, 1 fail, 1 timeout (403 total)
error: 'wasi.test.WASI — random_get fills buffer' timed out after 25.023s
error: 'leb128.test.overflow — value too large for u32' failed:
error: .{ .bytes = { 128, 128, 128, 128, 64 }, .pos = 0 }expected error.Overflow, found 0
/nix/store/rcl9v3y5112v9qxs0xlm2qksabj08sdv-zig-0.16.0/lib/std/testing.zig:65:9: 0x158db09 in expectError__anon_76846 (std.zig)
return error.TestExpectedError;
^
/home/ewan/Documents/zig/zwasm/src/leb128.zig:307:5: 0x158dd27 in test.overflow — value too large for u32 (types.zig)
try testing.expectError(error.Overflow, r.readU32());
^
failed command: ./.zig-cache/o/c89ca94fdf9ec0715edc8cf4c6f4f1ff/test --cache-dir=./.zig-cache --seed=0xab20887d --listen=-

Build Summary: 2/4 steps succeeded (1 failed); 398/403 tests passed (3 skipped, 1 failed, 1 timed out)
test transitive failure
+- run test 398 pass, 3 skip, 1 fail, 1 timeout (403 total)

error: the following build command failed with exit code 1:
.zig-cache/o/2fc72a677a00554ba15517cfc4b0e718/build /nix/store/rcl9v3y5112v9qxs0xlm2qksabj08sdv-zig-0.16.0/bin/zig /nix/store/rcl9v3y5112v9qxs0xlm2qksabj08sdv-zig-0.16.0/lib /home/ewan/Documents/zig/zwasm .zig-cache /home/ewan/.cache/zig --seed 0xab20887d -Zdd23c543245b78a8 test --test-timeout 25s
2 changes: 1 addition & 1 deletion build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ pub fn build(b: *std.Build) void {
.root_source_file = null,
.target = target,
.optimize = optimize,
.link_libc = true,
});
ct_mod.addCSourceFile(.{ .file = b.path(ct.src) });
ct_mod.addIncludePath(b.path("include"));
Expand All @@ -214,7 +215,6 @@ pub fn build(b: *std.Build) void {
.name = ct.name,
.root_module = ct_mod,
});
ct_exe.linkLibC();
// Install only via c-test step (not default install) to keep artifact count
// below Zig 0.15.2 build runner shuffle bug threshold on some platforms.
c_test_step.dependOn(&b.addInstallArtifact(ct_exe, .{}).step);
Expand Down
2 changes: 1 addition & 1 deletion docs/embedding.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const zwasm = @import("zwasm");

pub fn main() !void {
const allocator = std.heap.page_allocator;
const wasm_bytes = try std.fs.cwd().readFileAlloc(allocator, "module.wasm", 10 * 1024 * 1024);
const wasm_bytes = try std.Io.Dir.cwd().readFileAlloc(allocator, "module.wasm", 10 * 1024 * 1024);
defer allocator.free(wasm_bytes);

var module = try zwasm.WasmModule.load(allocator, wasm_bytes);
Expand Down
2 changes: 1 addition & 1 deletion examples/zig/basic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn main() !void {
}

fn readFile(allocator: std.mem.Allocator, path: []const u8) ![]const u8 {
const file = try std.fs.cwd().openFile(path, .{});
const file = try std.Io.Dir.cwd().openFile(".", io, path);
defer file.close();
const stat = try file.stat();
const data = try allocator.alloc(u8, stat.size);
Expand Down
2 changes: 1 addition & 1 deletion examples/zig/host_functions.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub fn main() !void {
}

fn readFile(allocator: std.mem.Allocator, path: []const u8) ![]const u8 {
const file = try std.fs.cwd().openFile(path, .{});
const file = try std.Io.Dir.cwd().openFile(".", io, path);
defer file.close();
const stat = try file.stat();
const data = try allocator.alloc(u8, stat.size);
Expand Down
2 changes: 1 addition & 1 deletion examples/zig/inspect.zig
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn main() !void {
}

fn readFile(allocator: std.mem.Allocator, path: []const u8) ![]const u8 {
const file = try std.fs.cwd().openFile(path, .{});
const file = try std.Io.Dir.cwd().openFile(".", io, path);
defer file.close();
const stat = try file.stat();
const data = try allocator.alloc(u8, stat.size);
Expand Down
2 changes: 1 addition & 1 deletion examples/zig/memory.zig
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub fn main() !void {
}

fn readFile(allocator: std.mem.Allocator, path: []const u8) ![]const u8 {
const file = try std.fs.cwd().openFile(path, .{});
const file = try std.Io.Dir.cwd().openFile(".", io, path);
defer file.close();
const stat = try file.stat();
const data = try allocator.alloc(u8, stat.size);
Expand Down
2 changes: 1 addition & 1 deletion examples/zig/wasi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn main() !void {
}

fn readFile(allocator: std.mem.Allocator, path: []const u8) ![]const u8 {
const file = try std.fs.cwd().openFile(path, .{});
const file = try std.Io.Dir.cwd().openFile(".", io, path);
defer file.close();
const stat = try file.stat();
const data = try allocator.alloc(u8, stat.size);
Expand Down
22 changes: 14 additions & 8 deletions src/cache.zig
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ pub fn wasmHash(wasm_bin: []const u8) [32]u8 {
pub fn getCacheDir(alloc: Allocator) ![]u8 {
const path = try platform.appCacheDir(alloc, "zwasm");
// Ensure directory exists
std.fs.makeDirAbsolute(path) catch |err| switch (err) {
var io_instance: std.Io.Threaded = undefined;
const io = io_instance.io();
std.Io.Dir.createDirAbsolute(io, path, .default_dir) catch |err| switch (err) {
error.PathAlreadyExists => {},
else => {
alloc.free(path);
Expand Down Expand Up @@ -199,22 +201,26 @@ pub fn saveToFile(alloc: Allocator, hash: [32]u8, ir_funcs: []const ?*const IrFu
defer alloc.free(data);
const path = try getCachePath(alloc, hash);
defer alloc.free(path);
const file = try std.fs.createFileAbsolute(path, .{});
defer file.close();
try file.writeAll(data);
var io_instance: std.Io.Threaded = undefined;
const io = io_instance.io();
const file = try std.Io.Dir.createFileAbsolute(io, path, .{});
defer file.close(io);
try file.writeStreamingAll(io, data);
}

/// Load cached IR from disk. Returns null on miss or mismatch.
pub fn loadFromFile(alloc: Allocator, hash: [32]u8) !?[]?*IrFunc {
const path = getCachePath(alloc, hash) catch return null;
defer alloc.free(path);
const file = std.fs.openFileAbsolute(path, .{}) catch return null;
defer file.close();
const stat = try file.stat();
var io_instance: std.Io.Threaded = undefined;
const io = io_instance.io();
const file = std.Io.Dir.openFileAbsolute(io, path, .{}) catch return null;
defer file.close(io);
const stat = try file.stat(io);
if (stat.size > 256 * 1024 * 1024) return null; // sanity limit: 256 MB
const data = try alloc.alloc(u8, stat.size);
defer alloc.free(data);
const bytes_read = try file.readAll(data);
const bytes_read = try file.readPositionalAll(io, data, 0);
if (bytes_read != stat.size) return null;
return deserialize(alloc, data, hash);
}
Expand Down
Loading