test-standalone: migrate from deprecated std.Build APIs

This commit is contained in:
mlugg 2024-12-16 22:26:34 +00:00 committed by Eric Joldasov
parent 82659c4594
commit 6bd590ad37
No known key found for this signature in database
GPG key ID: 5C9C69060686B588
56 changed files with 596 additions and 381 deletions

View file

@ -47,9 +47,11 @@ pub fn build(b: *std.Build) void {
}) |tool_src_path| { }) |tool_src_path| {
const tool = b.addTest(.{ const tool = b.addTest(.{
.name = std.fs.path.stem(tool_src_path), .name = std.fs.path.stem(tool_src_path),
.root_source_file = b.path(tool_src_path), .root_module = b.createModule(.{
.optimize = .Debug, .root_source_file = b.path(tool_src_path),
.target = tools_target, .optimize = .Debug,
.target = tools_target,
}),
}); });
const run = b.addRunArtifact(tool); const run = b.addRunArtifact(tool);
tools_tests_step.dependOn(&run.step); tools_tests_step.dependOn(&run.step);

View file

@ -20,22 +20,25 @@ fn add(
) void { ) void {
const target = b.graph.host; const target = b.graph.host;
const exe_c = b.addExecutable(.{ const c_mod = b.createModule(.{
.name = c_name,
.optimize = optimize, .optimize = optimize,
.target = target, .target = target,
}); });
exe_c.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[0][]const u8{} }); c_mod.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[0][]const u8{} });
exe_c.linkLibC(); c_mod.link_libc = true;
const exe_cpp = b.addExecutable(.{ const exe_c = b.addExecutable(.{ .name = c_name, .root_module = c_mod });
.name = cpp_name,
const cpp_mod = b.createModule(.{
.optimize = optimize, .optimize = optimize,
.target = target, .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); 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) { switch (target.result.os.tag) {
.windows => { .windows => {

View file

@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void {
const child = b.addExecutable(.{ const child = b.addExecutable(.{
.name = "child", .name = "child",
.root_source_file = b.path("child.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("child.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const main = b.addExecutable(.{ const main = b.addExecutable(.{
.name = "main", .name = "main",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const run = b.addRunArtifact(main); const run = b.addRunArtifact(main);
run.addArtifactArg(child); run.addArtifactArg(child);

View file

@ -14,19 +14,24 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "main", .name = "main",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const lib = b.addSharedLibrary(.{ const lib = b.addSharedLibrary(.{
.name = "shared_lib", .name = "shared_lib",
.optimize = optimize, .root_module = b.createModule(.{
.target = target, .root_source_file = null,
.optimize = optimize,
.target = target,
.link_libc = true,
}),
}); });
lib.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} }); lib.root_module.addCSourceFile(.{ .file = b.path("shared_lib.c"), .flags = &.{"-gdwarf"} });
lib.linkLibC(); exe.root_module.linkLibrary(lib);
exe.linkLibrary(lib);
const run = b.addRunArtifact(exe); const run = b.addRunArtifact(exe);
run.expectExitCode(0); run.expectExitCode(0);

View file

@ -12,11 +12,14 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "main", .name = "main",
.optimize = optimize, .root_module = b.createModule(.{
.target = target, .root_source_file = null,
.optimize = optimize,
.target = target,
.link_libc = true,
}),
}); });
exe.linkLibC(); exe.root_module.addCSourceFile(.{
exe.addCSourceFile(.{
.file = b.path("main.c"), .file = b.path("main.c"),
.flags = &.{}, .flags = &.{},
}); });

View file

@ -6,23 +6,23 @@ pub fn build(b: *std.Build) void {
const optimize: std.builtin.OptimizeMode = .Debug; const optimize: std.builtin.OptimizeMode = .Debug;
const shared = b.createModule(.{ const main_mod = b.createModule(.{
.root_source_file = b.path("shared.zig"),
});
const exe = b.addExecutable(.{
.name = "test",
.root_source_file = b.path("test.zig"), .root_source_file = b.path("test.zig"),
.target = b.graph.host, .target = b.graph.host,
.optimize = optimize, .optimize = optimize,
}); });
exe.root_module.addAnonymousImport("foo", .{ const shared_mod = b.createModule(.{ .root_source_file = b.path("shared.zig") });
.root_source_file = b.path("foo.zig"), const foo_mod = b.createModule(.{ .root_source_file = b.path("foo.zig") });
.imports = &.{.{ .name = "shared", .module = shared }}, const bar_mod = b.createModule(.{ .root_source_file = b.path("bar.zig") });
});
exe.root_module.addAnonymousImport("bar", .{ main_mod.addImport("foo", foo_mod);
.root_source_file = b.path("bar.zig"), main_mod.addImport("bar", bar_mod);
.imports = &.{.{ .name = "shared", .module = shared }}, 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); const run = b.addRunArtifact(exe);

View file

@ -4,29 +4,36 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const mod = b.addModule("mod", .{ const shared_mod = b.createModule(.{
.root_source_file = b.path("mod.zig"), .root_source_file = b.path("mod.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
const lib_mod = b.createModule(.{
const lib = b.addStaticLibrary(.{
.name = "lib",
.root_source_file = b.path("lib.zig"), .root_source_file = b.path("lib.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
lib.root_module.addImport("mod", mod); const exe_mod = b.createModule(.{
const exe = b.addExecutable(.{
.name = "app",
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
exe.root_module.addImport("mod", mod); lib_mod.addImport("mod", shared_mod);
exe.root_module.linkLibrary(lib); 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); b.installArtifact(exe);
} }

View file

@ -11,10 +11,13 @@ pub fn build(b: *std.Build) void {
const generated_main_c = write_files.add("main.c", ""); const generated_main_c = write_files.add("main.c", "");
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "test", .name = "test",
.target = b.graph.host, .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = null,
.target = b.graph.host,
.optimize = optimize,
}),
}); });
exe.addCSourceFiles(.{ exe.root_module.addCSourceFiles(.{
.root = generated_main_c.dirname(), .root = generated_main_c.dirname(),
.files = &.{"main.c"}, .files = &.{"main.c"},
}); });
@ -26,11 +29,13 @@ pub fn build(b: *std.Build) void {
const dir = write_files.addCopyDirectory(b.path("inc"), "", .{}); const dir = write_files.addCopyDirectory(b.path("inc"), "", .{});
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "test", .name = "test",
.root_source_file = b.path("inctest.zig"), .root_module = b.createModule(.{
.target = b.graph.host, .root_source_file = b.path("inctest.zig"),
.optimize = optimize, .target = b.graph.host,
.optimize = optimize,
}),
}); });
exe.addIncludePath(dir); exe.root_module.addIncludePath(dir);
b.step("copydir", "").dependOn(&exe.step); b.step("copydir", "").dependOn(&exe.step);
test_step.dependOn(&exe.step); test_step.dependOn(&exe.step);
} }

View file

@ -6,22 +6,26 @@ pub fn build(b: *std.Build) void {
const optimize: std.builtin.OptimizeMode = .Debug; const optimize: std.builtin.OptimizeMode = .Debug;
const foo = b.createModule(.{ const main_mod = 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",
.root_source_file = b.path("test.zig"), .root_source_file = b.path("test.zig"),
.target = b.graph.host, .target = b.graph.host,
.optimize = optimize, .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); const run = b.addRunArtifact(exe);
test_step.dependOn(&run.step); test_step.dependOn(&run.step);

View file

@ -6,18 +6,22 @@ pub fn build(b: *std.Build) void {
const optimize: std.builtin.OptimizeMode = .Debug; const optimize: std.builtin.OptimizeMode = .Debug;
const foo = b.createModule(.{ const main_mod = b.createModule(.{
.root_source_file = b.path("foo.zig"),
});
foo.addImport("foo", foo);
const exe = b.addExecutable(.{
.name = "test",
.root_source_file = b.path("test.zig"), .root_source_file = b.path("test.zig"),
.target = b.graph.host, .target = b.graph.host,
.optimize = optimize, .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); const run = b.addRunArtifact(exe);
test_step.dependOn(&run.step); test_step.dependOn(&run.step);

View file

@ -6,16 +6,22 @@ pub fn build(b: *std.Build) void {
const optimize: std.builtin.OptimizeMode = .Debug; const optimize: std.builtin.OptimizeMode = .Debug;
const exe = b.addExecutable(.{ const main_mod = b.createModule(.{
.name = "test",
.root_source_file = b.path("test.zig"), .root_source_file = b.path("test.zig"),
.target = b.graph.host, .target = b.graph.host,
.optimize = optimize, .optimize = optimize,
}); });
exe.root_module.addAnonymousImport("foo", .{ const foo_mod = b.createModule(.{
.root_source_file = b.path("foo.zig"), .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); const run = b.addRunArtifact(exe);
test_step.dependOn(&run.step); test_step.dependOn(&run.step);
} }

View file

@ -6,21 +6,26 @@ pub fn build(b: *std.Build) void {
const optimize: std.builtin.OptimizeMode = .Debug; const optimize: std.builtin.OptimizeMode = .Debug;
const shared = b.createModule(.{ const main_mod = b.createModule(.{
.root_source_file = b.path("shared.zig"),
});
const exe = b.addExecutable(.{
.name = "test",
.root_source_file = b.path("test.zig"), .root_source_file = b.path("test.zig"),
.target = b.graph.host, .target = b.graph.host,
.optimize = optimize, .optimize = optimize,
}); });
exe.root_module.addAnonymousImport("foo", .{ const foo_mod = b.createModule(.{
.root_source_file = b.path("foo.zig"), .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); const run = b.addRunArtifact(exe);
test_step.dependOn(&run.step); test_step.dependOn(&run.step);

View file

@ -7,19 +7,22 @@ pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{}); const optimize = b.standardOptimizeOption(.{});
const exe = b.addExecutable(.{ const main_mod = b.createModule(.{
.name = "depend_on_main_mod",
.root_source_file = b.path("src/main.zig"), .root_source_file = b.path("src/main.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
}); });
const foo_mod = b.createModule(.{
const foo_module = b.addModule("foo", .{
.root_source_file = b.path("src/foo.zig"), .root_source_file = b.path("src/foo.zig"),
}); });
foo_module.addImport("root2", exe.root_module); foo_mod.addImport("root2", main_mod);
exe.root_module.addImport("foo", foo_module); 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); const run_cmd = b.addRunArtifact(exe);
run_cmd.expectExitCode(0); run_cmd.expectExitCode(0);

View file

@ -10,24 +10,30 @@ pub fn build(b: *std.Build) void {
const touch = b.addExecutable(.{ const touch = b.addExecutable(.{
.name = "touch", .name = "touch",
.root_source_file = touch_src, .root_module = b.createModule(.{
.optimize = .Debug, .root_source_file = touch_src,
.target = target, .optimize = .Debug,
.target = target,
}),
}); });
const generated = b.addRunArtifact(touch).addOutputFileArg("subdir" ++ std.fs.path.sep_str ++ "generated.txt"); const generated = b.addRunArtifact(touch).addOutputFileArg("subdir" ++ std.fs.path.sep_str ++ "generated.txt");
const exists_in = b.addExecutable(.{ const exists_in = b.addExecutable(.{
.name = "exists_in", .name = "exists_in",
.root_source_file = b.path("exists_in.zig"), .root_module = b.createModule(.{
.optimize = .Debug, .root_source_file = b.path("exists_in.zig"),
.target = target, .optimize = .Debug,
.target = target,
}),
}); });
const has_basename = b.addExecutable(.{ const has_basename = b.addExecutable(.{
.name = "has_basename", .name = "has_basename",
.root_source_file = b.path("has_basename.zig"), .root_module = b.createModule(.{
.optimize = .Debug, .root_source_file = b.path("has_basename.zig"),
.target = target, .optimize = .Debug,
.target = target,
}),
}); });
// Known path: // Known path:

View file

@ -6,18 +6,21 @@ pub fn build(b: *std.Build) void {
const bootloader = b.addExecutable(.{ const bootloader = b.addExecutable(.{
.name = "bootloader", .name = "bootloader",
.root_source_file = b.path("bootloader.zig"), .root_module = b.createModule(.{
.target = b.resolveTargetQuery(.{ .root_source_file = b.path("bootloader.zig"),
.cpu_arch = .x86, .target = b.resolveTargetQuery(.{
.os_tag = .freestanding, .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"), .root_source_file = b.path("main.zig"),
.target = b.graph.host,
.optimize = .Debug, .optimize = .Debug,
}); }) });
exe.root_module.addAnonymousImport("bootloader.elf", .{ exe.root_module.addAnonymousImport("bootloader.elf", .{
.root_source_file = bootloader.getEmittedBin(), .root_source_file = bootloader.getEmittedBin(),
}); });

View file

@ -4,10 +4,11 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Test it"); const test_step = b.step("test", "Test it");
b.default_step = test_step; b.default_step = test_step;
const main = b.addTest(.{ const main = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.target = b.graph.host,
.optimize = b.standardOptimizeOption(.{}), .optimize = b.standardOptimizeOption(.{}),
}); }) });
// TODO: actually check these two artifacts for correctness // TODO: actually check these two artifacts for correctness
_ = main.getEmittedBin(); _ = main.getEmittedBin();
_ = main.getEmittedAsm(); _ = main.getEmittedAsm();

View file

@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void {
const obj = b.addObject(.{ const obj = b.addObject(.{
.name = "main", .name = "main",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.target = b.graph.host, .optimize = optimize,
.target = b.graph.host,
}),
}); });
_ = obj.getEmittedAsm(); _ = obj.getEmittedAsm();
b.default_step.dependOn(&obj.step); b.default_step.dependOn(&obj.step);

View file

@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void {
const obj = b.addObject(.{ const obj = b.addObject(.{
.name = "main", .name = "main",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.target = b.graph.host, .optimize = optimize,
.target = b.graph.host,
}),
}); });
_ = obj.getEmittedLlvmIr(); _ = obj.getEmittedLlvmIr();
_ = obj.getEmittedLlvmBc(); _ = obj.getEmittedLlvmBc();

View file

@ -21,9 +21,11 @@ pub fn build(b: *std.Build) void {
const main = b.addExecutable(.{ const main = b.addExecutable(.{
.name = "main", .name = "main",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.target = b.graph.host, .root_source_file = b.path("main.zig"),
.optimize = optimize, .target = b.graph.host,
.optimize = optimize,
}),
}); });
const run = b.addRunArtifact(main); const run = b.addRunArtifact(main);

View file

@ -8,22 +8,28 @@ pub fn build(b: *std.Build) void {
const obj = b.addObject(.{ const obj = b.addObject(.{
.name = "exports", .name = "exports",
.root_source_file = b.path("exports.zig"), .root_module = b.createModule(.{
.target = b.graph.host, .root_source_file = b.path("exports.zig"),
.optimize = optimize, .target = b.graph.host,
.optimize = optimize,
}),
}); });
const shared = b.addSharedLibrary(.{ const shared = b.addSharedLibrary(.{
.name = "shared", .name = "shared",
.target = b.graph.host, .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = null,
.link_libc = true, .target = b.graph.host,
.optimize = optimize,
.link_libc = true,
}),
}); });
if (b.graph.host.result.abi == .msvc) shared.root_module.addCMacro("API", "__declspec(dllexport)"); if (b.graph.host.result.abi == .msvc) shared.root_module.addCMacro("API", "__declspec(dllexport)");
shared.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} }); shared.root_module.addCSourceFile(.{ .file = b.path("shared.c"), .flags = &.{} });
const test_exe = b.addTest(.{ const test_exe = b.addTest(.{ .root_module = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.target = b.graph.host,
.optimize = optimize, .optimize = optimize,
}); }) });
test_exe.addObject(obj); test_exe.addObject(obj);
test_exe.linkLibrary(shared); test_exe.linkLibrary(shared);

View file

@ -9,24 +9,30 @@ pub fn build(b: *std.Build) void {
const obj1 = b.addStaticLibrary(.{ const obj1 = b.addStaticLibrary(.{
.name = "obj1", .name = "obj1",
.root_source_file = b.path("obj1.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("obj1.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const obj2 = b.addStaticLibrary(.{ const obj2 = b.addStaticLibrary(.{
.name = "obj2", .name = "obj2",
.root_source_file = b.path("obj2.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("obj2.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const main = b.addTest(.{ const main_mod = b.createModule(.{
.root_source_file = b.path("main.zig"), .root_source_file = b.path("main.zig"),
.target = b.graph.host,
.optimize = optimize, .optimize = optimize,
}); });
main.linkLibrary(obj1); main_mod.linkLibrary(obj1);
main.linkLibrary(obj2); main_mod.linkLibrary(obj2);
const main = b.addTest(.{ .root_module = main_mod });
test_step.dependOn(&b.addRunArtifact(main).step); test_step.dependOn(&b.addRunArtifact(main).step);
} }

View file

@ -8,18 +8,24 @@ pub fn build(b: *std.Build) void {
const libfoo = b.addStaticLibrary(.{ const libfoo = b.addStaticLibrary(.{
.name = "foo", .name = "foo",
.target = b.resolveTargetQuery(.{}), .root_module = b.createModule(.{
.optimize = .Debug, .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(.{ const exe = b.addExecutable(.{
.name = "exe", .name = "exe",
.target = b.resolveTargetQuery(.{}), .root_module = b.createModule(.{
.optimize = .Debug, .root_source_file = null,
.link_libc = true, .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 <stdio.h> \\#include <stdio.h>
\\#include <foo/a.h> \\#include <foo/a.h>
\\#include <foo/sub_dir/b.h> \\#include <foo/sub_dir/b.h>
@ -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", .{}); 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. // 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", .{}); 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(.{ const libbar = b.addStaticLibrary(.{
.name = "bar", .name = "bar",
.target = b.resolveTargetQuery(.{}), .root_module = b.createModule(.{
.optimize = .Debug, .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", libbar.installHeader(b.addWriteFiles().add("bar.h",
\\#define BAR_X "X" \\#define BAR_X "X"
\\ \\
@ -78,9 +88,11 @@ pub fn build(b: *std.Build) void {
}); });
const check_exists = b.addExecutable(.{ const check_exists = b.addExecutable(.{
.name = "check_exists", .name = "check_exists",
.root_source_file = b.path("check_exists.zig"), .root_module = b.createModule(.{
.target = b.resolveTargetQuery(.{}), .root_source_file = b.path("check_exists.zig"),
.optimize = .Debug, .target = b.resolveTargetQuery(.{}),
.optimize = .Debug,
}),
}); });
const run_check_exists = b.addRunArtifact(check_exists); const run_check_exists = b.addRunArtifact(check_exists);
run_check_exists.addArgs(&.{ run_check_exists.addArgs(&.{

View file

@ -16,9 +16,11 @@ pub fn build(b: *std.Build) void {
const elf = b.addExecutable(.{ const elf = b.addExecutable(.{
.name = "zig-nrf52-blink.elf", .name = "zig-nrf52-blink.elf",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("main.zig"),
.optimize = optimize, .target = target,
.optimize = optimize,
}),
}); });
const hex_step = elf.addObjCopy(.{ const hex_step = elf.addObjCopy(.{

View file

@ -18,16 +18,19 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "main", .name = "main",
.optimize = optimize, .root_module = b.createModule(.{
.target = target, .root_source_file = null,
.optimize = optimize,
.target = target,
.link_libc = true,
}),
}); });
exe.addCSourceFile(.{ .file = b.path("main.m"), .flags = &.{} }); exe.root_module.addCSourceFile(.{ .file = b.path("main.m"), .flags = &.{} });
exe.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) }); exe.root_module.addSystemIncludePath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/include" }) });
exe.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) }); exe.root_module.addSystemFrameworkPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/System/Library/Frameworks" }) });
exe.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/lib" }) }); exe.root_module.addLibraryPath(.{ .cwd_relative = b.pathJoin(&.{ sdk, "/usr/lib" }) });
exe.linkFramework("Foundation"); exe.root_module.linkFramework("Foundation", .{});
exe.linkFramework("UIKit"); exe.root_module.linkFramework("UIKit", .{});
exe.linkLibC();
const check = exe.checkObject(); const check = exe.checkObject();
check.checkInHeaders(); check.checkInHeaders();

View file

@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "zigtest", .name = "zigtest",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("main.zig"),
.optimize = optimize, .target = target,
.optimize = optimize,
}),
}); });
b.installArtifact(exe); b.installArtifact(exe);
@ -25,8 +27,8 @@ pub fn build(b: *std.Build) void {
"test.c", "test.c",
}; };
exe.addCSourceFiles(.{ .files = &c_sources }); exe.root_module.addCSourceFiles(.{ .files = &c_sources });
exe.linkLibC(); exe.root_module.link_libc = true;
var i: i32 = 0; var i: i32 = 0;
while (i < 1000) : (i += 1) { while (i < 1000) : (i += 1) {

View file

@ -10,16 +10,18 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "main", .name = "main",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const c_sources = [_][]const u8{ const c_sources = [_][]const u8{
"test.c", "test.c",
}; };
exe.addCSourceFiles(.{ .files = &c_sources }); exe.root_module.addCSourceFiles(.{ .files = &c_sources });
exe.linkLibC(); exe.root_module.link_libc = true;
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
run_cmd.expectExitCode(0); run_cmd.expectExitCode(0);

View file

@ -5,15 +5,24 @@ pub fn build(b: *std.Build) void {
b.default_step = test_step; b.default_step = test_step;
const test1 = b.addTest(.{ 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", .test_runner = "src/main.zig",
}); });
const test2 = b.addTest(.{ 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", .test_runner = "src/main.zig",
}); });
const test3 = b.addTest(.{ 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", .test_runner = "src/main.zig",
}); });

View file

@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void {
const obj = b.addObject(.{ const obj = b.addObject(.{
.name = "test", .name = "test",
.root_source_file = b.path("test.zig"), .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("test.zig"),
.optimize = optimize, .target = target,
.optimize = optimize,
}),
}); });
// TODO: actually check the output // TODO: actually check the output

View file

@ -16,20 +16,25 @@ pub fn build(b: *std.Build) void {
const optimize: std.builtin.OptimizeMode = .Debug; const optimize: std.builtin.OptimizeMode = .Debug;
const obj = b.addObject(.{ const obj = b.addObject(.{
.name = "issue_5825", .name = "issue_5825",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "issue_5825", .name = "issue_5825",
.optimize = optimize, .root_module = b.createModule(.{
.target = target, .root_source_file = null,
.optimize = optimize,
.target = target,
}),
}); });
exe.subsystem = .Console; exe.subsystem = .Console;
exe.linkSystemLibrary("kernel32"); exe.root_module.linkSystemLibrary("kernel32", .{});
exe.linkSystemLibrary("ntdll"); exe.root_module.linkSystemLibrary("ntdll", .{});
exe.addObject(obj); exe.root_module.addObject(obj);
// TODO: actually check the output // TODO: actually check the output
_ = exe.getEmittedBin(); _ = exe.getEmittedBin();

View file

@ -4,9 +4,10 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Test it"); const test_step = b.step("test", "Test it");
b.default_step = test_step; 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"), .root_source_file = b.path("main.zig"),
}); .target = b.graph.host,
}) });
test_artifact.addIncludePath(b.path("a_directory")); test_artifact.addIncludePath(b.path("a_directory"));
// TODO: actually check the output // TODO: actually check the output

View file

@ -15,11 +15,13 @@ pub fn build(b: *std.Build) !void {
const kernel = b.addExecutable(.{ const kernel = b.addExecutable(.{
.name = "kernel", .name = "kernel",
.root_source_file = b.path("./main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("./main.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
kernel.addObjectFile(b.path("./boot.S")); kernel.root_module.addObjectFile(b.path("./boot.S"));
kernel.setLinkerScript(b.path("./linker.ld")); kernel.setLinkerScript(b.path("./linker.ld"));
b.installArtifact(kernel); b.installArtifact(kernel);

View file

@ -11,12 +11,14 @@ pub fn build(b: *std.Build) void {
{ {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "mt", .name = "mt",
.root_source_file = b.path("mt.zig"), .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("mt.zig"),
.optimize = optimize, .target = target,
.optimize = optimize,
.link_libcpp = true,
}),
}); });
exe.linkLibCpp(); exe.root_module.addCSourceFile(.{ .file = b.path("mt_doit.cpp") });
exe.addCSourceFile(.{ .file = b.path("mt_doit.cpp") });
link_step.dependOn(&exe.step); link_step.dependOn(&exe.step);
b.installArtifact(exe); b.installArtifact(exe);
run_step.dependOn(&b.addRunArtifact(exe).step); run_step.dependOn(&b.addRunArtifact(exe).step);
@ -24,13 +26,15 @@ pub fn build(b: *std.Build) void {
{ {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "st", .name = "st",
.root_source_file = b.path("st.zig"), .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("st.zig"),
.optimize = optimize, .target = target,
.single_threaded = true, .optimize = optimize,
.link_libcpp = true,
.single_threaded = true,
}),
}); });
exe.linkLibCpp(); exe.root_module.addCSourceFile(.{ .file = b.path("st_doit.cpp") });
exe.addCSourceFile(.{ .file = b.path("st_doit.cpp") });
link_step.dependOn(&exe.step); link_step.dependOn(&exe.step);
b.installArtifact(exe); b.installArtifact(exe);
run_step.dependOn(&b.addRunArtifact(exe).step); run_step.dependOn(&b.addRunArtifact(exe).step);

View file

@ -12,17 +12,21 @@ pub fn build(b: *std.Build) void {
const lib = b.addSharedLibrary(.{ const lib = b.addSharedLibrary(.{
.name = "add", .name = "add",
.root_source_file = b.path("add.zig"),
.version = .{ .major = 1, .minor = 0, .patch = 0 }, .version = .{ .major = 1, .minor = 0, .patch = 0 },
.optimize = optimize, .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("add.zig"),
.optimize = optimize,
.target = target,
}),
}); });
const main = b.addExecutable(.{ const main = b.addExecutable(.{
.name = "main", .name = "main",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const run = b.addRunArtifact(main); const run = b.addRunArtifact(main);

View file

@ -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 { fn add(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "test", .name = "test",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.target = b.graph.host, .root_source_file = b.path("main.zig"),
.optimize = optimize, .target = b.graph.host,
.optimize = optimize,
.link_libc = true,
}),
}); });
exe.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c11"} }); exe.root_module.addCSourceFile(.{ .file = b.path("test.c"), .flags = &[_][]const u8{"-std=c11"} });
exe.linkLibC();
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
run_cmd.skip_foreign_checks = true; run_cmd.skip_foreign_checks = true;

View file

@ -9,22 +9,27 @@ pub fn build(b: *std.Build) void {
const obj = b.addObject(.{ const obj = b.addObject(.{
.name = "base64", .name = "base64",
.root_source_file = b.path("base64.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("base64.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "test", .name = "test",
.optimize = optimize, .root_module = b.createModule(.{
.target = target, .root_source_file = null,
.optimize = optimize,
.target = target,
.link_libc = true,
}),
}); });
exe.addCSourceFile(.{ exe.root_module.addCSourceFile(.{
.file = b.path("test.c"), .file = b.path("test.c"),
.flags = &[_][]const u8{"-std=c99"}, .flags = &[_][]const u8{"-std=c99"},
}); });
exe.addObject(obj); exe.root_module.addObject(obj);
exe.linkSystemLibrary("c");
b.default_step.dependOn(&exe.step); b.default_step.dependOn(&exe.step);

View file

@ -1,11 +1,11 @@
const std = @import("std"); const std = @import("std");
pub fn build(b: *std.Build) void { 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"), .root_source_file = b.path("src/main.zig"),
.target = b.graph.host, .target = b.graph.host,
.optimize = .Debug, .optimize = .Debug,
}); }) });
const options = b.addOptions(); const options = b.addOptions();
main.addOptions("build_options", options); main.addOptions("build_options", options);

View file

@ -11,9 +11,11 @@ pub fn build(b: *std.Build) void {
}); });
const main = b.addTest(.{ const main = b.addTest(.{
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
main.pie = true; main.pie = true;

View file

@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "test", .name = "test",
.root_source_file = b.path("test.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("test.zig"),
.target = b.graph.host, .optimize = optimize,
.target = b.graph.host,
}),
}); });
exe.root_module.addAnonymousImport("my_pkg", .{ .root_source_file = b.path("pkg.zig") }); exe.root_module.addAnonymousImport("my_pkg", .{ .root_source_file = b.path("pkg.zig") });

View file

@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "create-file", .name = "create-file",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("main.zig"),
.optimize = optimize, .target = target,
.optimize = optimize,
}),
}); });
{ {

View file

@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void {
const create_file_exe = b.addExecutable(.{ const create_file_exe = b.addExecutable(.{
.name = "create_file", .name = "create_file",
.root_source_file = b.path("create_file.zig"), .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("create_file.zig"),
.optimize = optimize, .target = target,
.optimize = optimize,
}),
}); });
const create_first = b.addRunArtifact(create_file_exe); const create_first = b.addRunArtifact(create_file_exe);

View file

@ -15,16 +15,20 @@ pub fn build(b: *std.Build) void {
const main = b.addExecutable(.{ const main = b.addExecutable(.{
.name = "main", .name = "main",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const create_symlink_exe = b.addExecutable(.{ const create_symlink_exe = b.addExecutable(.{
.name = "create-symlink", .name = "create-symlink",
.root_source_file = b.path("create-symlink.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("create-symlink.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
var run_create_symlink = b.addRunArtifact(create_symlink_exe); var run_create_symlink = b.addRunArtifact(create_symlink_exe);

View file

@ -8,23 +8,28 @@ pub fn build(b: *std.Build) void {
const target = b.graph.host; const target = b.graph.host;
const lib = b.addSharedLibrary(.{ const lib = b.addSharedLibrary(.{
.name = "mathtest", .name = "mathtest",
.root_source_file = b.path("mathtest.zig"),
.version = .{ .major = 1, .minor = 0, .patch = 0 }, .version = .{ .major = 1, .minor = 0, .patch = 0 },
.target = target, .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("mathtest.zig"),
.target = target,
.optimize = optimize,
}),
}); });
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "test", .name = "test",
.target = target, .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = null,
.target = target,
.optimize = optimize,
.link_libc = true,
}),
}); });
exe.addCSourceFile(.{ exe.root_module.addCSourceFile(.{
.file = b.path("test.c"), .file = b.path("test.c"),
.flags = &[_][]const u8{"-std=c99"}, .flags = &[_][]const u8{"-std=c99"},
}); });
exe.linkLibrary(lib); exe.root_module.linkLibrary(lib);
exe.linkSystemLibrary("c");
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
test_step.dependOn(&run_cmd.step); test_step.dependOn(&run_cmd.step);

View file

@ -42,11 +42,13 @@ pub fn build(b: *std.Build) void {
if (case.is_exe) { if (case.is_exe) {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = std.fs.path.stem(case.src_path), .name = std.fs.path.stem(case.src_path),
.root_source_file = b.path(case.src_path), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path(case.src_path),
.target = resolved_target, .optimize = optimize,
.target = resolved_target,
}),
}); });
if (case.link_libc) exe.linkLibC(); if (case.link_libc) exe.root_module.link_libc = true;
_ = exe.getEmittedBin(); _ = exe.getEmittedBin();
@ -56,11 +58,13 @@ pub fn build(b: *std.Build) void {
if (case.is_test) { if (case.is_test) {
const exe = b.addTest(.{ const exe = b.addTest(.{
.name = std.fs.path.stem(case.src_path), .name = std.fs.path.stem(case.src_path),
.root_source_file = b.path(case.src_path), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path(case.src_path),
.target = resolved_target, .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); const run = b.addRunArtifact(exe);
step.dependOn(&run.step); step.dependOn(&run.step);

View file

@ -20,11 +20,13 @@ pub fn build(b: *std.Build) void {
{ {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "unwind_fp", .name = "unwind_fp",
.root_source_file = b.path("unwind.zig"), .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("unwind.zig"),
.optimize = optimize, .target = target,
.unwind_tables = if (target.result.isDarwin()) .@"async" else null, .optimize = optimize,
.omit_frame_pointer = false, .unwind_tables = if (target.result.isDarwin()) .@"async" else null,
.omit_frame_pointer = false,
}),
}); });
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
@ -43,11 +45,13 @@ pub fn build(b: *std.Build) void {
{ {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "unwind_nofp", .name = "unwind_nofp",
.root_source_file = b.path("unwind.zig"), .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("unwind.zig"),
.optimize = optimize, .target = target,
.unwind_tables = .@"async", .optimize = optimize,
.omit_frame_pointer = true, .unwind_tables = .@"async",
.omit_frame_pointer = true,
}),
}); });
const run_cmd = b.addRunArtifact(exe); const run_cmd = b.addRunArtifact(exe);
@ -66,27 +70,32 @@ pub fn build(b: *std.Build) void {
{ {
const c_shared_lib = b.addSharedLibrary(.{ const c_shared_lib = b.addSharedLibrary(.{
.name = "c_shared_lib", .name = "c_shared_lib",
.target = target, .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = null,
.strip = false, .target = target,
.optimize = optimize,
.link_libc = true,
.strip = false,
}),
}); });
if (target.result.os.tag == .windows) if (target.result.os.tag == .windows)
c_shared_lib.root_module.addCMacro("LIB_API", "__declspec(dllexport)"); 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"), .file = b.path("shared_lib.c"),
.flags = &.{"-fomit-frame-pointer"}, .flags = &.{"-fomit-frame-pointer"},
}); });
c_shared_lib.linkLibC();
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "shared_lib_unwind", .name = "shared_lib_unwind",
.root_source_file = b.path("shared_lib_unwind.zig"), .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("shared_lib_unwind.zig"),
.optimize = optimize, .target = target,
.unwind_tables = if (target.result.isDarwin()) .@"async" else null, .optimize = optimize,
.omit_frame_pointer = true, .unwind_tables = if (target.result.isDarwin()) .@"async" else null,
.omit_frame_pointer = true,
}),
}); });
exe.linkLibrary(c_shared_lib); exe.linkLibrary(c_shared_lib);
@ -117,14 +126,16 @@ pub fn build(b: *std.Build) void {
inline for (no_os_targets) |os_tag| { inline for (no_os_targets) |os_tag| {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "unwind_freestanding", .name = "unwind_freestanding",
.root_source_file = b.path("unwind_freestanding.zig"), .root_module = b.createModule(.{
.target = b.resolveTargetQuery(.{ .root_source_file = b.path("unwind_freestanding.zig"),
.cpu_arch = .x86_64, .target = b.resolveTargetQuery(.{
.os_tag = os_tag, .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 // This "freestanding" binary is runnable because it invokes the

View file

@ -8,18 +8,22 @@ pub fn build(b: *std.Build) void {
const foo = b.addStaticLibrary(.{ const foo = b.addStaticLibrary(.{
.name = "foo", .name = "foo",
.optimize = optimize, .root_module = b.createModule(.{
.target = b.graph.host, .root_source_file = null,
.optimize = optimize,
.target = b.graph.host,
}),
}); });
foo.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} }); foo.root_module.addCSourceFile(.{ .file = b.path("foo.c"), .flags = &[_][]const u8{} });
foo.addIncludePath(b.path(".")); 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"), .root_source_file = b.path("foo.zig"),
.target = b.graph.host,
.optimize = optimize, .optimize = optimize,
}); }) });
test_exe.linkLibrary(foo); test_exe.root_module.linkLibrary(foo);
test_exe.addIncludePath(b.path(".")); test_exe.root_module.addIncludePath(b.path("."));
test_step.dependOn(&b.addRunArtifact(test_exe).step); test_step.dependOn(&b.addRunArtifact(test_exe).step);
} }

