wired/build.zig

54 lines
1.8 KiB
Zig
Raw Normal View History

2022-01-14 19:33:23 -07:00
const std = @import("std");
2022-08-03 16:23:59 -06:00
const LDtkImport = @import("tools/LDtkImport.zig");
2022-01-14 19:33:23 -07:00
pub fn build(b: *std.build.Builder) !void {
2022-01-14 21:58:57 -07:00
const assets = std.build.Pkg{
.name = "assets",
2022-08-01 11:44:28 -06:00
.source = .{ .path = "assets/assets.zig" },
2022-01-14 21:58:57 -07:00
};
2022-08-03 16:23:59 -06:00
const ldtk = LDtkImport.create(b, .{
.source_path = .{ .path = "assets/maps/wired.ldtk" },
.output_name = "mapldtk",
});
2022-08-04 01:59:32 -06:00
const data_step = b.addOptions();
data_step.addOptionFileSource("path", .{.generated = &ldtk.world_data });
2022-01-14 19:33:23 -07:00
const mode = b.standardReleaseOptions();
const lib = b.addSharedLibrary("cart", "src/main.zig", .unversioned);
2022-08-04 01:59:32 -06:00
lib.step.dependOn(&data_step.step);
lib.addPackage(data_step.getPackage("world_data"));
2022-01-14 21:58:57 -07:00
lib.addPackage(assets);
2022-01-14 19:33:23 -07:00
lib.setBuildMode(mode);
lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding });
lib.import_memory = true;
lib.initial_memory = 65536;
lib.max_memory = 65536;
2022-08-01 22:44:04 -06:00
lib.stack_size = 24752;
2022-01-14 19:33:23 -07:00
// 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();
2022-01-31 15:45:17 -07:00
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);
2022-01-14 19:33:23 -07:00
}