wired/build.zig

43 lines
1.4 KiB
Zig

const std = @import("std");
pub fn build(b: *std.build.Builder) !void {
const assets = std.build.Pkg{
.name = "assets",
.source = .{ .path = "assets/assets.zig" },
};
const mode = b.standardReleaseOptions();
const lib = b.addSharedLibrary("cart", "src/main.zig", .unversioned);
lib.addPackage(assets);
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 = 24752;
// Workaround https://github.com/ziglang/zig/issues/2910, preventing
// functions from compiler_rt getting incorrectly marked as exported, which
// prevents them from being removed even if unused.
lib.export_symbol_names = &[_][]const u8{ "start", "update" };
lib.install();
const prefix = b.getInstallPath(.lib, "");
const opt = b.addSystemCommand(&[_][]const u8{
"wasm-opt",
"-Oz",
"--strip-debug",
"--strip-producers",
"--zero-filled-memory",
});
opt.addArtifactArg(lib);
const optout = try std.fs.path.join(b.allocator, &.{ prefix, "opt.wasm" });
defer b.allocator.free(optout);
opt.addArgs(&.{ "--output", optout });
const opt_step = b.step("opt", "Run wasm-opt on cart.wasm, producing opt.wasm");
opt_step.dependOn(&lib.step);
opt_step.dependOn(&opt.step);
}