build.zig 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. const std = @import("std");
  2. const page_size = 65536; // in bytes
  3. // Initial and max memory must correspond to the memory size defined in script.js.
  4. // TODO: This used to be 10 pages. Find out why this needs 17 pages.
  5. const wasm_initial_memory = 17 * page_size;
  6. const wasm_max_memory = wasm_initial_memory;
  7. pub fn build(b: *std.build.Builder) void {
  8. const lib = b.addSharedLibrary(.{
  9. .name = "DodgeBallz",
  10. .root_source_file = .{ .path = "src/main.zig" },
  11. .target = .{
  12. .cpu_arch = .wasm32,
  13. .os_tag = .freestanding,
  14. .abi = .musl,
  15. },
  16. .optimize = .ReleaseSmall,
  17. });
  18. // https://github.com/ziglang/zig/issues/8633
  19. lib.global_base = 6560;
  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. }