Commit 82659c4594

mlugg <mlugg@mlugg.co.uk>
2024-12-16 17:47:17
test-link: migrate from deprecated std.Build APIs
1 parent 6179d9e
Changed files (21)
test
link
bss
common_symbols
common_symbols_alignment
glibc_compat
interdependent_static_c_libs
static_libs_from_object_files
wasm
archive
basic-features
bss
export
export-data
extern
extern-mangle
function-table
infer-features
producers
segments
shared-memory
stack_pointer
type
test/link/bss/build.zig
@@ -6,9 +6,11 @@ pub fn build(b: *std.Build) void {
 
     const exe = b.addExecutable(.{
         .name = "bss",
-        .root_source_file = b.path("main.zig"),
-        .target = b.graph.host,
-        .optimize = .Debug,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .target = b.graph.host,
+            .optimize = .Debug,
+        }),
     });
 
     const run = b.addRunArtifact(exe);
test/link/common_symbols/build.zig
@@ -13,19 +13,24 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
     const lib_a = b.addStaticLibrary(.{
         .name = "a",
-        .optimize = optimize,
-        .target = b.graph.host,
+        .root_module = b.createModule(.{
+            .root_source_file = null,
+            .optimize = optimize,
+            .target = b.graph.host,
+        }),
     });
-    lib_a.addCSourceFiles(.{
+    lib_a.root_module.addCSourceFiles(.{
         .files = &.{ "c.c", "a.c", "b.c" },
         .flags = &.{"-fcommon"},
     });
 
     const test_exe = b.addTest(.{
-        .root_source_file = b.path("main.zig"),
-        .optimize = optimize,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .optimize = optimize,
+        }),
     });
-    test_exe.linkLibrary(lib_a);
+    test_exe.root_module.linkLibrary(lib_a);
 
     test_step.dependOn(&b.addRunArtifact(test_exe).step);
 }
test/link/common_symbols_alignment/build.zig
@@ -13,19 +13,25 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
     const lib_a = b.addStaticLibrary(.{
         .name = "a",
-        .optimize = optimize,
-        .target = b.graph.host,
+        .root_module = b.createModule(.{
+            .root_source_file = null,
+            .optimize = optimize,
+            .target = b.graph.host,
+        }),
     });
-    lib_a.addCSourceFiles(.{
+    lib_a.root_module.addCSourceFiles(.{
         .files = &.{"a.c"},
         .flags = &.{"-fcommon"},
     });
 
     const test_exe = b.addTest(.{
-        .root_source_file = b.path("main.zig"),
-        .optimize = optimize,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .target = b.graph.host,
+            .optimize = optimize,
+        }),
     });
-    test_exe.linkLibrary(lib_a);
+    test_exe.root_module.linkLibrary(lib_a);
 
     test_step.dependOn(&b.addRunArtifact(test_exe).step);
 }
