build.zig 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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) void {
  7. const target = b.resolveTargetQuery(.{
  8. .cpu_arch = .wasm32,
  9. .os_tag = .freestanding,
  10. });
  11. const exe = b.addExecutable(.{
  12. .name = "DodgeBallz",
  13. .root_source_file = b.path("src/main.zig"),
  14. .target = target,
  15. .optimize = .ReleaseSmall,
  16. });
  17. exe.entry = .disabled;
  18. //exe.global_base = 6560;
  19. exe.rdynamic = true;
  20. exe.import_memory = true;
  21. exe.import_symbols = true;
  22. //exe.initial_memory = wasm_initial_memory; // initial size of the linear memory (1 page = 64kB)
  23. //exe.max_memory = wasm_initial_memory; // maximum size of the linear memory
  24. // https://github.com/ziglang/zig/issues/8633
  25. // lib.global_base = 6560;
  26. // lib.rdynamic = true;
  27. // lib.import_memory = true; // import linear memory from the environment
  28. // lib.initial_memory = wasm_initial_memory; // initial size of the linear memory (1 page = 64kB)
  29. // lib.max_memory = wasm_initial_memory; // maximum size of the linear memory
  30. // Pass options from the build script to the files being compiled. This is awesome!
  31. const exe_options = b.addOptions();
  32. exe_options.addOption(usize, "memory_size", wasm_max_memory);
  33. exe.root_module.addOptions("build_options", exe_options);
  34. // This declares intent for the library to be installed into the standard
  35. // location when the user invokes the "install" step (the default step when
  36. // running `zig build`).
  37. b.installArtifact(exe);
  38. }