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    // The code in question will pull-in compiler-rt,
15    // and therefore link with its archive file.
16    const lib = b.addExecutable(.{
17        .name = "main",
18        .root_module = b.createModule(.{
19            .root_source_file = b.path("main.zig"),
20            .optimize = optimize,
21            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
22            .strip = false,
23        }),
24    });
25    lib.entry = .disabled;
26    lib.use_llvm = false;
27    lib.use_lld = false;
28    lib.root_module.export_symbol_names = &.{"foo"};
29
30    const check = lib.checkObject();
31    check.checkInHeaders();
32    check.checkExact("Section custom");
33    check.checkExact("name __trunch"); // Ensure it was imported and resolved
34
35    test_step.dependOn(&check.step);
36}