master
 1const std = @import("std");
 2
 3pub fn build(b: *std.Build) void {
 4    // Wasm Object file which we will use to infer the features from
 5    const c_obj = b.addObject(.{
 6        .name = "c_obj",
 7        .root_module = b.createModule(.{
 8            .root_source_file = null,
 9            .optimize = .Debug,
10            .target = b.resolveTargetQuery(.{
11                .cpu_arch = .wasm32,
12                .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge },
13                .os_tag = .freestanding,
14            }),
15        }),
16    });
17    c_obj.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });
18
19    // Wasm library that doesn't have any features specified. This will
20    // infer its featureset from other linked object files.
21    const lib = b.addExecutable(.{
22        .name = "lib",
23        .root_module = b.createModule(.{
24            .root_source_file = b.path("main.zig"),
25            .optimize = .Debug,
26            .target = b.resolveTargetQuery(.{
27                .cpu_arch = .wasm32,
28                .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
29                .os_tag = .freestanding,
30            }),
31        }),
32    });
33    lib.entry = .disabled;
34    lib.use_llvm = false;
35    lib.use_lld = false;
36    lib.root_module.addObject(c_obj);
37
38    lib.expect_errors = .{ .contains = "error: object requires atomics but specified target features exclude atomics" };
39    _ = lib.getEmittedBin();
40
41    const test_step = b.step("test", "Run linker test");
42    test_step.dependOn(&lib.step);
43    b.default_step = test_step;
44}