authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-12-16 22:26:34+00:00
committergravatar for bratishkaerik@landless-city.netEric Joldasov <bratishkaerik@landless-city.net> 2024-12-18 01:49:13+05:00
log6bd590ad37dcb7e46c8eb78c54e69ad07e5b565e
tree512a9e21385bff95e3357ebad25d67a7d4503076
parent82659c4594d12e5b80d2684320e15ce93eedb966
signaturelock-open Commit is signed but in an unrecognized format.

test-standalone: migrate from deprecated std.Build APIs


56 files changed, 589 insertions(+), 374 deletions(-)

test/standalone/build.zig+5-3
......@@ -47,9 +47,11 @@ pub fn build(b: *std.Build) void {
4747 }) |tool_src_path| {
4848 const tool = b.addTest(.{
4949 .name = std.fs.path.stem(tool_src_path),
50 .root_source_file = b.path(tool_src_path),
51 .optimize = .Debug,
52 .target = tools_target,
50 .root_module = b.createModule(.{
51 .root_source_file = b.path(tool_src_path),
52 .optimize = .Debug,
53 .target = tools_target,
54 }),
5355 });
5456 const run = b.addRunArtifact(tool);
5557 tools_tests_step.dependOn(&run.step);
test/standalone/c_compiler/build.zig+11-8
......@@ -20,22 +20,25 @@ fn add(
2020) void {
2121 const target = b.graph.host;
2222
23 const exe_c = b.addExecutable(.{
24 .name = c_name,
23 const c_mod = b.createModule(.{
2524 .optimize = optimize,
2625 .target = target,
2726 });
28 exe_c.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[0][]const u8{} });
29 exe_c.linkLibC();
27 c_mod.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[0][]const u8{} });
28 c_mod.link_libc = true;
3029
31 const exe_cpp = b.addExecutable(.{
32 .name = cpp_name,
30 const exe_c = b.addExecutable(.{ .name = c_name, .root_module = c_mod });
31
32 const cpp_mod = b.createModule(.{
3333 .optimize = optimize,
3434 .target = target,
3535 });
36 cpp_mod.addCSourceFile(.{ .file = b.path("test.cpp"), .flags = &[0][]const u8{} });
37 cpp_mod.link_libcpp = true;
38
39 const exe_cpp = b.addExecutable(.{ .name = cpp_name, .root_module = cpp_mod });
40
3641 b.default_step.dependOn(&exe_cpp.step);
37 exe_cpp.addCSourceFile(.{ .file = b.path("test.cpp"), .flags = &[0][]const u8{} });
38 exe_cpp.linkLibCpp();
3942
4043 switch (target.result.os.tag) {
4144 .windows => {
test/standalone/child_process/build.zig+10-6
......@@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void {
1212
1313 const child = b.addExecutable(.{
1414 .name = "child",
15 .root_source_file = b.path("child.zig"),
16 .optimize = optimize,
17 .target = target,
15 .root_module = b.createModule(.{
16 .root_source_file = b.path("child.zig"),
17 .optimize = optimize,
18 .target = target,
19 }),
1820 });
1921
2022 const main = b.addExecutable(.{
2123 .name = "main",
22 .root_source_file = b.path("main.zig"),
23 .optimize = optimize,
24 .target = target,
24 .root_module = b.createModule(.{
25 .root_source_file = b.path("main.zig"),
26 .optimize = optimize,
27 .target = target,
28 }),
2529 });
2630 const run = b.addRunArtifact(main);
2731 run.addArtifactArg(child);
test/standalone/coff_dwarf/build.zig+13-8
......@@ -14,19 +14,24 @@ pub fn build(b: *std.Build) void {
1414
1515 const exe = b.addExecutable(.{
1616 .name = "main",
17 .root_source_file = b.path("main.zig"),
18 .optimize = optimize,
19 .target = target,
17 .root_module = b.createModule(.{
18 .root_source_file = b.path("main.zig"),
19 .optimize = optimize,
20 .target = target,
21 }),
2022 });
2123
2224 const lib = b.addSharedLibrary(.{
2325 .name = "shared_lib",
24 .optimize = optimize,
25 .target = target,
26 .root_module = b.createModule(.{
27 .root_source_file = null,
28 .optimize = optimize,
29 .target = target,
30 .link_libc = true,
31 }),
2632 });
27 lib.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} });
28 lib.linkLibC();
29 exe.linkLibrary(lib);
33 lib.root_module.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} });
34 exe.root_module.linkLibrary(lib);
3035
3136 const run = b.addRunArtifact(exe);
3237 run.expectExitCode(0);
test/standalone/compiler_rt_panic/build.zig+7-4
......@@ -12,11 +12,14 @@ pub fn build(b: *std.Build) void {
1212
1313 const exe = b.addExecutable(.{
1414 .name = "main",
15 .optimize = optimize,
16 .target = target,
15 .root_module = b.createModule(.{
16 .root_source_file = null,
17 .optimize = optimize,
18 .target = target,
19 .link_libc = true,
20 }),
1721 });
18 exe.linkLibC();
19 exe.addCSourceFile(.{
22 exe.root_module.addCSourceFile(.{
2023 .file = b.path("main.c"),
2124 .flags = &.{},
2225 });
test/standalone/dep_diamond/build.zig+13-13
......@@ -6,23 +6,23 @@ pub fn build(b: *std.Build) void {
66
77 const optimize: std.builtin.OptimizeMode = .Debug;
88
9 const shared = b.createModule(.{
10 .root_source_file = b.path("shared.zig"),
11 });
12
13 const exe = b.addExecutable(.{
14 .name = "test",
9 const main_mod = b.createModule(.{
1510 .root_source_file = b.path("test.zig"),
1611 .target = b.graph.host,
1712 .optimize = optimize,
1813 });
19 exe.root_module.addAnonymousImport("foo", .{
20 .root_source_file = b.path("foo.zig"),
21 .imports = &.{.{ .name = "shared", .module = shared }},
22 });
23 exe.root_module.addAnonymousImport("bar", .{
24 .root_source_file = b.path("bar.zig"),
25 .imports = &.{.{ .name = "shared", .module = shared }},
14 const shared_mod = b.createModule(.{ .root_source_file = b.path("shared.zig") });
15 const foo_mod = b.createModule(.{ .root_source_file = b.path("foo.zig") });
16 const bar_mod = b.createModule(.{ .root_source_file = b.path("bar.zig") });
17
18 main_mod.addImport("foo", foo_mod);
19 main_mod.addImport("bar", bar_mod);
20 foo_mod.addImport("shared", shared_mod);
21 bar_mod.addImport("shared", shared_mod);
22
23 const exe = b.addExecutable(.{
24 .name = "test",
25 .root_module = main_mod,
2626 });
2727
2828 const run = b.addRunArtifact(exe);
test/standalone/dep_duplicate_module/build.zig+17-10
......@@ -4,29 +4,36 @@ pub fn build(b: *std.Build) void {
44 const target = b.standardTargetOptions(.{});
55 const optimize = b.standardOptimizeOption(.{});
66
7 const mod = b.addModule("mod", .{
7 const shared_mod = b.createModule(.{
88 .root_source_file = b.path("mod.zig"),
99 .target = target,
1010 .optimize = optimize,
1111 });
12
13 const lib = b.addStaticLibrary(.{
14 .name = "lib",
12 const lib_mod = b.createModule(.{
1513 .root_source_file = b.path("lib.zig"),
1614 .target = target,
1715 .optimize = optimize,
1816 });
19 lib.root_module.addImport("mod", mod);
20
21 const exe = b.addExecutable(.{
22 .name = "app",
17 const exe_mod = b.createModule(.{
2318 .root_source_file = b.path("main.zig"),
2419 .target = target,
2520 .optimize = optimize,
2621 });
2722
28 exe.root_module.addImport("mod", mod);
29 exe.root_module.linkLibrary(lib);
23 lib_mod.addImport("mod", shared_mod);
24 exe_mod.addImport("mod", shared_mod);
25
26 const lib = b.addStaticLibrary(.{
27 .name = "lib",
28 .root_module = lib_mod,
29 });
30
31 exe_mod.linkLibrary(lib);
32
33 const exe = b.addExecutable(.{
34 .name = "app",
35 .root_module = exe_mod,
36 });
3037
3138 b.installArtifact(exe);
3239}
test/standalone/dep_lazypath/build.zig+12-7
......@@ -11,10 +11,13 @@ pub fn build(b: *std.Build) void {
1111 const generated_main_c = write_files.add("main.c", "");
1212 const exe = b.addExecutable(.{
1313 .name = "test",
14 .target = b.graph.host,
15 .optimize = optimize,
14 .root_module = b.createModule(.{
15 .root_source_file = null,
16 .target = b.graph.host,
17 .optimize = optimize,
18 }),
1619 });
17 exe.addCSourceFiles(.{
20 exe.root_module.addCSourceFiles(.{
1821 .root = generated_main_c.dirname(),
1922 .files = &.{"main.c"},
2023 });
......@@ -26,11 +29,13 @@ pub fn build(b: *std.Build) void {
2629 const dir = write_files.addCopyDirectory(b.path("inc"), "", .{});
2730 const exe = b.addExecutable(.{
2831 .name = "test",
29 .root_source_file = b.path("inctest.zig"),
30 .target = b.graph.host,
31 .optimize = optimize,
32 .root_module = b.createModule(.{
33 .root_source_file = b.path("inctest.zig"),
34 .target = b.graph.host,
35 .optimize = optimize,
36 }),
3237 });
33 exe.addIncludePath(dir);
38 exe.root_module.addIncludePath(dir);
3439 b.step("copydir", "").dependOn(&exe.step);
3540 test_step.dependOn(&exe.step);
3641 }
test/standalone/dep_mutually_recursive/build.zig+12-8
......@@ -6,22 +6,26 @@ pub fn build(b: *std.Build) void {
66
77 const optimize: std.builtin.OptimizeMode = .Debug;
88
9 const foo = b.createModule(.{
9 const main_mod = b.createModule(.{
10 .root_source_file = b.path("test.zig"),
11 .target = b.graph.host,
12 .optimize = optimize,
13 });
14 const foo_mod = b.createModule(.{
1015 .root_source_file = b.path("foo.zig"),
1116 });
12 const bar = b.createModule(.{
17 const bar_mod = b.createModule(.{
1318 .root_source_file = b.path("bar.zig"),
1419 });
15 foo.addImport("bar", bar);
16 bar.addImport("foo", foo);
20
21 main_mod.addImport("foo", foo_mod);
22 foo_mod.addImport("bar", bar_mod);
23 bar_mod.addImport("foo", foo_mod);
1724
1825 const exe = b.addExecutable(.{
1926 .name = "test",
20 .root_source_file = b.path("test.zig"),
21 .target = b.graph.host,
22 .optimize = optimize,
27 .root_module = main_mod,
2328 });
24 exe.root_module.addImport("foo", foo);
2529
2630 const run = b.addRunArtifact(exe);
2731 test_step.dependOn(&run.step);
test/standalone/dep_recursive/build.zig+10-6
......@@ -6,18 +6,22 @@ pub fn build(b: *std.Build) void {
66
77 const optimize: std.builtin.OptimizeMode = .Debug;
88
9 const foo = b.createModule(.{
9 const main_mod = b.createModule(.{
10 .root_source_file = b.path("test.zig"),
11 .target = b.graph.host,
12 .optimize = optimize,
13 });
14 const foo_mod = b.createModule(.{
1015 .root_source_file = b.path("foo.zig"),
1116 });
12 foo.addImport("foo", foo);
17
18 main_mod.addImport("foo", foo_mod);
19 foo_mod.addImport("foo", foo_mod);
1320
1421 const exe = b.addExecutable(.{
1522 .name = "test",
16 .root_source_file = b.path("test.zig"),
17 .target = b.graph.host,
18 .optimize = optimize,
23 .root_module = main_mod,
1924 });
20 exe.root_module.addImport("foo", foo);
2125
2226 const run = b.addRunArtifact(exe);
2327 test_step.dependOn(&run.step);
test/standalone/dep_shared_builtin/build.zig+9-3
......@@ -6,16 +6,22 @@ pub fn build(b: *std.Build) void {
66
77 const optimize: std.builtin.OptimizeMode = .Debug;
88
9 const exe = b.addExecutable(.{
10 .name = "test",
9 const main_mod = b.createModule(.{
1110 .root_source_file = b.path("test.zig"),
1211 .target = b.graph.host,
1312 .optimize = optimize,
1413 });
15 exe.root_module.addAnonymousImport("foo", .{
14 const foo_mod = b.createModule(.{
1615 .root_source_file = b.path("foo.zig"),
1716 });
1817
18 main_mod.addImport("foo", foo_mod);
19
20 const exe = b.addExecutable(.{
21 .name = "test",
22 .root_module = main_mod,
23 });
24
1925 const run = b.addRunArtifact(exe);
2026 test_step.dependOn(&run.step);
2127}
test/standalone/dep_triangle/build.zig+14-9
......@@ -6,21 +6,26 @@ pub fn build(b: *std.Build) void {
66
77 const optimize: std.builtin.OptimizeMode = .Debug;
88
9 const shared = b.createModule(.{
10 .root_source_file = b.path("shared.zig"),
11 });
12
13 const exe = b.addExecutable(.{
14 .name = "test",
9 const main_mod = b.createModule(.{
1510 .root_source_file = b.path("test.zig"),
1611 .target = b.graph.host,
1712 .optimize = optimize,
1813 });
19 exe.root_module.addAnonymousImport("foo", .{
14 const foo_mod = b.createModule(.{
2015 .root_source_file = b.path("foo.zig"),
21 .imports = &.{.{ .name = "shared", .module = shared }},
2216 });
23 exe.root_module.addImport("shared", shared);
17 const shared_mod = b.createModule(.{
18 .root_source_file = b.path("shared.zig"),
19 });
20
21 main_mod.addImport("foo", foo_mod);
22 main_mod.addImport("shared", shared_mod);
23 foo_mod.addImport("shared", shared_mod);
24
25 const exe = b.addExecutable(.{
26 .name = "test",
27 .root_module = main_mod,
28 });
2429
2530 const run = b.addRunArtifact(exe);
2631 test_step.dependOn(&run.step);
test/standalone/depend_on_main_mod/build.zig+9-6
......@@ -7,19 +7,22 @@ pub fn build(b: *std.Build) void {
77 const target = b.standardTargetOptions(.{});
88 const optimize = b.standardOptimizeOption(.{});
99
10 const exe = b.addExecutable(.{
11 .name = "depend_on_main_mod",
10 const main_mod = b.createModule(.{
1211 .root_source_file = b.path("src/main.zig"),
1312 .target = target,
1413 .optimize = optimize,
1514 });
16
17 const foo_module = b.addModule("foo", .{
15 const foo_mod = b.createModule(.{
1816 .root_source_file = b.path("src/foo.zig"),
1917 });
2018
21 foo_module.addImport("root2", exe.root_module);
22 exe.root_module.addImport("foo", foo_module);
19 foo_mod.addImport("root2", main_mod);
20 main_mod.addImport("foo", foo_mod);
21
22 const exe = b.addExecutable(.{
23 .name = "depend_on_main_mod",
24 .root_module = main_mod,
25 });
2326
2427 const run_cmd = b.addRunArtifact(exe);
2528 run_cmd.expectExitCode(0);
test/standalone/dirname/build.zig+15-9
......@@ -10,24 +10,30 @@ pub fn build(b: *std.Build) void {
1010
1111 const touch = b.addExecutable(.{
1212 .name = "touch",
13 .root_source_file = touch_src,
14 .optimize = .Debug,
15 .target = target,
13 .root_module = b.createModule(.{
14 .root_source_file = touch_src,
15 .optimize = .Debug,
16 .target = target,
17 }),
1618 });
1719 const generated = b.addRunArtifact(touch).addOutputFileArg("subdir" ++ std.fs.path.sep_str ++ "generated.txt");
1820
1921 const exists_in = b.addExecutable(.{
2022 .name = "exists_in",
21 .root_source_file = b.path("exists_in.zig"),
22 .optimize = .Debug,
23 .target = target,
23 .root_module = b.createModule(.{
24 .root_source_file = b.path("exists_in.zig"),
25 .optimize = .Debug,
26 .target = target,
27 }),
2428 });
2529
2630 const has_basename = b.addExecutable(.{
2731 .name = "has_basename",
28 .root_source_file = b.path("has_basename.zig"),
29 .optimize = .Debug,
30 .target = target,
32 .root_module = b.createModule(.{
33 .root_source_file = b.path("has_basename.zig"),
34 .optimize = .Debug,
35 .target = target,
36 }),
3137 });
3238
3339 // Known path:
test/standalone/embed_generated_file/build.zig+10-7
......@@ -6,18 +6,21 @@ pub fn build(b: *std.Build) void {
66
77 const bootloader = b.addExecutable(.{
88 .name = "bootloader",
9 .root_source_file = b.path("bootloader.zig"),
10 .target = b.resolveTargetQuery(.{
11 .cpu_arch = .x86,
12 .os_tag = .freestanding,
9 .root_module = b.createModule(.{
10 .root_source_file = b.path("bootloader.zig"),
11 .target = b.resolveTargetQuery(.{
12 .cpu_arch = .x86,
13 .os_tag = .freestanding,
14 }),
15 .optimize = .ReleaseSmall,
1316 }),
14 .optimize = .ReleaseSmall,
1517 });
1618
17 const exe = b.addTest(.{
19 const exe = b.addTest(.{ .root_module = b.createModule(.{
1820 .root_source_file = b.path("main.zig"),
21 .target = b.graph.host,
1922 .optimize = .Debug,
20 });
23 }) });
2124 exe.root_module.addAnonymousImport("bootloader.elf", .{
2225 .root_source_file = bootloader.getEmittedBin(),
2326 });
test/standalone/emit_asm_and_bin/build.zig+3-2
......@@ -4,10 +4,11 @@ pub fn build(b: *std.Build) void {
44 const test_step = b.step("test", "Test it");
55 b.default_step = test_step;
66
7 const main = b.addTest(.{
7 const main = b.addTest(.{ .root_module = b.createModule(.{
88 .root_source_file = b.path("main.zig"),
9 .target = b.graph.host,
910 .optimize = b.standardOptimizeOption(.{}),
10 });
11 }) });
1112 // TODO: actually check these two artifacts for correctness
1213 _ = main.getEmittedBin();
1314 _ = main.getEmittedAsm();
test/standalone/emit_asm_no_bin/build.zig+5-3
......@@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void {
88
99 const obj = b.addObject(.{
1010 .name = "main",
11 .root_source_file = b.path("main.zig"),
12 .optimize = optimize,
13 .target = b.graph.host,
11 .root_module = b.createModule(.{
12 .root_source_file = b.path("main.zig"),
13 .optimize = optimize,
14 .target = b.graph.host,
15 }),
1416 });
1517 _ = obj.getEmittedAsm();
1618 b.default_step.dependOn(&obj.step);
test/standalone/emit_llvm_no_bin/build.zig+5-3
......@@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void {
88
99 const obj = b.addObject(.{
1010 .name = "main",
11 .root_source_file = b.path("main.zig"),
12 .optimize = optimize,
13 .target = b.graph.host,
11 .root_module = b.createModule(.{
12 .root_source_file = b.path("main.zig"),
13 .optimize = optimize,
14 .target = b.graph.host,
15 }),
1416 });
1517 _ = obj.getEmittedLlvmIr();
1618 _ = obj.getEmittedLlvmBc();
test/standalone/empty_env/build.zig+5-3
......@@ -21,9 +21,11 @@ pub fn build(b: *std.Build) void {
2121
2222 const main = b.addExecutable(.{
2323 .name = "main",
24 .root_source_file = b.path("main.zig"),
25 .target = b.graph.host,
26 .optimize = optimize,
24 .root_module = b.createModule(.{
25 .root_source_file = b.path("main.zig"),
26 .target = b.graph.host,
27 .optimize = optimize,
28 }),
2729 });
2830
2931 const run = b.addRunArtifact(main);
test/standalone/extern/build.zig+15-9
......@@ -8,22 +8,28 @@ pub fn build(b: *std.Build) void {
88
99 const obj = b.addObject(.{
1010 .name = "exports",
11 .root_source_file = b.path("exports.zig"),
12 .target = b.graph.host,
13 .optimize = optimize,
11 .root_module = b.createModule(.{
12 .root_source_file = b.path("exports.zig"),
13 .target = b.graph.host,
14 .optimize = optimize,
15 }),
1416 });
1517 const shared = b.addSharedLibrary(.{
1618 .name = "shared",
17 .target = b.graph.host,
18 .optimize = optimize,
19 .link_libc = true,
19 .root_module = b.createModule(.{
20 .root_source_file = null,
21 .target = b.graph.host,
22 .optimize = optimize,
23 .link_libc = true,
24 }),
2025 });
2126 if (b.graph.host.result.abi == .msvc) shared.root_module.addCMacro("API", "__declspec(dllexport)");
22 shared.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} });
23 const test_exe = b.addTest(.{
27 shared.root_module.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} });
28 const test_exe = b.addTest(.{ .root_module = b.createModule(.{
2429 .root_source_file = b.path("main.zig"),
30 .target = b.graph.host,
2531 .optimize = optimize,
26 });
32 }) });
2733 test_exe.addObject(obj);
2834 test_exe.linkLibrary(shared);
2935
test/standalone/global_linkage/build.zig+15-9
......@@ -9,24 +9,30 @@ pub fn build(b: *std.Build) void {
99
1010 const obj1 = b.addStaticLibrary(.{
1111 .name = "obj1",
12 .root_source_file = b.path("obj1.zig"),
13 .optimize = optimize,
14 .target = target,
12 .root_module = b.createModule(.{
13 .root_source_file = b.path("obj1.zig"),
14 .optimize = optimize,
15 .target = target,
16 }),
1517 });
1618
1719 const obj2 = b.addStaticLibrary(.{
1820 .name = "obj2",
19 .root_source_file = b.path("obj2.zig"),
20 .optimize = optimize,
21 .target = target,
21 .root_module = b.createModule(.{
22 .root_source_file = b.path("obj2.zig"),
23 .optimize = optimize,
24 .target = target,
25 }),
2226 });
2327
24 const main = b.addTest(.{
28 const main_mod = b.createModule(.{
2529 .root_source_file = b.path("main.zig"),
30 .target = b.graph.host,
2631 .optimize = optimize,
2732 });
28 main.linkLibrary(obj1);
29 main.linkLibrary(obj2);
33 main_mod.linkLibrary(obj1);
34 main_mod.linkLibrary(obj2);
3035
36 const main = b.addTest(.{ .root_module = main_mod });
3137 test_step.dependOn(&b.addRunArtifact(main).step);
3238}
test/standalone/install_headers/build.zig+27-15
......@@ -8,18 +8,24 @@ pub fn build(b: *std.Build) void {
88
99 const libfoo = b.addStaticLibrary(.{
1010 .name = "foo",
11 .target = b.resolveTargetQuery(.{}),
12 .optimize = .Debug,
11 .root_module = b.createModule(.{
12 .root_source_file = null,
13 .target = b.resolveTargetQuery(.{}),
14 .optimize = .Debug,
15 }),
1316 });
14 libfoo.addCSourceFile(.{ .file = empty_c });
17 libfoo.root_module.addCSourceFile(.{ .file = empty_c });
1518
1619 const exe = b.addExecutable(.{
1720 .name = "exe",
18 .target = b.resolveTargetQuery(.{}),
19 .optimize = .Debug,
20 .link_libc = true,
21 .root_module = b.createModule(.{
22 .root_source_file = null,
23 .target = b.resolveTargetQuery(.{}),
24 .optimize = .Debug,
25 .link_libc = true,
26 }),
2127 });
22 exe.addCSourceFile(.{ .file = b.addWriteFiles().add("main.c",
28 exe.root_module.addCSourceFile(.{ .file = b.addWriteFiles().add("main.c",
2329 \\#include <stdio.h>
2430 \\#include <foo/a.h>
2531 \\#include <foo/sub_dir/b.h>
......@@ -40,9 +46,10 @@ pub fn build(b: *std.Build) void {
4046
4147 if (libfoo.installed_headers_include_tree != null) std.debug.panic("include tree step was created before linking", .{});
4248
43 // Link before we have registered all headers for installation,
49 // Link (and get the include tree) before we have registered all headers for installation,
4450 // to verify that the lazily created write files step is properly taken into account.
45 exe.linkLibrary(libfoo);
51 exe.root_module.linkLibrary(libfoo);
52 _ = libfoo.getEmittedIncludeTree();
4653
4754 if (libfoo.installed_headers_include_tree == null) std.debug.panic("include tree step was not created after linking", .{});
4855
......@@ -56,10 +63,13 @@ pub fn build(b: *std.Build) void {
5663
5764 const libbar = b.addStaticLibrary(.{
5865 .name = "bar",
59 .target = b.resolveTargetQuery(.{}),
60 .optimize = .Debug,
66 .root_module = b.createModule(.{
67 .root_source_file = null,
68 .target = b.resolveTargetQuery(.{}),
69 .optimize = .Debug,
70 }),
6171 });
62 libbar.addCSourceFile(.{ .file = empty_c });
72 libbar.root_module.addCSourceFile(.{ .file = empty_c });
6373 libbar.installHeader(b.addWriteFiles().add("bar.h",
6474 \\#define BAR_X "X"
6575 \\
......@@ -78,9 +88,11 @@ pub fn build(b: *std.Build) void {
7888 });
7989 const check_exists = b.addExecutable(.{
8090 .name = "check_exists",
81 .root_source_file = b.path("check_exists.zig"),
82 .target = b.resolveTargetQuery(.{}),
83 .optimize = .Debug,
91 .root_module = b.createModule(.{
92 .root_source_file = b.path("check_exists.zig"),
93 .target = b.resolveTargetQuery(.{}),
94 .optimize = .Debug,
95 }),
8496 });
8597 const run_check_exists = b.addRunArtifact(check_exists);
8698 run_check_exists.addArgs(&.{
test/standalone/install_raw_hex/build.zig+5-3
......@@ -16,9 +16,11 @@ pub fn build(b: *std.Build) void {
1616
1717 const elf = b.addExecutable(.{
1818 .name = "zig-nrf52-blink.elf",
19 .root_source_file = b.path("main.zig"),
20 .target = target,
21 .optimize = optimize,
19 .root_module = b.createModule(.{
20 .root_source_file = b.path("main.zig"),
21 .target = target,
22 .optimize = optimize,
23 }),
2224 });
2325
2426 const hex_step = elf.addObjCopy(.{
test/standalone/ios/build.zig+12-9
......@@ -18,16 +18,19 @@ pub fn build(b: *std.Build) void {
1818
1919 const exe = b.addExecutable(.{
2020 .name = "main",
21 .optimize = optimize,
22 .target = target,
21 .root_module = b.createModule(.{
22 .root_source_file = null,
23 .optimize = optimize,
24 .target = target,
25 .link_libc = true,
26 }),
2327 });
24 exe.addCSourceFile(.{ .file = b.path("main.m"), .flags = &.{} });
25 exe.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) });
26 exe.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) });
27 exe.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/lib" }) });
28 exe.linkFramework("Foundation");
29 exe.linkFramework("UIKit");
30 exe.linkLibC();
28 exe.root_module.addCSourceFile(.{ .file = b.path("main.m"), .flags = &.{} });
29 exe.root_module.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) });
30 exe.root_module.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) });
31 exe.root_module.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/lib" }) });
32 exe.root_module.linkFramework("Foundation", .{});
33 exe.root_module.linkFramework("UIKit", .{});
3134
3235 const check = exe.checkObject();
3336 check.checkInHeaders();
test/standalone/issue_11595/build.zig+7-5
......@@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
1515
1616 const exe = b.addExecutable(.{
1717 .name = "zigtest",
18 .root_source_file = b.path("main.zig"),
19 .target = target,
20 .optimize = optimize,
18 .root_module = b.createModule(.{
19 .root_source_file = b.path("main.zig"),
20 .target = target,
21 .optimize = optimize,
22 }),
2123 });
2224 b.installArtifact(exe);
2325
......@@ -25,8 +27,8 @@ pub fn build(b: *std.Build) void {
2527 "test.c",
2628 };
2729
28 exe.addCSourceFiles(.{ .files = &c_sources });
29 exe.linkLibC();
30 exe.root_module.addCSourceFiles(.{ .files = &c_sources });
31 exe.root_module.link_libc = true;
3032
3133 var i: i32 = 0;
3234 while (i < 1000) : (i += 1) {
test/standalone/issue_12706/build.zig+7-5
......@@ -10,16 +10,18 @@ pub fn build(b: *std.Build) void {
1010
1111 const exe = b.addExecutable(.{
1212 .name = "main",
13 .root_source_file = b.path("main.zig"),
14 .optimize = optimize,
15 .target = target,
13 .root_module = b.createModule(.{
14 .root_source_file = b.path("main.zig"),
15 .optimize = optimize,
16 .target = target,
17 }),
1618 });
1719
1820 const c_sources = [_][]const u8{
1921 "test.c",
2022 };
21 exe.addCSourceFiles(.{ .files = &c_sources });
22 exe.linkLibC();
23 exe.root_module.addCSourceFiles(.{ .files = &c_sources });
24 exe.root_module.link_libc = true;
2325
2426 const run_cmd = b.addRunArtifact(exe);
2527 run_cmd.expectExitCode(0);
test/standalone/issue_13970/build.zig+12-3
......@@ -5,15 +5,24 @@ pub fn build(b: *std.Build) void {
55 b.default_step = test_step;
66
77 const test1 = b.addTest(.{
8 .root_source_file = b.path("test_root/empty.zig"),
8 .root_module = b.createModule(.{
9 .root_source_file = b.path("test_root/empty.zig"),
10 .target = b.graph.host,
11 }),
912 .test_runner = "src/main.zig",
1013 });
1114 const test2 = b.addTest(.{
12 .root_source_file = b.path("src/empty.zig"),
15 .root_module = b.createModule(.{
16 .root_source_file = b.path("src/empty.zig"),
17 .target = b.graph.host,
18 }),
1319 .test_runner = "src/main.zig",
1420 });
1521 const test3 = b.addTest(.{
16 .root_source_file = b.path("empty.zig"),
22 .root_module = b.createModule(.{
23 .root_source_file = b.path("empty.zig"),
24 .target = b.graph.host,
25 }),
1726 .test_runner = "src/main.zig",
1827 });
1928
test/standalone/issue_339/build.zig+5-3
......@@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void {
99
1010 const obj = b.addObject(.{
1111 .name = "test",
12 .root_source_file = b.path("test.zig"),
13 .target = target,
14 .optimize = optimize,
12 .root_module = b.createModule(.{
13 .root_source_file = b.path("test.zig"),
14 .target = target,
15 .optimize = optimize,
16 }),
1517 });
1618
1719 // TODO: actually check the output
test/standalone/issue_5825/build.zig+13-8
......@@ -16,20 +16,25 @@ pub fn build(b: *std.Build) void {
1616 const optimize: std.builtin.OptimizeMode = .Debug;
1717 const obj = b.addObject(.{
1818 .name = "issue_5825",
19 .root_source_file = b.path("main.zig"),
20 .optimize = optimize,
21 .target = target,
19 .root_module = b.createModule(.{
20 .root_source_file = b.path("main.zig"),
21 .optimize = optimize,
22 .target = target,
23 }),
2224 });
2325
2426 const exe = b.addExecutable(.{
2527 .name = "issue_5825",
26 .optimize = optimize,
27 .target = target,
28 .root_module = b.createModule(.{
29 .root_source_file = null,
30 .optimize = optimize,
31 .target = target,
32 }),
2833 });
2934 exe.subsystem = .Console;
30 exe.linkSystemLibrary("kernel32");
31 exe.linkSystemLibrary("ntdll");
32 exe.addObject(obj);
35 exe.root_module.linkSystemLibrary("kernel32", .{});
36 exe.root_module.linkSystemLibrary("ntdll", .{});
37 exe.root_module.addObject(obj);
3338
3439 // TODO: actually check the output
3540 _ = exe.getEmittedBin();
test/standalone/issue_794/build.zig+3-2
......@@ -4,9 +4,10 @@ pub fn build(b: *std.Build) void {
44 const test_step = b.step("test", "Test it");
55 b.default_step = test_step;
66
7 const test_artifact = b.addTest(.{
7 const test_artifact = b.addTest(.{ .root_module = b.createModule(.{
88 .root_source_file = b.path("main.zig"),
9 });
9 .target = b.graph.host,
10 }) });
1011 test_artifact.addIncludePath(b.path("a_directory"));
1112
1213 // TODO: actually check the output
test/standalone/issue_8550/build.zig+6-4
......@@ -15,11 +15,13 @@ pub fn build(b: *std.Build) !void {
1515
1616 const kernel = b.addExecutable(.{
1717 .name = "kernel",
18 .root_source_file = b.path("./main.zig"),
19 .optimize = optimize,
20 .target = target,
18 .root_module = b.createModule(.{
19 .root_source_file = b.path("./main.zig"),
20 .optimize = optimize,
21 .target = target,
22 }),
2123 });
22 kernel.addObjectFile(b.path("./boot.S"));
24 kernel.root_module.addObjectFile(b.path("./boot.S"));
2325 kernel.setLinkerScript(b.path("./linker.ld"));
2426 b.installArtifact(kernel);
2527
test/standalone/libcxx/build.zig+15-11
......@@ -11,12 +11,14 @@ pub fn build(b: *std.Build) void {
1111 {
1212 const exe = b.addExecutable(.{
1313 .name = "mt",
14 .root_source_file = b.path("mt.zig"),
15 .target = target,
16 .optimize = optimize,
14 .root_module = b.createModule(.{
15 .root_source_file = b.path("mt.zig"),
16 .target = target,
17 .optimize = optimize,
18 .link_libcpp = true,
19 }),
1720 });
18 exe.linkLibCpp();
19 exe.addCSourceFile(.{ .file = b.path("mt_doit.cpp") });
21 exe.root_module.addCSourceFile(.{ .file = b.path("mt_doit.cpp") });
2022 link_step.dependOn(&exe.step);
2123 b.installArtifact(exe);
2224 run_step.dependOn(&b.addRunArtifact(exe).step);
......@@ -24,13 +26,15 @@ pub fn build(b: *std.Build) void {
2426 {
2527 const exe = b.addExecutable(.{
2628 .name = "st",
27 .root_source_file = b.path("st.zig"),
28 .target = target,
29 .optimize = optimize,
30 .single_threaded = true,
29 .root_module = b.createModule(.{
30 .root_source_file = b.path("st.zig"),
31 .target = target,
32 .optimize = optimize,
33 .link_libcpp = true,
34 .single_threaded = true,
35 }),
3136 });
32 exe.linkLibCpp();
33 exe.addCSourceFile(.{ .file = b.path("st_doit.cpp") });
37 exe.root_module.addCSourceFile(.{ .file = b.path("st_doit.cpp") });
3438 link_step.dependOn(&exe.step);
3539 b.installArtifact(exe);
3640 run_step.dependOn(&b.addRunArtifact(exe).step);
test/standalone/load_dynamic_library/build.zig+10-6
......@@ -12,17 +12,21 @@ pub fn build(b: *std.Build) void {
1212
1313 const lib = b.addSharedLibrary(.{
1414 .name = "add",
15 .root_source_file = b.path("add.zig"),
1615 .version = .{ .major = 1, .minor = 0, .patch = 0 },
17 .optimize = optimize,
18 .target = target,
16 .root_module = b.createModule(.{
17 .root_source_file = b.path("add.zig"),
18 .optimize = optimize,
19 .target = target,
20 }),
1921 });
2022
2123 const main = b.addExecutable(.{
2224 .name = "main",
23 .root_source_file = b.path("main.zig"),
24 .optimize = optimize,
25 .target = target,
25 .root_module = b.createModule(.{
26 .root_source_file = b.path("main.zig"),
27 .optimize = optimize,
28 .target = target,
29 }),
2630 });
2731
2832 const run = b.addRunArtifact(main);
test/standalone/mix_c_files/build.zig+7-5
......@@ -18,12 +18,14 @@ pub fn build(b: *std.Build) void {
1818fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
1919 const exe = b.addExecutable(.{
2020 .name = "test",
21 .root_source_file = b.path("main.zig"),
22 .target = b.graph.host,
23 .optimize = optimize,
21 .root_module = b.createModule(.{
22 .root_source_file = b.path("main.zig"),
23 .target = b.graph.host,
24 .optimize = optimize,
25 .link_libc = true,
26 }),
2427 });
25 exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c11"} });
26 exe.linkLibC();
28 exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c11"} });
2729
2830 const run_cmd = b.addRunArtifact(exe);
2931 run_cmd.skip_foreign_checks = true;
test/standalone/mix_o_files/build.zig+13-8
......@@ -9,22 +9,27 @@ pub fn build(b: *std.Build) void {
99
1010 const obj = b.addObject(.{
1111 .name = "base64",
12 .root_source_file = b.path("base64.zig"),
13 .optimize = optimize,
14 .target = target,
12 .root_module = b.createModule(.{
13 .root_source_file = b.path("base64.zig"),
14 .optimize = optimize,
15 .target = target,
16 }),
1517 });
1618
1719 const exe = b.addExecutable(.{
1820 .name = "test",
19 .optimize = optimize,
20 .target = target,
21 .root_module = b.createModule(.{
22 .root_source_file = null,
23 .optimize = optimize,
24 .target = target,
25 .link_libc = true,
26 }),
2127 });
22 exe.addCSourceFile(.{
28 exe.root_module.addCSourceFile(.{
2329 .file = b.path("test.c"),
2430 .flags = &[_][]const u8{"-std=c99"},
2531 });
26 exe.addObject(obj);
27 exe.linkSystemLibrary("c");
32 exe.root_module.addObject(obj);
2833
2934 b.default_step.dependOn(&exe.step);
3035
test/standalone/options/build.zig+2-2
......@@ -1,11 +1,11 @@
11const std = @import("std");
22
33pub fn build(b: *std.Build) void {
4 const main = b.addTest(.{
4 const main = b.addTest(.{ .root_module = b.createModule(.{
55 .root_source_file = b.path("src/main.zig"),
66 .target = b.graph.host,
77 .optimize = .Debug,
8 });
8 }) });
99
1010 const options = b.addOptions();
1111 main.addOptions("build_options", options);
test/standalone/pie/build.zig+5-3
......@@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void {
1111 });
1212
1313 const main = b.addTest(.{
14 .root_source_file = b.path("main.zig"),
15 .optimize = optimize,
16 .target = target,
14 .root_module = b.createModule(.{
15 .root_source_file = b.path("main.zig"),
16 .optimize = optimize,
17 .target = target,
18 }),
1719 });
1820 main.pie = true;
1921
test/standalone/pkg_import/build.zig+5-3
......@@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void {
88
99 const exe = b.addExecutable(.{
1010 .name = "test",
11 .root_source_file = b.path("test.zig"),
12 .optimize = optimize,
13 .target = b.graph.host,
11 .root_module = b.createModule(.{
12 .root_source_file = b.path("test.zig"),
13 .optimize = optimize,
14 .target = b.graph.host,
15 }),
1416 });
1517 exe.root_module.addAnonymousImport("my_pkg", .{ .root_source_file = b.path("pkg.zig") });
1618
test/standalone/run_output_caching/build.zig+5-3
......@@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void {
99
1010 const exe = b.addExecutable(.{
1111 .name = "create-file",
12 .root_source_file = b.path("main.zig"),
13 .target = target,
14 .optimize = optimize,
12 .root_module = b.createModule(.{
13 .root_source_file = b.path("main.zig"),
14 .target = target,
15 .optimize = optimize,
16 }),
1517 });
1618
1719 {
test/standalone/run_output_paths/build.zig+5-3
......@@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void {
99
1010 const create_file_exe = b.addExecutable(.{
1111 .name = "create_file",
12 .root_source_file = b.path("create_file.zig"),
13 .target = target,
14 .optimize = optimize,
12 .root_module = b.createModule(.{
13 .root_source_file = b.path("create_file.zig"),
14 .target = target,
15 .optimize = optimize,
16 }),
1517 });
1618
1719 const create_first = b.addRunArtifact(create_file_exe);
test/standalone/self_exe_symlink/build.zig+10-6
......@@ -15,16 +15,20 @@ pub fn build(b: *std.Build) void {
1515
1616 const main = b.addExecutable(.{
1717 .name = "main",
18 .root_source_file = b.path("main.zig"),
19 .optimize = optimize,
20 .target = target,
18 .root_module = b.createModule(.{
19 .root_source_file = b.path("main.zig"),
20 .optimize = optimize,
21 .target = target,
22 }),
2123 });
2224
2325 const create_symlink_exe = b.addExecutable(.{
2426 .name = "create-symlink",
25 .root_source_file = b.path("create-symlink.zig"),
26 .optimize = optimize,
27 .target = target,
27 .root_module = b.createModule(.{
28 .root_source_file = b.path("create-symlink.zig"),
29 .optimize = optimize,
30 .target = target,
31 }),
2832 });
2933
3034 var run_create_symlink = b.addRunArtifact(create_symlink_exe);
test/standalone/shared_library/build.zig+13-8
......@@ -8,23 +8,28 @@ pub fn build(b: *std.Build) void {
88 const target = b.graph.host;
99 const lib = b.addSharedLibrary(.{
1010 .name = "mathtest",
11 .root_source_file = b.path("mathtest.zig"),
1211 .version = .{ .major = 1, .minor = 0, .patch = 0 },
13 .target = target,
14 .optimize = optimize,
12 .root_module = b.createModule(.{
13 .root_source_file = b.path("mathtest.zig"),
14 .target = target,
15 .optimize = optimize,
16 }),
1517 });
1618
1719 const exe = b.addExecutable(.{
1820 .name = "test",
19 .target = target,
20 .optimize = optimize,
21 .root_module = b.createModule(.{
22 .root_source_file = null,
23 .target = target,
24 .optimize = optimize,
25 .link_libc = true,
26 }),
2127 });
22 exe.addCSourceFile(.{
28 exe.root_module.addCSourceFile(.{
2329 .file = b.path("test.c"),
2430 .flags = &[_][]const u8{"-std=c99"},
2531 });
26 exe.linkLibrary(lib);
27 exe.linkSystemLibrary("c");
32 exe.root_module.linkLibrary(lib);
2833
2934 const run_cmd = b.addRunArtifact(exe);
3035 test_step.dependOn(&run_cmd.step);
test/standalone/simple/build.zig+12-8
......@@ -42,11 +42,13 @@ pub fn build(b: *std.Build) void {
4242 if (case.is_exe) {
4343 const exe = b.addExecutable(.{
4444 .name = std.fs.path.stem(case.src_path),
45 .root_source_file = b.path(case.src_path),
46 .optimize = optimize,
47 .target = resolved_target,
45 .root_module = b.createModule(.{
46 .root_source_file = b.path(case.src_path),
47 .optimize = optimize,
48 .target = resolved_target,
49 }),
4850 });
49 if (case.link_libc) exe.linkLibC();
51 if (case.link_libc) exe.root_module.link_libc = true;
5052
5153 _ = exe.getEmittedBin();
5254
......@@ -56,11 +58,13 @@ pub fn build(b: *std.Build) void {
5658 if (case.is_test) {
5759 const exe = b.addTest(.{
5860 .name = std.fs.path.stem(case.src_path),
59 .root_source_file = b.path(case.src_path),
60 .optimize = optimize,
61 .target = resolved_target,
61 .root_module = b.createModule(.{
62 .root_source_file = b.path(case.src_path),
63 .optimize = optimize,
64 .target = resolved_target,
65 }),
6266 });
63 if (case.link_libc) exe.linkLibC();
67 if (case.link_libc) exe.root_module.link_libc = true;
6468
6569 const run = b.addRunArtifact(exe);
6670 step.dependOn(&run.step);
test/standalone/stack_iterator/build.zig+38-27
......@@ -20,11 +20,13 @@ pub fn build(b: *std.Build) void {
2020 {
2121 const exe = b.addExecutable(.{
2222 .name = "unwind_fp",
23 .root_source_file = b.path("unwind.zig"),
24 .target = target,
25 .optimize = optimize,
26 .unwind_tables = if (target.result.isDarwin()) .@"async" else null,
27 .omit_frame_pointer = false,
23 .root_module = b.createModule(.{
24 .root_source_file = b.path("unwind.zig"),
25 .target = target,
26 .optimize = optimize,
27 .unwind_tables = if (target.result.isDarwin()) .@"async" else null,
28 .omit_frame_pointer = false,
29 }),
2830 });
2931
3032 const run_cmd = b.addRunArtifact(exe);
......@@ -43,11 +45,13 @@ pub fn build(b: *std.Build) void {
4345 {
4446 const exe = b.addExecutable(.{
4547 .name = "unwind_nofp",
46 .root_source_file = b.path("unwind.zig"),
47 .target = target,
48 .optimize = optimize,
49 .unwind_tables = .@"async",
50 .omit_frame_pointer = true,
48 .root_module = b.createModule(.{
49 .root_source_file = b.path("unwind.zig"),
50 .target = target,
51 .optimize = optimize,
52 .unwind_tables = .@"async",
53 .omit_frame_pointer = true,
54 }),
5155 });
5256
5357 const run_cmd = b.addRunArtifact(exe);
......@@ -66,27 +70,32 @@ pub fn build(b: *std.Build) void {
6670 {
6771 const c_shared_lib = b.addSharedLibrary(.{
6872 .name = "c_shared_lib",
69 .target = target,
70 .optimize = optimize,
71 .strip = false,
73 .root_module = b.createModule(.{
74 .root_source_file = null,
75 .target = target,
76 .optimize = optimize,
77 .link_libc = true,
78 .strip = false,
79 }),
7280 });
7381
7482 if (target.result.os.tag == .windows)
7583 c_shared_lib.root_module.addCMacro("LIB_API", "__declspec(dllexport)");
7684
77 c_shared_lib.addCSourceFile(.{
85 c_shared_lib.root_module.addCSourceFile(.{
7886 .file = b.path("shared_lib.c"),
7987 .flags = &.{"-fomit-frame-pointer"},
8088 });
81 c_shared_lib.linkLibC();
8289
8390 const exe = b.addExecutable(.{
8491 .name = "shared_lib_unwind",
85 .root_source_file = b.path("shared_lib_unwind.zig"),
86 .target = target,
87 .optimize = optimize,
88 .unwind_tables = if (target.result.isDarwin()) .@"async" else null,
89 .omit_frame_pointer = true,
92 .root_module = b.createModule(.{
93 .root_source_file = b.path("shared_lib_unwind.zig"),
94 .target = target,
95 .optimize = optimize,
96 .unwind_tables = if (target.result.isDarwin()) .@"async" else null,
97 .omit_frame_pointer = true,
98 }),
9099 });
91100
92101 exe.linkLibrary(c_shared_lib);
......@@ -117,14 +126,16 @@ pub fn build(b: *std.Build) void {
117126 inline for (no_os_targets) |os_tag| {
118127 const exe = b.addExecutable(.{
119128 .name = "unwind_freestanding",
120 .root_source_file = b.path("unwind_freestanding.zig"),
121 .target = b.resolveTargetQuery(.{
122 .cpu_arch = .x86_64,
123 .os_tag = os_tag,
129 .root_module = b.createModule(.{
130 .root_source_file = b.path("unwind_freestanding.zig"),
131 .target = b.resolveTargetQuery(.{
132 .cpu_arch = .x86_64,
133 .os_tag = os_tag,
134 }),
135 .optimize = optimize,
136 .unwind_tables = null,
137 .omit_frame_pointer = false,
124138 }),
125 .optimize = optimize,
126 .unwind_tables = null,
127 .omit_frame_pointer = false,
128139 });
129140
130141 // This "freestanding" binary is runnable because it invokes the
test/standalone/static_c_lib/build.zig+12-8
......@@ -8,18 +8,22 @@ pub fn build(b: *std.Build) void {
88
99 const foo = b.addStaticLibrary(.{
1010 .name = "foo",
11 .optimize = optimize,
12 .target = b.graph.host,
11 .root_module = b.createModule(.{
12 .root_source_file = null,
13 .optimize = optimize,
14 .target = b.graph.host,
15 }),
1316 });
14 foo.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} });
15 foo.addIncludePath(b.path("."));
17 foo.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} });
18 foo.root_module.addIncludePath(b.path("."));
1619
17 const test_exe = b.addTest(.{
20 const test_exe = b.addTest(.{ .root_module = b.createModule(.{
1821 .root_source_file = b.path("foo.zig"),
22 .target = b.graph.host,
1923 .optimize = optimize,
20 });
21 test_exe.linkLibrary(foo);
22 test_exe.addIncludePath(b.path("."));
24 }) });
25 test_exe.root_module.linkLibrary(foo);
26 test_exe.root_module.addIncludePath(b.path("."));
2327
2428 test_step.dependOn(&b.addRunArtifact(test_exe).step);
2529}
test/standalone/strip_empty_loop/build.zig+6-4
......@@ -9,10 +9,12 @@ pub fn build(b: *std.Build) void {
99
1010 const main = b.addExecutable(.{
1111 .name = "main",
12 .root_source_file = b.path("main.zig"),
13 .optimize = optimize,
14 .target = target,
15 .strip = true,
12 .root_module = b.createModule(.{
13 .root_source_file = b.path("main.zig"),
14 .optimize = optimize,
15 .target = target,
16 .strip = true,
17 }),
1618 });
1719
1820 // TODO: actually check the output
test/standalone/strip_struct_init/build.zig+6-3
......@@ -7,9 +7,12 @@ pub fn build(b: *std.Build) void {
77 const optimize: std.builtin.OptimizeMode = .Debug;
88
99 const main = b.addTest(.{
10 .root_source_file = b.path("main.zig"),
11 .optimize = optimize,
12 .strip = true,
10 .root_module = b.createModule(.{
11 .root_source_file = b.path("main.zig"),
12 .target = b.graph.host,
13 .optimize = optimize,
14 .strip = true,
15 }),
1316 });
1417
1518 test_step.dependOn(&b.addRunArtifact(main).step);
test/standalone/test_runner_module_imports/build.zig+10-8
......@@ -1,18 +1,20 @@
11const std = @import("std");
22
33pub fn build(b: *std.Build) void {
4 const t = b.addTest(.{
4 const test_mod = b.createModule(.{
55 .root_source_file = b.path("src/main.zig"),
6 .test_runner = b.path("test_runner/main.zig"),
6 .target = b.graph.host,
77 });
8
98 const module1 = b.createModule(.{ .root_source_file = b.path("module1/main.zig") });
10 const module2 = b.createModule(.{
11 .root_source_file = b.path("module2/main.zig"),
12 .imports = &.{.{ .name = "module1", .module = module1 }},
13 });
9 const module2 = b.createModule(.{ .root_source_file = b.path("module2/main.zig") });
1410
15 t.root_module.addImport("module2", module2);
11 module2.addImport("module1", module1);
12 test_mod.addImport("module2", module2);
13
14 const t = b.addTest(.{
15 .root_module = test_mod,
16 .test_runner = b.path("test_runner/main.zig"),
17 });
1618
1719 const test_step = b.step("test", "Run unit tests");
1820 test_step.dependOn(&b.addRunArtifact(t).step);
test/standalone/test_runner_path/build.zig+3-2
......@@ -6,9 +6,10 @@ pub fn build(b: *std.Build) void {
66 const test_step = b.step("test", "Test the program");
77 b.default_step = test_step;
88
9 const test_exe = b.addTest(.{
9 const test_exe = b.addTest(.{ .root_module = b.createModule(.{
10 .target = b.graph.host,
1011 .root_source_file = b.path("test.zig"),
11 });
12 }) });
1213 test_exe.test_runner = b.path("test_runner.zig");
1314
1415 const test_run = b.addRunArtifact(test_exe);
test/standalone/use_alias/build.zig+4-3
......@@ -6,11 +6,12 @@ pub fn build(b: *std.Build) void {
66
77 const optimize: std.builtin.OptimizeMode = .Debug;
88
9 const main = b.addTest(.{
9 const main = b.addTest(.{ .root_module = b.createModule(.{
1010 .root_source_file = b.path("main.zig"),
11 .target = b.graph.host,
1112 .optimize = optimize,
12 });
13 main.addIncludePath(b.path("."));
13 }) });
14 main.root_module.addIncludePath(b.path("."));
1415
1516 test_step.dependOn(&b.addRunArtifact(main).step);
1617}
test/standalone/windows_argv/build.zig+35-23
......@@ -11,32 +11,39 @@ pub fn build(b: *std.Build) !void {
1111
1212 const lib_gnu = b.addStaticLibrary(.{
1313 .name = "toargv-gnu",
14 .root_source_file = b.path("lib.zig"),
15 .target = b.resolveTargetQuery(.{
16 .abi = .gnu,
14 .root_module = b.createModule(.{
15 .root_source_file = b.path("lib.zig"),
16 .target = b.resolveTargetQuery(.{
17 .abi = .gnu,
18 }),
19 .optimize = optimize,
1720 }),
18 .optimize = optimize,
1921 });
2022 const verify_gnu = b.addExecutable(.{
2123 .name = "verify-gnu",
22 .target = b.resolveTargetQuery(.{
23 .abi = .gnu,
24 .root_module = b.createModule(.{
25 .root_source_file = null,
26 .target = b.resolveTargetQuery(.{
27 .abi = .gnu,
28 }),
29 .optimize = optimize,
2430 }),
25 .optimize = optimize,
2631 });
27 verify_gnu.addCSourceFile(.{
32 verify_gnu.root_module.addCSourceFile(.{
2833 .file = b.path("verify.c"),
2934 .flags = &.{ "-DUNICODE", "-D_UNICODE" },
3035 });
3136 verify_gnu.mingw_unicode_entry_point = true;
32 verify_gnu.linkLibrary(lib_gnu);
33 verify_gnu.linkLibC();
37 verify_gnu.root_module.linkLibrary(lib_gnu);
38 verify_gnu.root_module.link_libc = true;
3439
3540 const fuzz = b.addExecutable(.{
3641 .name = "fuzz",
37 .root_source_file = b.path("fuzz.zig"),
38 .target = b.graph.host,
39 .optimize = optimize,
42 .root_module = b.createModule(.{
43 .root_source_file = b.path("fuzz.zig"),
44 .target = b.graph.host,
45 .optimize = optimize,
46 }),
4047 });
4148
4249 const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100;
......@@ -69,25 +76,30 @@ pub fn build(b: *std.Build) !void {
6976 if (has_msvc) {
7077 const lib_msvc = b.addStaticLibrary(.{
7178 .name = "toargv-msvc",
72 .root_source_file = b.path("lib.zig"),
73 .target = b.resolveTargetQuery(.{
74 .abi = .msvc,
79 .root_module = b.createModule(.{
80 .root_source_file = b.path("lib.zig"),
81 .target = b.resolveTargetQuery(.{
82 .abi = .msvc,
83 }),
84 .optimize = optimize,
7585 }),
76 .optimize = optimize,
7786 });
7887 const verify_msvc = b.addExecutable(.{
7988 .name = "verify-msvc",
80 .target = b.resolveTargetQuery(.{
81 .abi = .msvc,
89 .root_module = b.createModule(.{
90 .root_source_file = null,
91 .target = b.resolveTargetQuery(.{
92 .abi = .msvc,
93 }),
94 .optimize = optimize,
8295 }),
83 .optimize = optimize,
8496 });
85 verify_msvc.addCSourceFile(.{
97 verify_msvc.root_module.addCSourceFile(.{
8698 .file = b.path("verify.c"),
8799 .flags = &.{ "-DUNICODE", "-D_UNICODE" },
88100 });
89 verify_msvc.linkLibrary(lib_msvc);
90 verify_msvc.linkLibC();
101 verify_msvc.root_module.linkLibrary(lib_msvc);
102 verify_msvc.root_module.link_libc = true;
91103
92104 const run_msvc = b.addRunArtifact(fuzz);
93105 run_msvc.setName("fuzz-msvc");
test/standalone/windows_bat_args/build.zig+15-9
......@@ -12,16 +12,20 @@ pub fn build(b: *std.Build) !void {
1212
1313 const echo_args = b.addExecutable(.{
1414 .name = "echo-args",
15 .root_source_file = b.path("echo-args.zig"),
16 .optimize = optimize,
17 .target = target,
15 .root_module = b.createModule(.{
16 .root_source_file = b.path("echo-args.zig"),
17 .optimize = optimize,
18 .target = target,
19 }),
1820 });
1921
2022 const test_exe = b.addExecutable(.{
2123 .name = "test",
22 .root_source_file = b.path("test.zig"),
23 .optimize = optimize,
24 .target = target,
24 .root_module = b.createModule(.{
25 .root_source_file = b.path("test.zig"),
26 .optimize = optimize,
27 .target = target,
28 }),
2529 });
2630
2731 const run = b.addRunArtifact(test_exe);
......@@ -33,9 +37,11 @@ pub fn build(b: *std.Build) !void {
3337
3438 const fuzz = b.addExecutable(.{
3539 .name = "fuzz",
36 .root_source_file = b.path("fuzz.zig"),
37 .optimize = optimize,
38 .target = target,
40 .root_module = b.createModule(.{
41 .root_source_file = b.path("fuzz.zig"),
42 .optimize = optimize,
43 .target = target,
44 }),
3945 });
4046
4147 const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100;
test/standalone/windows_entry_points/build.zig+28-16
......@@ -13,11 +13,14 @@ pub fn build(b: *std.Build) void {
1313 {
1414 const exe = b.addExecutable(.{
1515 .name = "main",
16 .target = target,
17 .optimize = .Debug,
18 .link_libc = true,
16 .root_module = b.createModule(.{
17 .root_source_file = null,
18 .target = target,
19 .optimize = .Debug,
20 .link_libc = true,
21 }),
1922 });
20 exe.addCSourceFile(.{ .file = b.path("main.c") });
23 exe.root_module.addCSourceFile(.{ .file = b.path("main.c") });
2124
2225 _ = exe.getEmittedBin();
2326 test_step.dependOn(&exe.step);
......@@ -26,12 +29,15 @@ pub fn build(b: *std.Build) void {
2629 {
2730 const exe = b.addExecutable(.{
2831 .name = "wmain",
29 .target = target,
30 .optimize = .Debug,
31 .link_libc = true,
32 .root_module = b.createModule(.{
33 .root_source_file = null,
34 .target = target,
35 .optimize = .Debug,
36 .link_libc = true,
37 }),
3238 });
3339 exe.mingw_unicode_entry_point = true;
34 exe.addCSourceFile(.{ .file = b.path("wmain.c") });
40 exe.root_module.addCSourceFile(.{ .file = b.path("wmain.c") });
3541
3642 _ = exe.getEmittedBin();
3743 test_step.dependOn(&exe.step);
......@@ -40,12 +46,15 @@ pub fn build(b: *std.Build) void {
4046 {
4147 const exe = b.addExecutable(.{
4248 .name = "winmain",
43 .target = target,
44 .optimize = .Debug,
45 .link_libc = true,
49 .root_module = b.createModule(.{
50 .root_source_file = null,
51 .target = target,
52 .optimize = .Debug,
53 .link_libc = true,
54 }),
4655 });
4756 // Note: `exe.subsystem = .Windows;` is not necessary
48 exe.addCSourceFile(.{ .file = b.path("winmain.c") });
57 exe.root_module.addCSourceFile(.{ .file = b.path("winmain.c") });
4958
5059 _ = exe.getEmittedBin();
5160 test_step.dependOn(&exe.step);
......@@ -54,13 +63,16 @@ pub fn build(b: *std.Build) void {
5463 {
5564 const exe = b.addExecutable(.{
5665 .name = "wwinmain",
57 .target = target,
58 .optimize = .Debug,
59 .link_libc = true,
66 .root_module = b.createModule(.{
67 .root_source_file = null,
68 .target = target,
69 .optimize = .Debug,
70 .link_libc = true,
71 }),
6072 });
6173 exe.mingw_unicode_entry_point = true;
6274 // Note: `exe.subsystem = .Windows;` is not necessary
63 exe.addCSourceFile(.{ .file = b.path("wwinmain.c") });
75 exe.root_module.addCSourceFile(.{ .file = b.path("wwinmain.c") });
6476
6577 _ = exe.getEmittedBin();
6678 test_step.dependOn(&exe.step);
test/standalone/windows_resources/build.zig+6-4
......@@ -28,11 +28,13 @@ fn add(
2828) void {
2929 const exe = b.addExecutable(.{
3030 .name = "zig_resource_test",
31 .root_source_file = b.path("main.zig"),
32 .target = target,
33 .optimize = .Debug,
31 .root_module = b.createModule(.{
32 .root_source_file = b.path("main.zig"),
33 .target = target,
34 .optimize = .Debug,
35 }),
3436 });
35 exe.addWin32ResourceFile(.{
37 exe.root_module.addWin32ResourceFile(.{
3638 .file = b.path("res/zig.rc"),
3739 .flags = &.{"/c65001"}, // UTF-8 code page
3840 .include_paths = &.{
test/standalone/windows_spawn/build.zig+10-6
......@@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void {
1212
1313 const hello = b.addExecutable(.{
1414 .name = "hello",
15 .root_source_file = b.path("hello.zig"),
16 .optimize = optimize,
17 .target = target,
15 .root_module = b.createModule(.{
16 .root_source_file = b.path("hello.zig"),
17 .optimize = optimize,
18 .target = target,
19 }),
1820 });
1921
2022 const main = b.addExecutable(.{
2123 .name = "main",
22 .root_source_file = b.path("main.zig"),
23 .optimize = optimize,
24 .target = target,
24 .root_module = b.createModule(.{
25 .root_source_file = b.path("main.zig"),
26 .optimize = optimize,
27 .target = target,
28 }),
2529 });
2630
2731 const run = b.addRunArtifact(main);
test/standalone/zerolength_check/build.zig+2-2
......@@ -11,7 +11,7 @@ pub fn build(b: *std.Build) void {
1111}
1212
1313fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
14 const unit_tests = b.addTest(.{
14 const unit_tests = b.addTest(.{ .root_module = b.createModule(.{
1515 .root_source_file = b.path("src/main.zig"),
1616 .target = b.resolveTargetQuery(.{
1717 .os_tag = .wasi,
......@@ -19,7 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize
1919 .cpu_features_add = std.Target.wasm.featureSet(&.{.bulk_memory}),
2020 }),
2121 .optimize = optimize,
22 });
22 }) });
2323
2424 const run_unit_tests = b.addRunArtifact(unit_tests);
2525 run_unit_tests.skip_foreign_checks = true;