build.zig 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const std = @import("std");
  2. // Initial and max memory must correspond to the memory size defined in script.js.
  3. // TODO: This used to be 10 pages. Find out why this needs 17 pages.
  4. const wasm_initial_memory = 17 * std.wasm.page_size;
  5. const wasm_max_memory = wasm_initial_memory;
  6. pub fn build(b: *std.build.Builder) void {
  7. const lib = b.addSharedLibrary(.{
  8. .name = "DodgeBallz",
  9. .root_source_file = .{ .path = "src/main.zig" },
  10. .target = .{
  11. .cpu_arch = .wasm32,
  12. .os_tag = .freestanding,
  13. .abi = .musl,
  14. },
  15. .optimize = .ReleaseSmall,
  16. });
  17. // https://github.com/ziglang/zig/issues/8633
  18. lib.global_base = 6560;
  19. lib.rdynamic = true;
  20. lib.import_memory = true; // import linear memory from the environment
  21. lib.initial_memory = wasm_initial_memory; // initial size of the linear memory (1 page = 64kB)
  22. lib.max_memory = wasm_initial_memory; // maximum size of the linear memory
  23. // Pass options from the build script to the files being compiled. This is awesome!
  24. const lib_options = b.addOptions();
  25. lib.addOptions("build_options", lib_options);
  26. lib_options.addOption(usize, "memory_size", wasm_max_memory);
  27. // This declares intent for the library to be installed into the standard
  28. // location when the user invokes the "install" step (the default step when
  29. // running `zig build`).
  30. b.installArtifact(lib);
  31. }