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    add(b, test_step, .ReleaseFast);
 9    add(b, test_step, .ReleaseSmall);
10    add(b, test_step, .ReleaseSafe);
11}
12
13fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
14    const lib = b.addExecutable(.{
15        .name = "lib",
16        .root_module = b.createModule(.{
17            .root_source_file = b.path("lib.zig"),
18            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
19            .optimize = optimize,
20        }),
21    });
22    lib.entry = .disabled;
23    lib.import_symbols = true; // import `a` and `b`
24    lib.rdynamic = true; // export `foo`
25
26    const check_lib = lib.checkObject();
27    check_lib.checkInHeaders();
28    check_lib.checkExact("Section import");
29    check_lib.checkExact("entries 2"); // a.hello & b.hello
30    check_lib.checkExact("module a");
31    check_lib.checkExact("name hello");
32    check_lib.checkExact("module b");
33    check_lib.checkExact("name hello");
34
35    test_step.dependOn(&check_lib.step);
36}