test/link/glibc_compat/build.zig
@@ -14,12 +14,15 @@ pub fn build(b: *std.Build) void {
     for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| {
         const exe = b.addExecutable(.{
             .name = t,
-            .target = b.resolveTargetQuery(std.Target.Query.parse(
-                .{ .arch_os_abi = t },
-            ) catch unreachable),
+            .root_module = b.createModule(.{
+                .root_source_file = null,
+                .target = b.resolveTargetQuery(std.Target.Query.parse(
+                    .{ .arch_os_abi = t },
+                ) catch unreachable),
+                .link_libc = true,
+            }),
         });
-        exe.addCSourceFile(.{ .file = b.path("main.c") });
-        exe.linkLibC();
+        exe.root_module.addCSourceFile(.{ .file = b.path("main.c") });
         // TODO: actually test the output
         _ = exe.getEmittedBin();
         test_step.dependOn(&exe.step);
@@ -53,10 +56,13 @@ pub fn build(b: *std.Build) void {
 
         const exe = b.addExecutable(.{
             .name = t,
-            .target = target,
+            .root_module = b.createModule(.{
+                .root_source_file = null,
+                .target = target,
+                .link_libc = true,
+            }),
         });
-        exe.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") });
-        exe.linkLibC();
+        exe.root_module.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") });
 
         // Only try running the test if the host glibc is known to be good enough.  Ideally, the Zig
         // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453
@@ -149,10 +155,12 @@ pub fn build(b: *std.Build) void {
 
         const exe = b.addExecutable(.{
             .name = t,
-            .root_source_file = b.path("glibc_runtime_check.zig"),
-            .target = target,
+            .root_module = b.createModule(.{
+                .root_source_file = b.path("glibc_runtime_check.zig"),
+                .target = target,
+                .link_libc = true,
+            }),
         });
-        exe.linkLibC();
 
         // Only try running the test if the host glibc is known to be good enough.  Ideally, the Zig
         // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453
test/link/interdependent_static_c_libs/build.zig
@@ -13,27 +13,36 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
     const lib_a = b.addStaticLibrary(.{
         .name = "a",
-        .optimize = optimize,
-        .target = b.graph.host,
+        .root_module = b.createModule(.{
+            .root_source_file = null,
+            .optimize = optimize,
+            .target = b.graph.host,
+        }),
     });
-    lib_a.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} });
-    lib_a.addIncludePath(b.path("."));
+    lib_a.root_module.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} });
+    lib_a.root_module.addIncludePath(b.path("."));
 
     const lib_b = b.addStaticLibrary(.{
         .name = "b",
-        .optimize = optimize,
-        .target = b.graph.host,
+        .root_module = b.createModule(.{
+            .root_source_file = null,
+            .optimize = optimize,
+            .target = b.graph.host,
+        }),
     });
-    lib_b.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} });
-    lib_b.addIncludePath(b.path("."));
+    lib_b.root_module.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} });
+    lib_b.root_module.addIncludePath(b.path("."));
 
     const test_exe = b.addTest(.{
-        .root_source_file = b.path("main.zig"),
-        .optimize = optimize,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .target = b.graph.host,
+            .optimize = optimize,
+        }),
     });
-    test_exe.linkLibrary(lib_a);
-    test_exe.linkLibrary(lib_b);
-    test_exe.addIncludePath(b.path("."));
+    test_exe.root_module.linkLibrary(lib_a);
+    test_exe.root_module.linkLibrary(lib_b);
+    test_exe.root_module.addIncludePath(b.path("."));
 
     test_step.dependOn(&b.addRunArtifact(test_exe).step);
 }
