Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes for compatibility with zig 0.11.0 #190

Merged
merged 16 commits into from
Jul 8, 2023
Merged
Show file tree
Hide file tree
Changes from 15 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
31 changes: 19 additions & 12 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,41 +16,48 @@ jobs:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.10.0
version: master
- run: zig build test
testsuite:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.10.0
- run: zig build --build-file test/testrunner/build.zig --prefix ./
- run: cp bin/testrunner testrunner
- run: cp test/testsuite-generated/* ./
- run: bash test/run-generated.sh
version: master
- name: Build test runner
working-directory: ./test/testrunner
run: zig build --prefix ./
- name: Run testsuite
working-directory: ./test/
run: bash test/run-generated.sh
parsecheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.10.0
- run: zig build --build-file test/parsecheck/build.zig --prefix ./
- run: bin/parsecheck test/testsuite-generated
version: master
- name: Build parsecheck
working-directory: ./test/parsecheck
run: zig build --prefix ./
- name: Run parse check
run: test/parsecheck/bin/parsecheck test/testsuite-generated
build_interface:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.10.0
- run: zig build --build-file test/interface/build.zig
version: master
- name: Build interface
working-directory: ./test/interface
run: zig build
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: goto-bus-stop/setup-zig@v1
with:
version: 0.10.0
version: master
- run: zig fmt --check src/*.zig
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
zig-cache
zig-out
test/testrunner/bin
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub fn main() !void {

### Compile-time

- Zig 0.10.0
- Zig 0.11 (master)

### Run-time

Expand Down Expand Up @@ -80,7 +80,8 @@ pub fn main() !void {
1. Build the test runner

```
zig build --build-file test/testrunner/build.zig --prefix ./
cd test/testrunner
zig build --prefix ./
```

2. Run
Expand Down
23 changes: 16 additions & 7 deletions build.zig
Original file line number Diff line number Diff line change
@@ -1,14 +1,23 @@
const Builder = @import("std").build.Builder;

pub fn build(b: *Builder) void {
const mode = b.standardReleaseOptions();
const lib = b.addStaticLibrary("zware", "src/main.zig");
lib.setBuildMode(mode);
lib.install();
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

var main_tests = b.addTest("src/main.zig");
main_tests.setBuildMode(mode);
const lib = b.addStaticLibrary(.{
.name = "zware",
.root_source_file = .{ .path = "src/main.zig" },
.target = target,
.optimize = optimize,
});
b.installArtifact(lib);

const main_tests = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.optimize = optimize,
});

const run_main_tests = b.addRunArtifact(main_tests);
const test_step = b.step("test", "Run library tests");
test_step.dependOn(&main_tests.step);
test_step.dependOn(&run_main_tests.step);
}
25 changes: 11 additions & 14 deletions examples/fib/build.zig
Original file line number Diff line number Diff line change
@@ -1,23 +1,20 @@
const Builder = @import("std").build.Builder;

pub fn build(b: *Builder) void {
// Standard target options allows the person running `zig build` to choose
// what target to build for. Here we do not override the defaults, which
// means any target is allowed, and the default is native. Other options
// for restricting supported target set are available.
const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{});

// Standard release options allow the person running `zig build` to select
// between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall.
const mode = b.standardReleaseOptions();
const exe = b.addExecutable(.{
.name = "fib",
.root_source_file = .{ .path = "src/fib.zig" },
.target = target,
.optimize = optimize,
});
exe.addAnonymousModule("zware", .{
.source_file = .{ .path = "../../src/main.zig" },
});

const exe = b.addExecutable("fib", "src/fib.zig");
exe.addPackagePath("zware", "../../src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.install();

const run_cmd = exe.run();
const run_cmd = b.addRunArtifact(exe);
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
Expand Down
20 changes: 10 additions & 10 deletions src/instance.zig
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ pub const Instance = struct {
//
// For 2, we need to add the function to the store
const imported_function_count = self.funcaddrs.items.len;
for (self.module.functions.list.items) |function_def, i| {
for (self.module.functions.list.items, 0..) |function_def, i| {
if (function_def.import) |_| {
// Check that the function defintion (which this module expects)
// is the same as the function in the store
Expand Down Expand Up @@ -174,7 +174,7 @@ pub const Instance = struct {
}

fn instantiateGlobals(self: *Instance) !void {
for (self.module.globals.list.items) |global_def, i| {
for (self.module.globals.list.items, 0..) |global_def, i| {
if (global_def.import != null) {
const imported_global = try self.getGlobal(i);
if (imported_global.mutability != global_def.mutability) return error.MismatchedMutability;
Expand All @@ -192,7 +192,7 @@ pub const Instance = struct {
}

fn instantiateMemories(self: *Instance) !void {
for (self.module.memories.list.items) |memtype, i| {
for (self.module.memories.list.items, 0..) |memtype, i| {
if (memtype.import != null) {
const imported_mem = try self.getMemory(i);
// Use the current size of the imported mem as min (rather than imported_mem.min). See https://github.com/WebAssembly/spec/pull/1293
Expand All @@ -205,7 +205,7 @@ pub const Instance = struct {
}

fn instantiateTables(self: *Instance) !void {
for (self.module.tables.list.items) |tabletype, i| {
for (self.module.tables.list.items, 0..) |tabletype, i| {
if (tabletype.import != null) {
const imported_table = try self.getTable(i);
if (imported_table.reftype != tabletype.reftype) return error.ImportedTableRefTypeMismatch;
Expand All @@ -224,7 +224,7 @@ pub const Instance = struct {
var data = try self.store.data(dataddr);

// TODO: Do we actually need to copy the data or just close over module bytes?
for (datatype.data) |byte, j| {
for (datatype.data, 0..) |byte, j| {
try data.set(j, byte);
}

Expand All @@ -248,9 +248,9 @@ pub const Instance = struct {
try self.elemaddrs.append(elemaddr);
var elem = try self.store.elem(elemaddr);

for (self.module.element_init_offsets.items[elemtype.init .. elemtype.init + elemtype.count]) |expr, j| {
for (self.module.element_init_offsets.items[elemtype.init .. elemtype.init + elemtype.count], 0..) |expr, j| {
const funcaddr = try self.invokeExpression(expr, u32, .{});
try elem.set(@intCast(u32, j), funcaddr);
try elem.set(@intCast(j), funcaddr);
}

if (elemtype.mode != .Passive) {
Expand All @@ -264,8 +264,8 @@ pub const Instance = struct {
const index = math.add(u32, offset, elemtype.count) catch return error.OutOfBoundsMemoryAccess;
if (index > table.size()) return error.OutOfBoundsMemoryAccess;

for (elem.elem) |funcaddr, i| {
try table.set(@intCast(u32, offset + i), funcaddr);
for (elem.elem, 0..) |funcaddr, i| {
try table.set(@intCast(offset + i), funcaddr);
}
}
}
Expand Down Expand Up @@ -329,7 +329,7 @@ pub const Instance = struct {
try vm.invoke(f.start);

// 9.
for (out) |_, out_index| {
for (out, 0..) |_, out_index| {
out[out_index] = vm.popOperand(u64);
}
},
Expand Down
Loading