| ... | ... | @@ -1,91 +0,0 @@ |
| 1 | | const std = @import("std"); |
| 2 | | |
| 3 | | pub const requires_stage2 = true; |
| 4 | | |
| 5 | | pub fn build(b: *std.Build) void { |
| 6 | | const test_step = b.step("test", "Test"); |
| 7 | | b.default_step = test_step; |
| 8 | | |
| 9 | | add(b, test_step, .Debug, true); |
| 10 | | add(b, test_step, .ReleaseFast, false); |
| 11 | | add(b, test_step, .ReleaseSmall, false); |
| 12 | | add(b, test_step, .ReleaseSafe, true); |
| 13 | | } |
| 14 | | |
| 15 | | fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode, is_safe: bool) void { |
| 16 | | { |
| 17 | | const lib = b.addExecutable(.{ |
| 18 | | .name = "lib", |
| 19 | | .root_module = b.createModule(.{ |
| 20 | | .root_source_file = b.path("lib.zig"), |
| 21 | | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 22 | | .optimize = optimize_mode, |
| 23 | | .strip = false, |
| 24 | | }), |
| 25 | | }); |
| 26 | | lib.entry = .disabled; |
| 27 | | lib.use_llvm = false; |
| 28 | | lib.use_lld = false; |
| 29 | | // to make sure the bss segment is emitted, we must import memory |
| 30 | | lib.import_memory = true; |
| 31 | | lib.link_gc_sections = false; |
| 32 | | |
| 33 | | const check_lib = lib.checkObject(); |
| 34 | | |
| 35 | | // since we import memory, make sure it exists with the correct naming |
| 36 | | check_lib.checkInHeaders(); |
| 37 | | check_lib.checkExact("Section import"); |
| 38 | | check_lib.checkExact("entries 1"); |
| 39 | | check_lib.checkExact("module env"); // default module name is "env" |
| 40 | | check_lib.checkExact("name memory"); // as per linker specification |
| 41 | | |
| 42 | | // since we are importing memory, ensure it's not exported |
| 43 | | check_lib.checkInHeaders(); |
| 44 | | check_lib.checkNotPresent("Section export"); |
| 45 | | |
| 46 | | // validate the name of the stack pointer |
| 47 | | check_lib.checkInHeaders(); |
| 48 | | check_lib.checkExact("Section custom"); |
| 49 | | check_lib.checkExact("type data_segment"); |
| 50 | | check_lib.checkExact("names 1"); |
| 51 | | // for safe optimization modes `undefined` is stored in data instead of bss. |
| 52 | | if (is_safe) { |
| 53 | | check_lib.checkExact("index 0"); |
| 54 | | check_lib.checkExact("name .data"); |
| 55 | | check_lib.checkNotPresent("name .bss"); |
| 56 | | } else { |
| 57 | | check_lib.checkExact("index 0"); // bss section always last |
| 58 | | check_lib.checkExact("name .bss"); |
| 59 | | } |
| 60 | | test_step.dependOn(&check_lib.step); |
| 61 | | } |
| 62 | | |
| 63 | | // verify zero'd declaration is stored in bss for all optimization modes. |
| 64 | | { |
| 65 | | const lib = b.addExecutable(.{ |
| 66 | | .name = "lib", |
| 67 | | .root_module = b.createModule(.{ |
| 68 | | .root_source_file = b.path("lib2.zig"), |
| 69 | | .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }), |
| 70 | | .optimize = optimize_mode, |
| 71 | | .strip = false, |
| 72 | | }), |
| 73 | | }); |
| 74 | | lib.entry = .disabled; |
| 75 | | lib.use_llvm = false; |
| 76 | | lib.use_lld = false; |
| 77 | | // to make sure the bss segment is emitted, we must import memory |
| 78 | | lib.import_memory = true; |
| 79 | | lib.link_gc_sections = false; |
| 80 | | |
| 81 | | const check_lib = lib.checkObject(); |
| 82 | | check_lib.checkInHeaders(); |
| 83 | | check_lib.checkExact("Section custom"); |
| 84 | | check_lib.checkExact("type data_segment"); |
| 85 | | check_lib.checkExact("names 1"); |
| 86 | | check_lib.checkExact("index 0"); |
| 87 | | check_lib.checkExact("name .bss"); |
| 88 | | |
| 89 | | test_step.dependOn(&check_lib.step); |
| 90 | | } |
| 91 | | } |