test/link/static_libs_from_object_files/build.zig
@@ -57,13 +57,15 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
     {
         const exe = b.addExecutable(.{
             .name = "test1",
-            .root_source_file = b.path("main.zig"),
-            .optimize = optimize,
-            .target = b.graph.host,
+            .root_module = b.createModule(.{
+                .root_source_file = b.path("main.zig"),
+                .optimize = optimize,
+                .target = b.graph.host,
+            }),
         });
 
         for (files) |file| {
-            exe.addCSourceFile(.{ .file = file, .flags = &flags });
+            exe.root_module.addCSourceFile(.{ .file = file, .flags = &flags });
         }
 
         const run_cmd = b.addRunArtifact(exe);
@@ -75,30 +77,33 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
 
     // using static librairies
     {
+        const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
+        const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
+
+        for (files, 1..) |file, i| {
+            const mod = if (i & 1 == 0) mod_a else mod_b;
+            mod.addCSourceFile(.{ .file = file, .flags = &flags });
+        }
+
         const lib_a = b.addStaticLibrary(.{
             .name = "test2_a",
-            .target = b.graph.host,
-            .optimize = optimize,
+            .root_module = mod_a,
         });
         const lib_b = b.addStaticLibrary(.{
             .name = "test2_b",
-            .target = b.graph.host,
-            .optimize = optimize,
+            .root_module = mod_b,
         });
 
-        for (files, 1..) |file, i| {
-            const lib = if (i & 1 == 0) lib_a else lib_b;
-            lib.addCSourceFile(.{ .file = file, .flags = &flags });
-        }
-
         const exe = b.addExecutable(.{
             .name = "test2",
-            .root_source_file = b.path("main.zig"),
-            .target = b.graph.host,
-            .optimize = optimize,
+            .root_module = b.createModule(.{
+                .root_source_file = b.path("main.zig"),
+                .target = b.graph.host,
+                .optimize = optimize,
+            }),
         });
-        exe.linkLibrary(lib_a);
-        exe.linkLibrary(lib_b);
+        exe.root_module.linkLibrary(lib_a);
+        exe.root_module.linkLibrary(lib_b);
 
         const run_cmd = b.addRunArtifact(exe);
         run_cmd.skip_foreign_checks = true;
@@ -109,37 +114,41 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
 
     // using static librairies and object files
     {
-        const lib_a = b.addStaticLibrary(.{
-            .name = "test3_a",
-            .target = b.graph.host,
-            .optimize = optimize,
-        });
-        const lib_b = b.addStaticLibrary(.{
-            .name = "test3_b",
-            .target = b.graph.host,
-            .optimize = optimize,
-        });
+        const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
+        const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
 
         for (files, 1..) |file, i| {
+            const obj_mod = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
+            obj_mod.addCSourceFile(.{ .file = file, .flags = &flags });
+
             const obj = b.addObject(.{
                 .name = b.fmt("obj_{}", .{i}),
-                .target = b.graph.host,
-                .optimize = optimize,
+                .root_module = obj_mod,
             });
-            obj.addCSourceFile(.{ .file = file, .flags = &flags });
 
-            const lib = if (i & 1 == 0) lib_a else lib_b;
-            lib.addObject(obj);
+            const lib_mod = if (i & 1 == 0) mod_a else mod_b;
+            lib_mod.addObject(obj);
         }
 
+        const lib_a = b.addStaticLibrary(.{
+            .name = "test3_a",
+            .root_module = mod_a,
+        });
+        const lib_b = b.addStaticLibrary(.{
+            .name = "test3_b",
+            .root_module = mod_b,
+        });
+
         const exe = b.addExecutable(.{
             .name = "test3",
-            .root_source_file = b.path("main.zig"),
-            .target = b.graph.host,
-            .optimize = optimize,
+            .root_module = b.createModule(.{
+                .root_source_file = b.path("main.zig"),
+                .target = b.graph.host,
+                .optimize = optimize,
+            }),
         });
-        exe.linkLibrary(lib_a);
-        exe.linkLibrary(lib_b);
+        exe.root_module.linkLibrary(lib_a);
+        exe.root_module.linkLibrary(lib_b);
 
         const run_cmd = b.addRunArtifact(exe);
         run_cmd.skip_foreign_checks = true;
test/link/wasm/archive/build.zig
@@ -17,10 +17,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
     // and therefore link with its archive file.
     const lib = b.addExecutable(.{
         .name = "main",
-        .root_source_file = b.path("main.zig"),
-        .optimize = optimize,
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
-        .strip = false,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .optimize = optimize,
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+            .strip = false,
+        }),
     });
     lib.entry = .disabled;
     lib.use_llvm = false;
test/link/wasm/basic-features/build.zig
@@ -6,13 +6,15 @@ pub fn build(b: *std.Build) void {
     // Library with explicitly set cpu features
     const lib = b.addExecutable(.{
         .name = "lib",
-        .root_source_file = b.path("main.zig"),
-        .optimize = .Debug,
-        .target = b.resolveTargetQuery(.{
-            .cpu_arch = .wasm32,
-            .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
-            .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}),
-            .os_tag = .freestanding,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .optimize = .Debug,
+            .target = b.resolveTargetQuery(.{
+                .cpu_arch = .wasm32,
+                .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
+                .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}),
+                .os_tag = .freestanding,
+            }),
         }),
     });
     lib.entry = .disabled;
