From f47b8b17546abc5ff485f85a34316520b7ef2bfe Mon Sep 17 00:00:00 2001 From: Xe Iaso Date: Sun, 26 Jun 2022 19:32:01 -0400 Subject: [PATCH] make things build Signed-off-by: Xe Iaso --- build.zig | 29 +++++++++++++---------------- dist/.gitignore | 1 + release.sh | 9 +++++++++ src/main.zig | 4 +++- 4 files changed, 26 insertions(+), 17 deletions(-) create mode 100644 dist/.gitignore create mode 100755 release.sh diff --git a/build.zig b/build.zig index df8e4d7..d6b1c04 100644 --- a/build.zig +++ b/build.zig @@ -1,30 +1,27 @@ const std = @import("std"); -pub fn build(b: *std.build.Builder) !void { +pub fn build(b: *std.build.Builder) void { const mode = b.standardReleaseOptions(); - const lib = b.addSharedLibrary("cart", "src/main.zig", .unversioned); + const lib = b.addSharedLibrary("cart", "src/main.zig", .unversioned); lib.setBuildMode(mode); lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); lib.import_memory = true; lib.initial_memory = 65536; lib.max_memory = 65536; - lib.stack_size = 14752; - - // Export WASM-4 symbols + lib.global_base = 6560; + lib.stack_size = 8192; lib.export_symbol_names = &[_][]const u8{ "start", "update" }; - lib.install(); + const lib_artifact = b.addInstallArtifact(lib); - const run_cmd = b.addSystemCommand(&.{"w4", "run-native"}); - run_cmd.step.dependOn(&lib.step); - run_cmd.addFileSourceArg(lib.getOutputSource()); - if (b.args) |args| { - run_cmd.addArgs(args); - } + const run_command = b.addSystemCommand(&.{ + "w4", "run", "zig-out/lib/cart.wasm", + "--no-open", + }); + run_command.step.dependOn(&lib_artifact.step); - const run_step = b.step("run", "Run Cartridge with w4"); - run_step.dependOn(&run_cmd.step); - -} + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_command.step); +} \ No newline at end of file diff --git a/dist/.gitignore b/dist/.gitignore new file mode 100644 index 0000000..19e1bce --- /dev/null +++ b/dist/.gitignore @@ -0,0 +1 @@ +*.wasm diff --git a/release.sh b/release.sh new file mode 100755 index 0000000..047018c --- /dev/null +++ b/release.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +set -e + +mkdir -p dist +rm -rf dist/* +zig build -Drelease-small=true +wasm-opt -Oz --zero-filled-memory --strip-producers --dce ./zig-out/lib/cart.wasm -o ./dist/tamamo.wasm +wasm-strip ./dist/tamamo.wasm \ No newline at end of file diff --git a/src/main.zig b/src/main.zig index 04e4b99..9c38112 100644 --- a/src/main.zig +++ b/src/main.zig @@ -11,12 +11,14 @@ const smiley = [8]u8{ 0b11000011, }; +export fn start() void {} + export fn update() void { w4.m.colors._0 = .p1; w4.text("Hello from Zig!", 10, 10); const gamepad = w4.m.gamepads[0]; - if (gamepad.x) { + if (gamepad.a) { w4.m.colors._0 = .p3; }