diff --git a/test/standalone/build.zig b/test/standalone/build.zig index fee8c03161..f89ccd2a18 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 5328d6e01d..af9d8b492a 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 0180fb8a83..81b40835f3 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 bb9879d089..b95ebed80d 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 93331a0282..e25fe0eff7 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 44338b36d4..ba437c310a 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 733d49b91c..5974ba9968 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 = b.addStaticLibrary(.{ - .name = "lib", + const lib_mod = b.createModule(.{ .root_source_file = b.path("lib.zig"), .target = target, .optimize = optimize, }); - lib.root_module.addImport("mod", mod); - - const exe = b.addExecutable(.{ - .name = "app", + const exe_mod = b.createModule(.{ .root_source_file = b.path("main.zig"), .target = target, .optimize = optimize, }); - exe.root_module.addImport("mod", mod); - exe.root_module.linkLibrary(lib); + lib_mod.addImport("mod", shared_mod); + exe_mod.addImport("mod", shared_mod); + + const lib = b.addStaticLibrary(.{ + .name = "lib", + .root_module = lib_mod, + }); + + exe_mod.linkLibrary(lib); + + const exe = b.addExecutable(.{ + .name = "app", + .root_module = exe_mod, + }); b.installArtifact(exe); } diff --git a/test/standalone/dep_lazypath/build.zig b/test/standalone/dep_lazypath/build.zig index f309487981..01b4be8fd4 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 0dc739b7af..f333c1917a 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(.{ - .root_source_file = b.path("foo.zig"), - }); - const bar = b.createModule(.{ - .root_source_file = b.path("bar.zig"), - }); - foo.addImport("bar", bar); - bar.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"), + }); + const bar_mod = b.createModule(.{ + .root_source_file = b.path("bar.zig"), + }); + + 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_module = main_mod, + }); 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 bc1b7a55bb..133b7706b0 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 85a58da95a..eb8457e494 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 c8562fd716..70f64dc334 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 ae1dc8fb75..4dc08ba1bb 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 2562c677c3..0da85e2923 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 f7430b7716..75670f6ba0 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 51b4066e6a..cc38a87ddc 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 f2f2391bc1..cd5b670146 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 f82dd51930..04946e47b6 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 dcbb0ad052..592566d62c 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 1886408933..a3907e20db 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 50e270d1c3..795bf008b3 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 889ee717d6..9f725c0c81 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 515528534e..c12949a9ce 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 c4ae240bd6..6148920b54 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 c37dfb12b5..88b7af06a5 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 9cb858d019..cace3c7d2d 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 e7d3a82431..bad94161af 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 321a635254..364dc0e81b 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 d4462bb5a1..3b4bb33def 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 d42ff1f304..4b0c089f97 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 a0dea518d6..ee82332973 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 3989bda9bc..aaa62abdb4 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 f484d2a6e6..ec05c45c21 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 0b626ba0fa..32b1d57b5c 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 7be4ff5090..12b90f3624 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 1c17e30d6a..07efea2a7b 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 25ed330abc..79d078a9eb 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 b0d0c035dd..3d94930ef3 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 3842f097d1..98f5a63dd5 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 f4c7254d8f..78b75e147d 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 2b7b3d423c..651740c04b 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 28c1bdb13e..ab90c129b9 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 c623780fa5..ba4464cefc 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 20027428b0..9d660b5c57 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 c952e9b250..98b417aaf7 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 d34120ed06..9f268d4cb8 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 ef7960d130..175724df63 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 cad3b05e08..6b24ef7124 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"), + .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") }); + + 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"), }); - 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 }}, - }); - - 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 48ca3c19db..a7b8eaf321 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 7ee501713c..399a23d924 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 4e41a8716e..ea4b26cc22 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 7c35cf2b76..b91b4fb3bb 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 c3d9c49940..1889b0c843 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 27f4fa919e..d3afadb60d 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 7f59ff1da4..2b967b16d5 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 8118c6e172..7edc55932c 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;