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 {...@@ -6,9 +6,11 @@ pub fn build(b: *std.Build) void {
66
7 const exe = b.addExecutable(.{7 const exe = b.addExecutable(.{
8 .name = "bss",8 .name = "bss",
9 .root_source_file = b.path("main.zig"),9 .root_module = b.createModule(.{
10 .target = b.graph.host,10 .root_source_file = b.path("main.zig"),
11 .optimize = .Debug,11 .target = b.graph.host,
12 .optimize = .Debug,
13 }),
12 });14 });
1315
14 const run = b.addRunArtifact(exe);16 const run = b.addRunArtifact(exe);
test/link/common_symbols/build.zig+11-6
...@@ -13,19 +13,24 @@ pub fn build(b: *std.Build) void {...@@ -13,19 +13,24 @@ pub fn build(b: *std.Build) void {
13fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {13fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
14 const lib_a = b.addStaticLibrary(.{14 const lib_a = b.addStaticLibrary(.{
15 .name = "a",15 .name = "a",
16 .optimize = optimize,16 .root_module = b.createModule(.{
17 .target = b.graph.host,17 .root_source_file = null,
18 .optimize = optimize,
19 .target = b.graph.host,
20 }),
18 });21 });
19 lib_a.addCSourceFiles(.{22 lib_a.root_module.addCSourceFiles(.{
20 .files = &.{ "c.c", "a.c", "b.c" },23 .files = &.{ "c.c", "a.c", "b.c" },
21 .flags = &.{"-fcommon"},24 .flags = &.{"-fcommon"},
22 });25 });
2326
24 const test_exe = b.addTest(.{27 const test_exe = b.addTest(.{
25 .root_source_file = b.path("main.zig"),28 .root_module = b.createModule(.{
26 .optimize = optimize,29 .root_source_file = b.path("main.zig"),
30 .optimize = optimize,
31 }),
27 });32 });
28 test_exe.linkLibrary(lib_a);33 test_exe.root_module.linkLibrary(lib_a);
2934
30 test_step.dependOn(&b.addRunArtifact(test_exe).step);35 test_step.dependOn(&b.addRunArtifact(test_exe).step);
31}36}
test/link/common_symbols_alignment/build.zig+12-6
...@@ -13,19 +13,25 @@ pub fn build(b: *std.Build) void {...@@ -13,19 +13,25 @@ pub fn build(b: *std.Build) void {
13fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {13fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
14 const lib_a = b.addStaticLibrary(.{14 const lib_a = b.addStaticLibrary(.{
15 .name = "a",15 .name = "a",
16 .optimize = optimize,16 .root_module = b.createModule(.{
17 .target = b.graph.host,17 .root_source_file = null,
18 .optimize = optimize,
19 .target = b.graph.host,
20 }),
18 });21 });
19 lib_a.addCSourceFiles(.{22 lib_a.root_module.addCSourceFiles(.{
20 .files = &.{"a.c"},23 .files = &.{"a.c"},
21 .flags = &.{"-fcommon"},24 .flags = &.{"-fcommon"},
22 });25 });
2326
24 const test_exe = b.addTest(.{27 const test_exe = b.addTest(.{
25 .root_source_file = b.path("main.zig"),28 .root_module = b.createModule(.{
26 .optimize = optimize,29 .root_source_file = b.path("main.zig"),
30 .target = b.graph.host,
31 .optimize = optimize,
32 }),
27 });33 });
28 test_exe.linkLibrary(lib_a);34 test_exe.root_module.linkLibrary(lib_a);
2935
30 test_step.dependOn(&b.addRunArtifact(test_exe).step);36 test_step.dependOn(&b.addRunArtifact(test_exe).step);
31}37}
test/link/glibc_compat/build.zig+19-11
...@@ -14,12 +14,15 @@ pub fn build(b: *std.Build) void {...@@ -14,12 +14,15 @@ pub fn build(b: *std.Build) void {
14 for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| {14 for ([_][]const u8{ "aarch64-linux-gnu.2.27", "aarch64-linux-gnu.2.34" }) |t| {
15 const exe = b.addExecutable(.{15 const exe = b.addExecutable(.{
16 .name = t,16 .name = t,
17 .target = b.resolveTargetQuery(std.Target.Query.parse(17 .root_module = b.createModule(.{
18 .{ .arch_os_abi = t },18 .root_source_file = null,
19 ) catch unreachable),19 .target = b.resolveTargetQuery(std.Target.Query.parse(
20 .{ .arch_os_abi = t },
21 ) catch unreachable),
22 .link_libc = true,
23 }),
20 });24 });
21 exe.addCSourceFile(.{ .file = b.path("main.c") });25 exe.root_module.addCSourceFile(.{ .file = b.path("main.c") });
22 exe.linkLibC();
23 // TODO: actually test the output26 // TODO: actually test the output
24 _ = exe.getEmittedBin();27 _ = exe.getEmittedBin();
25 test_step.dependOn(&exe.step);28 test_step.dependOn(&exe.step);
...@@ -53,10 +56,13 @@ pub fn build(b: *std.Build) void {...@@ -53,10 +56,13 @@ pub fn build(b: *std.Build) void {
5356
54 const exe = b.addExecutable(.{57 const exe = b.addExecutable(.{
55 .name = t,58 .name = t,
56 .target = target,59 .root_module = b.createModule(.{
60 .root_source_file = null,
61 .target = target,
62 .link_libc = true,
63 }),
57 });64 });
58 exe.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") });65 exe.root_module.addCSourceFile(.{ .file = b.path("glibc_runtime_check.c") });
59 exe.linkLibC();
6066
61 // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig67 // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig
62 // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-183131045368 // 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 {...@@ -149,10 +155,12 @@ pub fn build(b: *std.Build) void {
149155
150 const exe = b.addExecutable(.{156 const exe = b.addExecutable(.{
151 .name = t,157 .name = t,
152 .root_source_file = b.path("glibc_runtime_check.zig"),158 .root_module = b.createModule(.{
153 .target = target,159 .root_source_file = b.path("glibc_runtime_check.zig"),
160 .target = target,
161 .link_libc = true,
162 }),
154 });163 });
155 exe.linkLibC();
156164
157 // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig165 // Only try running the test if the host glibc is known to be good enough. Ideally, the Zig
158 // test runner would be able to check this, but see https://github.com/ziglang/zig/pull/17702#issuecomment-1831310453166 // 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 {...@@ -13,27 +13,36 @@ pub fn build(b: *std.Build) void {
13fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {13fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
14 const lib_a = b.addStaticLibrary(.{14 const lib_a = b.addStaticLibrary(.{
15 .name = "a",15 .name = "a",
16 .optimize = optimize,16 .root_module = b.createModule(.{
17 .target = b.graph.host,17 .root_source_file = null,
18 .optimize = optimize,
19 .target = b.graph.host,
20 }),
18 });21 });
19 lib_a.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} });22 lib_a.root_module.addCSourceFile(.{ .file = b.path("a.c"), .flags = &[_][]const u8{} });
20 lib_a.addIncludePath(b.path("."));23 lib_a.root_module.addIncludePath(b.path("."));
2124
22 const lib_b = b.addStaticLibrary(.{25 const lib_b = b.addStaticLibrary(.{
23 .name = "b",26 .name = "b",
24 .optimize = optimize,27 .root_module = b.createModule(.{
25 .target = b.graph.host,28 .root_source_file = null,
29 .optimize = optimize,
30 .target = b.graph.host,
31 }),
26 });32 });
27 lib_b.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} });33 lib_b.root_module.addCSourceFile(.{ .file = b.path("b.c"), .flags = &[_][]const u8{} });
28 lib_b.addIncludePath(b.path("."));34 lib_b.root_module.addIncludePath(b.path("."));
2935
30 const test_exe = b.addTest(.{36 const test_exe = b.addTest(.{
31 .root_source_file = b.path("main.zig"),37 .root_module = b.createModule(.{
32 .optimize = optimize,38 .root_source_file = b.path("main.zig"),
39 .target = b.graph.host,
40 .optimize = optimize,
41 }),
33 });42 });
34 test_exe.linkLibrary(lib_a);43 test_exe.root_module.linkLibrary(lib_a);
35 test_exe.linkLibrary(lib_b);44 test_exe.root_module.linkLibrary(lib_b);
36 test_exe.addIncludePath(b.path("."));45 test_exe.root_module.addIncludePath(b.path("."));
3746
38 test_step.dependOn(&b.addRunArtifact(test_exe).step);47 test_step.dependOn(&b.addRunArtifact(test_exe).step);
39}48}
test/link/link.zig+47-43
...@@ -47,81 +47,85 @@ const OverlayOptions = struct {...@@ -47,81 +47,85 @@ const OverlayOptions = struct {
47};47};
4848
49pub fn addExecutable(b: *std.Build, base: Options, overlay: OverlayOptions) *Compile {49pub 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 });
51}56}
5257
53pub fn addObject(b: *Build, base: Options, overlay: OverlayOptions) *Compile {58pub 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 });
55}65}
5666
57pub fn addStaticLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile {67pub 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 });
59}74}
6075
61pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile {76pub fn addSharedLibrary(b: *Build, base: Options, overlay: OverlayOptions) *Compile {
62 return addCompileStep(b, base, overlay, .shared_lib);77 return b.addSharedLibrary(.{
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, .{
72 .name = overlay.name,78 .name = overlay.name,
73 .root_module = b.createModule(.{79 .root_module = createModule(b, base, overlay),
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 }),
84 .use_llvm = base.use_llvm,80 .use_llvm = base.use_llvm,
85 .use_lld = base.use_lld,81 .use_lld = base.use_lld,
86 .kind = switch (kind) {82 });
87 .exe => .exe,83}
88 .obj => .obj,84
89 .shared_lib, .static_lib => .lib,85fn createModule(b: *Build, base: Options, overlay: OverlayOptions) *Build.Module {
90 },86 const write_files = b.addWriteFiles();
91 .linkage = switch (kind) {87
92 .exe, .obj => null,88 const mod = b.createModule(.{
93 .shared_lib => .dynamic,89 .target = base.target,
94 .static_lib => .static,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);
95 },95 },
96 .pic = overlay.pic,
97 .strip = if (base.strip) |s| s else overlay.strip,
96 });98 });
99
97 if (overlay.objcpp_source_bytes) |bytes| {100 if (overlay.objcpp_source_bytes) |bytes| {
98 compile_step.addCSourceFile(.{101 mod.addCSourceFile(.{
99 .file = b.addWriteFiles().add("a.mm", bytes),102 .file = write_files.add("a.mm", bytes),
100 .flags = overlay.objcpp_source_flags,103 .flags = overlay.objcpp_source_flags,
101 });104 });
102 }105 }
103 if (overlay.objc_source_bytes) |bytes| {106 if (overlay.objc_source_bytes) |bytes| {
104 compile_step.addCSourceFile(.{107 mod.addCSourceFile(.{
105 .file = b.addWriteFiles().add("a.m", bytes),108 .file = write_files.add("a.m", bytes),
106 .flags = overlay.objc_source_flags,109 .flags = overlay.objc_source_flags,
107 });110 });
108 }111 }
109 if (overlay.cpp_source_bytes) |bytes| {112 if (overlay.cpp_source_bytes) |bytes| {
110 compile_step.addCSourceFile(.{113 mod.addCSourceFile(.{
111 .file = b.addWriteFiles().add("a.cpp", bytes),114 .file = write_files.add("a.cpp", bytes),
112 .flags = overlay.cpp_source_flags,115 .flags = overlay.cpp_source_flags,
113 });116 });
114 }117 }
115 if (overlay.c_source_bytes) |bytes| {118 if (overlay.c_source_bytes) |bytes| {
116 compile_step.addCSourceFile(.{119 mod.addCSourceFile(.{
117 .file = b.addWriteFiles().add("a.c", bytes),120 .file = write_files.add("a.c", bytes),
118 .flags = overlay.c_source_flags,121 .flags = overlay.c_source_flags,
119 });122 });
120 }123 }
121 if (overlay.asm_source_bytes) |bytes| {124 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));
123 }126 }
124 return compile_step;127
128 return mod;
125}129}
126130
127pub fn addRunArtifact(comp: *Compile) *Run {131pub 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...@@ -57,13 +57,15 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
57 {57 {
58 const exe = b.addExecutable(.{58 const exe = b.addExecutable(.{
59 .name = "test1",59 .name = "test1",
60 .root_source_file = b.path("main.zig"),60 .root_module = b.createModule(.{
61 .optimize = optimize,61 .root_source_file = b.path("main.zig"),
62 .target = b.graph.host,62 .optimize = optimize,
63 .target = b.graph.host,
64 }),
63 });65 });
6466
65 for (files) |file| {67 for (files) |file| {
66 exe.addCSourceFile(.{ .file = file, .flags = &flags });68 exe.root_module.addCSourceFile(.{ .file = file, .flags = &flags });
67 }69 }
6870
69 const run_cmd = b.addRunArtifact(exe);71 const run_cmd = b.addRunArtifact(exe);
...@@ -75,30 +77,33 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built...@@ -75,30 +77,33 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
7577
76 // using static librairies78 // using static librairies
77 {79 {
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
78 const lib_a = b.addStaticLibrary(.{88 const lib_a = b.addStaticLibrary(.{
79 .name = "test2_a",89 .name = "test2_a",
80 .target = b.graph.host,90 .root_module = mod_a,
81 .optimize = optimize,
82 });91 });
83 const lib_b = b.addStaticLibrary(.{92 const lib_b = b.addStaticLibrary(.{
84 .name = "test2_b",93 .name = "test2_b",
85 .target = b.graph.host,94 .root_module = mod_b,
86 .optimize = optimize,
87 });95 });
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
94 const exe = b.addExecutable(.{97 const exe = b.addExecutable(.{
95 .name = "test2",98 .name = "test2",
96 .root_source_file = b.path("main.zig"),99 .root_module = b.createModule(.{
97 .target = b.graph.host,100 .root_source_file = b.path("main.zig"),
98 .optimize = optimize,101 .target = b.graph.host,
102 .optimize = optimize,
103 }),
99 });104 });
100 exe.linkLibrary(lib_a);105 exe.root_module.linkLibrary(lib_a);
101 exe.linkLibrary(lib_b);106 exe.root_module.linkLibrary(lib_b);
102107
103 const run_cmd = b.addRunArtifact(exe);108 const run_cmd = b.addRunArtifact(exe);
104 run_cmd.skip_foreign_checks = true;109 run_cmd.skip_foreign_checks = true;
...@@ -109,37 +114,41 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built...@@ -109,37 +114,41 @@ fn add(b: *Build, test_step: *Step, files: []const LazyPath, optimize: std.built
109114
110 // using static librairies and object files115 // using static librairies and object files
111 {116 {
112 const lib_a = b.addStaticLibrary(.{117 const mod_a = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
113 .name = "test3_a",118 const mod_b = b.createModule(.{ .target = b.graph.host, .optimize = optimize });
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 });
122119
123 for (files, 1..) |file, i| {120 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
124 const obj = b.addObject(.{124 const obj = b.addObject(.{
125 .name = b.fmt("obj_{}", .{i}),125 .name = b.fmt("obj_{}", .{i}),
126 .target = b.graph.host,126 .root_module = obj_mod,
127 .optimize = optimize,
128 });127 });
129 obj.addCSourceFile(.{ .file = file, .flags = &flags });
130128
131 const lib = if (i & 1 == 0) lib_a else lib_b;129 const lib_mod = if (i & 1 == 0) mod_a else mod_b;
132 lib.addObject(obj);130 lib_mod.addObject(obj);
133 }131 }
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
135 const exe = b.addExecutable(.{142 const exe = b.addExecutable(.{
136 .name = "test3",143 .name = "test3",
137 .root_source_file = b.path("main.zig"),144 .root_module = b.createModule(.{
138 .target = b.graph.host,145 .root_source_file = b.path("main.zig"),
139 .optimize = optimize,146 .target = b.graph.host,
147 .optimize = optimize,
148 }),
140 });149 });
141 exe.linkLibrary(lib_a);150 exe.root_module.linkLibrary(lib_a);
142 exe.linkLibrary(lib_b);151 exe.root_module.linkLibrary(lib_b);
143152
144 const run_cmd = b.addRunArtifact(exe);153 const run_cmd = b.addRunArtifact(exe);
145 run_cmd.skip_foreign_checks = true;154 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...@@ -17,10 +17,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
17 // and therefore link with its archive file.17 // and therefore link with its archive file.
18 const lib = b.addExecutable(.{18 const lib = b.addExecutable(.{
19 .name = "main",19 .name = "main",
20 .root_source_file = b.path("main.zig"),20 .root_module = b.createModule(.{
21 .optimize = optimize,21 .root_source_file = b.path("main.zig"),
22 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),22 .optimize = optimize,
23 .strip = false,23 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
24 .strip = false,
25 }),
24 });26 });
25 lib.entry = .disabled;27 lib.entry = .disabled;
26 lib.use_llvm = false;28 lib.use_llvm = false;
test/link/wasm/basic-features/build.zig+9-7
...@@ -6,13 +6,15 @@ pub fn build(b: *std.Build) void {...@@ -6,13 +6,15 @@ pub fn build(b: *std.Build) void {
6 // Library with explicitly set cpu features6 // Library with explicitly set cpu features
7 const lib = b.addExecutable(.{7 const lib = b.addExecutable(.{
8 .name = "lib",8 .name = "lib",
9 .root_source_file = b.path("main.zig"),9 .root_module = b.createModule(.{
10 .optimize = .Debug,10 .root_source_file = b.path("main.zig"),
11 .target = b.resolveTargetQuery(.{11 .optimize = .Debug,
12 .cpu_arch = .wasm32,12 .target = b.resolveTargetQuery(.{
13 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },13 .cpu_arch = .wasm32,
14 .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}),14 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
15 .os_tag = .freestanding,15 .cpu_features_add = std.Target.wasm.featureSet(&.{.atomics}),
16 .os_tag = .freestanding,
17 }),
16 }),18 }),
17 });19 });
18 lib.entry = .disabled;20 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...@@ -16,10 +16,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
16 {16 {
17 const lib = b.addExecutable(.{17 const lib = b.addExecutable(.{
18 .name = "lib",18 .name = "lib",
19 .root_source_file = b.path("lib.zig"),19 .root_module = b.createModule(.{
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),20 .root_source_file = b.path("lib.zig"),
21 .optimize = optimize_mode,21 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
22 .strip = false,22 .optimize = optimize_mode,
23 .strip = false,
24 }),
23 });25 });
24 lib.entry = .disabled;26 lib.entry = .disabled;
25 lib.use_llvm = false;27 lib.use_llvm = false;
...@@ -64,10 +66,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt...@@ -64,10 +66,12 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.Opt
64 {66 {
65 const lib = b.addExecutable(.{67 const lib = b.addExecutable(.{
66 .name = "lib",68 .name = "lib",
67 .root_source_file = b.path("lib2.zig"),69 .root_module = b.createModule(.{
68 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),70 .root_source_file = b.path("lib2.zig"),
69 .optimize = optimize_mode,71 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
70 .strip = false,72 .optimize = optimize_mode,
73 .strip = false,
74 }),
71 });75 });
72 lib.entry = .disabled;76 lib.entry = .disabled;
73 lib.use_llvm = false;77 lib.use_llvm = false;
test/link/wasm/export-data/build.zig+5-3
...@@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void {...@@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void {
1111
12 const lib = b.addExecutable(.{12 const lib = b.addExecutable(.{
13 .name = "lib",13 .name = "lib",
14 .root_source_file = b.path("lib.zig"),14 .root_module = b.createModule(.{
15 .optimize = .ReleaseSafe, // to make the output deterministic in address positions15 .root_source_file = b.path("lib.zig"),
16 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),16 .optimize = .ReleaseSafe, // to make the output deterministic in address positions
17 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
18 }),
17 });19 });
18 lib.entry = .disabled;20 lib.entry = .disabled;
19 lib.use_lld = false;21 lib.use_lld = false;
test/link/wasm/export/build.zig+15-9
...@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {...@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const no_export = b.addExecutable(.{16 const no_export = b.addExecutable(.{
17 .name = "no-export",17 .name = "no-export",
18 .root_source_file = b.path("main.zig"),18 .root_module = b.createModule(.{
19 .optimize = optimize,19 .root_source_file = b.path("main.zig"),
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),20 .optimize = optimize,
21 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
22 }),
21 });23 });
22 no_export.entry = .disabled;24 no_export.entry = .disabled;
23 no_export.use_llvm = false;25 no_export.use_llvm = false;
...@@ -25,9 +27,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize...@@ -25,9 +27,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2527
26 const dynamic_export = b.addExecutable(.{28 const dynamic_export = b.addExecutable(.{
27 .name = "dynamic",29 .name = "dynamic",
28 .root_source_file = b.path("main.zig"),30 .root_module = b.createModule(.{
29 .optimize = optimize,31 .root_source_file = b.path("main.zig"),
30 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),32 .optimize = optimize,
33 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
34 }),
31 });35 });
32 dynamic_export.entry = .disabled;36 dynamic_export.entry = .disabled;
33 dynamic_export.rdynamic = true;37 dynamic_export.rdynamic = true;
...@@ -36,9 +40,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize...@@ -36,9 +40,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3640
37 const force_export = b.addExecutable(.{41 const force_export = b.addExecutable(.{
38 .name = "force",42 .name = "force",
39 .root_source_file = b.path("main.zig"),43 .root_module = b.createModule(.{
40 .optimize = optimize,44 .root_source_file = b.path("main.zig"),
41 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),45 .optimize = optimize,
46 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
47 }),
42 });48 });
43 force_export.entry = .disabled;49 force_export.entry = .disabled;
44 force_export.root_module.export_symbol_names = &.{"foo"};50 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 {...@@ -13,9 +13,11 @@ pub fn build(b: *std.Build) void {
13fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {13fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
14 const lib = b.addExecutable(.{14 const lib = b.addExecutable(.{
15 .name = "lib",15 .name = "lib",
16 .root_source_file = b.path("lib.zig"),16 .root_module = b.createModule(.{
17 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),17 .root_source_file = b.path("lib.zig"),
18 .optimize = optimize,18 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
19 .optimize = optimize,
20 }),
19 });21 });
20 lib.entry = .disabled;22 lib.entry = .disabled;
21 lib.import_symbols = true; // import `a` and `b`23 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 {...@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const exe = b.addExecutable(.{16 const exe = b.addExecutable(.{
17 .name = "extern",17 .name = "extern",
18 .root_source_file = b.path("main.zig"),18 .root_module = b.createModule(.{
19 .optimize = optimize,19 .root_source_file = b.path("main.zig"),
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }),20 .optimize = optimize,
21 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .wasi }),
22 }),
21 });23 });
22 exe.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });24 exe.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });
23 exe.use_llvm = false;25 exe.use_llvm = false;
test/link/wasm/function-table/build.zig+15-9
...@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {...@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const import_table = b.addExecutable(.{16 const import_table = b.addExecutable(.{
17 .name = "import_table",17 .name = "import_table",
18 .root_source_file = b.path("lib.zig"),18 .root_module = b.createModule(.{
19 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),19 .root_source_file = b.path("lib.zig"),
20 .optimize = optimize,20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
21 .optimize = optimize,
22 }),
21 });23 });
22 import_table.entry = .disabled;24 import_table.entry = .disabled;
23 import_table.use_llvm = false;25 import_table.use_llvm = false;
...@@ -27,9 +29,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize...@@ -27,9 +29,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
2729
28 const export_table = b.addExecutable(.{30 const export_table = b.addExecutable(.{
29 .name = "export_table",31 .name = "export_table",
30 .root_source_file = b.path("lib.zig"),32 .root_module = b.createModule(.{
31 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),33 .root_source_file = b.path("lib.zig"),
32 .optimize = optimize,34 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
35 .optimize = optimize,
36 }),
33 });37 });
34 export_table.entry = .disabled;38 export_table.entry = .disabled;
35 export_table.use_llvm = false;39 export_table.use_llvm = false;
...@@ -39,9 +43,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize...@@ -39,9 +43,11 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
3943
40 const regular_table = b.addExecutable(.{44 const regular_table = b.addExecutable(.{
41 .name = "regular_table",45 .name = "regular_table",
42 .root_source_file = b.path("lib.zig"),46 .root_module = b.createModule(.{
43 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),47 .root_source_file = b.path("lib.zig"),
44 .optimize = optimize,48 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
49 .optimize = optimize,
50 }),
45 });51 });
46 regular_table.entry = .disabled;52 regular_table.entry = .disabled;
47 regular_table.use_llvm = false;53 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 {...@@ -6,31 +6,36 @@ pub fn build(b: *std.Build) void {
6 // Wasm Object file which we will use to infer the features from6 // Wasm Object file which we will use to infer the features from
7 const c_obj = b.addObject(.{7 const c_obj = b.addObject(.{
8 .name = "c_obj",8 .name = "c_obj",
9 .optimize = .Debug,9 .root_module = b.createModule(.{
10 .target = b.resolveTargetQuery(.{10 .root_source_file = null,
11 .cpu_arch = .wasm32,11 .optimize = .Debug,
12 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge },12 .target = b.resolveTargetQuery(.{
13 .os_tag = .freestanding,13 .cpu_arch = .wasm32,
14 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.bleeding_edge },
15 .os_tag = .freestanding,
16 }),
14 }),17 }),
15 });18 });
16 c_obj.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });19 c_obj.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &.{} });
1720
18 // Wasm library that doesn't have any features specified. This will21 // Wasm library that doesn't have any features specified. This will
19 // infer its featureset from other linked object files.22 // infer its featureset from other linked object files.
20 const lib = b.addExecutable(.{23 const lib = b.addExecutable(.{
21 .name = "lib",24 .name = "lib",
22 .root_source_file = b.path("main.zig"),25 .root_module = b.createModule(.{
23 .optimize = .Debug,26 .root_source_file = b.path("main.zig"),
24 .target = b.resolveTargetQuery(.{27 .optimize = .Debug,
25 .cpu_arch = .wasm32,28 .target = b.resolveTargetQuery(.{
26 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },29 .cpu_arch = .wasm32,
27 .os_tag = .freestanding,30 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
31 .os_tag = .freestanding,
32 }),
28 }),33 }),
29 });34 });
30 lib.entry = .disabled;35 lib.entry = .disabled;
31 lib.use_llvm = false;36 lib.use_llvm = false;
32 lib.use_lld = false;37 lib.use_lld = false;
33 lib.addObject(c_obj);38 lib.root_module.addObject(c_obj);
3439
35 // Verify the result contains the features from the C Object file.40 // Verify the result contains the features from the C Object file.
36 const check = lib.checkObject();41 const check = lib.checkObject();
test/link/wasm/producers/build.zig+6-4
...@@ -16,10 +16,12 @@ pub fn build(b: *std.Build) void {...@@ -16,10 +16,12 @@ pub fn build(b: *std.Build) void {
16fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {16fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
17 const lib = b.addExecutable(.{17 const lib = b.addExecutable(.{
18 .name = "lib",18 .name = "lib",
19 .root_source_file = b.path("lib.zig"),19 .root_module = b.createModule(.{
20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),20 .root_source_file = b.path("lib.zig"),
21 .optimize = optimize,21 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
22 .strip = false,22 .optimize = optimize,
23 .strip = false,
24 }),
23 });25 });
24 lib.entry = .disabled;26 lib.entry = .disabled;
25 lib.use_llvm = false;27 lib.use_llvm = false;
test/link/wasm/segments/build.zig+6-4
...@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {...@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const lib = b.addExecutable(.{16 const lib = b.addExecutable(.{
17 .name = "lib",17 .name = "lib",
18 .root_source_file = b.path("lib.zig"),18 .root_module = b.createModule(.{
19 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),19 .root_source_file = b.path("lib.zig"),
20 .optimize = optimize,20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
21 .strip = false,21 .optimize = optimize,
22 .strip = false,
23 }),
22 });24 });
23 lib.entry = .disabled;25 lib.entry = .disabled;
24 lib.use_llvm = false;26 lib.use_llvm = false;
test/link/wasm/shared-memory/build.zig+11-9
...@@ -13,16 +13,18 @@ pub fn build(b: *std.Build) void {...@@ -13,16 +13,18 @@ pub fn build(b: *std.Build) void {
13fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void {13fn add(b: *std.Build, test_step: *std.Build.Step, optimize_mode: std.builtin.OptimizeMode) void {
14 const exe = b.addExecutable(.{14 const exe = b.addExecutable(.{
15 .name = "lib",15 .name = "lib",
16 .root_source_file = b.path("lib.zig"),16 .root_module = b.createModule(.{
17 .target = b.resolveTargetQuery(.{17 .root_source_file = b.path("lib.zig"),
18 .cpu_arch = .wasm32,18 .target = b.resolveTargetQuery(.{
19 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },19 .cpu_arch = .wasm32,
20 .cpu_features_add = std.Target.wasm.featureSet(&.{ .atomics, .bulk_memory }),20 .cpu_model = .{ .explicit = &std.Target.wasm.cpu.mvp },
21 .os_tag = .freestanding,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,
22 }),27 }),
23 .optimize = optimize_mode,
24 .strip = false,
25 .single_threaded = false,
26 });28 });
27 exe.entry = .disabled;29 exe.entry = .disabled;
28 exe.use_lld = false;30 exe.use_lld = false;
test/link/wasm/stack_pointer/build.zig+6-4
...@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {...@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const lib = b.addExecutable(.{16 const lib = b.addExecutable(.{
17 .name = "lib",17 .name = "lib",
18 .root_source_file = b.path("lib.zig"),18 .root_module = b.createModule(.{
19 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),19 .root_source_file = b.path("lib.zig"),
20 .optimize = optimize,20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
21 .strip = false,21 .optimize = optimize,
22 .strip = false,
23 }),
22 });24 });
23 lib.entry = .disabled;25 lib.entry = .disabled;
24 lib.use_llvm = false;26 lib.use_llvm = false;
test/link/wasm/type/build.zig+6-4
...@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {...@@ -15,10 +15,12 @@ pub fn build(b: *std.Build) void {
15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {15fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
16 const exe = b.addExecutable(.{16 const exe = b.addExecutable(.{
17 .name = "lib",17 .name = "lib",
18 .root_source_file = b.path("lib.zig"),18 .root_module = b.createModule(.{
19 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),19 .root_source_file = b.path("lib.zig"),
20 .optimize = optimize,20 .target = b.resolveTargetQuery(.{ .cpu_arch = .wasm32, .os_tag = .freestanding }),
21 .strip = false,21 .optimize = optimize,
22 .strip = false,
23 }),
22 });24 });
23 exe.entry = .disabled;25 exe.entry = .disabled;
24 exe.use_llvm = false;26 exe.use_llvm = false;