master
 1const std = @import("std");
 2
 3pub fn build(b: *std.Build) void {
 4    const test_step = b.step("test", "Test it");
 5    b.default_step = test_step;
 6
 7    add(b, test_step, .Debug);
 8}
 9
10fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
11    const exe = b.addExecutable(.{
12        .name = "lib",
13        .root_module = b.createModule(.{
14            .root_source_file = b.path("lib.zig"),
15            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
16            .optimize = optimize,
17            .strip = false,
18        }),
19    });
20    exe.entry = .disabled;
21    exe.use_llvm = false;
22    exe.use_lld = false;
23    exe.root_module.export_symbol_names = &.{"foo"};
24    // Don't pull in ubsan, since we're just expecting a very minimal executable.
25    exe.bundle_ubsan_rt = false;
26    b.installArtifact(exe);
27
28    const check_exe = exe.checkObject();
29    check_exe.checkInHeaders();
30    check_exe.checkExact("Section type");
31    // only 2 entries, although we have more functions.
32    // This is to test functions with the same function signature
33    // have their types deduplicated.
34    check_exe.checkExact("entries 2");
35    check_exe.checkExact("params 1");
36    check_exe.checkExact("type i32");
37    check_exe.checkExact("returns 1");
38    check_exe.checkExact("type i64");
39    check_exe.checkExact("params 0");
40    check_exe.checkExact("returns 0");
41
42    test_step.dependOn(&check_exe.step);
43}