build.zig 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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.rdynamic = true;
  21. lib.import_memory = true; // import linear memory from the environment
  22. lib.initial_memory = wasm_initial_memory; // initial size of the linear memory (1 page = 64kB)
  23. lib.max_memory = wasm_initial_memory; // maximum size of the linear memory
  24. // Pass options from the build script to the files being compiled. This is awesome!
  25. const lib_options = b.addOptions();
  26. lib.addOptions("build_options", lib_options);
  27. lib_options.addOption(usize, "memory_size", wasm_max_memory);
  28. // This declares intent for the library to be installed into the standard
  29. // location when the user invokes the "install" step (the default step when
  30. // running `zig build`).
  31. b.installArtifact(lib);
  32. }