Skip to content

Commit

Permalink
refactor(examples): update all zig examples to use zig v0.11-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Feb 28, 2023
1 parent 060a3a6 commit 37c6b29
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 26 deletions.
10 changes: 5 additions & 5 deletions examples/zig-canvas/build.zig
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
// IMPORTANT: This build file is more complicated than needed due to being part of this monorepo
// 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, .{
// Only needed for this monorepo!!
.base = "../../node_modules",
// Declare extra WASM API packages to use
.packages = &.{
.{ .id = "wasm-api-dom", .path = "@thi.ng/wasm-api-dom/zig/lib.zig" },
// Declare extra WASM API module to use
.modules = &.{
.{ .name = "wasm-api-dom", .path = "@thi.ng/wasm-api-dom/zig/lib.zig" },
},
// build mode override
.mode = .ReleaseSmall,
.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 @@ -11,7 +11,7 @@
"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",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build.zig wasm-api-build.zig",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build-v0.11.zig wasm-api-build.zig",
"preview": "vite preview --host --open"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions examples/zig-cellular/build.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
// IMPORTANT: This build file is more complicated than needed due to being part of this monorepo
// Please consult the thi.ng/wasm-api README for details!
// Outside the umbrella monorepo, the import path for that file will be (usually):
Expand All @@ -9,11 +9,11 @@ pub fn build(b: *std.build.Builder) void {
// Only needed for this monorepo!!
.base = "../../node_modules",
// Declare extra WASM API packages to use
.packages = &.{
.{ .id = "wasm-api-canvas", .path = "@thi.ng/wasm-api-canvas/zig/lib.zig" },
.{ .id = "wasm-api-dom", .path = "@thi.ng/wasm-api-dom/zig/lib.zig" },
.modules = &.{
.{ .name = "wasm-api-canvas", .path = "@thi.ng/wasm-api-canvas/zig/lib.zig" },
.{ .name = "wasm-api-dom", .path = "@thi.ng/wasm-api-dom/zig/lib.zig" },
},
// build mode override
.mode = .ReleaseSmall,
.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 @@ -11,7 +11,7 @@
"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",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build.zig wasm-api-build.zig",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build-v0.11.zig wasm-api-build.zig",
"preview": "vite preview --host --open"
},
"devDependencies": {
Expand Down
10 changes: 5 additions & 5 deletions examples/zig-counter/build.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
// IMPORTANT: This build file is more complicated than needed due to being part of this monorepo
// Please consult the thi.ng/wasm-api README for details!
// Outside the umbrella monorepo, the import path for that file will be (usually):
Expand All @@ -9,11 +9,11 @@ pub fn build(b: *std.build.Builder) void {
// Only needed for this monorepo!!
.base = "../../node_modules",
// Declare extra WASM API packages to use
.packages = &.{
.{ .id = "wasm-api-dom", .path = "@thi.ng/wasm-api-dom/zig/lib.zig" },
.{ .id = "wasm-api-schedule", .path = "@thi.ng/wasm-api-schedule/zig/lib.zig" },
.modules = &.{
.{ .name = "wasm-api-dom", .path = "@thi.ng/wasm-api-dom/zig/lib.zig" },
.{ .name = "wasm-api-schedule", .path = "@thi.ng/wasm-api-schedule/zig/lib.zig" },
},
// build mode override
.mode = .ReleaseSmall,
.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 @@ -11,7 +11,7 @@
"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",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build.zig wasm-api-build.zig",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build-v0.11.zig wasm-api-build.zig",
"preview": "vite preview --host --open"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/zig-counter/zig/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ fn init() !void {
// try schedule.init(customAllocator);

// then instantiate all counter components
for (counters) |*counter, i| try counter.init(dom.body, i + 1);
for (&counters, 0..) |*counter, i| try counter.init(dom.body, i + 1);
}

/// Main entry point
Expand Down
10 changes: 5 additions & 5 deletions examples/zig-todo-list/build.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const std = @import("std");

pub fn build(b: *std.build.Builder) void {
pub fn build(b: *std.Build) void {
// IMPORTANT: This build file is more complicated than needed due to being part of this monorepo
// Please consult the thi.ng/wasm-api README for details!
// Outside the umbrella monorepo, the import path for that file will be (usually):
Expand All @@ -9,11 +9,11 @@ pub fn build(b: *std.build.Builder) void {
// Only needed for this monorepo!!
.base = "../../node_modules",
// Declare extra WASM API packages to use
.packages = &.{
.{ .id = "wasm-api-dom", .path = "@thi.ng/wasm-api-dom/zig/lib.zig" },
.{ .id = "wasm-api-schedule", .path = "@thi.ng/wasm-api-schedule/zig/lib.zig" },
.modules = &.{
.{ .name = "wasm-api-dom", .path = "@thi.ng/wasm-api-dom/zig/lib.zig" },
.{ .name = "wasm-api-schedule", .path = "@thi.ng/wasm-api-schedule/zig/lib.zig" },
},
// build mode override
.mode = .ReleaseSmall,
.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 @@ -12,7 +12,7 @@
"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",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build.zig wasm-api-build.zig",
"prepare:zig": "cp ../../node_modules/@thi.ng/wasm-api/zig/build-v0.11.zig wasm-api-build.zig",
"preview": "vite preview --host --open"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion examples/zig-todo-list/zig/state.zig
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub const TaskItem = struct {
}

pub fn deinit(self: *TaskItem) void {
for (self.parent.tasks.items) |item, i| {
for (self.parent.tasks.items, 0..) |item, i| {
if (item == self) {
_ = self.parent.tasks.orderedRemove(i);
break;
Expand Down

0 comments on commit 37c6b29

Please sign in to comment.