test/link/wasm/bss/build.zig
@@ -16,10 +16,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
     {
         const lib = b.addExecutable(.{
             .name = "lib",
-            .root_source_file = b.path("lib.zig"),
-            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
-            .optimize = optimize_mode,
-            .strip = false,
+            .root_module = b.createModule(.{
+                .root_source_file = b.path("lib.zig"),
+                .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+                .optimize = optimize_mode,
+                .strip = false,
+            }),
         });
         lib.entry = .disabled;
         lib.use_llvm = false;
@@ -64,10 +66,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
     {
         const lib = b.addExecutable(.{
             .name = "lib",
-            .root_source_file = b.path("lib2.zig"),
-            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
-            .optimize = optimize_mode,
-            .strip = false,
+            .root_module = b.createModule(.{
+                .root_source_file = b.path("lib2.zig"),
+                .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+                .optimize = optimize_mode,
+                .strip = false,
+            }),
         });
         lib.entry = .disabled;
         lib.use_llvm = false;
test/link/wasm/export/build.zig
@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
     const no_export = b.addExecutable(.{
         .name = "no-export",
-        .root_source_file = b.path("main.zig"),
-        .optimize = optimize,
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .optimize = optimize,
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+        }),
     });
     no_export.entry = .disabled;
     no_export.use_llvm = false;
@@ -25,9 +27,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
 
     const dynamic_export = b.addExecutable(.{
         .name = "dynamic",
-        .root_source_file = b.path("main.zig"),
-        .optimize = optimize,
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .optimize = optimize,
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+        }),
     });
     dynamic_export.entry = .disabled;
     dynamic_export.rdynamic = true;
@@ -36,9 +40,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
 
     const force_export = b.addExecutable(.{
         .name = "force",
-        .root_source_file = b.path("main.zig"),
-        .optimize = optimize,
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .optimize = optimize,
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+        }),
     });
     force_export.entry = .disabled;
     force_export.root_module.export_symbol_names = &.{"foo"};
test/link/wasm/export-data/build.zig
@@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void {
 
     const lib = b.addExecutable(.{
         .name = "lib",
-        .root_source_file = b.path("lib.zig"),
-        .optimize = .ReleaseSafe, // to make the output deterministic in address positions
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("lib.zig"),
+            .optimize = .ReleaseSafe, // to make the output deterministic in address positions
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+        }),
     });
     lib.entry = .disabled;
     lib.use_lld = false;
test/link/wasm/extern/build.zig
@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
     const exe = b.addExecutable(.{
         .name = "extern",
-        .root_source_file = b.path("main.zig"),
-        .optimize = optimize,
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }),
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .optimize = optimize,
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }),
+        }),
     });
     exe.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });
     exe.use_llvm = false;
test/link/wasm/extern-mangle/build.zig
@@ -13,9 +13,11 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
     const lib = b.addExecutable(.{
         .name = "lib",
-        .root_source_file = b.path("lib.zig"),
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
-        .optimize = optimize,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("lib.zig"),
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+            .optimize = optimize,
+        }),
     });
     lib.entry = .disabled;
     lib.import_symbols = true; // import `a` and `b`
test/link/wasm/function-table/build.zig
@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
     const import_table = b.addExecutable(.{
         .name = "import_table",
-        .root_source_file = b.path("lib.zig"),
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
-        .optimize = optimize,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("lib.zig"),
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+            .optimize = optimize,
+        }),
     });
     import_table.entry = .disabled;
     import_table.use_llvm = false;
@@ -27,9 +29,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
 
     const export_table = b.addExecutable(.{
         .name = "export_table",
-        .root_source_file = b.path("lib.zig"),
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
-        .optimize = optimize,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("lib.zig"),
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+            .optimize = optimize,
+        }),
     });
     export_table.entry = .disabled;
     export_table.use_llvm = false;
@@ -39,9 +43,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
 
     const regular_table = b.addExecutable(.{
         .name = "regular_table",
-        .root_source_file = b.path("lib.zig"),
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
-        .optimize = optimize,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("lib.zig"),
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+            .optimize = optimize,
+        }),
     });
     regular_table.entry = .disabled;
     regular_table.use_llvm = false;
