authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-16 16:47:17+00:00
committergravatar for bratishkaerik@landless-city.netEric Joldasov <bratishkaerik@landless-city.net> 2024-12-18 01:49:10+05:00
log82659c4594d12e5b80d2684320e15ce93eedb966
treecbef43f220baf1e0ee70e7b550074629807321a5
parent6179d9ef55b071677100af27eeb18582c15c149f
signaturelock-open Commit is signed but in an unrecognized format.

test-link: migrate from deprecated std.Build APIs


21 files changed, 288 insertions(+), 204 deletions(-)

test/link/bss/build.zig+5-3
......@@ -6,9 +6,11 @@ pub fn build(b: *std.Build) void {
66
77 const exe = b.addExecutable(.{
88 .name = "bss",
9 .root_source_file = b.path("main.zig"),
10 .target = b.graph.host,
11 .optimize = .Debug,
9 .root_module = b.createModule(.{
10 .root_source_file = b.path("main.zig"),
11 .target = b.graph.host,
12 .optimize = .Debug,
13 }),
1214 });
1315
1416 const run = b.addRunArtifact(exe);
test/link/common_symbols/build.zig+11-6
......@@ -13,19 +13,24 @@ pub fn build(b: *std.Build) void {
1313fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1414 const lib_a = b.addStaticLibrary(.{
1515 .name = "a",
16 .optimize = optimize,
17 .target = b.graph.host,
16 .root_module = b.createModule(.{
17 .root_source_file = null,
18 .optimize = optimize,
19 .target = b.graph.host,
20 }),
1821 });
19 lib_a.addCSourceFiles(.{
22 lib_a.root_module.addCSourceFiles(.{
2023 .files = &.{ "c.c", "a.c", "b.c" },
2124 .flags = &.{"-fcommon"},
2225 });
2326
2427 const test_exe = b.addTest(.{
25 .root_source_file = b.path("main.zig"),
26 .optimize = optimize,
28 .root_module = b.createModule(.{
29 .root_source_file = b.path("main.zig"),
30 .optimize = optimize,
31 }),
2732 });
28 test_exe.linkLibrary(lib_a);
33 test_exe.root_module.linkLibrary(lib_a);
2934
3035 test_step.dependOn(&b.addRunArtifact(test_exe).step);
3136}
test/link/common_symbols_alignment/build.zig+12-6
......@@ -13,19 +13,25 @@ pub fn build(b: *std.Build) void {
1313fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1414 const lib_a = b.addStaticLibrary(.{
1515 .name = "a",
16 .optimize = optimize,
17 .target = b.graph.host,
16 .root_module = b.createModule(.{
17 .root_source_file = null,
18 .optimize = optimize,
19 .target = b.graph.host,
20 }),
1821 });
19 lib_a.addCSourceFiles(.{
22 lib_a.root_module.addCSourceFiles(.{
2023 .files = &.{"a.c"},
2124 .flags = &.{"-fcommon"},
2225 });
2326
2427 const test_exe = b.addTest(.{
25 .root_source_file = b.path("main.zig"),
26 .optimize = optimize,
28 .root_module = b.createModule(.{
29 .root_source_file = b.path("main.zig"),
30 .target = b.graph.host,
31 .optimize = optimize,
32 }),
2733 });
28 test_exe.linkLibrary(lib_a);
34 test_exe.root_module.linkLibrary(lib_a);
2935
3036 test_step.dependOn(&b.addRunArtifact(test_exe).step);
3137}
test/link/glibc_compat/build.zig+19-11
......@@ -14,12 +14,15 @@ pub fn build(b: *std.Build) void {
1414 for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| {
1515 const exe = b.addExecutable(.{
1616 .name = t,
17 .target = b.resolveTargetQuery(std.Target.Query.parse(
18 .{ .arch_os_abi = t },
19 ) catch unreachable),
17 .root_module = b.createModule(.{
18 .root_source_file = null,
19 .target = b.resolveTargetQuery(std.Target.Query.parse(
20 .{ .arch_os_abi = t },
21 ) catch unreachable),
22 .link_libc = true,
23 }),
2024 });
21 exe.addCSourceFile(.{ .file = b.path("main.c") });
22 exe.linkLibC();
25 exe.root_module.addCSourceFile(.{ .file = b.path("main.c") });
2326 // TODO: actually test the output
2427 _ = exe.getEmittedBin();
2528 test_step.dependOn(&exe.step);
......@@ -53,10 +56,13 @@ pub fn build(b: *std.Build) void {
5356
5457 const exe = b.addExecutable(.{
5558 .name = t,
56 .target = target,
59 .root_module = b.createModule(.{
60 .root_source_file = null,
61 .target = target,
62 .link_libc = true,
63 }),
5764 });
58 exe.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") });
59 exe.linkLibC();
65 exe.root_module.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") });
6066
6167 // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig
6268 // 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 {
149155
150156 const exe = b.addExecutable(.{
151157 .name = t,
152 .root_source_file = b.path("glibc_runtime_check.zig"),
153 .target = target,
158 .root_module = b.createModule(.{
159 .root_source_file = b.path("glibc_runtime_check.zig"),
160 .target = target,
161 .link_libc = true,
162 }),
154163 });
155 exe.linkLibC();
156164
157165 // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig
158166 // 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+22-13
......@@ -13,27 +13,36 @@ pub fn build(b: *std.Build) void {
1313fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1414 const lib_a = b.addStaticLibrary(.{
1515 .name = "a",
16 .optimize = optimize,
17 .target = b.graph.host,
16 .root_module = b.createModule(.{
17 .root_source_file = null,
18 .optimize = optimize,
19 .target = b.graph.host,
20 }),
1821 });
19 lib_a.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} });
20 lib_a.addIncludePath(b.path("."));
22 lib_a.root_module.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} });
23 lib_a.root_module.addIncludePath(b.path("."));
2124
2225 const lib_b = b.addStaticLibrary(.{
2326 .name = "b",
24 .optimize = optimize,
25 .target = b.graph.host,
27 .root_module = b.createModule(.{
28 .root_source_file = null,
29 .optimize = optimize,
30 .target = b.graph.host,
31 }),
2632 });
27 lib_b.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} });
28 lib_b.addIncludePath(b.path("."));
33 lib_b.root_module.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} });
34 lib_b.root_module.addIncludePath(b.path("."));
2935
3036 const test_exe = b.addTest(.{
31 .root_source_file = b.path("main.zig"),
32 .optimize = optimize,
37 .root_module = b.createModule(.{
38 .root_source_file = b.path("main.zig"),
39 .target = b.graph.host,
40 .optimize = optimize,
41 }),
3342 });
34 test_exe.linkLibrary(lib_a);
35 test_exe.linkLibrary(lib_b);
36 test_exe.addIncludePath(b.path("."));
43 test_exe.root_module.linkLibrary(lib_a);
44 test_exe.root_module.linkLibrary(lib_b);
45 test_exe.root_module.addIncludePath(b.path("."));
3746
3847 test_step.dependOn(&b.addRunArtifact(test_exe).step);
3948}
test/link/link.zig+47-43
......@@ -47,81 +47,85 @@ const OverlayOptions = struct {
4747};
4848
4949pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Compile {
50 return addCompileStep(b, base, overlay, .exe);
50 return b.addExecutable(.{
51 .name = overlay.name,
52 .root_module = createModule(b, base, overlay),
53 .use_llvm = base.use_llvm,
54 .use_lld = base.use_lld,
55 });
5156}
5257
5358pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
54 return addCompileStep(b, base, overlay, .obj);
59 return b.addObject(.{
60 .name = overlay.name,
61 .root_module = createModule(b, base, overlay),
62 .use_llvm = base.use_llvm,
63 .use_lld = base.use_lld,
64 });
5565}
5666
5767pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
58 return addCompileStep(b, base, overlay, .static_lib);
68 return b.addStaticLibrary(.{
69 .name = overlay.name,
70 .root_module = createModule(b, base, overlay),
71 .use_llvm = base.use_llvm,
72 .use_lld = base.use_lld,
73 });
5974}
6075
6176pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
62 return addCompileStep(b, base, overlay, .shared_lib);
63}
64
65fn addCompileStep(
66 b: *Build,
67 base: Options,
68 overlay: OverlayOptions,
69 kind: enum { exe, obj, shared_lib, static_lib },
70) *Compile {
71 const compile_step = Compile.create(b, .{
77 return b.addSharedLibrary(.{
7278 .name = overlay.name,
73 .root_module = b.createModule(.{
74 .target = base.target,
75 .optimize = base.optimize,
76 .root_source_file = rsf: {
77 const bytes = overlay.zig_source_bytes orelse break :rsf null;
78 const name = b.fmt("{s}.zig", .{overlay.name});
79 break :rsf b.addWriteFiles().add(name, bytes);
80 },
81 .pic = overlay.pic,
82 .strip = if (base.strip) |s| s else overlay.strip,
83 }),
79 .root_module = createModule(b, base, overlay),
8480 .use_llvm = base.use_llvm,
8581 .use_lld = base.use_lld,
86 .kind = switch (kind) {
87 .exe => .exe,
88 .obj => .obj,
89 .shared_lib, .static_lib => .lib,
90 },
91 .linkage = switch (kind) {
92 .exe, .obj => null,
93 .shared_lib => .dynamic,
94 .static_lib => .static,
82 });
83}
84
85fn createModule(b: *Build, base: Options, overlay: OverlayOptions) *Build.Module {
86 const write_files = b.addWriteFiles();
87
88 const mod = b.createModule(.{
89 .target = base.target,
90 .optimize = base.optimize,
91 .root_source_file = rsf: {
92 const bytes = overlay.zig_source_bytes orelse break :rsf null;
93 const name = b.fmt("{s}.zig", .{overlay.name});
94 break :rsf write_files.add(name, bytes);
9595 },
96 .pic = overlay.pic,
97 .strip = if (base.strip) |s| s else overlay.strip,
9698 });
99
97100 if (overlay.objcpp_source_bytes) |bytes| {
98 compile_step.addCSourceFile(.{
99 .file = b.addWriteFiles().add("a.mm", bytes),
101 mod.addCSourceFile(.{
102 .file = write_files.add("a.mm", bytes),
100103 .flags = overlay.objcpp_source_flags,
101104 });
102105 }
103106 if (overlay.objc_source_bytes) |bytes| {
104 compile_step.addCSourceFile(.{
105 .file = b.addWriteFiles().add("a.m", bytes),
107 mod.addCSourceFile(.{
108 .file = write_files.add("a.m", bytes),
106109 .flags = overlay.objc_source_flags,
107110 });
108111 }
109112 if (overlay.cpp_source_bytes) |bytes| {
110 compile_step.addCSourceFile(.{
111 .file = b.addWriteFiles().add("a.cpp", bytes),
113 mod.addCSourceFile(.{
114 .file = write_files.add("a.cpp", bytes),
112115 .flags = overlay.cpp_source_flags,
113116 });
114117 }
115118 if (overlay.c_source_bytes) |bytes| {
116 compile_step.addCSourceFile(.{
117 .file = b.addWriteFiles().add("a.c", bytes),
119 mod.addCSourceFile(.{
120 .file = write_files.add("a.c", bytes),
118121 .flags = overlay.c_source_flags,
119122 });
120123 }
121124 if (overlay.asm_source_bytes) |bytes| {
122 compile_step.addAssemblyFile(b.addWriteFiles().add("a.s", bytes));
125 mod.addAssemblyFile(write_files.add("a.s", bytes));
123126 }
124 return compile_step;
127
128 return mod;
125129}
126130
127131pub fn addRunArtifact(comp: *Compile) *Run {
test/link/static_libs_from_object_files/build.zig+47-38
......@@ -57,13 +57,15 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
5757 {
5858 const exe = b.addExecutable(.{
5959 .name = "test1",
60 .root_source_file = b.path("main.zig"),
61 .optimize = optimize,
62 .target = b.graph.host,
60 .root_module = b.createModule(.{
61 .root_source_file = b.path("main.zig"),
62 .optimize = optimize,
63 .target = b.graph.host,
64 }),
6365 });
6466
6567 for (files) |file| {
66 exe.addCSourceFile(.{ .file = file, .flags = &flags });
68 exe.root_module.addCSourceFile(.{ .file = file, .flags = &flags });
6769 }
6870
6971 const run_cmd = b.addRunArtifact(exe);
......@@ -75,30 +77,33 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
7577
7678 // using static librairies
7779 {
80 const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
81 const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
82
83 for (files, 1..) |file, i| {
84 const mod = if (i & 1 == 0) mod_a else mod_b;
85 mod.addCSourceFile(.{ .file = file, .flags = &flags });
86 }
87
7888 const lib_a = b.addStaticLibrary(.{
7989 .name = "test2_a",
80 .target = b.graph.host,
81 .optimize = optimize,
90 .root_module = mod_a,
8291 });
8392 const lib_b = b.addStaticLibrary(.{
8493 .name = "test2_b",
85 .target = b.graph.host,
86 .optimize = optimize,
94 .root_module = mod_b,
8795 });
8896
89 for (files, 1..) |file, i| {
90 const lib = if (i & 1 == 0) lib_a else lib_b;
91 lib.addCSourceFile(.{ .file = file, .flags = &flags });
92 }
93
9497 const exe = b.addExecutable(.{
9598 .name = "test2",
96 .root_source_file = b.path("main.zig"),
97 .target = b.graph.host,
98 .optimize = optimize,
99 .root_module = b.createModule(.{
100 .root_source_file = b.path("main.zig"),
101 .target = b.graph.host,
102 .optimize = optimize,
103 }),
99104 });
100 exe.linkLibrary(lib_a);
101 exe.linkLibrary(lib_b);
105 exe.root_module.linkLibrary(lib_a);
106 exe.root_module.linkLibrary(lib_b);
102107
103108 const run_cmd = b.addRunArtifact(exe);
104109 run_cmd.skip_foreign_checks = true;
......@@ -109,37 +114,41 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
109114
110115 // using static librairies and object files
111116 {
112 const lib_a = b.addStaticLibrary(.{
113 .name = "test3_a",
114 .target = b.graph.host,
115 .optimize = optimize,
116 });
117 const lib_b = b.addStaticLibrary(.{
118 .name = "test3_b",
119 .target = b.graph.host,
120 .optimize = optimize,
121 });
117 const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
118 const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
122119
123120 for (files, 1..) |file, i| {
121 const obj_mod = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
122 obj_mod.addCSourceFile(.{ .file = file, .flags = &flags });
123
124124 const obj = b.addObject(.{
125125 .name = b.fmt("obj_{}", .{i}),
126 .target = b.graph.host,
127 .optimize = optimize,
126 .root_module = obj_mod,
128127 });
129 obj.addCSourceFile(.{ .file = file, .flags = &flags });
130128
131 const lib = if (i & 1 == 0) lib_a else lib_b;
132 lib.addObject(obj);
129 const lib_mod = if (i & 1 == 0) mod_a else mod_b;
130 lib_mod.addObject(obj);
133131 }
134132
133 const lib_a = b.addStaticLibrary(.{
134 .name = "test3_a",
135 .root_module = mod_a,
136 });
137 const lib_b = b.addStaticLibrary(.{
138 .name = "test3_b",
139 .root_module = mod_b,
140 });
141
135142 const exe = b.addExecutable(.{
136143 .name = "test3",
137 .root_source_file = b.path("main.zig"),
138 .target = b.graph.host,
139 .optimize = optimize,
144 .root_module = b.createModule(.{
145 .root_source_file = b.path("main.zig"),
146 .target = b.graph.host,
147 .optimize = optimize,
148 }),
140149 });
141 exe.linkLibrary(lib_a);
142 exe.linkLibrary(lib_b);
150 exe.root_module.linkLibrary(lib_a);
151 exe.root_module.linkLibrary(lib_b);
143152
144153 const run_cmd = b.addRunArtifact(exe);
145154 run_cmd.skip_foreign_checks = true;
test/link/wasm/archive/build.zig+6-4
......@@ -17,10 +17,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
1717 // and therefore link with its archive file.
1818 const lib = b.addExecutable(.{
1919 .name = "main",
20 .root_source_file = b.path("main.zig"),
21 .optimize = optimize,
22 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
23 .strip = false,
20 .root_module = b.createModule(.{
21 .root_source_file = b.path("main.zig"),
22 .optimize = optimize,
23 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
24 .strip = false,
25 }),
2426 });
2527 lib.entry = .disabled;
2628 lib.use_llvm = false;
test/link/wasm/basic-features/build.zig+9-7
......@@ -6,13 +6,15 @@ pub fn build(b: *std.Build) void {
66 // Library with explicitly set cpu features
77 const lib = b.addExecutable(.{
88 .name = "lib",
9 .root_source_file = b.path("main.zig"),
10 .optimize = .Debug,
11 .target = b.resolveTargetQuery(.{
12 .cpu_arch = .wasm32,
13 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
14 .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}),
15 .os_tag = .freestanding,
9 .root_module = b.createModule(.{
10 .root_source_file = b.path("main.zig"),
11 .optimize = .Debug,
12 .target = b.resolveTargetQuery(.{
13 .cpu_arch = .wasm32,
14 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
15 .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}),
16 .os_tag = .freestanding,
17 }),
1618 }),
1719 });
1820 lib.entry = .disabled;
test/link/wasm/bss/build.zig+12-8
......@@ -16,10 +16,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
1616 {
1717 const lib = b.addExecutable(.{
1818 .name = "lib",
19 .root_source_file = b.path("lib.zig"),
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
21 .optimize = optimize_mode,
22 .strip = false,
19 .root_module = b.createModule(.{
20 .root_source_file = b.path("lib.zig"),
21 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
22 .optimize = optimize_mode,
23 .strip = false,
24 }),
2325 });
2426 lib.entry = .disabled;
2527 lib.use_llvm = false;
......@@ -64,10 +66,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
6466 {
6567 const lib = b.addExecutable(.{
6668 .name = "lib",
67 .root_source_file = b.path("lib2.zig"),
68 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
69 .optimize = optimize_mode,
70 .strip = false,
69 .root_module = b.createModule(.{
70 .root_source_file = b.path("lib2.zig"),
71 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
72 .optimize = optimize_mode,
73 .strip = false,
74 }),
7175 });
7276 lib.entry = .disabled;
7377 lib.use_llvm = false;
test/link/wasm/export-data/build.zig+5-3
......@@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void {
1111
1212 const lib = b.addExecutable(.{
1313 .name = "lib",
14 .root_source_file = b.path("lib.zig"),
15 .optimize = .ReleaseSafe, // to make the output deterministic in address positions
16 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
14 .root_module = b.createModule(.{
15 .root_source_file = b.path("lib.zig"),
16 .optimize = .ReleaseSafe, // to make the output deterministic in address positions
17 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
18 }),
1719 });
1820 lib.entry = .disabled;
1921 lib.use_lld = false;
test/link/wasm/export/build.zig+15-9
......@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1616 const no_export = b.addExecutable(.{
1717 .name = "no-export",
18 .root_source_file = b.path("main.zig"),
19 .optimize = optimize,
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
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 }),
2123 });
2224 no_export.entry = .disabled;
2325 no_export.use_llvm = false;
......@@ -25,9 +27,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2527
2628 const dynamic_export = b.addExecutable(.{
2729 .name = "dynamic",
28 .root_source_file = b.path("main.zig"),
29 .optimize = optimize,
30 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
30 .root_module = b.createModule(.{
31 .root_source_file = b.path("main.zig"),
32 .optimize = optimize,
33 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
34 }),
3135 });
3236 dynamic_export.entry = .disabled;
3337 dynamic_export.rdynamic = true;
......@@ -36,9 +40,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3640
3741 const force_export = b.addExecutable(.{
3842 .name = "force",
39 .root_source_file = b.path("main.zig"),
40 .optimize = optimize,
41 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
43 .root_module = b.createModule(.{
44 .root_source_file = b.path("main.zig"),
45 .optimize = optimize,
46 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
47 }),
4248 });
4349 force_export.entry = .disabled;
4450 force_export.root_module.export_symbol_names = &.{"foo"};
test/link/wasm/extern-mangle/build.zig+5-3
......@@ -13,9 +13,11 @@ pub fn build(b: *std.Build) void {
1313fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1414 const lib = b.addExecutable(.{
1515 .name = "lib",
16 .root_source_file = b.path("lib.zig"),
17 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
18 .optimize = optimize,
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 }),
1921 });
2022 lib.entry = .disabled;
2123 lib.import_symbols = true; // import `a` and `b`
test/link/wasm/extern/build.zig+5-3
......@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1616 const exe = b.addExecutable(.{
1717 .name = "extern",
18 .root_source_file = b.path("main.zig"),
19 .optimize = optimize,
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }),
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 = .wasi }),
22 }),
2123 });
2224 exe.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });
2325 exe.use_llvm = false;
test/link/wasm/function-table/build.zig+15-9
......@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1616 const import_table = b.addExecutable(.{
1717 .name = "import_table",
18 .root_source_file = b.path("lib.zig"),
19 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
20 .optimize = optimize,
18 .root_module = b.createModule(.{
19 .root_source_file = b.path("lib.zig"),
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
21 .optimize = optimize,
22 }),
2123 });
2224 import_table.entry = .disabled;
2325 import_table.use_llvm = false;
......@@ -27,9 +29,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2729
2830 const export_table = b.addExecutable(.{
2931 .name = "export_table",
30 .root_source_file = b.path("lib.zig"),
31 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
32 .optimize = optimize,
32 .root_module = b.createModule(.{
33 .root_source_file = b.path("lib.zig"),
34 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
35 .optimize = optimize,
36 }),
3337 });
3438 export_table.entry = .disabled;
3539 export_table.use_llvm = false;
......@@ -39,9 +43,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3943
4044 const regular_table = b.addExecutable(.{
4145 .name = "regular_table",
42 .root_source_file = b.path("lib.zig"),
43 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
44 .optimize = optimize,
46 .root_module = b.createModule(.{
47 .root_source_file = b.path("lib.zig"),
48 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
49 .optimize = optimize,
50 }),
4551 });
4652 regular_table.entry = .disabled;
4753 regular_table.use_llvm = false;
test/link/wasm/infer-features/build.zig+18-13
......@@ -6,31 +6,36 @@ pub fn build(b: *std.Build) void {
66 // Wasm Object file which we will use to infer the features from
77 const c_obj = b.addObject(.{
88 .name = "c_obj",
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,
9 .root_module = b.createModule(.{
10 .root_source_file = null,
11 .optimize = .Debug,
12 .target = b.resolveTargetQuery(.{
13 .cpu_arch = .wasm32,
14 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge },
15 .os_tag = .freestanding,
16 }),
1417 }),
1518 });
16 c_obj.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });
19 c_obj.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });
1720
1821 // Wasm library that doesn't have any features specified. This will
1922 // infer its featureset from other linked object files.
2023 const lib = b.addExecutable(.{
2124 .name = "lib",
22 .root_source_file = b.path("main.zig"),
23 .optimize = .Debug,
24 .target = b.resolveTargetQuery(.{
25 .cpu_arch = .wasm32,
26 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
27 .os_tag = .freestanding,
25 .root_module = b.createModule(.{
26 .root_source_file = b.path("main.zig"),
27 .optimize = .Debug,
28 .target = b.resolveTargetQuery(.{
29 .cpu_arch = .wasm32,
30 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
31 .os_tag = .freestanding,
32 }),
2833 }),
2934 });
3035 lib.entry = .disabled;
3136 lib.use_llvm = false;
3237 lib.use_lld = false;
33 lib.addObject(c_obj);
38 lib.root_module.addObject(c_obj);
3439
3540 // Verify the result contains the features from the C Object file.
3641 const check = lib.checkObject();
test/link/wasm/producers/build.zig+6-4
......@@ -16,10 +16,12 @@ pub fn build(b: *std.Build) void {
1616fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1717 const lib = b.addExecutable(.{
1818 .name = "lib",
19 .root_source_file = b.path("lib.zig"),
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
21 .optimize = optimize,
22 .strip = false,
19 .root_module = b.createModule(.{
20 .root_source_file = b.path("lib.zig"),
21 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
22 .optimize = optimize,
23 .strip = false,
24 }),
2325 });
2426 lib.entry = .disabled;
2527 lib.use_llvm = false;
test/link/wasm/segments/build.zig+6-4
......@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1616 const lib = b.addExecutable(.{
1717 .name = "lib",
18 .root_source_file = b.path("lib.zig"),
19 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
20 .optimize = optimize,
21 .strip = false,
18 .root_module = b.createModule(.{
19 .root_source_file = b.path("lib.zig"),
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
21 .optimize = optimize,
22 .strip = false,
23 }),
2224 });
2325 lib.entry = .disabled;
2426 lib.use_llvm = false;
test/link/wasm/shared-memory/build.zig+11-9
......@@ -13,16 +13,18 @@ pub fn build(b: *std.Build) void {
1313fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void {
1414 const exe = b.addExecutable(.{
1515 .name = "lib",
16 .root_source_file = b.path("lib.zig"),
17 .target = b.resolveTargetQuery(.{
18 .cpu_arch = .wasm32,
19 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
20 .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }),
21 .os_tag = .freestanding,
16 .root_module = b.createModule(.{
17 .root_source_file = b.path("lib.zig"),
18 .target = b.resolveTargetQuery(.{
19 .cpu_arch = .wasm32,
20 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
21 .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }),
22 .os_tag = .freestanding,
23 }),
24 .optimize = optimize_mode,
25 .strip = false,
26 .single_threaded = false,
2227 }),
23 .optimize = optimize_mode,
24 .strip = false,
25 .single_threaded = false,
2628 });
2729 exe.entry = .disabled;
2830 exe.use_lld = false;
test/link/wasm/stack_pointer/build.zig+6-4
......@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1616 const lib = b.addExecutable(.{
1717 .name = "lib",
18 .root_source_file = b.path("lib.zig"),
19 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
20 .optimize = optimize,
21 .strip = false,
18 .root_module = b.createModule(.{
19 .root_source_file = b.path("lib.zig"),
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
21 .optimize = optimize,
22 .strip = false,
23 }),
2224 });
2325 lib.entry = .disabled;
2426 lib.use_llvm = false;
test/link/wasm/type/build.zig+6-4
......@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
1515fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1616 const exe = b.addExecutable(.{
1717 .name = "lib",
18 .root_source_file = b.path("lib.zig"),
19 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
20 .optimize = optimize,
21 .strip = false,
18 .root_module = b.createModule(.{
19 .root_source_file = b.path("lib.zig"),
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
21 .optimize = optimize,
22 .strip = false,
23 }),
2224 });
2325 exe.entry = .disabled;
2426 exe.use_llvm = false;