|
| 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 import_table = b.addSharedLibrary("lib", "lib.zig", .unversioned); |
| 11 | + import_table.setBuildMode(mode); |
| 12 | + import_table.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); |
| 13 | + import_table.use_llvm = false; |
| 14 | + import_table.use_lld = false; |
| 15 | + import_table.import_table = true; |
| 16 | + |
| 17 | + const export_table = b.addSharedLibrary("lib", "lib.zig", .unversioned); |
| 18 | + export_table.setBuildMode(mode); |
| 19 | + export_table.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); |
| 20 | + export_table.use_llvm = false; |
| 21 | + export_table.use_lld = false; |
| 22 | + export_table.export_table = true; |
| 23 | + |
| 24 | + const regular_table = b.addSharedLibrary("lib", "lib.zig", .unversioned); |
| 25 | + regular_table.setBuildMode(mode); |
| 26 | + regular_table.setTarget(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }); |
| 27 | + regular_table.use_llvm = false; |
| 28 | + regular_table.use_lld = false; |
| 29 | + |
| 30 | + const check_import = import_table.checkObject(.wasm); |
| 31 | + const check_export = export_table.checkObject(.wasm); |
| 32 | + const check_regular = regular_table.checkObject(.wasm); |
| 33 | + |
| 34 | + check_import.checkStart("Section import"); |
| 35 | + check_import.checkNext("entries 1"); |
| 36 | + check_import.checkNext("module env"); |
| 37 | + check_import.checkNext("name __indirect_function_table"); |
| 38 | + check_import.checkNext("kind table"); |
| 39 | + check_import.checkNext("type funcref"); |
| 40 | + check_import.checkNext("min 1"); // 1 function pointer |
| 41 | + check_import.checkNotPresent("max"); // when importing, we do not provide a max |
| 42 | + check_import.checkNotPresent("Section table"); // we're importing it |
| 43 | + |
| 44 | + check_export.checkStart("Section export"); |
| 45 | + check_export.checkNext("entries 2"); |
| 46 | + check_export.checkNext("name __indirect_function_table"); // as per linker specification |
| 47 | + check_export.checkNext("kind table"); |
| 48 | + |
| 49 | + check_regular.checkStart("Section table"); |
| 50 | + check_regular.checkNext("entries 1"); |
| 51 | + check_regular.checkNext("type funcref"); |
| 52 | + check_regular.checkNext("min 2"); // index starts at 1 & 1 function pointer = 2. |
| 53 | + check_regular.checkNext("max 2"); |
| 54 | + check_regular.checkStart("Section element"); |
| 55 | + check_regular.checkNext("entries 1"); |
| 56 | + check_regular.checkNext("table index 0"); |
| 57 | + check_regular.checkNext("i32.const 1"); // we want to start function indexes at 1 |
| 58 | + check_regular.checkNext("indexes 1"); // 1 function pointer |
| 59 | + |
| 60 | + test_step.dependOn(&check_import.step); |
| 61 | + test_step.dependOn(&check_export.step); |
| 62 | + test_step.dependOn(&check_regular.step); |
| 63 | +} |
0 commit comments