test/link/wasm/infer-features/build.zig
@@ -6,31 +6,36 @@ pub fn build(b: *std.Build) void {
     // Wasm Object file which we will use to infer the features from
     const c_obj = b.addObject(.{
         .name = "c_obj",
-        .optimize = .Debug,
-        .target = b.resolveTargetQuery(.{
-            .cpu_arch = .wasm32,
-            .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge },
-            .os_tag = .freestanding,
+        .root_module = b.createModule(.{
+            .root_source_file = null,
+            .optimize = .Debug,
+            .target = b.resolveTargetQuery(.{
+                .cpu_arch = .wasm32,
+                .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge },
+                .os_tag = .freestanding,
+            }),
         }),
     });
-    c_obj.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });
+    c_obj.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });
 
     // Wasm library that doesn't have any features specified. This will
     // infer its featureset from other linked object files.
     const lib = b.addExecutable(.{
         .name = "lib",
-        .root_source_file = b.path("main.zig"),
-        .optimize = .Debug,
-        .target = b.resolveTargetQuery(.{
-            .cpu_arch = .wasm32,
-            .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
-            .os_tag = .freestanding,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("main.zig"),
+            .optimize = .Debug,
+            .target = b.resolveTargetQuery(.{
+                .cpu_arch = .wasm32,
+                .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
+                .os_tag = .freestanding,
+            }),
         }),
     });
     lib.entry = .disabled;
     lib.use_llvm = false;
     lib.use_lld = false;
-    lib.addObject(c_obj);
+    lib.root_module.addObject(c_obj);
 
     // Verify the result contains the features from the C Object file.
     const check = lib.checkObject();
test/link/wasm/producers/build.zig
@@ -16,10 +16,12 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
     const lib = b.addExecutable(.{
         .name = "lib",
-        .root_source_file = b.path("lib.zig"),
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
-        .optimize = optimize,
-        .strip = false,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("lib.zig"),
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+            .optimize = optimize,
+            .strip = false,
+        }),
     });
     lib.entry = .disabled;
     lib.use_llvm = false;
test/link/wasm/segments/build.zig
@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
     const lib = b.addExecutable(.{
         .name = "lib",
-        .root_source_file = b.path("lib.zig"),
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
-        .optimize = optimize,
-        .strip = false,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("lib.zig"),
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+            .optimize = optimize,
+            .strip = false,
+        }),
     });
     lib.entry = .disabled;
     lib.use_llvm = false;
test/link/wasm/shared-memory/build.zig
@@ -13,16 +13,18 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void {
     const exe = b.addExecutable(.{
         .name = "lib",
-        .root_source_file = b.path("lib.zig"),
-        .target = b.resolveTargetQuery(.{
-            .cpu_arch = .wasm32,
-            .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
-            .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }),
-            .os_tag = .freestanding,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("lib.zig"),
+            .target = b.resolveTargetQuery(.{
+                .cpu_arch = .wasm32,
+                .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
+                .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }),
+                .os_tag = .freestanding,
+            }),
+            .optimize = optimize_mode,
+            .strip = false,
+            .single_threaded = false,
         }),
-        .optimize = optimize_mode,
-        .strip = false,
-        .single_threaded = false,
     });
     exe.entry = .disabled;
     exe.use_lld = false;
test/link/wasm/stack_pointer/build.zig
@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
     const lib = b.addExecutable(.{
         .name = "lib",
-        .root_source_file = b.path("lib.zig"),
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
-        .optimize = optimize,
-        .strip = false,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("lib.zig"),
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+            .optimize = optimize,
+            .strip = false,
+        }),
     });
     lib.entry = .disabled;
     lib.use_llvm = false;
test/link/wasm/type/build.zig
@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
 fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
     const exe = b.addExecutable(.{
         .name = "lib",
-        .root_source_file = b.path("lib.zig"),
-        .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
-        .optimize = optimize,
-        .strip = false,
+        .root_module = b.createModule(.{
+            .root_source_file = b.path("lib.zig"),
+            .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
+            .optimize = optimize,
+            .strip = false,
+        }),
     });
     exe.entry = .disabled;
     exe.use_llvm = false;
test/link/link.zig
@@ -47,81 +47,85 @@ const OverlayOptions = struct {
 };
 
 pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Compile {
-    return addCompileStep(b, base, overlay, .exe);
+    return b.addExecutable(.{
+        .name = overlay.name,
+        .root_module = createModule(b, base, overlay),
+        .use_llvm = base.use_llvm,
+        .use_lld = base.use_lld,
+    });
 }
 
 pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
