#adding custom commands to build.zig

1 messages · Page 1 of 1 (latest)

surreal scarab
#

hello

i'm trying to use zig with tic80 (a fantasy console using WASM).

i want to have zig build import that would do :

  1. regular zig build to build the WASM artifact
  2. copy the artifact to the TIC-80 folder copy zig-out/lib/cart.wasm tic80fs/cart.wasm
  3. run tic80 --fs=./tic80fs/ ./tic80fs/cart.tic --cmd="import binary cart.wasm"

tho i'm not sure how to do that within build.zig

#

for now my build.zig is

const std = @import("std");

pub fn build(b: *std.build.Builder) void {
  const target: std.zig.CrossTarget = .{
    .cpu_arch = .wasm32, 
    .os_tag = .freestanding
  };

  const optimize = b.standardOptimizeOption(.{});

  const cart = b.addSharedLibrary(.{ 
    .name = "cart",
    .root_source_file = .{ .path = "src/main.zig" },
    .target = target,
    .optimize = optimize,
  });
  cart.import_memory = true;
  cart.initial_memory = 65536 * 4;
  cart.max_memory = 65536 * 4;
  cart.export_table = true;
  cart.global_base = 96 * 1024;
  cart.stack_size = 8192;
  cart.export_symbol_names = &[_][]const u8{ "TIC", "OVR", "BDR", "SCR", "BOOT" };
  cart.install();

  const copy_step = b.addSystemCommand(&[_][]const u8 { "copy", "zig-out/lib/cart.wasm", "tic80fs/cart.wasm" });
  copy_step.step.dependOn(b.getInstallStep());

  const import_step = b.addSystemCommand(&[_][]const u8 { "./tic80.exe", "--fs=./tic80fs", "./tic80fs/cart.tic", "--cmd=\"import binary cart.wasm\""});
  import_step.step.dependOn(&copy_step.step);
  
}