diff --git a/test/standalone/build.zig b/test/standalone/build.zig index fee8c031619fdb26305b8e53395e1a3104ebe316..f89ccd2a18284efd534873224b5e6b3bd434bb1a 100644 --- a/test/standalone/build.zig +++ b/test/standalone/build.zig @@ -47,9 +47,11 @@ pub fn build(b: *std.Build) void { }) |tool_src_path| { const tool = b.addTest(.{ .name = std.fs.path.stem(tool_src_path), - .root_source_file = b.path(tool_src_path), - .optimize = .Debug, - .target = tools_target, + .root_module = b.createModule(.{ + .root_source_file = b.path(tool_src_path), + .optimize = .Debug, + .target = tools_target, + }), }); const run = b.addRunArtifact(tool); tools_tests_step.dependOn(&run.step); diff --git a/test/standalone/c_compiler/build.zig b/test/standalone/c_compiler/build.zig index 5328d6e01d0e49e98bda6dc4c1b74cec1ad3500e..af9d8b492a3b081e9444524b2ff44a40ab402ab1 100644 --- a/test/standalone/c_compiler/build.zig +++ b/test/standalone/c_compiler/build.zig @@ -20,22 +20,25 @@ fn add( ) void { const target = b.graph.host; - const exe_c = b.addExecutable(.{ - .name = c_name, + const c_mod = b.createModule(.{ .optimize = optimize, .target = target, }); - exe_c.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[0][]const u8{} }); - exe_c.linkLibC(); + c_mod.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[0][]const u8{} }); + c_mod.link_libc = true; - const exe_cpp = b.addExecutable(.{ - .name = cpp_name, + const exe_c = b.addExecutable(.{ .name = c_name, .root_module = c_mod }); + + const cpp_mod = b.createModule(.{ .optimize = optimize, .target = target, }); + cpp_mod.addCSourceFile(.{ .file = b.path("test.cpp"), .flags = &[0][]const u8{} }); + cpp_mod.link_libcpp = true; + + const exe_cpp = b.addExecutable(.{ .name = cpp_name, .root_module = cpp_mod }); + b.default_step.dependOn(&exe_cpp.step); - exe_cpp.addCSourceFile(.{ .file = b.path("test.cpp"), .flags = &[0][]const u8{} }); - exe_cpp.linkLibCpp(); switch (target.result.os.tag) { .windows => { diff --git a/test/standalone/child_process/build.zig b/test/standalone/child_process/build.zig index 0180fb8a83d62cda8a0fdfd039bc494f176e2b18..81b40835f3d7950356a41ec3a723e9913e553745 100644 --- a/test/standalone/child_process/build.zig +++ b/test/standalone/child_process/build.zig @@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void { const child = b.addExecutable(.{ .name = "child", - .root_source_file = b.path("child.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("child.zig"), + .optimize = optimize, + .target = target, + }), }); const main = b.addExecutable(.{ .name = "main", - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .optimize = optimize, + .target = target, + }), }); const run = b.addRunArtifact(main); run.addArtifactArg(child); diff --git a/test/standalone/coff_dwarf/build.zig b/test/standalone/coff_dwarf/build.zig index bb9879d089ddb8f188036025efc68015ce6b63ca..b95ebed80dff67d64ec083106d2537a24cf1fb97 100644 --- a/test/standalone/coff_dwarf/build.zig +++ b/test/standalone/coff_dwarf/build.zig @@ -14,19 +14,24 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "main", - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .optimize = optimize, + .target = target, + }), }); const lib = b.addSharedLibrary(.{ .name = "shared_lib", - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = null, + .optimize = optimize, + .target = target, + .link_libc = true, + }), }); - lib.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} }); - lib.linkLibC(); - exe.linkLibrary(lib); + lib.root_module.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} }); + exe.root_module.linkLibrary(lib); const run = b.addRunArtifact(exe); run.expectExitCode(0); diff --git a/test/standalone/compiler_rt_panic/build.zig b/test/standalone/compiler_rt_panic/build.zig index 93331a028245d686d729141eeeff3d44a58715ef..e25fe0eff78347aec5ab3fed9428bbf1e8608aa5 100644 --- a/test/standalone/compiler_rt_panic/build.zig +++ b/test/standalone/compiler_rt_panic/build.zig @@ -12,11 +12,14 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "main", - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = null, + .optimize = optimize, + .target = target, + .link_libc = true, + }), }); - exe.linkLibC(); - exe.addCSourceFile(.{ + exe.root_module.addCSourceFile(.{ .file = b.path("main.c"), .flags = &.{}, }); diff --git a/test/standalone/dep_diamond/build.zig b/test/standalone/dep_diamond/build.zig index 44338b36d44568b001374b6523afc7651f428af5..ba437c310abd4411db868265be93bc2438929d83 100644 --- a/test/standalone/dep_diamond/build.zig +++ b/test/standalone/dep_diamond/build.zig @@ -6,23 +6,23 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; - const shared = b.createModule(.{ - .root_source_file = b.path("shared.zig"), - }); - - const exe = b.addExecutable(.{ - .name = "test", + const main_mod = b.createModule(.{ .root_source_file = b.path("test.zig"), .target = b.graph.host, .optimize = optimize, }); - exe.root_module.addAnonymousImport("foo", .{ - .root_source_file = b.path("foo.zig"), - .imports = &.{.{ .name = "shared", .module = shared }}, - }); - exe.root_module.addAnonymousImport("bar", .{ - .root_source_file = b.path("bar.zig"), - .imports = &.{.{ .name = "shared", .module = shared }}, + const shared_mod = b.createModule(.{ .root_source_file = b.path("shared.zig") }); + const foo_mod = b.createModule(.{ .root_source_file = b.path("foo.zig") }); + const bar_mod = b.createModule(.{ .root_source_file = b.path("bar.zig") }); + + main_mod.addImport("foo", foo_mod); + main_mod.addImport("bar", bar_mod); + foo_mod.addImport("shared", shared_mod); + bar_mod.addImport("shared", shared_mod); + + const exe = b.addExecutable(.{ + .name = "test", + .root_module = main_mod, }); const run = b.addRunArtifact(exe); diff --git a/test/standalone/dep_duplicate_module/build.zig b/test/standalone/dep_duplicate_module/build.zig index 733d49b91c939c113d38a42bdb7cccdba84ade1a..5974ba9968ffb0406df03030c0cd9086efa67519 100644 --- a/test/standalone/dep_duplicate_module/build.zig +++ b/test/standalone/dep_duplicate_module/build.zig @@ -4,29 +4,36 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const mod = b.addModule("mod", .{ + const shared_mod = b.createModule(.{ .root_source_file = b.path("mod.zig"), .target = target, .optimize = optimize, }); + const lib_mod = b.createModule(.{ + .root_source_file = b.path("lib.zig"), + .target = target, + .optimize = optimize, + }); + const exe_mod = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .target = target, + .optimize = optimize, + }); + + lib_mod.addImport("mod", shared_mod); + exe_mod.addImport("mod", shared_mod); const lib = b.addStaticLibrary(.{ .name = "lib", - .root_source_file = b.path("lib.zig"), - .target = target, - .optimize = optimize, + .root_module = lib_mod, }); - lib.root_module.addImport("mod", mod); + + exe_mod.linkLibrary(lib); const exe = b.addExecutable(.{ .name = "app", - .root_source_file = b.path("main.zig"), - .target = target, - .optimize = optimize, + .root_module = exe_mod, }); - exe.root_module.addImport("mod", mod); - exe.root_module.linkLibrary(lib); - b.installArtifact(exe); } diff --git a/test/standalone/dep_lazypath/build.zig b/test/standalone/dep_lazypath/build.zig index f309487981c796f86ac223a2348aaa13c57806a3..01b4be8fd476a3eb8f0b7a4c91e2e6236c9a923e 100644 --- a/test/standalone/dep_lazypath/build.zig +++ b/test/standalone/dep_lazypath/build.zig @@ -11,10 +11,13 @@ pub fn build(b: *std.Build) void { const generated_main_c = write_files.add("main.c", ""); const exe = b.addExecutable(.{ .name = "test", - .target = b.graph.host, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = b.graph.host, + .optimize = optimize, + }), }); - exe.addCSourceFiles(.{ + exe.root_module.addCSourceFiles(.{ .root = generated_main_c.dirname(), .files = &.{"main.c"}, }); @@ -26,11 +29,13 @@ pub fn build(b: *std.Build) void { const dir = write_files.addCopyDirectory(b.path("inc"), "", .{}); const exe = b.addExecutable(.{ .name = "test", - .root_source_file = b.path("inctest.zig"), - .target = b.graph.host, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("inctest.zig"), + .target = b.graph.host, + .optimize = optimize, + }), }); - exe.addIncludePath(dir); + exe.root_module.addIncludePath(dir); b.step("copydir", "").dependOn(&exe.step); test_step.dependOn(&exe.step); } diff --git a/test/standalone/dep_mutually_recursive/build.zig b/test/standalone/dep_mutually_recursive/build.zig index 0dc739b7aff081bc71b9f8e734143e1ce8215d53..f333c1917a4798b3b09aa56732b3486e7c49008a 100644 --- a/test/standalone/dep_mutually_recursive/build.zig +++ b/test/standalone/dep_mutually_recursive/build.zig @@ -6,22 +6,26 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; - const foo = b.createModule(.{ + const main_mod = b.createModule(.{ + .root_source_file = b.path("test.zig"), + .target = b.graph.host, + .optimize = optimize, + }); + const foo_mod = b.createModule(.{ .root_source_file = b.path("foo.zig"), }); - const bar = b.createModule(.{ + const bar_mod = b.createModule(.{ .root_source_file = b.path("bar.zig"), }); - foo.addImport("bar", bar); - bar.addImport("foo", foo); + + main_mod.addImport("foo", foo_mod); + foo_mod.addImport("bar", bar_mod); + bar_mod.addImport("foo", foo_mod); const exe = b.addExecutable(.{ .name = "test", - .root_source_file = b.path("test.zig"), - .target = b.graph.host, - .optimize = optimize, + .root_module = main_mod, }); - exe.root_module.addImport("foo", foo); const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); diff --git a/test/standalone/dep_recursive/build.zig b/test/standalone/dep_recursive/build.zig index bc1b7a55bb3d4733d2fe8026cf64448d3e9a0f18..133b7706b008913897217e4038b3058b7f55ce9f 100644 --- a/test/standalone/dep_recursive/build.zig +++ b/test/standalone/dep_recursive/build.zig @@ -6,18 +6,22 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; - const foo = b.createModule(.{ - .root_source_file = b.path("foo.zig"), - }); - foo.addImport("foo", foo); - - const exe = b.addExecutable(.{ - .name = "test", + const main_mod = b.createModule(.{ .root_source_file = b.path("test.zig"), .target = b.graph.host, .optimize = optimize, }); - exe.root_module.addImport("foo", foo); + const foo_mod = b.createModule(.{ + .root_source_file = b.path("foo.zig"), + }); + + main_mod.addImport("foo", foo_mod); + foo_mod.addImport("foo", foo_mod); + + const exe = b.addExecutable(.{ + .name = "test", + .root_module = main_mod, + }); const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); diff --git a/test/standalone/dep_shared_builtin/build.zig b/test/standalone/dep_shared_builtin/build.zig index 85a58da95a4822dddb1cb11f3caec7c9da1f26a5..eb8457e4942ac29ebf22df73f810d1d987cc0192 100644 --- a/test/standalone/dep_shared_builtin/build.zig +++ b/test/standalone/dep_shared_builtin/build.zig @@ -6,16 +6,22 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; - const exe = b.addExecutable(.{ - .name = "test", + const main_mod = b.createModule(.{ .root_source_file = b.path("test.zig"), .target = b.graph.host, .optimize = optimize, }); - exe.root_module.addAnonymousImport("foo", .{ + const foo_mod = b.createModule(.{ .root_source_file = b.path("foo.zig"), }); + main_mod.addImport("foo", foo_mod); + + const exe = b.addExecutable(.{ + .name = "test", + .root_module = main_mod, + }); + const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); } diff --git a/test/standalone/dep_triangle/build.zig b/test/standalone/dep_triangle/build.zig index c8562fd7168cd47d8421ddc9491249ff5cadd875..70f64dc3347985b3964c09a1816efdac468073aa 100644 --- a/test/standalone/dep_triangle/build.zig +++ b/test/standalone/dep_triangle/build.zig @@ -6,21 +6,26 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; - const shared = b.createModule(.{ - .root_source_file = b.path("shared.zig"), - }); - - const exe = b.addExecutable(.{ - .name = "test", + const main_mod = b.createModule(.{ .root_source_file = b.path("test.zig"), .target = b.graph.host, .optimize = optimize, }); - exe.root_module.addAnonymousImport("foo", .{ + const foo_mod = b.createModule(.{ .root_source_file = b.path("foo.zig"), - .imports = &.{.{ .name = "shared", .module = shared }}, }); - exe.root_module.addImport("shared", shared); + const shared_mod = b.createModule(.{ + .root_source_file = b.path("shared.zig"), + }); + + main_mod.addImport("foo", foo_mod); + main_mod.addImport("shared", shared_mod); + foo_mod.addImport("shared", shared_mod); + + const exe = b.addExecutable(.{ + .name = "test", + .root_module = main_mod, + }); const run = b.addRunArtifact(exe); test_step.dependOn(&run.step); diff --git a/test/standalone/depend_on_main_mod/build.zig b/test/standalone/depend_on_main_mod/build.zig index ae1dc8fb757c4a57114522cd9f5eff8cd46e5dc8..4dc08ba1bb9a04784c8016a5bb3254cda34f73aa 100644 --- a/test/standalone/depend_on_main_mod/build.zig +++ b/test/standalone/depend_on_main_mod/build.zig @@ -7,19 +7,22 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); - const exe = b.addExecutable(.{ - .name = "depend_on_main_mod", + const main_mod = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = target, .optimize = optimize, }); - - const foo_module = b.addModule("foo", .{ + const foo_mod = b.createModule(.{ .root_source_file = b.path("src/foo.zig"), }); - foo_module.addImport("root2", exe.root_module); - exe.root_module.addImport("foo", foo_module); + foo_mod.addImport("root2", main_mod); + main_mod.addImport("foo", foo_mod); + + const exe = b.addExecutable(.{ + .name = "depend_on_main_mod", + .root_module = main_mod, + }); const run_cmd = b.addRunArtifact(exe); run_cmd.expectExitCode(0); diff --git a/test/standalone/dirname/build.zig b/test/standalone/dirname/build.zig index 2562c677c3dc784d477675c85e9d796c621a42ad..0da85e29236dc7dc80a496b72b699c900e3805fd 100644 --- a/test/standalone/dirname/build.zig +++ b/test/standalone/dirname/build.zig @@ -10,24 +10,30 @@ pub fn build(b: *std.Build) void { const touch = b.addExecutable(.{ .name = "touch", - .root_source_file = touch_src, - .optimize = .Debug, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = touch_src, + .optimize = .Debug, + .target = target, + }), }); const generated = b.addRunArtifact(touch).addOutputFileArg("subdir" ++ std.fs.path.sep_str ++ "generated.txt"); const exists_in = b.addExecutable(.{ .name = "exists_in", - .root_source_file = b.path("exists_in.zig"), - .optimize = .Debug, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("exists_in.zig"), + .optimize = .Debug, + .target = target, + }), }); const has_basename = b.addExecutable(.{ .name = "has_basename", - .root_source_file = b.path("has_basename.zig"), - .optimize = .Debug, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("has_basename.zig"), + .optimize = .Debug, + .target = target, + }), }); // Known path: diff --git a/test/standalone/embed_generated_file/build.zig b/test/standalone/embed_generated_file/build.zig index f7430b7716ba4a57a632fcb1c82efe6bb0cf0b7f..75670f6ba0bff84d431309a5d27b7a5249828e7b 100644 --- a/test/standalone/embed_generated_file/build.zig +++ b/test/standalone/embed_generated_file/build.zig @@ -6,18 +6,21 @@ pub fn build(b: *std.Build) void { const bootloader = b.addExecutable(.{ .name = "bootloader", - .root_source_file = b.path("bootloader.zig"), - .target = b.resolveTargetQuery(.{ - .cpu_arch = .x86, - .os_tag = .freestanding, + .root_module = b.createModule(.{ + .root_source_file = b.path("bootloader.zig"), + .target = b.resolveTargetQuery(.{ + .cpu_arch = .x86, + .os_tag = .freestanding, + }), + .optimize = .ReleaseSmall, }), - .optimize = .ReleaseSmall, }); - const exe = b.addTest(.{ + const exe = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("main.zig"), + .target = b.graph.host, .optimize = .Debug, - }); + }) }); exe.root_module.addAnonymousImport("bootloader.elf", .{ .root_source_file = bootloader.getEmittedBin(), }); diff --git a/test/standalone/emit_asm_and_bin/build.zig b/test/standalone/emit_asm_and_bin/build.zig index 51b4066e6ab6bc4a4c51b1ba8b2b6b7854ea1231..cc38a87ddc19d42a1b245e225f0834273d332ab6 100644 --- a/test/standalone/emit_asm_and_bin/build.zig +++ b/test/standalone/emit_asm_and_bin/build.zig @@ -4,10 +4,11 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Test it"); b.default_step = test_step; - const main = b.addTest(.{ + const main = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("main.zig"), + .target = b.graph.host, .optimize = b.standardOptimizeOption(.{}), - }); + }) }); // TODO: actually check these two artifacts for correctness _ = main.getEmittedBin(); _ = main.getEmittedAsm(); diff --git a/test/standalone/emit_asm_no_bin/build.zig b/test/standalone/emit_asm_no_bin/build.zig index f2f2391bc1794606f95a548d724a11a8d45ed61f..cd5b670146c372f3d95c747ec14338502b7d8a1e 100644 --- a/test/standalone/emit_asm_no_bin/build.zig +++ b/test/standalone/emit_asm_no_bin/build.zig @@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "main", - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = b.graph.host, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .optimize = optimize, + .target = b.graph.host, + }), }); _ = obj.getEmittedAsm(); b.default_step.dependOn(&obj.step); diff --git a/test/standalone/emit_llvm_no_bin/build.zig b/test/standalone/emit_llvm_no_bin/build.zig index f82dd5193043ab7048950106e2a96c95d841ae0f..04946e47b6be011553450f86d6c1e68047d8c922 100644 --- a/test/standalone/emit_llvm_no_bin/build.zig +++ b/test/standalone/emit_llvm_no_bin/build.zig @@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "main", - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = b.graph.host, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .optimize = optimize, + .target = b.graph.host, + }), }); _ = obj.getEmittedLlvmIr(); _ = obj.getEmittedLlvmBc(); diff --git a/test/standalone/empty_env/build.zig b/test/standalone/empty_env/build.zig index dcbb0ad052f6255fa4ea8492119033b7b5f7c5d9..592566d62ccf5541fdc8148e00cf0d96c027bc6e 100644 --- a/test/standalone/empty_env/build.zig +++ b/test/standalone/empty_env/build.zig @@ -21,9 +21,11 @@ pub fn build(b: *std.Build) void { const main = b.addExecutable(.{ .name = "main", - .root_source_file = b.path("main.zig"), - .target = b.graph.host, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .target = b.graph.host, + .optimize = optimize, + }), }); const run = b.addRunArtifact(main); diff --git a/test/standalone/extern/build.zig b/test/standalone/extern/build.zig index 1886408933e347e9f512492328d70121c736f83c..a3907e20dba8fa38bdba59bc415e1c6c3d2c0387 100644 --- a/test/standalone/extern/build.zig +++ b/test/standalone/extern/build.zig @@ -8,22 +8,28 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "exports", - .root_source_file = b.path("exports.zig"), - .target = b.graph.host, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("exports.zig"), + .target = b.graph.host, + .optimize = optimize, + }), }); const shared = b.addSharedLibrary(.{ .name = "shared", - .target = b.graph.host, - .optimize = optimize, - .link_libc = true, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = b.graph.host, + .optimize = optimize, + .link_libc = true, + }), }); if (b.graph.host.result.abi == .msvc) shared.root_module.addCMacro("API", "__declspec(dllexport)"); - shared.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} }); - const test_exe = b.addTest(.{ + shared.root_module.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} }); + const test_exe = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("main.zig"), + .target = b.graph.host, .optimize = optimize, - }); + }) }); test_exe.addObject(obj); test_exe.linkLibrary(shared); diff --git a/test/standalone/global_linkage/build.zig b/test/standalone/global_linkage/build.zig index 50e270d1c359a4564902bf75178d4a28d84507cf..795bf008b31398364cad3b4ebe43f335e3d6c81d 100644 --- a/test/standalone/global_linkage/build.zig +++ b/test/standalone/global_linkage/build.zig @@ -9,24 +9,30 @@ pub fn build(b: *std.Build) void { const obj1 = b.addStaticLibrary(.{ .name = "obj1", - .root_source_file = b.path("obj1.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("obj1.zig"), + .optimize = optimize, + .target = target, + }), }); const obj2 = b.addStaticLibrary(.{ .name = "obj2", - .root_source_file = b.path("obj2.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("obj2.zig"), + .optimize = optimize, + .target = target, + }), }); - const main = b.addTest(.{ + const main_mod = b.createModule(.{ .root_source_file = b.path("main.zig"), + .target = b.graph.host, .optimize = optimize, }); - main.linkLibrary(obj1); - main.linkLibrary(obj2); + main_mod.linkLibrary(obj1); + main_mod.linkLibrary(obj2); + const main = b.addTest(.{ .root_module = main_mod }); test_step.dependOn(&b.addRunArtifact(main).step); } diff --git a/test/standalone/install_headers/build.zig b/test/standalone/install_headers/build.zig index 889ee717d685b0c13fefbd4021cb2457f3ee0b17..9f725c0c8149b03e69e6fa77d1c76ce46dfc6d27 100644 --- a/test/standalone/install_headers/build.zig +++ b/test/standalone/install_headers/build.zig @@ -8,18 +8,24 @@ pub fn build(b: *std.Build) void { const libfoo = b.addStaticLibrary(.{ .name = "foo", - .target = b.resolveTargetQuery(.{}), - .optimize = .Debug, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = b.resolveTargetQuery(.{}), + .optimize = .Debug, + }), }); - libfoo.addCSourceFile(.{ .file = empty_c }); + libfoo.root_module.addCSourceFile(.{ .file = empty_c }); const exe = b.addExecutable(.{ .name = "exe", - .target = b.resolveTargetQuery(.{}), - .optimize = .Debug, - .link_libc = true, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = b.resolveTargetQuery(.{}), + .optimize = .Debug, + .link_libc = true, + }), }); - exe.addCSourceFile(.{ .file = b.addWriteFiles().add("main.c", + exe.root_module.addCSourceFile(.{ .file = b.addWriteFiles().add("main.c", \\#include \\#include \\#include @@ -40,9 +46,10 @@ pub fn build(b: *std.Build) void { if (libfoo.installed_headers_include_tree != null) std.debug.panic("include tree step was created before linking", .{}); - // Link before we have registered all headers for installation, + // Link (and get the include tree) before we have registered all headers for installation, // to verify that the lazily created write files step is properly taken into account. - exe.linkLibrary(libfoo); + exe.root_module.linkLibrary(libfoo); + _ = libfoo.getEmittedIncludeTree(); if (libfoo.installed_headers_include_tree == null) std.debug.panic("include tree step was not created after linking", .{}); @@ -56,10 +63,13 @@ pub fn build(b: *std.Build) void { const libbar = b.addStaticLibrary(.{ .name = "bar", - .target = b.resolveTargetQuery(.{}), - .optimize = .Debug, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = b.resolveTargetQuery(.{}), + .optimize = .Debug, + }), }); - libbar.addCSourceFile(.{ .file = empty_c }); + libbar.root_module.addCSourceFile(.{ .file = empty_c }); libbar.installHeader(b.addWriteFiles().add("bar.h", \\#define BAR_X "X" \\ @@ -78,9 +88,11 @@ pub fn build(b: *std.Build) void { }); const check_exists = b.addExecutable(.{ .name = "check_exists", - .root_source_file = b.path("check_exists.zig"), - .target = b.resolveTargetQuery(.{}), - .optimize = .Debug, + .root_module = b.createModule(.{ + .root_source_file = b.path("check_exists.zig"), + .target = b.resolveTargetQuery(.{}), + .optimize = .Debug, + }), }); const run_check_exists = b.addRunArtifact(check_exists); run_check_exists.addArgs(&.{ diff --git a/test/standalone/install_raw_hex/build.zig b/test/standalone/install_raw_hex/build.zig index 515528534ee7238a0bed9aacd41a3f093353ab90..c12949a9cec08b55180d367f07197d5e451a1b66 100644 --- a/test/standalone/install_raw_hex/build.zig +++ b/test/standalone/install_raw_hex/build.zig @@ -16,9 +16,11 @@ pub fn build(b: *std.Build) void { const elf = b.addExecutable(.{ .name = "zig-nrf52-blink.elf", - .root_source_file = b.path("main.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .target = target, + .optimize = optimize, + }), }); const hex_step = elf.addObjCopy(.{ diff --git a/test/standalone/ios/build.zig b/test/standalone/ios/build.zig index c4ae240bd6f5ffed531c76f80c89d681db57a7c0..6148920b54ba6494359c58f7e6393e36ac3094f1 100644 --- a/test/standalone/ios/build.zig +++ b/test/standalone/ios/build.zig @@ -18,16 +18,19 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "main", - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = null, + .optimize = optimize, + .target = target, + .link_libc = true, + }), }); - exe.addCSourceFile(.{ .file = b.path("main.m"), .flags = &.{} }); - exe.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); - exe.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); - exe.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/lib" }) }); - exe.linkFramework("Foundation"); - exe.linkFramework("UIKit"); - exe.linkLibC(); + exe.root_module.addCSourceFile(.{ .file = b.path("main.m"), .flags = &.{} }); + exe.root_module.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); + exe.root_module.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); + exe.root_module.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/lib" }) }); + exe.root_module.linkFramework("Foundation", .{}); + exe.root_module.linkFramework("UIKit", .{}); const check = exe.checkObject(); check.checkInHeaders(); diff --git a/test/standalone/issue_11595/build.zig b/test/standalone/issue_11595/build.zig index c37dfb12b57d8b87ba09443a312d1ad675fdc2e1..88b7af06a55ee440b3766169cb69f3b3343a687a 100644 --- a/test/standalone/issue_11595/build.zig +++ b/test/standalone/issue_11595/build.zig @@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "zigtest", - .root_source_file = b.path("main.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .target = target, + .optimize = optimize, + }), }); b.installArtifact(exe); @@ -25,8 +27,8 @@ pub fn build(b: *std.Build) void { "test.c", }; - exe.addCSourceFiles(.{ .files = &c_sources }); - exe.linkLibC(); + exe.root_module.addCSourceFiles(.{ .files = &c_sources }); + exe.root_module.link_libc = true; var i: i32 = 0; while (i < 1000) : (i += 1) { diff --git a/test/standalone/issue_12706/build.zig b/test/standalone/issue_12706/build.zig index 9cb858d0194e0a175214d2ab40f89bb0536f7a89..cace3c7d2d3b66376e529376ffabb316a2fd4e8f 100644 --- a/test/standalone/issue_12706/build.zig +++ b/test/standalone/issue_12706/build.zig @@ -10,16 +10,18 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "main", - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .optimize = optimize, + .target = target, + }), }); const c_sources = [_][]const u8{ "test.c", }; - exe.addCSourceFiles(.{ .files = &c_sources }); - exe.linkLibC(); + exe.root_module.addCSourceFiles(.{ .files = &c_sources }); + exe.root_module.link_libc = true; const run_cmd = b.addRunArtifact(exe); run_cmd.expectExitCode(0); diff --git a/test/standalone/issue_13970/build.zig b/test/standalone/issue_13970/build.zig index e7d3a8243162e43ad274a4d8c344bdb60848624c..bad94161af0dd5f413591d1da2568c75e9aac594 100644 --- a/test/standalone/issue_13970/build.zig +++ b/test/standalone/issue_13970/build.zig @@ -5,15 +5,24 @@ pub fn build(b: *std.Build) void { b.default_step = test_step; const test1 = b.addTest(.{ - .root_source_file = b.path("test_root/empty.zig"), + .root_module = b.createModule(.{ + .root_source_file = b.path("test_root/empty.zig"), + .target = b.graph.host, + }), .test_runner = "src/main.zig", }); const test2 = b.addTest(.{ - .root_source_file = b.path("src/empty.zig"), + .root_module = b.createModule(.{ + .root_source_file = b.path("src/empty.zig"), + .target = b.graph.host, + }), .test_runner = "src/main.zig", }); const test3 = b.addTest(.{ - .root_source_file = b.path("empty.zig"), + .root_module = b.createModule(.{ + .root_source_file = b.path("empty.zig"), + .target = b.graph.host, + }), .test_runner = "src/main.zig", }); diff --git a/test/standalone/issue_339/build.zig b/test/standalone/issue_339/build.zig index 321a6352549467b6931f62cc4d1d590f76799bf1..364dc0e81bef9816b6a186bfb51a6348a4c95e10 100644 --- a/test/standalone/issue_339/build.zig +++ b/test/standalone/issue_339/build.zig @@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "test", - .root_source_file = b.path("test.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("test.zig"), + .target = target, + .optimize = optimize, + }), }); // TODO: actually check the output diff --git a/test/standalone/issue_5825/build.zig b/test/standalone/issue_5825/build.zig index d4462bb5a1080e4748e8315d17296101123a661c..3b4bb33defa7bbbd9214b4d8d3e0a7ed14985654 100644 --- a/test/standalone/issue_5825/build.zig +++ b/test/standalone/issue_5825/build.zig @@ -16,20 +16,25 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const obj = b.addObject(.{ .name = "issue_5825", - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .optimize = optimize, + .target = target, + }), }); const exe = b.addExecutable(.{ .name = "issue_5825", - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = null, + .optimize = optimize, + .target = target, + }), }); exe.subsystem = .Console; - exe.linkSystemLibrary("kernel32"); - exe.linkSystemLibrary("ntdll"); - exe.addObject(obj); + exe.root_module.linkSystemLibrary("kernel32", .{}); + exe.root_module.linkSystemLibrary("ntdll", .{}); + exe.root_module.addObject(obj); // TODO: actually check the output _ = exe.getEmittedBin(); diff --git a/test/standalone/issue_794/build.zig b/test/standalone/issue_794/build.zig index d42ff1f3049f6ebb68facc22115806841b89ebda..4b0c089f97ee382630e274c9f46f42c0f19e2911 100644 --- a/test/standalone/issue_794/build.zig +++ b/test/standalone/issue_794/build.zig @@ -4,9 +4,10 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Test it"); b.default_step = test_step; - const test_artifact = b.addTest(.{ + const test_artifact = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("main.zig"), - }); + .target = b.graph.host, + }) }); test_artifact.addIncludePath(b.path("a_directory")); // TODO: actually check the output diff --git a/test/standalone/issue_8550/build.zig b/test/standalone/issue_8550/build.zig index a0dea518d683aeecc9126c0d4e29b326908494a8..ee82332973d072bf7464dca1f2c4606e09c4e4eb 100644 --- a/test/standalone/issue_8550/build.zig +++ b/test/standalone/issue_8550/build.zig @@ -15,11 +15,13 @@ pub fn build(b: *std.Build) !void { const kernel = b.addExecutable(.{ .name = "kernel", - .root_source_file = b.path("./main.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("./main.zig"), + .optimize = optimize, + .target = target, + }), }); - kernel.addObjectFile(b.path("./boot.S")); + kernel.root_module.addObjectFile(b.path("./boot.S")); kernel.setLinkerScript(b.path("./linker.ld")); b.installArtifact(kernel); diff --git a/test/standalone/libcxx/build.zig b/test/standalone/libcxx/build.zig index 3989bda9bc8bafc9c0d3b0bfad66234f38f8c0a6..aaa62abdb4db67c6b108b4a4281e3a7ea0319b52 100644 --- a/test/standalone/libcxx/build.zig +++ b/test/standalone/libcxx/build.zig @@ -11,12 +11,14 @@ pub fn build(b: *std.Build) void { { const exe = b.addExecutable(.{ .name = "mt", - .root_source_file = b.path("mt.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("mt.zig"), + .target = target, + .optimize = optimize, + .link_libcpp = true, + }), }); - exe.linkLibCpp(); - exe.addCSourceFile(.{ .file = b.path("mt_doit.cpp") }); + exe.root_module.addCSourceFile(.{ .file = b.path("mt_doit.cpp") }); link_step.dependOn(&exe.step); b.installArtifact(exe); run_step.dependOn(&b.addRunArtifact(exe).step); @@ -24,13 +26,15 @@ pub fn build(b: *std.Build) void { { const exe = b.addExecutable(.{ .name = "st", - .root_source_file = b.path("st.zig"), - .target = target, - .optimize = optimize, - .single_threaded = true, + .root_module = b.createModule(.{ + .root_source_file = b.path("st.zig"), + .target = target, + .optimize = optimize, + .link_libcpp = true, + .single_threaded = true, + }), }); - exe.linkLibCpp(); - exe.addCSourceFile(.{ .file = b.path("st_doit.cpp") }); + exe.root_module.addCSourceFile(.{ .file = b.path("st_doit.cpp") }); link_step.dependOn(&exe.step); b.installArtifact(exe); run_step.dependOn(&b.addRunArtifact(exe).step); diff --git a/test/standalone/load_dynamic_library/build.zig b/test/standalone/load_dynamic_library/build.zig index f484d2a6e6fff88e06f31a7ac7c33fbd05336f5a..ec05c45c21e2ab585916a8f9cd9b20777aaf9b0e 100644 --- a/test/standalone/load_dynamic_library/build.zig +++ b/test/standalone/load_dynamic_library/build.zig @@ -12,17 +12,21 @@ pub fn build(b: *std.Build) void { const lib = b.addSharedLibrary(.{ .name = "add", - .root_source_file = b.path("add.zig"), .version = .{ .major = 1, .minor = 0, .patch = 0 }, - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("add.zig"), + .optimize = optimize, + .target = target, + }), }); const main = b.addExecutable(.{ .name = "main", - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .optimize = optimize, + .target = target, + }), }); const run = b.addRunArtifact(main); diff --git a/test/standalone/mix_c_files/build.zig b/test/standalone/mix_c_files/build.zig index 0b626ba0faa4edc5e55b1b4abae6bcf338b57b4a..32b1d57b5cb87f39463ffc01cd45670a769345e8 100644 --- a/test/standalone/mix_c_files/build.zig +++ b/test/standalone/mix_c_files/build.zig @@ -18,12 +18,14 @@ pub fn build(b: *std.Build) void { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const exe = b.addExecutable(.{ .name = "test", - .root_source_file = b.path("main.zig"), - .target = b.graph.host, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .target = b.graph.host, + .optimize = optimize, + .link_libc = true, + }), }); - exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c11"} }); - exe.linkLibC(); + exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c11"} }); const run_cmd = b.addRunArtifact(exe); run_cmd.skip_foreign_checks = true; diff --git a/test/standalone/mix_o_files/build.zig b/test/standalone/mix_o_files/build.zig index 7be4ff5090ac9730a524a100f973bcd747ad2dbb..12b90f36247b379422b4ff616d671b85d5b5a66c 100644 --- a/test/standalone/mix_o_files/build.zig +++ b/test/standalone/mix_o_files/build.zig @@ -9,22 +9,27 @@ pub fn build(b: *std.Build) void { const obj = b.addObject(.{ .name = "base64", - .root_source_file = b.path("base64.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("base64.zig"), + .optimize = optimize, + .target = target, + }), }); const exe = b.addExecutable(.{ .name = "test", - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = null, + .optimize = optimize, + .target = target, + .link_libc = true, + }), }); - exe.addCSourceFile(.{ + exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c99"}, }); - exe.addObject(obj); - exe.linkSystemLibrary("c"); + exe.root_module.addObject(obj); b.default_step.dependOn(&exe.step); diff --git a/test/standalone/options/build.zig b/test/standalone/options/build.zig index 1c17e30d6a03a909e7080412e644934dc0063158..07efea2a7b8e094182e437b3529b7ccc02fef434 100644 --- a/test/standalone/options/build.zig +++ b/test/standalone/options/build.zig @@ -1,11 +1,11 @@ const std = @import("std"); pub fn build(b: *std.Build) void { - const main = b.addTest(.{ + const main = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = b.graph.host, .optimize = .Debug, - }); + }) }); const options = b.addOptions(); main.addOptions("build_options", options); diff --git a/test/standalone/pie/build.zig b/test/standalone/pie/build.zig index 25ed330abce22e388dbe1159b778fc97d79fe348..79d078a9eba56d191f7cdd1f55452aa91e632001 100644 --- a/test/standalone/pie/build.zig +++ b/test/standalone/pie/build.zig @@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void { }); const main = b.addTest(.{ - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .optimize = optimize, + .target = target, + }), }); main.pie = true; diff --git a/test/standalone/pkg_import/build.zig b/test/standalone/pkg_import/build.zig index b0d0c035ddb80dd5183b46fb9c471154e0a9d3d9..3d94930ef3fdbcfb61b15623dd51036f23855045 100644 --- a/test/standalone/pkg_import/build.zig +++ b/test/standalone/pkg_import/build.zig @@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "test", - .root_source_file = b.path("test.zig"), - .optimize = optimize, - .target = b.graph.host, + .root_module = b.createModule(.{ + .root_source_file = b.path("test.zig"), + .optimize = optimize, + .target = b.graph.host, + }), }); exe.root_module.addAnonymousImport("my_pkg", .{ .root_source_file = b.path("pkg.zig") }); diff --git a/test/standalone/run_output_caching/build.zig b/test/standalone/run_output_caching/build.zig index 3842f097d1e6308de9716d108f83abc7ffcbd24b..98f5a63dd540878d8f706268071ff650ac95027c 100644 --- a/test/standalone/run_output_caching/build.zig +++ b/test/standalone/run_output_caching/build.zig @@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void { const exe = b.addExecutable(.{ .name = "create-file", - .root_source_file = b.path("main.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .target = target, + .optimize = optimize, + }), }); { diff --git a/test/standalone/run_output_paths/build.zig b/test/standalone/run_output_paths/build.zig index f4c7254d8fc7286766c495a03b06a91dd5dd7bdd..78b75e147d33eded9dffb672c043074e58bd5306 100644 --- a/test/standalone/run_output_paths/build.zig +++ b/test/standalone/run_output_paths/build.zig @@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void { const create_file_exe = b.addExecutable(.{ .name = "create_file", - .root_source_file = b.path("create_file.zig"), - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("create_file.zig"), + .target = target, + .optimize = optimize, + }), }); const create_first = b.addRunArtifact(create_file_exe); diff --git a/test/standalone/self_exe_symlink/build.zig b/test/standalone/self_exe_symlink/build.zig index 2b7b3d423c5d3e1b656d2001c7b39fa4ddae1bc9..651740c04be04442d1f85007f6a23bc2938a6a30 100644 --- a/test/standalone/self_exe_symlink/build.zig +++ b/test/standalone/self_exe_symlink/build.zig @@ -15,16 +15,20 @@ pub fn build(b: *std.Build) void { const main = b.addExecutable(.{ .name = "main", - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .optimize = optimize, + .target = target, + }), }); const create_symlink_exe = b.addExecutable(.{ .name = "create-symlink", - .root_source_file = b.path("create-symlink.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("create-symlink.zig"), + .optimize = optimize, + .target = target, + }), }); var run_create_symlink = b.addRunArtifact(create_symlink_exe); diff --git a/test/standalone/shared_library/build.zig b/test/standalone/shared_library/build.zig index 28c1bdb13e1d81f328246325cd1e7508b0fd21de..ab90c129b9965cd79d8a124715f6d149ee59eeda 100644 --- a/test/standalone/shared_library/build.zig +++ b/test/standalone/shared_library/build.zig @@ -8,23 +8,28 @@ pub fn build(b: *std.Build) void { const target = b.graph.host; const lib = b.addSharedLibrary(.{ .name = "mathtest", - .root_source_file = b.path("mathtest.zig"), .version = .{ .major = 1, .minor = 0, .patch = 0 }, - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("mathtest.zig"), + .target = target, + .optimize = optimize, + }), }); const exe = b.addExecutable(.{ .name = "test", - .target = target, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = target, + .optimize = optimize, + .link_libc = true, + }), }); - exe.addCSourceFile(.{ + exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c99"}, }); - exe.linkLibrary(lib); - exe.linkSystemLibrary("c"); + exe.root_module.linkLibrary(lib); const run_cmd = b.addRunArtifact(exe); test_step.dependOn(&run_cmd.step); diff --git a/test/standalone/simple/build.zig b/test/standalone/simple/build.zig index c623780fa5df43627de0d71f026f19b2120759f5..ba4464cefcea85c3a7582b1a1f026d4033e16f88 100644 --- a/test/standalone/simple/build.zig +++ b/test/standalone/simple/build.zig @@ -42,11 +42,13 @@ pub fn build(b: *std.Build) void { if (case.is_exe) { const exe = b.addExecutable(.{ .name = std.fs.path.stem(case.src_path), - .root_source_file = b.path(case.src_path), - .optimize = optimize, - .target = resolved_target, + .root_module = b.createModule(.{ + .root_source_file = b.path(case.src_path), + .optimize = optimize, + .target = resolved_target, + }), }); - if (case.link_libc) exe.linkLibC(); + if (case.link_libc) exe.root_module.link_libc = true; _ = exe.getEmittedBin(); @@ -56,11 +58,13 @@ pub fn build(b: *std.Build) void { if (case.is_test) { const exe = b.addTest(.{ .name = std.fs.path.stem(case.src_path), - .root_source_file = b.path(case.src_path), - .optimize = optimize, - .target = resolved_target, + .root_module = b.createModule(.{ + .root_source_file = b.path(case.src_path), + .optimize = optimize, + .target = resolved_target, + }), }); - if (case.link_libc) exe.linkLibC(); + if (case.link_libc) exe.root_module.link_libc = true; const run = b.addRunArtifact(exe); step.dependOn(&run.step); diff --git a/test/standalone/stack_iterator/build.zig b/test/standalone/stack_iterator/build.zig index 20027428b0ff41126c235d1d936b78828e9b3923..9d660b5c57bac985af4c37483645b103aac49298 100644 --- a/test/standalone/stack_iterator/build.zig +++ b/test/standalone/stack_iterator/build.zig @@ -20,11 +20,13 @@ pub fn build(b: *std.Build) void { { const exe = b.addExecutable(.{ .name = "unwind_fp", - .root_source_file = b.path("unwind.zig"), - .target = target, - .optimize = optimize, - .unwind_tables = if (target.result.isDarwin()) .@"async" else null, - .omit_frame_pointer = false, + .root_module = b.createModule(.{ + .root_source_file = b.path("unwind.zig"), + .target = target, + .optimize = optimize, + .unwind_tables = if (target.result.isDarwin()) .@"async" else null, + .omit_frame_pointer = false, + }), }); const run_cmd = b.addRunArtifact(exe); @@ -43,11 +45,13 @@ pub fn build(b: *std.Build) void { { const exe = b.addExecutable(.{ .name = "unwind_nofp", - .root_source_file = b.path("unwind.zig"), - .target = target, - .optimize = optimize, - .unwind_tables = .@"async", - .omit_frame_pointer = true, + .root_module = b.createModule(.{ + .root_source_file = b.path("unwind.zig"), + .target = target, + .optimize = optimize, + .unwind_tables = .@"async", + .omit_frame_pointer = true, + }), }); const run_cmd = b.addRunArtifact(exe); @@ -66,27 +70,32 @@ pub fn build(b: *std.Build) void { { const c_shared_lib = b.addSharedLibrary(.{ .name = "c_shared_lib", - .target = target, - .optimize = optimize, - .strip = false, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = target, + .optimize = optimize, + .link_libc = true, + .strip = false, + }), }); if (target.result.os.tag == .windows) c_shared_lib.root_module.addCMacro("LIB_API", "__declspec(dllexport)"); - c_shared_lib.addCSourceFile(.{ + c_shared_lib.root_module.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-fomit-frame-pointer"}, }); - c_shared_lib.linkLibC(); const exe = b.addExecutable(.{ .name = "shared_lib_unwind", - .root_source_file = b.path("shared_lib_unwind.zig"), - .target = target, - .optimize = optimize, - .unwind_tables = if (target.result.isDarwin()) .@"async" else null, - .omit_frame_pointer = true, + .root_module = b.createModule(.{ + .root_source_file = b.path("shared_lib_unwind.zig"), + .target = target, + .optimize = optimize, + .unwind_tables = if (target.result.isDarwin()) .@"async" else null, + .omit_frame_pointer = true, + }), }); exe.linkLibrary(c_shared_lib); @@ -117,14 +126,16 @@ pub fn build(b: *std.Build) void { inline for (no_os_targets) |os_tag| { const exe = b.addExecutable(.{ .name = "unwind_freestanding", - .root_source_file = b.path("unwind_freestanding.zig"), - .target = b.resolveTargetQuery(.{ - .cpu_arch = .x86_64, - .os_tag = os_tag, + .root_module = b.createModule(.{ + .root_source_file = b.path("unwind_freestanding.zig"), + .target = b.resolveTargetQuery(.{ + .cpu_arch = .x86_64, + .os_tag = os_tag, + }), + .optimize = optimize, + .unwind_tables = null, + .omit_frame_pointer = false, }), - .optimize = optimize, - .unwind_tables = null, - .omit_frame_pointer = false, }); // This "freestanding" binary is runnable because it invokes the diff --git a/test/standalone/static_c_lib/build.zig b/test/standalone/static_c_lib/build.zig index c952e9b25013e1395c6a235532b7da33827687f8..98b417aaf7cb69cc982fde714499ea04567318ea 100644 --- a/test/standalone/static_c_lib/build.zig +++ b/test/standalone/static_c_lib/build.zig @@ -8,18 +8,22 @@ pub fn build(b: *std.Build) void { const foo = b.addStaticLibrary(.{ .name = "foo", - .optimize = optimize, - .target = b.graph.host, + .root_module = b.createModule(.{ + .root_source_file = null, + .optimize = optimize, + .target = b.graph.host, + }), }); - foo.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} }); - foo.addIncludePath(b.path(".")); + foo.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} }); + foo.root_module.addIncludePath(b.path(".")); - const test_exe = b.addTest(.{ + const test_exe = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("foo.zig"), + .target = b.graph.host, .optimize = optimize, - }); - test_exe.linkLibrary(foo); - test_exe.addIncludePath(b.path(".")); + }) }); + test_exe.root_module.linkLibrary(foo); + test_exe.root_module.addIncludePath(b.path(".")); test_step.dependOn(&b.addRunArtifact(test_exe).step); } diff --git a/test/standalone/strip_empty_loop/build.zig b/test/standalone/strip_empty_loop/build.zig index d34120ed06b8230902e9dedc1d5339bfbf012f9b..9f268d4cb864cf7ea6a405ddf238f2b040af7c1b 100644 --- a/test/standalone/strip_empty_loop/build.zig +++ b/test/standalone/strip_empty_loop/build.zig @@ -9,10 +9,12 @@ pub fn build(b: *std.Build) void { const main = b.addExecutable(.{ .name = "main", - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, - .strip = true, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .optimize = optimize, + .target = target, + .strip = true, + }), }); // TODO: actually check the output diff --git a/test/standalone/strip_struct_init/build.zig b/test/standalone/strip_struct_init/build.zig index ef7960d13051ccf348b65f4df4676b6d994eb9cc..175724df6348f524f7680a73177ec81ab2e97cf0 100644 --- a/test/standalone/strip_struct_init/build.zig +++ b/test/standalone/strip_struct_init/build.zig @@ -7,9 +7,12 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; const main = b.addTest(.{ - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .strip = true, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .target = b.graph.host, + .optimize = optimize, + .strip = true, + }), }); test_step.dependOn(&b.addRunArtifact(main).step); diff --git a/test/standalone/test_runner_module_imports/build.zig b/test/standalone/test_runner_module_imports/build.zig index cad3b05e08eaf9a9149118c0717b66c655232f72..6b24ef7124f7b4539ee15ed81d1d4b81386f95d2 100644 --- a/test/standalone/test_runner_module_imports/build.zig +++ b/test/standalone/test_runner_module_imports/build.zig @@ -1,19 +1,21 @@ const std = @import("std"); pub fn build(b: *std.Build) void { - const t = b.addTest(.{ + const test_mod = b.createModule(.{ .root_source_file = b.path("src/main.zig"), - .test_runner = b.path("test_runner/main.zig"), + .target = b.graph.host, }); - const module1 = b.createModule(.{ .root_source_file = b.path("module1/main.zig") }); - const module2 = b.createModule(.{ - .root_source_file = b.path("module2/main.zig"), - .imports = &.{.{ .name = "module1", .module = module1 }}, + const module2 = b.createModule(.{ .root_source_file = b.path("module2/main.zig") }); + + module2.addImport("module1", module1); + test_mod.addImport("module2", module2); + + const t = b.addTest(.{ + .root_module = test_mod, + .test_runner = b.path("test_runner/main.zig"), }); - t.root_module.addImport("module2", module2); - const test_step = b.step("test", "Run unit tests"); test_step.dependOn(&b.addRunArtifact(t).step); b.default_step = test_step; diff --git a/test/standalone/test_runner_path/build.zig b/test/standalone/test_runner_path/build.zig index 48ca3c19db8849d935c24bf1301b71c46224533f..a7b8eaf321361316afa5a6323b2beed987364ee5 100644 --- a/test/standalone/test_runner_path/build.zig +++ b/test/standalone/test_runner_path/build.zig @@ -6,9 +6,10 @@ pub fn build(b: *std.Build) void { const test_step = b.step("test", "Test the program"); b.default_step = test_step; - const test_exe = b.addTest(.{ + const test_exe = b.addTest(.{ .root_module = b.createModule(.{ + .target = b.graph.host, .root_source_file = b.path("test.zig"), - }); + }) }); test_exe.test_runner = b.path("test_runner.zig"); const test_run = b.addRunArtifact(test_exe); diff --git a/test/standalone/use_alias/build.zig b/test/standalone/use_alias/build.zig index 7ee501713c32e29f0dc0410e4bdcf9632ca4f8a1..399a23d924ca43eb56e2e4533d29bde77848d138 100644 --- a/test/standalone/use_alias/build.zig +++ b/test/standalone/use_alias/build.zig @@ -6,11 +6,12 @@ pub fn build(b: *std.Build) void { const optimize: std.builtin.OptimizeMode = .Debug; - const main = b.addTest(.{ + const main = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("main.zig"), + .target = b.graph.host, .optimize = optimize, - }); - main.addIncludePath(b.path(".")); + }) }); + main.root_module.addIncludePath(b.path(".")); test_step.dependOn(&b.addRunArtifact(main).step); } diff --git a/test/standalone/windows_argv/build.zig b/test/standalone/windows_argv/build.zig index 4e41a8716e96619c73cd95ed3ab25fbcc79b4053..ea4b26cc2281bd95bc33ff4dce38f65d943f0777 100644 --- a/test/standalone/windows_argv/build.zig +++ b/test/standalone/windows_argv/build.zig @@ -11,32 +11,39 @@ pub fn build(b: *std.Build) !void { const lib_gnu = b.addStaticLibrary(.{ .name = "toargv-gnu", - .root_source_file = b.path("lib.zig"), - .target = b.resolveTargetQuery(.{ - .abi = .gnu, + .root_module = b.createModule(.{ + .root_source_file = b.path("lib.zig"), + .target = b.resolveTargetQuery(.{ + .abi = .gnu, + }), + .optimize = optimize, }), - .optimize = optimize, }); const verify_gnu = b.addExecutable(.{ .name = "verify-gnu", - .target = b.resolveTargetQuery(.{ - .abi = .gnu, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = b.resolveTargetQuery(.{ + .abi = .gnu, + }), + .optimize = optimize, }), - .optimize = optimize, }); - verify_gnu.addCSourceFile(.{ + verify_gnu.root_module.addCSourceFile(.{ .file = b.path("verify.c"), .flags = &.{ "-DUNICODE", "-D_UNICODE" }, }); verify_gnu.mingw_unicode_entry_point = true; - verify_gnu.linkLibrary(lib_gnu); - verify_gnu.linkLibC(); + verify_gnu.root_module.linkLibrary(lib_gnu); + verify_gnu.root_module.link_libc = true; const fuzz = b.addExecutable(.{ .name = "fuzz", - .root_source_file = b.path("fuzz.zig"), - .target = b.graph.host, - .optimize = optimize, + .root_module = b.createModule(.{ + .root_source_file = b.path("fuzz.zig"), + .target = b.graph.host, + .optimize = optimize, + }), }); 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 { if (has_msvc) { const lib_msvc = b.addStaticLibrary(.{ .name = "toargv-msvc", - .root_source_file = b.path("lib.zig"), - .target = b.resolveTargetQuery(.{ - .abi = .msvc, + .root_module = b.createModule(.{ + .root_source_file = b.path("lib.zig"), + .target = b.resolveTargetQuery(.{ + .abi = .msvc, + }), + .optimize = optimize, }), - .optimize = optimize, }); const verify_msvc = b.addExecutable(.{ .name = "verify-msvc", - .target = b.resolveTargetQuery(.{ - .abi = .msvc, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = b.resolveTargetQuery(.{ + .abi = .msvc, + }), + .optimize = optimize, }), - .optimize = optimize, }); - verify_msvc.addCSourceFile(.{ + verify_msvc.root_module.addCSourceFile(.{ .file = b.path("verify.c"), .flags = &.{ "-DUNICODE", "-D_UNICODE" }, }); - verify_msvc.linkLibrary(lib_msvc); - verify_msvc.linkLibC(); + verify_msvc.root_module.linkLibrary(lib_msvc); + verify_msvc.root_module.link_libc = true; const run_msvc = b.addRunArtifact(fuzz); run_msvc.setName("fuzz-msvc"); diff --git a/test/standalone/windows_bat_args/build.zig b/test/standalone/windows_bat_args/build.zig index 7c35cf2b768ef27b0293fca74d36d187ceeae58e..b91b4fb3bbfd510bf3f89eb9eb0dce16067410f7 100644 --- a/test/standalone/windows_bat_args/build.zig +++ b/test/standalone/windows_bat_args/build.zig @@ -12,16 +12,20 @@ pub fn build(b: *std.Build) !void { const echo_args = b.addExecutable(.{ .name = "echo-args", - .root_source_file = b.path("echo-args.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("echo-args.zig"), + .optimize = optimize, + .target = target, + }), }); const test_exe = b.addExecutable(.{ .name = "test", - .root_source_file = b.path("test.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("test.zig"), + .optimize = optimize, + .target = target, + }), }); const run = b.addRunArtifact(test_exe); @@ -33,9 +37,11 @@ pub fn build(b: *std.Build) !void { const fuzz = b.addExecutable(.{ .name = "fuzz", - .root_source_file = b.path("fuzz.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("fuzz.zig"), + .optimize = optimize, + .target = target, + }), }); const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100; diff --git a/test/standalone/windows_entry_points/build.zig b/test/standalone/windows_entry_points/build.zig index c3d9c49940830291bc53d25f1d2a8f66eb81df2b..1889b0c8435ff665fcad98717c160bb939c2e113 100644 --- a/test/standalone/windows_entry_points/build.zig +++ b/test/standalone/windows_entry_points/build.zig @@ -13,11 +13,14 @@ pub fn build(b: *std.Build) void { { const exe = b.addExecutable(.{ .name = "main", - .target = target, - .optimize = .Debug, - .link_libc = true, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = target, + .optimize = .Debug, + .link_libc = true, + }), }); - exe.addCSourceFile(.{ .file = b.path("main.c") }); + exe.root_module.addCSourceFile(.{ .file = b.path("main.c") }); _ = exe.getEmittedBin(); test_step.dependOn(&exe.step); @@ -26,12 +29,15 @@ pub fn build(b: *std.Build) void { { const exe = b.addExecutable(.{ .name = "wmain", - .target = target, - .optimize = .Debug, - .link_libc = true, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = target, + .optimize = .Debug, + .link_libc = true, + }), }); exe.mingw_unicode_entry_point = true; - exe.addCSourceFile(.{ .file = b.path("wmain.c") }); + exe.root_module.addCSourceFile(.{ .file = b.path("wmain.c") }); _ = exe.getEmittedBin(); test_step.dependOn(&exe.step); @@ -40,12 +46,15 @@ pub fn build(b: *std.Build) void { { const exe = b.addExecutable(.{ .name = "winmain", - .target = target, - .optimize = .Debug, - .link_libc = true, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = target, + .optimize = .Debug, + .link_libc = true, + }), }); // Note: `exe.subsystem = .Windows;` is not necessary - exe.addCSourceFile(.{ .file = b.path("winmain.c") }); + exe.root_module.addCSourceFile(.{ .file = b.path("winmain.c") }); _ = exe.getEmittedBin(); test_step.dependOn(&exe.step); @@ -54,13 +63,16 @@ pub fn build(b: *std.Build) void { { const exe = b.addExecutable(.{ .name = "wwinmain", - .target = target, - .optimize = .Debug, - .link_libc = true, + .root_module = b.createModule(.{ + .root_source_file = null, + .target = target, + .optimize = .Debug, + .link_libc = true, + }), }); exe.mingw_unicode_entry_point = true; // Note: `exe.subsystem = .Windows;` is not necessary - exe.addCSourceFile(.{ .file = b.path("wwinmain.c") }); + exe.root_module.addCSourceFile(.{ .file = b.path("wwinmain.c") }); _ = exe.getEmittedBin(); test_step.dependOn(&exe.step); diff --git a/test/standalone/windows_resources/build.zig b/test/standalone/windows_resources/build.zig index 27f4fa919ee2b5470b9f1686ae10644c919a21a4..d3afadb60d5d4a6e16cc3f98f04a45c75c350307 100644 --- a/test/standalone/windows_resources/build.zig +++ b/test/standalone/windows_resources/build.zig @@ -28,11 +28,13 @@ fn add( ) void { const exe = b.addExecutable(.{ .name = "zig_resource_test", - .root_source_file = b.path("main.zig"), - .target = target, - .optimize = .Debug, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .target = target, + .optimize = .Debug, + }), }); - exe.addWin32ResourceFile(.{ + exe.root_module.addWin32ResourceFile(.{ .file = b.path("res/zig.rc"), .flags = &.{"/c65001"}, // UTF-8 code page .include_paths = &.{ diff --git a/test/standalone/windows_spawn/build.zig b/test/standalone/windows_spawn/build.zig index 7f59ff1da4a81c7e3778ab5aa96981347a369905..2b967b16d5b3572db345d34ddc538053f2ce0d62 100644 --- a/test/standalone/windows_spawn/build.zig +++ b/test/standalone/windows_spawn/build.zig @@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void { const hello = b.addExecutable(.{ .name = "hello", - .root_source_file = b.path("hello.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("hello.zig"), + .optimize = optimize, + .target = target, + }), }); const main = b.addExecutable(.{ .name = "main", - .root_source_file = b.path("main.zig"), - .optimize = optimize, - .target = target, + .root_module = b.createModule(.{ + .root_source_file = b.path("main.zig"), + .optimize = optimize, + .target = target, + }), }); const run = b.addRunArtifact(main); diff --git a/test/standalone/zerolength_check/build.zig b/test/standalone/zerolength_check/build.zig index 8118c6e17231ed40e0516c3ea07aac76715c06d6..7edc55932cbdedcd594988abe605cbeb282e31b6 100644 --- a/test/standalone/zerolength_check/build.zig +++ b/test/standalone/zerolength_check/build.zig @@ -11,7 +11,7 @@ pub fn build(b: *std.Build) void { } fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { - const unit_tests = b.addTest(.{ + const unit_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/main.zig"), .target = b.resolveTargetQuery(.{ .os_tag = .wasi, @@ -19,7 +19,7 @@ fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.Optimize .cpu_features_add = std.Target.wasm.featureSet(&.{.bulk_memory}), }), .optimize = optimize, - }); + }) }); const run_unit_tests = b.addRunArtifact(unit_tests); run_unit_tests.skip_foreign_checks = true;