-    return addCompileStep(b, base, overlay, .obj);
+    return b.addObject(.{
+        .name = overlay.name,
+        .root_module = createModule(b, base, overlay),
+        .use_llvm = base.use_llvm,
+        .use_lld = base.use_lld,
+    });
 }
 
 pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
-    return addCompileStep(b, base, overlay, .static_lib);
+    return b.addStaticLibrary(.{
+        .name = overlay.name,
+        .root_module = createModule(b, base, overlay),
+        .use_llvm = base.use_llvm,
+        .use_lld = base.use_lld,
+    });
 }
 
 pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
-    return addCompileStep(b, base, overlay, .shared_lib);
-}
-
-fn addCompileStep(
-    b: *Build,
-    base: Options,
-    overlay: OverlayOptions,
-    kind: enum { exe, obj, shared_lib, static_lib },
-) *Compile {
-    const compile_step = Compile.create(b, .{
+    return b.addSharedLibrary(.{
         .name = overlay.name,
-        .root_module = b.createModule(.{
-            .target = base.target,
-            .optimize = base.optimize,
-            .root_source_file = rsf: {
-                const bytes = overlay.zig_source_bytes orelse break :rsf null;
-                const name = b.fmt("{s}.zig", .{overlay.name});
-                break :rsf b.addWriteFiles().add(name, bytes);
-            },
-            .pic = overlay.pic,
-            .strip = if (base.strip) |s| s else overlay.strip,
-        }),
+        .root_module = createModule(b, base, overlay),
         .use_llvm = base.use_llvm,
         .use_lld = base.use_lld,
-        .kind = switch (kind) {
-            .exe => .exe,
-            .obj => .obj,
-            .shared_lib, .static_lib => .lib,
-        },
-        .linkage = switch (kind) {
-            .exe, .obj => null,
-            .shared_lib => .dynamic,
-            .static_lib => .static,
+    });
+}
+
+fn createModule(b: *Build, base: Options, overlay: OverlayOptions) *Build.Module {
+    const write_files = b.addWriteFiles();
+
+    const mod = b.createModule(.{
+        .target = base.target,
+        .optimize = base.optimize,
+        .root_source_file = rsf: {
+            const bytes = overlay.zig_source_bytes orelse break :rsf null;
+            const name = b.fmt("{s}.zig", .{overlay.name});
+            break :rsf write_files.add(name, bytes);
         },
+        .pic = overlay.pic,
+        .strip = if (base.strip) |s| s else overlay.strip,
     });
+
     if (overlay.objcpp_source_bytes) |bytes| {
-        compile_step.addCSourceFile(.{
-            .file = b.addWriteFiles().add("a.mm", bytes),
+        mod.addCSourceFile(.{
+            .file = write_files.add("a.mm", bytes),
             .flags = overlay.objcpp_source_flags,
         });
     }
     if (overlay.objc_source_bytes) |bytes| {
-        compile_step.addCSourceFile(.{
-            .file = b.addWriteFiles().add("a.m", bytes),
+        mod.addCSourceFile(.{
+            .file = write_files.add("a.m", bytes),
             .flags = overlay.objc_source_flags,
         });
     }
     if (overlay.cpp_source_bytes) |bytes| {
-        compile_step.addCSourceFile(.{
-            .file = b.addWriteFiles().add("a.cpp", bytes),
+        mod.addCSourceFile(.{
+            .file = write_files.add("a.cpp", bytes),
             .flags = overlay.cpp_source_flags,
         });
     }
     if (overlay.c_source_bytes) |bytes| {
-        compile_step.addCSourceFile(.{
-            .file = b.addWriteFiles().add("a.c", bytes),
+        mod.addCSourceFile(.{
+            .file = write_files.add("a.c", bytes),
             .flags = overlay.c_source_flags,
         });
     }
     if (overlay.asm_source_bytes) |bytes| {
-        compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes));
+        mod.addAssemblyFile(write_files.add("a.s", bytes));
     }
-    return compile_step;
+
+    return mod;
 }
 
 pub fn addRunArtifact(comp: *Compile) *Run {