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| {
const tool = b.addTest(.{
.name = std.fs.path.stem(tool_src_path),
.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);

View file

@ -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 => {

View file

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

View file

@ -14,19 +14,24 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{
.name = "main",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.optimize = optimize,
.target = target,
}),
});
const lib = b.addSharedLibrary(.{
.name = "shared_lib",
.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);

View file

@ -12,11 +12,14 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{
.name = "main",
.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 = &.{},
});

View file

@ -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);

View file

@ -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);
}

View file

@ -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",
.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_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);
}

View file

@ -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);

View file

@ -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);

View file

@ -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);
}

View file

@ -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);

View file

@ -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);

View file

@ -10,24 +10,30 @@ pub fn build(b: *std.Build) void {
const touch = b.addExecutable(.{
.name = "touch",
.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_module = b.createModule(.{
.root_source_file = b.path("exists_in.zig"),
.optimize = .Debug,
.target = target,
}),
});
const has_basename = b.addExecutable(.{
.name = "has_basename",
.root_module = b.createModule(.{
.root_source_file = b.path("has_basename.zig"),
.optimize = .Debug,
.target = target,
}),
});
// Known path:

View file

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

View file

@ -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();

View file

@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void {
const obj = b.addObject(.{
.name = "main",
.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);

View file

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

View file

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

View file

@ -8,22 +8,28 @@ pub fn build(b: *std.Build) void {
const obj = b.addObject(.{
.name = "exports",
.root_module = b.createModule(.{
.root_source_file = b.path("exports.zig"),
.target = b.graph.host,
.optimize = optimize,
}),
});
const shared = b.addSharedLibrary(.{
.name = "shared",
.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);

View file

@ -9,24 +9,30 @@ pub fn build(b: *std.Build) void {
const obj1 = b.addStaticLibrary(.{
.name = "obj1",
.root_module = b.createModule(.{
.root_source_file = b.path("obj1.zig"),
.optimize = optimize,
.target = target,
}),
});
const obj2 = b.addStaticLibrary(.{
.name = "obj2",
.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);
}

View file

@ -8,18 +8,24 @@ pub fn build(b: *std.Build) void {
const libfoo = b.addStaticLibrary(.{
.name = "foo",
.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",
.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 <stdio.h>
\\#include <foo/a.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", .{});
// 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",
.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_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(&.{

View file

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

View file

@ -18,16 +18,19 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{
.name = "main",
.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();

View file

@ -15,9 +15,11 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{
.name = "zigtest",
.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) {

View file

@ -10,16 +10,18 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{
.name = "main",
.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);

View file

@ -5,15 +5,24 @@ pub fn build(b: *std.Build) void {
b.default_step = test_step;
const test1 = b.addTest(.{
.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_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_module = b.createModule(.{
.root_source_file = b.path("empty.zig"),
.target = b.graph.host,
}),
.test_runner = "src/main.zig",
});

View file

@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void {
const obj = b.addObject(.{
.name = "test",
.root_module = b.createModule(.{
.root_source_file = b.path("test.zig"),
.target = target,
.optimize = optimize,
}),
});
// 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 obj = b.addObject(.{
.name = "issue_5825",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.optimize = optimize,
.target = target,
}),
});
const exe = b.addExecutable(.{
.name = "issue_5825",
.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();

View file

@ -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

View file

@ -15,11 +15,13 @@ pub fn build(b: *std.Build) !void {
const kernel = b.addExecutable(.{
.name = "kernel",
.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);

View file

@ -11,12 +11,14 @@ pub fn build(b: *std.Build) void {
{
const exe = b.addExecutable(.{
.name = "mt",
.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_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);

View file

@ -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 },
.root_module = b.createModule(.{
.root_source_file = b.path("add.zig"),
.optimize = optimize,
.target = target,
}),
});
const main = b.addExecutable(.{
.name = "main",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.optimize = optimize,
.target = target,
}),
});
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 {
const exe = b.addExecutable(.{
.name = "test",
.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;

View file

@ -9,22 +9,27 @@ pub fn build(b: *std.Build) void {
const obj = b.addObject(.{
.name = "base64",
.root_module = b.createModule(.{
.root_source_file = b.path("base64.zig"),
.optimize = optimize,
.target = target,
}),
});
const exe = b.addExecutable(.{
.name = "test",
.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);

View file

@ -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);

View file

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

View file

@ -8,9 +8,11 @@ pub fn build(b: *std.Build) void {
const exe = b.addExecutable(.{
.name = "test",
.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") });

View file

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

View file

@ -9,9 +9,11 @@ pub fn build(b: *std.Build) void {
const create_file_exe = b.addExecutable(.{
.name = "create_file",
.root_module = b.createModule(.{
.root_source_file = b.path("create_file.zig"),
.target = target,
.optimize = optimize,
}),
});
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(.{
.name = "main",
.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_module = b.createModule(.{
.root_source_file = b.path("create-symlink.zig"),
.optimize = optimize,
.target = target,
}),
});
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 lib = b.addSharedLibrary(.{
.name = "mathtest",
.root_source_file = b.path("mathtest.zig"),
.version = .{ .major = 1, .minor = 0, .patch = 0 },
.root_module = b.createModule(.{
.root_source_file = b.path("mathtest.zig"),
.target = target,
.optimize = optimize,
}),
});
const exe = b.addExecutable(.{
.name = "test",
.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);

View file

@ -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_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_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);

View file

@ -20,11 +20,13 @@ pub fn build(b: *std.Build) void {
{
const exe = b.addExecutable(.{
.name = "unwind_fp",
.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_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",
.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_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,6 +126,7 @@ pub fn build(b: *std.Build) void {
inline for (no_os_targets) |os_tag| {
const exe = b.addExecutable(.{
.name = "unwind_freestanding",
.root_module = b.createModule(.{
.root_source_file = b.path("unwind_freestanding.zig"),
.target = b.resolveTargetQuery(.{
.cpu_arch = .x86_64,
@ -125,6 +135,7 @@ pub fn build(b: *std.Build) void {
.optimize = optimize,
.unwind_tables = null,
.omit_frame_pointer = false,
}),
});
// 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(.{
.name = "foo",
.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);
}

View file

@ -9,10 +9,12 @@ pub fn build(b: *std.Build) void {
const main = b.addExecutable(.{
.name = "main",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.optimize = optimize,
.target = target,
.strip = true,
}),
});
// 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 main = b.addTest(.{
.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);

View file

@ -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;

View file

@ -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);

View file

@ -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);
}

View file

@ -11,32 +11,39 @@ pub fn build(b: *std.Build) !void {
const lib_gnu = b.addStaticLibrary(.{
.name = "toargv-gnu",
.root_module = b.createModule(.{
.root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{
.abi = .gnu,
}),
.optimize = optimize,
}),
});
const verify_gnu = b.addExecutable(.{
.name = "verify-gnu",
.root_module = b.createModule(.{
.root_source_file = null,
.target = b.resolveTargetQuery(.{
.abi = .gnu,
}),
.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_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_module = b.createModule(.{
.root_source_file = b.path("lib.zig"),
.target = b.resolveTargetQuery(.{
.abi = .msvc,
}),
.optimize = optimize,
}),
});
const verify_msvc = b.addExecutable(.{
.name = "verify-msvc",
.root_module = b.createModule(.{
.root_source_file = null,
.target = b.resolveTargetQuery(.{
.abi = .msvc,
}),
.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");

View file

@ -12,16 +12,20 @@ pub fn build(b: *std.Build) !void {
const echo_args = b.addExecutable(.{
.name = "echo-args",
.root_module = b.createModule(.{
.root_source_file = b.path("echo-args.zig"),
.optimize = optimize,
.target = target,
}),
});
const test_exe = b.addExecutable(.{
.name = "test",
.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_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;

View file

@ -13,11 +13,14 @@ pub fn build(b: *std.Build) void {
{
const exe = b.addExecutable(.{
.name = "main",
.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",
.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",
.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",
.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);

View file

@ -28,11 +28,13 @@ fn add(
) void {
const exe = b.addExecutable(.{
.name = "zig_resource_test",
.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 = &.{

View file

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