From 82659c4594d12e5b80d2684320e15ce93eedb966 Mon Sep 17 00:00:00 2001 From: mlugg Date: Mon, 16 Dec 2024 16:47:17 +0000 Subject: [PATCH] test-link: migrate from deprecated std.Build APIs --- test/link/bss/build.zig | 8 +- test/link/common_symbols/build.zig | 17 ++-- test/link/common_symbols_alignment/build.zig | 18 ++-- test/link/glibc_compat/build.zig | 30 +++--- .../interdependent_static_c_libs/build.zig | 35 ++++--- test/link/link.zig | 92 ++++++++++--------- .../static_libs_from_object_files/build.zig | 87 ++++++++++-------- test/link/wasm/archive/build.zig | 10 +- test/link/wasm/basic-features/build.zig | 16 ++-- test/link/wasm/bss/build.zig | 20 ++-- test/link/wasm/export-data/build.zig | 8 +- test/link/wasm/export/build.zig | 24 +++-- test/link/wasm/extern-mangle/build.zig | 8 +- test/link/wasm/extern/build.zig | 8 +- test/link/wasm/function-table/build.zig | 24 +++-- test/link/wasm/infer-features/build.zig | 31 ++++--- test/link/wasm/producers/build.zig | 10 +- test/link/wasm/segments/build.zig | 10 +- test/link/wasm/shared-memory/build.zig | 20 ++-- test/link/wasm/stack_pointer/build.zig | 10 +- test/link/wasm/type/build.zig | 10 +- 21 files changed, 290 insertions(+), 206 deletions(-) diff --git a/test/link/bss/build.zig b/test/link/bss/build.zig index 27fd016ea1..128ec04caa 100644 --- a/test/link/bss/build.zig +++ b/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); diff --git a/test/link/common_symbols/build.zig b/test/link/common_symbols/build.zig index 3f0e4a19f0..d4826956a5 100644 --- a/test/link/common_symbols/build.zig +++ b/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); } diff --git a/test/link/common_symbols_alignment/build.zig b/test/link/common_symbols_alignment/build.zig index 384d60b90d..6f0a0efd80 100644 --- a/test/link/common_symbols_alignment/build.zig +++ b/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); } diff --git a/test/link/glibc_compat/build.zig b/test/link/glibc_compat/build.zig index e9d7ee412e..972a7a6ae9 100644 --- a/test/link/glibc_compat/build.zig +++ b/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 diff --git a/test/link/interdependent_static_c_libs/build.zig b/test/link/interdependent_static_c_libs/build.zig index 8a700b74ff..b18371fdcc 100644 --- a/test/link/interdependent_static_c_libs/build.zig +++ b/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); } diff --git a/test/link/link.zig b/test/link/link.zig index 6885aa9321..960d8fd743 100644 --- a/test/link/link.zig +++ b/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 { diff --git a/test/link/static_libs_from_object_files/build.zig b/test/link/static_libs_from_object_files/build.zig index 8e4a6151be..461f26a374 100644 --- a/test/link/static_libs_from_object_files/build.zig +++ b/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 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}), + .root_module = obj_mod, + }); + + const lib_mod = if (i & 1 == 0) mod_a else mod_b; + lib_mod.addObject(obj); + } + const lib_a = b.addStaticLibrary(.{ .name = "test3_a", - .target = b.graph.host, - .optimize = optimize, + .root_module = mod_a, }); const lib_b = b.addStaticLibrary(.{ .name = "test3_b", - .target = b.graph.host, - .optimize = optimize, + .root_module = mod_b, }); - for (files, 1..) |file, i| { - const obj = b.addObject(.{ - .name = b.fmt("obj_{}", .{i}), - .target = b.graph.host, - .optimize = optimize, - }); - obj.addCSourceFile(.{ .file = file, .flags = &flags }); - - const lib = if (i & 1 == 0) lib_a else lib_b; - lib.addObject(obj); - } - 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; diff --git a/test/link/wasm/archive/build.zig b/test/link/wasm/archive/build.zig index 34c5818ad8..e57eb25fc6 100644 --- a/test/link/wasm/archive/build.zig +++ b/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; diff --git a/test/link/wasm/basic-features/build.zig b/test/link/wasm/basic-features/build.zig index 87355a5c12..1eaeeb5196 100644 --- a/test/link/wasm/basic-features/build.zig +++ b/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; diff --git a/test/link/wasm/bss/build.zig b/test/link/wasm/bss/build.zig index dc7d1bae4b..d73c7ed757 100644 --- a/test/link/wasm/bss/build.zig +++ b/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; diff --git a/test/link/wasm/export-data/build.zig b/test/link/wasm/export-data/build.zig index 7e3c5e5841..726d6caba5 100644 --- a/test/link/wasm/export-data/build.zig +++ b/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; diff --git a/test/link/wasm/export/build.zig b/test/link/wasm/export/build.zig index 368826843a..5c40612ca2 100644 --- a/test/link/wasm/export/build.zig +++ b/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"}; diff --git a/test/link/wasm/extern-mangle/build.zig b/test/link/wasm/extern-mangle/build.zig index 5a4cbc1cda..c856611e97 100644 --- a/test/link/wasm/extern-mangle/build.zig +++ b/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` diff --git a/test/link/wasm/extern/build.zig b/test/link/wasm/extern/build.zig index 77dcbc47c5..236f01fd88 100644 --- a/test/link/wasm/extern/build.zig +++ b/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; diff --git a/test/link/wasm/function-table/build.zig b/test/link/wasm/function-table/build.zig index 3042ddf5d5..7fd306285c 100644 --- a/test/link/wasm/function-table/build.zig +++ 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; diff --git a/test/link/wasm/infer-features/build.zig b/test/link/wasm/infer-features/build.zig index af40175da0..83aab77841 100644 --- a/test/link/wasm/infer-features/build.zig +++ b/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(); diff --git a/test/link/wasm/producers/build.zig b/test/link/wasm/producers/build.zig index 2dae6e3f9b..e31b07ce8b 100644 --- a/test/link/wasm/producers/build.zig +++ b/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; diff --git a/test/link/wasm/segments/build.zig b/test/link/wasm/segments/build.zig index 3c8bac3f07..c2c62a3b88 100644 --- a/test/link/wasm/segments/build.zig +++ b/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; diff --git a/test/link/wasm/shared-memory/build.zig b/test/link/wasm/shared-memory/build.zig index 7807a95a4f..7725454f3f 100644 --- a/test/link/wasm/shared-memory/build.zig +++ b/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; diff --git a/test/link/wasm/stack_pointer/build.zig b/test/link/wasm/stack_pointer/build.zig index e42e362880..57ce5ddefd 100644 --- a/test/link/wasm/stack_pointer/build.zig +++ b/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; diff --git a/test/link/wasm/type/build.zig b/test/link/wasm/type/build.zig index 46b80dbfe5..aa19d4d403 100644 --- a/test/link/wasm/type/build.zig +++ b/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;