View file

@ -9,10 +9,12 @@ pub fn build(b: *std.Build) void {
const main = b.addExecutable(.{ const main = b.addExecutable(.{
.name = "main", .name = "main",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.target = target, .optimize = optimize,
.strip = true, .target = target,
.strip = true,
}),
}); });
// TODO: actually check the output // TODO: actually check the output

View file

@ -7,9 +7,12 @@ pub fn build(b: *std.Build) void {
const optimize: std.builtin.OptimizeMode = .Debug; const optimize: std.builtin.OptimizeMode = .Debug;
const main = b.addTest(.{ const main = b.addTest(.{
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.strip = true, .target = b.graph.host,
.optimize = optimize,
.strip = true,
}),
}); });
test_step.dependOn(&b.addRunArtifact(main).step); test_step.dependOn(&b.addRunArtifact(main).step);

View file

@ -1,19 +1,21 @@
const std = @import("std"); const std = @import("std");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const t = b.addTest(.{ const test_mod = b.createModule(.{
.root_source_file = b.path("src/main.zig"), .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"), .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"); const test_step = b.step("test", "Run unit tests");
test_step.dependOn(&b.addRunArtifact(t).step); test_step.dependOn(&b.addRunArtifact(t).step);
b.default_step = test_step; b.default_step = test_step;

View file

@ -6,9 +6,10 @@ pub fn build(b: *std.Build) void {
const test_step = b.step("test", "Test the program"); const test_step = b.step("test", "Test the program");
b.default_step = test_step; 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"), .root_source_file = b.path("test.zig"),
}); }) });
test_exe.test_runner = b.path("test_runner.zig"); test_exe.test_runner = b.path("test_runner.zig");
const test_run = b.addRunArtifact(test_exe); const test_run = b.addRunArtifact(test_exe);

