Merge pull request #15234 from ziglang/remove-legacy-build-api

remove --enable-cache option; std.Build.CompileStep: remove output_dir
This commit is contained in:
Andrew Kelley 2023-04-11 11:54:43 -04:00 committed by GitHub
commit d3a237a98c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 89 additions and 227 deletions

View File

@ -325,7 +325,6 @@ const Code = struct {
link_objects: []const []const u8,
target_str: ?[]const u8,
link_libc: bool,
backend_stage1: bool,
link_mode: ?std.builtin.LinkMode,
disable_cache: bool,
verbose_cimport: bool,
@ -596,7 +595,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
var link_mode: ?std.builtin.LinkMode = null;
var disable_cache = false;
var verbose_cimport = false;
var backend_stage1 = false;
var additional_options = std.ArrayList([]const u8).init(allocator);
defer additional_options.deinit();
@ -631,8 +629,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
link_libc = true;
} else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) {
link_mode = .Dynamic;
} else if (mem.eql(u8, end_tag_name, "backend_stage1")) {
backend_stage1 = true;
} else if (mem.eql(u8, end_tag_name, "additonal_option")) {
_ = try eatToken(tokenizer, Token.Id.Separator);
const option = try eatToken(tokenizer, Token.Id.TagContent);
@ -660,7 +656,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
.link_objects = try link_objects.toOwnedSlice(),
.target_str = target_str,
.link_libc = link_libc,
.backend_stage1 = backend_stage1,
.link_mode = link_mode,
.disable_cache = disable_cache,
.verbose_cimport = verbose_cimport,
@ -1380,10 +1375,10 @@ fn genHtml(
var build_args = std.ArrayList([]const u8).init(allocator);
defer build_args.deinit();
try build_args.appendSlice(&[_][]const u8{
zig_exe, "build-exe",
"--name", code.name,
"--color", "on",
"--enable-cache", tmp_source_file_name,
zig_exe, "build-exe",
"--name", code.name,
"--color", "on",
name_plus_ext,
});
if (opt_zig_lib_dir) |zig_lib_dir| {
try build_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir });
@ -1400,21 +1395,13 @@ fn genHtml(
}
for (code.link_objects) |link_object| {
const name_with_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ link_object, obj_ext });
const full_path_object = try fs.path.join(
allocator,
&[_][]const u8{ tmp_dir_name, name_with_ext },
);
try build_args.append(full_path_object);
try build_args.append(name_with_ext);
try shell_out.print("{s} ", .{name_with_ext});
}
if (code.link_libc) {
try build_args.append("-lc");
try shell_out.print("-lc ", .{});
}
if (code.backend_stage1) {
try build_args.append("-fstage1");
try shell_out.print("-fstage1", .{});
}
const target = try std.zig.CrossTarget.parse(.{
.arch_os_abi = code.target_str orelse "native",
});
@ -1461,7 +1448,7 @@ fn genHtml(
try shell_out.writeAll(colored_stderr);
break :code_block;
}
const exec_result = exec(allocator, &env_map, build_args.items) catch
const exec_result = exec(allocator, &env_map, tmp_dir_name, build_args.items) catch
return parseError(tokenizer, code.source_token, "example failed to compile", .{});
if (code.verbose_cimport) {
@ -1480,15 +1467,10 @@ fn genHtml(
}
}
const path_to_exe_dir = mem.trim(u8, exec_result.stdout, " \r\n");
const path_to_exe_basename = try std.fmt.allocPrint(allocator, "{s}{s}", .{
const path_to_exe = try std.fmt.allocPrint(allocator, "./{s}{s}", .{
code.name,
target.exeFileExt(),
});
const path_to_exe = try fs.path.join(allocator, &[_][]const u8{
path_to_exe_dir,
path_to_exe_basename,
});
const run_args = &[_][]const u8{path_to_exe};
var exited_with_signal = false;
@ -1498,6 +1480,7 @@ fn genHtml(
.allocator = allocator,
.argv = run_args,
.env_map = &env_map,
.cwd = tmp_dir_name,
.max_output_bytes = max_doc_file_size,
});
switch (result.term) {
@ -1514,7 +1497,7 @@ fn genHtml(
}
break :blk result;
} else blk: {
break :blk exec(allocator, &env_map, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{});
break :blk exec(allocator, &env_map, tmp_dir_name, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{});
};
const escaped_stderr = try escapeHtml(allocator, result.stderr);
@ -1555,10 +1538,6 @@ fn genHtml(
try test_args.append("-lc");
try shell_out.print("-lc ", .{});
}
if (code.backend_stage1) {
try test_args.append("-fstage1");
try shell_out.print("-fstage1", .{});
}
if (code.target_str) |triple| {
try test_args.appendSlice(&[_][]const u8{ "-target", triple });
try shell_out.print("-target {s} ", .{triple});
@ -1579,7 +1558,7 @@ fn genHtml(
},
}
}
const result = exec(allocator, &env_map, test_args.items) catch
const result = exec(allocator, &env_map, null, test_args.items) catch
return parseError(tokenizer, code.source_token, "test failed", .{});
const escaped_stderr = try escapeHtml(allocator, result.stderr);
const escaped_stdout = try escapeHtml(allocator, result.stdout);
@ -1610,10 +1589,6 @@ fn genHtml(
try test_args.append("-lc");
try shell_out.print("-lc ", .{});
}
if (code.backend_stage1) {
try test_args.append("-fstage1");
try shell_out.print("-fstage1", .{});
}
const result = try ChildProcess.exec(.{
.allocator = allocator,
.argv = test_args.items,
@ -1778,7 +1753,7 @@ fn genHtml(
const colored_stderr = try termColor(allocator, escaped_stderr);
try shell_out.print("\n{s} ", .{colored_stderr});
} else {
_ = exec(allocator, &env_map, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
_ = exec(allocator, &env_map, null, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
}
try shell_out.writeAll("\n");
},
@ -1831,7 +1806,7 @@ fn genHtml(
try test_args.append(option);
try shell_out.print("{s} ", .{option});
}
const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
const result = exec(allocator, &env_map, null, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
const escaped_stderr = try escapeHtml(allocator, result.stderr);
const escaped_stdout = try escapeHtml(allocator, result.stdout);
try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout });
@ -1846,11 +1821,17 @@ fn genHtml(
}
}
fn exec(allocator: Allocator, env_map: *process.EnvMap, args: []const []const u8) !ChildProcess.ExecResult {
fn exec(
allocator: Allocator,
env_map: *process.EnvMap,
cwd: ?[]const u8,
args: []const []const u8,
) !ChildProcess.ExecResult {
const result = try ChildProcess.exec(.{
.allocator = allocator,
.argv = args,
.env_map = env_map,
.cwd = cwd,
.max_output_bytes = max_doc_file_size,
});
switch (result.term) {
@ -1877,12 +1858,12 @@ fn getBuiltinCode(
opt_zig_lib_dir: ?[]const u8,
) ![]const u8 {
if (opt_zig_lib_dir) |zig_lib_dir| {
const result = try exec(allocator, env_map, &.{
const result = try exec(allocator, env_map, null, &.{
zig_exe, "build-obj", "--show-builtin", "--zig-lib-dir", zig_lib_dir,
});
return result.stdout;
} else {
const result = try exec(allocator, env_map, &.{
const result = try exec(allocator, env_map, null, &.{
zig_exe, "build-obj", "--show-builtin",
});
return result.stdout;

View File

@ -539,6 +539,8 @@ pub const TestOptions = struct {
optimize: std.builtin.Mode = .Debug,
version: ?std.builtin.Version = null,
max_rss: usize = 0,
filter: ?[]const u8 = null,
test_runner: ?[]const u8 = null,
};
pub fn addTest(b: *Build, options: TestOptions) *CompileStep {
@ -549,6 +551,8 @@ pub fn addTest(b: *Build, options: TestOptions) *CompileStep {
.target = options.target,
.optimize = options.optimize,
.max_rss = options.max_rss,
.filter = options.filter,
.test_runner = options.test_runner,
});
}

View File

@ -97,13 +97,10 @@ out_lib_filename: []const u8,
out_pdb_filename: []const u8,
modules: std.StringArrayHashMap(*Module),
object_src: []const u8,
link_objects: ArrayList(LinkObject),
include_dirs: ArrayList(IncludeDir),
c_macros: ArrayList([]const u8),
installed_headers: ArrayList(*Step),
output_dir: ?[]const u8,
is_linking_libc: bool = false,
is_linking_libcpp: bool = false,
vcpkg_bin_path: ?[]const u8 = null,
@ -288,6 +285,8 @@ pub const Options = struct {
linkage: ?Linkage = null,
version: ?std.builtin.Version = null,
max_rss: usize = 0,
filter: ?[]const u8 = null,
test_runner: ?[]const u8 = null,
};
pub const Kind = enum {
@ -340,6 +339,23 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
options.target.zigTriple(owner.allocator) catch @panic("OOM"),
});
const target_info = NativeTargetInfo.detect(options.target) catch @panic("unhandled error");
const out_filename = std.zig.binNameAlloc(owner.allocator, .{
.root_name = name,
.target = target_info.target,
.output_mode = switch (options.kind) {
.lib => .Lib,
.obj => .Obj,
.exe, .@"test" => .Exe,
},
.link_mode = if (options.linkage) |some| @as(std.builtin.LinkMode, switch (some) {
.dynamic => .Dynamic,
.static => .Static,
}) else null,
.version = options.version,
}) catch @panic("OOM");
const self = owner.allocator.create(CompileStep) catch @panic("OOM");
self.* = CompileStep{
.strip = null,
@ -361,7 +377,7 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
.max_rss = options.max_rss,
}),
.version = options.version,
.out_filename = undefined,
.out_filename = out_filename,
.out_h_filename = owner.fmt("{s}.h", .{name}),
.out_lib_filename = undefined,
.out_pdb_filename = owner.fmt("{s}.pdb", .{name}),
@ -375,18 +391,16 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
.rpaths = ArrayList(FileSource).init(owner.allocator),
.framework_dirs = ArrayList(FileSource).init(owner.allocator),
.installed_headers = ArrayList(*Step).init(owner.allocator),
.object_src = undefined,
.c_std = std.Build.CStd.C99,
.zig_lib_dir = null,
.main_pkg_path = null,
.exec_cmd_args = null,
.filter = null,
.test_runner = null,
.filter = options.filter,
.test_runner = options.test_runner,
.disable_stack_probing = false,
.disable_sanitize_c = false,
.sanitize_thread = false,
.rdynamic = false,
.output_dir = null,
.override_dest_dir = null,
.installed_path = null,
.force_undefined_symbols = StringHashMap(void).init(owner.allocator),
@ -397,70 +411,41 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
.output_pdb_path_source = GeneratedFile{ .step = &self.step },
.output_dirname_source = GeneratedFile{ .step = &self.step },
.target_info = NativeTargetInfo.detect(self.target) catch @panic("unhandled error"),
.target_info = target_info,
};
self.computeOutFileNames();
if (root_src) |rs| rs.addStepDependencies(&self.step);
return self;
}
fn computeOutFileNames(self: *CompileStep) void {
const b = self.step.owner;
const target = self.target_info.target;
self.out_filename = std.zig.binNameAlloc(b.allocator, .{
.root_name = self.name,
.target = target,
.output_mode = switch (self.kind) {
.lib => .Lib,
.obj => .Obj,
.exe, .@"test" => .Exe,
},
.link_mode = if (self.linkage) |some| @as(std.builtin.LinkMode, switch (some) {
.dynamic => .Dynamic,
.static => .Static,
}) else null,
.version = self.version,
}) catch @panic("OOM");
if (self.kind == .lib) {
if (self.linkage != null and self.linkage.? == .static) {
self.out_lib_filename = self.out_filename;
} else if (self.version) |version| {
if (target.isDarwin()) {
self.major_only_filename = b.fmt("lib{s}.{d}.dylib", .{
if (target_info.target.isDarwin()) {
self.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{
self.name,
version.major,
});
self.name_only_filename = b.fmt("lib{s}.dylib", .{self.name});
self.name_only_filename = owner.fmt("lib{s}.dylib", .{self.name});
self.out_lib_filename = self.out_filename;
} else if (target.os.tag == .windows) {
self.out_lib_filename = b.fmt("{s}.lib", .{self.name});
} else if (target_info.target.os.tag == .windows) {
self.out_lib_filename = owner.fmt("{s}.lib", .{self.name});
} else {
self.major_only_filename = b.fmt("lib{s}.so.{d}", .{ self.name, version.major });
self.name_only_filename = b.fmt("lib{s}.so", .{self.name});
self.major_only_filename = owner.fmt("lib{s}.so.{d}", .{ self.name, version.major });
self.name_only_filename = owner.fmt("lib{s}.so", .{self.name});
self.out_lib_filename = self.out_filename;
}
} else {
if (target.isDarwin()) {
if (target_info.target.isDarwin()) {
self.out_lib_filename = self.out_filename;
} else if (target.os.tag == .windows) {
self.out_lib_filename = b.fmt("{s}.lib", .{self.name});
} else if (target_info.target.os.tag == .windows) {
self.out_lib_filename = owner.fmt("{s}.lib", .{self.name});
} else {
self.out_lib_filename = self.out_filename;
}
}
if (self.output_dir != null) {
self.output_lib_path_source.path = b.pathJoin(
&.{ self.output_dir.?, self.out_lib_filename },
);
}
}
}
pub fn setOutputDir(self: *CompileStep, dir: []const u8) void {
const b = self.step.owner;
self.output_dir = b.dupePath(dir);
if (root_src) |rs| rs.addStepDependencies(&self.step);
return self;
}
pub fn installHeader(cs: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void {
@ -853,24 +838,6 @@ fn linkSystemLibraryInner(self: *CompileStep, name: []const u8, opts: struct {
}) catch @panic("OOM");
}
pub fn setName(self: *CompileStep, text: []const u8) void {
const b = self.step.owner;
assert(self.kind == .@"test");
self.name = b.dupe(text);
}
pub fn setFilter(self: *CompileStep, text: ?[]const u8) void {
const b = self.step.owner;
assert(self.kind == .@"test");
self.filter = if (text) |t| b.dupe(t) else null;
}
pub fn setTestRunner(self: *CompileStep, path: ?[]const u8) void {
const b = self.step.owner;
assert(self.kind == .@"test");
self.test_runner = if (path) |p| b.dupePath(p) else null;
}
/// Handy when you have many C/C++ source files and want them all to have the same flags.
pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []const []const u8) void {
const b = self.step.owner;
@ -1864,7 +1831,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
});
}
try zig_args.append("--enable-cache");
try zig_args.append("--listen=-");
// Windows has an argument length limit of 32,766 characters, macOS 262,144 and Linux
@ -1932,54 +1898,31 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
},
else => |e| return e,
};
const build_output_dir = fs.path.dirname(output_bin_path).?;
if (self.output_dir) |output_dir| {
var src_dir = try fs.cwd().openIterableDir(build_output_dir, .{});
defer src_dir.close();
// Create the output directory if it doesn't exist.
try fs.cwd().makePath(output_dir);
var dest_dir = try fs.cwd().openDir(output_dir, .{});
defer dest_dir.close();
var it = src_dir.iterate();
while (try it.next()) |entry| {
// The compiler can put these files into the same directory, but we don't
// want to copy them over.
if (mem.eql(u8, entry.name, "llvm-ar.id") or
mem.eql(u8, entry.name, "libs.txt") or
mem.eql(u8, entry.name, "builtin.zig") or
mem.eql(u8, entry.name, "zld.id") or
mem.eql(u8, entry.name, "lld.id")) continue;
_ = try src_dir.dir.updateFile(entry.name, dest_dir, entry.name, .{});
}
} else {
self.output_dir = build_output_dir;
}
// This will ensure all output filenames will now have the output_dir available!
self.computeOutFileNames();
const output_dir = fs.path.dirname(output_bin_path).?;
// Update generated files
if (self.output_dir != null) {
self.output_dirname_source.path = self.output_dir.?;
{
self.output_dirname_source.path = output_dir;
self.output_path_source.path = b.pathJoin(
&.{ self.output_dir.?, self.out_filename },
&.{ output_dir, self.out_filename },
);
if (self.kind == .lib) {
self.output_lib_path_source.path = b.pathJoin(
&.{ output_dir, self.out_lib_filename },
);
}
if (self.emit_h) {
self.output_h_path_source.path = b.pathJoin(
&.{ self.output_dir.?, self.out_h_filename },
&.{ output_dir, self.out_h_filename },
);
}
if (self.target.isWindows() or self.target.isUefi()) {
self.output_pdb_path_source.path = b.pathJoin(
&.{ self.output_dir.?, self.out_pdb_filename },
&.{ output_dir, self.out_pdb_filename },
);
}
}

View File

@ -100,7 +100,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
try argv_list.append("translate-c");
try argv_list.append("-lc");
try argv_list.append("--enable-cache");
try argv_list.append("--listen=-");
if (!self.target.isNative()) {

View File

@ -386,7 +386,6 @@ const usage_build_generic =
\\ --cache-dir [path] Override the local cache directory
\\ --global-cache-dir [path] Override the global cache directory
\\ --zig-lib-dir [path] Override path to Zig installation lib directory
\\ --enable-cache Output to cache directory; print path to stdout
\\
\\Compile Options:
\\ -target [name] <arch><sub>-<os>-<abi> see the targets command
@ -756,7 +755,6 @@ fn buildOutputType(
var link_libcpp = false;
var link_libunwind = false;
var want_native_include_dirs = false;
var enable_cache: ?bool = null;
var want_pic: ?bool = null;
var want_pie: ?bool = null;
var want_lto: ?bool = null;
@ -1203,8 +1201,6 @@ fn buildOutputType(
build_id = true;
} else if (mem.eql(u8, arg, "-fno-build-id")) {
build_id = false;
} else if (mem.eql(u8, arg, "--enable-cache")) {
enable_cache = true;
} else if (mem.eql(u8, arg, "--test-cmd-bin")) {
try test_exec_args.append(null);
} else if (mem.eql(u8, arg, "--test-evented-io")) {
@ -2641,7 +2637,7 @@ fn buildOutputType(
var cleanup_emit_bin_dir: ?fs.Dir = null;
defer if (cleanup_emit_bin_dir) |*dir| dir.close();
const have_enable_cache = enable_cache orelse false;
const output_to_cache = listen != .none;
const optional_version = if (have_version) version else null;
const resolved_soname: ?[]const u8 = switch (soname) {
@ -2668,7 +2664,7 @@ fn buildOutputType(
switch (arg_mode) {
.run, .zig_test => break :blk null,
else => {
if (have_enable_cache) {
if (output_to_cache) {
break :blk null;
} else {
break :blk .{ .path = null, .handle = fs.cwd() };
@ -2686,12 +2682,6 @@ fn buildOutputType(
},
.yes => |full_path| b: {
const basename = fs.path.basename(full_path);
if (have_enable_cache) {
break :b Compilation.EmitLoc{
.basename = basename,
.directory = null,
};
}
if (fs.path.dirname(full_path)) |dirname| {
const handle = fs.cwd().openDir(dirname, .{}) catch |err| {
fatal("unable to open output directory '{s}': {s}", .{ dirname, @errorName(err) });
@ -3145,7 +3135,7 @@ fn buildOutputType(
.test_filter = test_filter,
.test_name_prefix = test_name_prefix,
.test_runner_path = test_runner_path,
.disable_lld_caching = !have_enable_cache,
.disable_lld_caching = !output_to_cache,
.subsystem = subsystem,
.wasi_exec_model = wasi_exec_model,
.debug_compile_errors = debug_compile_errors,
@ -3240,19 +3230,7 @@ fn buildOutputType(
return cmdTranslateC(comp, arena, null);
}
const hook: AfterUpdateHook = blk: {
if (!have_enable_cache)
break :blk .none;
switch (emit_bin) {
.no => break :blk .none,
.yes_default_path => break :blk .print_emit_bin_dir_path,
.yes => |full_path| break :blk .{ .update = full_path },
.yes_a_out => break :blk .{ .update = a_out_basename },
}
};
updateModule(gpa, comp, hook) catch |err| switch (err) {
updateModule(comp) catch |err| switch (err) {
error.SemanticAnalyzeFail => if (listen == .none) process.exit(1),
else => |e| return e,
};
@ -3800,13 +3778,7 @@ fn runOrTestHotSwap(
}
}
const AfterUpdateHook = union(enum) {
none,
print_emit_bin_dir_path,
update: []const u8,
};
fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void {
fn updateModule(comp: *Compilation) !void {
{
// If the terminal is dumb, we dont want to show the user all the output.
var progress: std.Progress = .{ .dont_print_on_dumb = true };
@ -3832,43 +3804,6 @@ fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void
if (errors.errorMessageCount() > 0) {
errors.renderToStdErr(renderOptions(comp.color));
return error.SemanticAnalyzeFail;
} else switch (hook) {
.none => {},
.print_emit_bin_dir_path => {
const emit = comp.bin_file.options.emit.?;
const full_path = try emit.directory.join(gpa, &.{emit.sub_path});
defer gpa.free(full_path);
const dir_path = fs.path.dirname(full_path).?;
try io.getStdOut().writer().print("{s}\n", .{dir_path});
},
.update => |full_path| {
const bin_sub_path = comp.bin_file.options.emit.?.sub_path;
const cwd = fs.cwd();
const cache_dir = comp.bin_file.options.emit.?.directory.handle;
_ = try cache_dir.updateFile(bin_sub_path, cwd, full_path, .{});
// If a .pdb file is part of the expected output, we must also copy
// it into place here.
const is_coff = comp.bin_file.options.target.ofmt == .coff;
const have_pdb = is_coff and !comp.bin_file.options.strip;
if (have_pdb) {
// Replace `.out` or `.exe` with `.pdb` on both the source and destination
const src_bin_ext = fs.path.extension(bin_sub_path);
const dst_bin_ext = fs.path.extension(full_path);
const src_pdb_path = try std.fmt.allocPrint(gpa, "{s}.pdb", .{
bin_sub_path[0 .. bin_sub_path.len - src_bin_ext.len],
});
defer gpa.free(src_pdb_path);
const dst_pdb_path = try std.fmt.allocPrint(gpa, "{s}.pdb", .{
full_path[0 .. full_path.len - dst_bin_ext.len],
});
defer gpa.free(dst_pdb_path);
_ = try cache_dir.updateFile(src_pdb_path, cwd, dst_pdb_path, .{});
}
},
}
}
@ -4499,7 +4434,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
};
defer comp.destroy();
updateModule(gpa, comp, .none) catch |err| switch (err) {
updateModule(comp) catch |err| switch (err) {
error.SemanticAnalyzeFail => process.exit(2),
else => |e| return e,
};

View File

@ -6,16 +6,16 @@ pub fn build(b: *std.Build) void {
const test1 = b.addTest(.{
.root_source_file = .{ .path = "test_root/empty.zig" },
.test_runner = "src/main.zig",
});
const test2 = b.addTest(.{
.root_source_file = .{ .path = "src/empty.zig" },
.test_runner = "src/main.zig",
});
const test3 = b.addTest(.{
.root_source_file = .{ .path = "empty.zig" },
.test_runner = "src/main.zig",
});
test1.setTestRunner("src/main.zig");
test2.setTestRunner("src/main.zig");
test3.setTestRunner("src/main.zig");
test_step.dependOn(&b.addRunArtifact(test1).step);
test_step.dependOn(&b.addRunArtifact(test2).step);

View File

@ -3,8 +3,8 @@ const std = @import("std");
pub fn build(b: *std.Build) void {
const t = b.addTest(.{
.root_source_file = .{ .path = "src/main.zig" },
.test_runner = "test_runner/main.zig",
});
t.setTestRunner("test_runner/main.zig");
const module1 = b.createModule(.{ .source_file = .{ .path = "module1/main.zig" } });
const module2 = b.createModule(.{

View File

@ -977,11 +977,11 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
.optimize = test_target.optimize_mode,
.target = test_target.target,
.max_rss = max_rss,
.filter = options.test_filter,
});
const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
const backend_txt = if (test_target.backend) |backend| @tagName(backend) else "default";
these_tests.single_threaded = test_target.single_threaded;
these_tests.setFilter(options.test_filter);
if (test_target.link_libc) {
these_tests.linkSystemLibrary("c");
}
@ -1037,10 +1037,15 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S
continue;
}
const triple_prefix = c_abi_target.zigTriple(b.allocator) catch @panic("OOM");
const test_step = b.addTest(.{
.root_source_file = .{ .path = "test/c_abi/main.zig" },
.optimize = optimize_mode,
.target = c_abi_target,
.name = b.fmt("test-c-abi-{s}-{s}", .{
triple_prefix, @tagName(optimize_mode),
}),
});
if (c_abi_target.abi != null and c_abi_target.abi.?.isMusl()) {
// TODO NativeTargetInfo insists on dynamically linking musl
@ -1057,11 +1062,6 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S
test_step.want_lto = false;
}
const triple_prefix = c_abi_target.zigTriple(b.allocator) catch @panic("OOM");
test_step.setName(b.fmt("test-c-abi-{s}-{s} ", .{
triple_prefix, @tagName(optimize_mode),
}));
const run = b.addRunArtifact(test_step);
run.skip_foreign_checks = true;
step.dependOn(&run.step);