| ... | ... | @@ -0,0 +1,41 @@ |
| 1 | const std = @import("std"); |
| 2 | const Builder = std.build.Builder; |
| 3 | |
| 4 | pub fn build(b: *Builder) void { |
| 5 | const mode = b.standardReleaseOptions(); |
| 6 | |
| 7 | const test_step = b.step("test", "Test"); |
| 8 | test_step.dependOn(b.getInstallStep()); |
| 9 | |
| 10 | const lib = b.addSharedLibrary("lib", "lib.zig", .unversioned); |
| 11 | lib.setBuildMode(mode); |
| 12 | lib.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); |
| 13 | lib.use_lld = false; |
| 14 | lib.export_symbol_names = &.{ "foo", "bar" }; |
| 15 | lib.global_base = 0; // put data section at address 0 to make data symbols easier to parse |
| 16 | |
| 17 | const check_lib = lib.checkObject(.wasm); |
| 18 | |
| 19 | check_lib.checkStart("Section global"); |
| 20 | check_lib.checkNext("entries 3"); |
| 21 | check_lib.checkNext("type i32"); // stack pointer so skip other fields |
| 22 | check_lib.checkNext("type i32"); |
| 23 | check_lib.checkNext("mutable false"); |
| 24 | check_lib.checkNext("i32.const {foo_address}"); |
| 25 | check_lib.checkNext("type i32"); |
| 26 | check_lib.checkNext("mutable false"); |
| 27 | check_lib.checkNext("i32.const {bar_address}"); |
| 28 | check_lib.checkComputeCompare("foo_address", .{ .op = .eq, .value = .{ .literal = 0x0c } }); |
| 29 | check_lib.checkComputeCompare("bar_address", .{ .op = .eq, .value = .{ .literal = 0x10 } }); |
| 30 | |
| 31 | check_lib.checkStart("Section export"); |
| 32 | check_lib.checkNext("entries 3"); |
| 33 | check_lib.checkNext("name foo"); |
| 34 | check_lib.checkNext("kind global"); |
| 35 | check_lib.checkNext("index 1"); |
| 36 | check_lib.checkNext("name bar"); |
| 37 | check_lib.checkNext("kind global"); |
| 38 | check_lib.checkNext("index 2"); |
| 39 | |
| 40 | test_step.dependOn(&check_lib.step); |
| 41 | } |