Skip to content

Commit

Permalink
refactor(examples): update all zig examples for latest Zig v0.11-dev
Browse files Browse the repository at this point in the history
- update build scripts
- apply syntax changes
  • Loading branch information
postspectacular committed Jun 28, 2023
1 parent cf63c04 commit 64929c7
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions examples/zig-canvas/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void {
// Please consult the thi.ng/wasm-api README for details!
// Outside the umbrella monorepo, the import path for that file will be (usually):
// node_modules/@thi.ng/wasm-api/zig/build.zig
@import("wasm-api-build.zig").wasmLib(b, .{
b.installArtifact(@import("wasm-api-build.zig").wasmLib(b, .{
// Only needed for this monorepo!!
.base = "../../node_modules",
// Declare extra WASM API module to use
Expand All @@ -14,5 +14,5 @@ pub fn build(b: *std.Build) void {
},
// build mode override
.optimize = .ReleaseSmall,
}).install();
}));
}
2 changes: 1 addition & 1 deletion examples/zig-canvas/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"start": "yarn build:zig && vite --open --host",
"clean": "rimraf zig-cache zig-out",
"build": "tsc && yarn build:zig && vite build --base='./'",
"build:zig": "yarn prepare:zig && zig build && wasm-opt src/main.wasm -o src/main.wasm -O3 && wasm-dis -o src/main.wast src/main.wasm",
"build:zig": "yarn prepare:zig && zig build && wasm-opt zig-out/lib/main.wasm -o src/main.wasm -O3 && wasm-dis -o src/main.wast src/main.wasm",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build-v0.11.zig wasm-api-build.zig",
"preview": "vite preview --host --open"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/zig-cellular/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void {
// Please consult the thi.ng/wasm-api README for details!
// Outside the umbrella monorepo, the import path for that file will be (usually):
// node_modules/@thi.ng/wasm-api/zig/build.zig
@import("wasm-api-build.zig").wasmLib(b, .{
b.installArtifact(@import("wasm-api-build.zig").wasmLib(b, .{
// Only needed for this monorepo!!
.base = "../../node_modules",
// Declare extra WASM API packages to use
Expand All @@ -15,5 +15,5 @@ pub fn build(b: *std.Build) void {
},
// build mode override
.optimize = .ReleaseSmall,
}).install();
}));
}
2 changes: 1 addition & 1 deletion examples/zig-cellular/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"start": "yarn build:zig && vite --open --host",
"clean": "rimraf zig-cache zig-out",
"build": "tsc && yarn build:zig && vite build --base='./'",
"build:zig": "yarn prepare:zig && zig build && wasm-opt src/main.wasm -o src/main.wasm -O3 && wasm-dis -o src/main.wast src/main.wasm",
"build:zig": "yarn prepare:zig && zig build && wasm-opt zig-out/lib/main.wasm -o src/main.wasm -O3 && wasm-dis -o src/main.wast src/main.wasm",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build-v0.11.zig wasm-api-build.zig",
"preview": "vite preview --host --open"
},
Expand Down
6 changes: 3 additions & 3 deletions examples/zig-cellular/zig/ca.zig
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ pub fn update(self: *Self) void {
const behavior = self.behaviors[@mod(currState, self.behaviors.len)];
var num: u8 = 0;
for (behavior.neighbors) |offset| {
var xx = wrapAround(i16, x + offset[0], @intCast(i16, self.width));
var yy = wrapAround(i16, y + offset[1], @intCast(i16, self.height));
if (self.cells[@intCast(usize, yy) * self.width + @intCast(usize, xx)] == nextState) num += 1;
var xx = wrapAround(i16, x + offset[0], @as(i16, @intCast(self.width)));
var yy = wrapAround(i16, y + offset[1], @as(i16, @intCast(self.height)));
if (self.cells[@as(usize, @intCast(yy)) * self.width + @as(usize, @intCast(xx))] == nextState) num += 1;
if (num >= behavior.threshold) break;
}
self.swap[i] = if (num >= behavior.threshold or self.rnd.float(f32) < behavior.mutate) nextState else currState;
Expand Down
4 changes: 2 additions & 2 deletions examples/zig-counter/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void {
// Please consult the thi.ng/wasm-api README for details!
// Outside the umbrella monorepo, the import path for that file will be (usually):
// node_modules/@thi.ng/wasm-api/zig/build.zig
@import("wasm-api-build.zig").wasmLib(b, .{
b.installArtifact(@import("wasm-api-build.zig").wasmLib(b, .{
// Only needed for this monorepo!!
.base = "../../node_modules",
// Declare extra WASM API packages to use
Expand All @@ -15,5 +15,5 @@ pub fn build(b: *std.Build) void {
},
// build mode override
.optimize = .ReleaseSmall,
}).install();
}));
}
2 changes: 1 addition & 1 deletion examples/zig-counter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"start": "yarn build:zig && vite --open --host",
"clean": "rimraf zig-cache zig-out",
"build": "tsc && yarn build:zig && vite build --base='./'",
"build:zig": "yarn prepare:zig && zig build && wasm-opt src/main.wasm -o src/main.wasm -O3 && wasm-dis -o src/main.wast src/main.wasm",
"build:zig": "yarn prepare:zig && zig build && wasm-opt zig-out/lib/main.wasm -o src/main.wasm -O3 && wasm-dis -o src/main.wast src/main.wasm",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build-v0.11.zig wasm-api-build.zig",
"preview": "vite preview --host --open"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/zig-todo-list/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub fn build(b: *std.Build) void {
// Please consult the thi.ng/wasm-api README for details!
// Outside the umbrella monorepo, the import path for that file will be (usually):
// node_modules/@thi.ng/wasm-api/zig/build.zig
@import("wasm-api-build.zig").wasmLib(b, .{
b.installArtifact(@import("wasm-api-build.zig").wasmLib(b, .{
// Only needed for this monorepo!!
.base = "../../node_modules",
// Declare extra WASM API packages to use
Expand All @@ -15,5 +15,5 @@ pub fn build(b: *std.Build) void {
},
// build mode override
.optimize = .ReleaseSmall,
}).install();
}));
}
2 changes: 1 addition & 1 deletion examples/zig-todo-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"clean": "rimraf zig-cache zig-out",
"build": "tsc && yarn build:zig && vite build --base='./'",
"build:types": "npx wasm-api-bindgen -a analytics.json --lang ts -o src/generated/api.ts --lang zig -o zig/api-generated.zig src/typedefs.json",
"build:zig": "yarn prepare:zig && zig build && wasm-opt src/main.wasm -o src/main.wasm -O3 && wasm-dis -o src/main.wast src/main.wasm",
"build:zig": "yarn prepare:zig && zig build && wasm-opt zig-out/lib/main.wasm -o src/main.wasm -O3 && wasm-dis -o src/main.wast src/main.wasm",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build-v0.11.zig wasm-api-build.zig",
"preview": "vite preview --host --open"
},
Expand Down
4 changes: 2 additions & 2 deletions examples/zig-todo-list/zig/state.zig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub const TaskItem = struct {
.parent = parent,
.task = .{
.body = body,
.dateCreated = @intCast(u32, wasm.epoch() / 1000),
.dateCreated = @intCast(wasm.epoch() / 1000),
},
};
}
Expand Down Expand Up @@ -75,7 +75,7 @@ pub const TaskItem = struct {
pub fn markDone(self: *TaskItem) void {
var buf: [32]u8 = undefined;
self.task.state = .done;
self.task.dateDone = @intCast(u32, wasm.epoch() / 1000);
self.task.dateDone = @intCast(wasm.epoch() / 1000);
dom.setInnerText(self.date, todo.formatDateTime(self.task.dateDone, &buf));
dom.addClass(self.root, "task-done");
dom.addClass(self.root, "fadeout");
Expand Down

0 comments on commit 64929c7

Please sign in to comment.