From 105d7d33951f6a9c1971cfd0b5e642d48af995e8 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Mon, 31 Jan 2022 15:45:17 -0700 Subject: [PATCH] Add opt build step --- build.zig | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/build.zig b/build.zig index f9576b2..11c21ca 100644 --- a/build.zig +++ b/build.zig @@ -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); }