Add opt build step

master
Louis Pearson 2022-01-31 15:45:17 -07:00
parent b1b25753a3
commit 105d7d3395
1 changed files with 18 additions and 0 deletions

View File

@ -72,4 +72,22 @@ pub fn build(b: *std.build.Builder) !void {
// 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);
}