View file

@ -6,11 +6,12 @@ pub fn build(b: *std.Build) void {
const optimize: std.builtin.OptimizeMode = .Debug; 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"), .root_source_file = b.path("main.zig"),
.target = b.graph.host,
.optimize = optimize, .optimize = optimize,
}); }) });
main.addIncludePath(b.path(".")); main.root_module.addIncludePath(b.path("."));
test_step.dependOn(&b.addRunArtifact(main).step); test_step.dependOn(&b.addRunArtifact(main).step);
} }

View file

@ -11,32 +11,39 @@ pub fn build(b: *std.Build) !void {
const lib_gnu = b.addStaticLibrary(.{ const lib_gnu = b.addStaticLibrary(.{
.name = "toargv-gnu", .name = "toargv-gnu",
.root_source_file = b.path("lib.zig"), .root_module = b.createModule(.{
.target = b.resolveTargetQuery(.{ .root_source_file = b.path("lib.zig"),
.abi = .gnu, .target = b.resolveTargetQuery(.{
.abi = .gnu,
}),
.optimize = optimize,
}), }),
.optimize = optimize,
}); });
const verify_gnu = b.addExecutable(.{ const verify_gnu = b.addExecutable(.{
.name = "verify-gnu", .name = "verify-gnu",
.target = b.resolveTargetQuery(.{ .root_module = b.createModule(.{
.abi = .gnu, .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"), .file = b.path("verify.c"),
.flags = &.{ "-DUNICODE", "-D_UNICODE" }, .flags = &.{ "-DUNICODE", "-D_UNICODE" },
}); });
verify_gnu.mingw_unicode_entry_point = true; verify_gnu.mingw_unicode_entry_point = true;
verify_gnu.linkLibrary(lib_gnu); verify_gnu.root_module.linkLibrary(lib_gnu);
verify_gnu.linkLibC(); verify_gnu.root_module.link_libc = true;
const fuzz = b.addExecutable(.{ const fuzz = b.addExecutable(.{
.name = "fuzz", .name = "fuzz",
.root_source_file = b.path("fuzz.zig"), .root_module = b.createModule(.{
.target = b.graph.host, .root_source_file = b.path("fuzz.zig"),
.optimize = optimize, .target = b.graph.host,
.optimize = optimize,
}),
}); });
const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100; 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) { if (has_msvc) {
const lib_msvc = b.addStaticLibrary(.{ const lib_msvc = b.addStaticLibrary(.{
.name = "toargv-msvc", .name = "toargv-msvc",
.root_source_file = b.path("lib.zig"), .root_module = b.createModule(.{
.target = b.resolveTargetQuery(.{ .root_source_file = b.path("lib.zig"),
.abi = .msvc, .target = b.resolveTargetQuery(.{
.abi = .msvc,
}),
.optimize = optimize,
}), }),
.optimize = optimize,
}); });
const verify_msvc = b.addExecutable(.{ const verify_msvc = b.addExecutable(.{
.name = "verify-msvc", .name = "verify-msvc",
.target = b.resolveTargetQuery(.{ .root_module = b.createModule(.{
.abi = .msvc, .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"), .file = b.path("verify.c"),
.flags = &.{ "-DUNICODE", "-D_UNICODE" }, .flags = &.{ "-DUNICODE", "-D_UNICODE" },
}); });
verify_msvc.linkLibrary(lib_msvc); verify_msvc.root_module.linkLibrary(lib_msvc);
verify_msvc.linkLibC(); verify_msvc.root_module.link_libc = true;
const run_msvc = b.addRunArtifact(fuzz); const run_msvc = b.addRunArtifact(fuzz);
run_msvc.setName("fuzz-msvc"); run_msvc.setName("fuzz-msvc");

View file

@ -12,16 +12,20 @@ pub fn build(b: *std.Build) !void {
const echo_args = b.addExecutable(.{ const echo_args = b.addExecutable(.{
.name = "echo-args", .name = "echo-args",
.root_source_file = b.path("echo-args.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("echo-args.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const test_exe = b.addExecutable(.{ const test_exe = b.addExecutable(.{
.name = "test", .name = "test",
.root_source_file = b.path("test.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("test.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const run = b.addRunArtifact(test_exe); const run = b.addRunArtifact(test_exe);
@ -33,9 +37,11 @@ pub fn build(b: *std.Build) !void {
const fuzz = b.addExecutable(.{ const fuzz = b.addExecutable(.{
.name = "fuzz", .name = "fuzz",
.root_source_file = b.path("fuzz.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("fuzz.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100; const fuzz_max_iterations = b.option(u64, "iterations", "The max fuzz iterations (default: 100)") orelse 100;

View file

@ -13,11 +13,14 @@ pub fn build(b: *std.Build) void {
{ {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "main", .name = "main",
.target = target, .root_module = b.createModule(.{
.optimize = .Debug, .root_source_file = null,
.link_libc = true, .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(); _ = exe.getEmittedBin();
test_step.dependOn(&exe.step); test_step.dependOn(&exe.step);
@ -26,12 +29,15 @@ pub fn build(b: *std.Build) void {
{ {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "wmain", .name = "wmain",
.target = target, .root_module = b.createModule(.{
.optimize = .Debug, .root_source_file = null,
.link_libc = true, .target = target,
.optimize = .Debug,
.link_libc = true,
}),
}); });
exe.mingw_unicode_entry_point = 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(); _ = exe.getEmittedBin();
test_step.dependOn(&exe.step); test_step.dependOn(&exe.step);
@ -40,12 +46,15 @@ pub fn build(b: *std.Build) void {
{ {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "winmain", .name = "winmain",
.target = target, .root_module = b.createModule(.{
.optimize = .Debug, .root_source_file = null,
.link_libc = true, .target = target,
.optimize = .Debug,
.link_libc = true,
}),
}); });
// Note: `exe.subsystem = .Windows;` is not necessary // 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(); _ = exe.getEmittedBin();
test_step.dependOn(&exe.step); test_step.dependOn(&exe.step);
@ -54,13 +63,16 @@ pub fn build(b: *std.Build) void {
{ {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "wwinmain", .name = "wwinmain",
.target = target, .root_module = b.createModule(.{
.optimize = .Debug, .root_source_file = null,
.link_libc = true, .target = target,
.optimize = .Debug,
.link_libc = true,
}),
}); });
exe.mingw_unicode_entry_point = true; exe.mingw_unicode_entry_point = true;
// Note: `exe.subsystem = .Windows;` is not necessary // 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(); _ = exe.getEmittedBin();
test_step.dependOn(&exe.step); test_step.dependOn(&exe.step);

View file

@ -28,11 +28,13 @@ fn add(
) void { ) void {
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "zig_resource_test", .name = "zig_resource_test",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.target = target, .root_source_file = b.path("main.zig"),
.optimize = .Debug, .target = target,
.optimize = .Debug,
}),
}); });
exe.addWin32ResourceFile(.{ exe.root_module.addWin32ResourceFile(.{
.file = b.path("res/zig.rc"), .file = b.path("res/zig.rc"),
.flags = &.{"/c65001"}, // UTF-8 code page .flags = &.{"/c65001"}, // UTF-8 code page
.include_paths = &.{ .include_paths = &.{

View file

@ -12,16 +12,20 @@ pub fn build(b: *std.Build) void {
const hello = b.addExecutable(.{ const hello = b.addExecutable(.{
.name = "hello", .name = "hello",
.root_source_file = b.path("hello.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("hello.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const main = b.addExecutable(.{ const main = b.addExecutable(.{
.name = "main", .name = "main",
.root_source_file = b.path("main.zig"), .root_module = b.createModule(.{
.optimize = optimize, .root_source_file = b.path("main.zig"),
.target = target, .optimize = optimize,
.target = target,
}),
}); });
const run = b.addRunArtifact(main); const run = b.addRunArtifact(main);

View file

@ -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 { 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"), .root_source_file = b.path("src/main.zig"),
.target = b.resolveTargetQuery(.{ .target = b.resolveTargetQuery(.{
.os_tag = .wasi, .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}), .cpu_features_add = std.Target.wasm.featureSet(&.{.bulk_memory}),
}), }),
.optimize = optimize, .optimize = optimize,
}); }) });
const run_unit_tests = b.addRunArtifact(unit_tests); const run_unit_tests = b.addRunArtifact(unit_tests);
run_unit_tests.skip_foreign_checks = true; run_unit_tests.skip_foreign_checks = true;