make things build

Signed-off-by: Xe Iaso <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-06-26 19:32:01 -04:00
parent d497fbf302
commit f47b8b1754
4 changed files with 26 additions and 17 deletions

View File

@ -1,30 +1,27 @@
const std = @import("std"); 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 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.setBuildMode(mode);
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
lib.import_memory = true; lib.import_memory = true;
lib.initial_memory = 65536; lib.initial_memory = 65536;
lib.max_memory = 65536; lib.max_memory = 65536;
lib.stack_size = 14752; lib.global_base = 6560;
lib.stack_size = 8192;
// Export WASM-4 symbols
lib.export_symbol_names = &[_][]const u8{ "start", "update" }; lib.export_symbol_names = &[_][]const u8{ "start", "update" };
lib.install(); lib.install();
const lib_artifact = b.addInstallArtifact(lib);
const run_cmd = b.addSystemCommand(&.{"w4", "run-native"}); const run_command = b.addSystemCommand(&.{
run_cmd.step.dependOn(&lib.step); "w4", "run", "zig-out/lib/cart.wasm",
run_cmd.addFileSourceArg(lib.getOutputSource()); "--no-open",
if (b.args) |args| { });
run_cmd.addArgs(args); run_command.step.dependOn(&lib_artifact.step);
}
const run_step = b.step("run", "Run Cartridge with w4"); const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step); run_step.dependOn(&run_command.step);
}
}

1
dist/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
*.wasm

9
release.sh Executable file
View File

@ -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

View File

@ -11,12 +11,14 @@ const smiley = [8]u8{
0b11000011, 0b11000011,
}; };
export fn start() void {}
export fn update() void { export fn update() void {
w4.m.colors._0 = .p1; w4.m.colors._0 = .p1;
w4.text("Hello from Zig!", 10, 10); w4.text("Hello from Zig!", 10, 10);
const gamepad = w4.m.gamepads[0]; const gamepad = w4.m.gamepads[0];
if (gamepad.x) { if (gamepad.a) {
w4.m.colors._0 = .p3; w4.m.colors._0 = .p3;
} }