authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-04-11 11:54:43-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-04-11 11:54:43-04:00
logd3a237a98c5a2ccf72a774b5f93425c02fea4bea
treeb440fbaf013ed472c39a60381928c0224e694f5c
parent1728d92f60d4e9aa10d878e3235fc63764d3909b
parent3c3cee2cfabc5d03bb83cf6cc6a8ed80f13ee1df
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

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

remove --enable-cache option; std.Build.CompileStep: remove output_dir

8 files changed, 89 insertions(+), 227 deletions(-)

doc/docgen.zig+21-40
......@@ -325,7 +325,6 @@ const Code = struct {
325325 link_objects: []const []const u8,
326326 target_str: ?[]const u8,
327327 link_libc: bool,
328 backend_stage1: bool,
329328 link_mode: ?std.builtin.LinkMode,
330329 disable_cache: bool,
331330 verbose_cimport: bool,
......@@ -596,7 +595,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
596595 var link_mode: ?std.builtin.LinkMode = null;
597596 var disable_cache = false;
598597 var verbose_cimport = false;
599 var backend_stage1 = false;
600598 var additional_options = std.ArrayList([]const u8).init(allocator);
601599 defer additional_options.deinit();
602600
......@@ -631,8 +629,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
631629 link_libc = true;
632630 } else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) {
633631 link_mode = .Dynamic;
634 } else if (mem.eql(u8, end_tag_name, "backend_stage1")) {
635 backend_stage1 = true;
636632 } else if (mem.eql(u8, end_tag_name, "additonal_option")) {
637633 _ = try eatToken(tokenizer, Token.Id.Separator);
638634 const option = try eatToken(tokenizer, Token.Id.TagContent);
......@@ -660,7 +656,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc {
660656 .link_objects = try link_objects.toOwnedSlice(),
661657 .target_str = target_str,
662658 .link_libc = link_libc,
663 .backend_stage1 = backend_stage1,
664659 .link_mode = link_mode,
665660 .disable_cache = disable_cache,
666661 .verbose_cimport = verbose_cimport,
......@@ -1380,10 +1375,10 @@ fn genHtml(
13801375 var build_args = std.ArrayList([]const u8).init(allocator);
13811376 defer build_args.deinit();
13821377 try build_args.appendSlice(&[_][]const u8{
1383 zig_exe, "build-exe",
1384 "--name", code.name,
1385 "--color", "on",
1386 "--enable-cache", tmp_source_file_name,
1378 zig_exe, "build-exe",
1379 "--name", code.name,
1380 "--color", "on",
1381 name_plus_ext,
13871382 });
13881383 if (opt_zig_lib_dir) |zig_lib_dir| {
13891384 try build_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir });
......@@ -1400,21 +1395,13 @@ fn genHtml(
14001395 }
14011396 for (code.link_objects) |link_object| {
14021397 const name_with_ext = try std.fmt.allocPrint(allocator, "{s}{s}", .{ link_object, obj_ext });
1403 const full_path_object = try fs.path.join(
1404 allocator,
1405 &[_][]const u8{ tmp_dir_name, name_with_ext },
1406 );
1407 try build_args.append(full_path_object);
1398 try build_args.append(name_with_ext);
14081399 try shell_out.print("{s} ", .{name_with_ext});
14091400 }
14101401 if (code.link_libc) {
14111402 try build_args.append("-lc");
14121403 try shell_out.print("-lc ", .{});
14131404 }
1414 if (code.backend_stage1) {
1415 try build_args.append("-fstage1");
1416 try shell_out.print("-fstage1", .{});
1417 }
14181405 const target = try std.zig.CrossTarget.parse(.{
14191406 .arch_os_abi = code.target_str orelse "native",
14201407 });
......@@ -1461,7 +1448,7 @@ fn genHtml(
14611448 try shell_out.writeAll(colored_stderr);
14621449 break :code_block;
14631450 }
1464 const exec_result = exec(allocator, &env_map, build_args.items) catch
1451 const exec_result = exec(allocator, &env_map, tmp_dir_name, build_args.items) catch
14651452 return parseError(tokenizer, code.source_token, "example failed to compile", .{});
14661453
14671454 if (code.verbose_cimport) {
......@@ -1480,15 +1467,10 @@ fn genHtml(
14801467 }
14811468 }
14821469
1483 const path_to_exe_dir = mem.trim(u8, exec_result.stdout, " \r\n");
1484 const path_to_exe_basename = try std.fmt.allocPrint(allocator, "{s}{s}", .{
1470 const path_to_exe = try std.fmt.allocPrint(allocator, "./{s}{s}", .{
14851471 code.name,
14861472 target.exeFileExt(),
14871473 });
1488 const path_to_exe = try fs.path.join(allocator, &[_][]const u8{
1489 path_to_exe_dir,
1490 path_to_exe_basename,
1491 });
14921474 const run_args = &[_][]const u8{path_to_exe};
14931475
14941476 var exited_with_signal = false;
......@@ -1498,6 +1480,7 @@ fn genHtml(
14981480 .allocator = allocator,
14991481 .argv = run_args,
15001482 .env_map = &env_map,
1483 .cwd = tmp_dir_name,
15011484 .max_output_bytes = max_doc_file_size,
15021485 });
15031486 switch (result.term) {
......@@ -1514,7 +1497,7 @@ fn genHtml(
15141497 }
15151498 break :blk result;
15161499 } else blk: {
1517 break :blk exec(allocator, &env_map, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{});
1500 break :blk exec(allocator, &env_map, tmp_dir_name, run_args) catch return parseError(tokenizer, code.source_token, "example crashed", .{});
15181501 };
15191502
15201503 const escaped_stderr = try escapeHtml(allocator, result.stderr);
......@@ -1555,10 +1538,6 @@ fn genHtml(
15551538 try test_args.append("-lc");
15561539 try shell_out.print("-lc ", .{});
15571540 }
1558 if (code.backend_stage1) {
1559 try test_args.append("-fstage1");
1560 try shell_out.print("-fstage1", .{});
1561 }
15621541 if (code.target_str) |triple| {
15631542 try test_args.appendSlice(&[_][]const u8{ "-target", triple });
15641543 try shell_out.print("-target {s} ", .{triple});
......@@ -1579,7 +1558,7 @@ fn genHtml(
15791558 },
15801559 }
15811560 }
1582 const result = exec(allocator, &env_map, test_args.items) catch
1561 const result = exec(allocator, &env_map, null, test_args.items) catch
15831562 return parseError(tokenizer, code.source_token, "test failed", .{});
15841563 const escaped_stderr = try escapeHtml(allocator, result.stderr);
15851564 const escaped_stdout = try escapeHtml(allocator, result.stdout);
......@@ -1610,10 +1589,6 @@ fn genHtml(
16101589 try test_args.append("-lc");
16111590 try shell_out.print("-lc ", .{});
16121591 }
1613 if (code.backend_stage1) {
1614 try test_args.append("-fstage1");
1615 try shell_out.print("-fstage1", .{});
1616 }
16171592 const result = try ChildProcess.exec(.{
16181593 .allocator = allocator,
16191594 .argv = test_args.items,
......@@ -1778,7 +1753,7 @@ fn genHtml(
17781753 const colored_stderr = try termColor(allocator, escaped_stderr);
17791754 try shell_out.print("\n{s} ", .{colored_stderr});
17801755 } else {
1781 _ = exec(allocator, &env_map, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
1756 _ = exec(allocator, &env_map, null, build_args.items) catch return parseError(tokenizer, code.source_token, "example failed to compile", .{});
17821757 }
17831758 try shell_out.writeAll("\n");
17841759 },
......@@ -1831,7 +1806,7 @@ fn genHtml(
18311806 try test_args.append(option);
18321807 try shell_out.print("{s} ", .{option});
18331808 }
1834 const result = exec(allocator, &env_map, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
1809 const result = exec(allocator, &env_map, null, test_args.items) catch return parseError(tokenizer, code.source_token, "test failed", .{});
18351810 const escaped_stderr = try escapeHtml(allocator, result.stderr);
18361811 const escaped_stdout = try escapeHtml(allocator, result.stdout);
18371812 try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout });
......@@ -1846,11 +1821,17 @@ fn genHtml(
18461821 }
18471822}
18481823
1849fn exec(allocator: Allocator, env_map: *process.EnvMap, args: []const []const u8) !ChildProcess.ExecResult {
1824fn exec(
1825 allocator: Allocator,
1826 env_map: *process.EnvMap,
1827 cwd: ?[]const u8,
1828 args: []const []const u8,
1829) !ChildProcess.ExecResult {
18501830 const result = try ChildProcess.exec(.{
18511831 .allocator = allocator,
18521832 .argv = args,
18531833 .env_map = env_map,
1834 .cwd = cwd,
18541835 .max_output_bytes = max_doc_file_size,
18551836 });
18561837 switch (result.term) {
......@@ -1877,12 +1858,12 @@ fn getBuiltinCode(
18771858 opt_zig_lib_dir: ?[]const u8,
18781859) ![]const u8 {
18791860 if (opt_zig_lib_dir) |zig_lib_dir| {
1880 const result = try exec(allocator, env_map, &.{
1861 const result = try exec(allocator, env_map, null, &.{
18811862 zig_exe, "build-obj", "--show-builtin", "--zig-lib-dir", zig_lib_dir,
18821863 });
18831864 return result.stdout;
18841865 } else {
1885 const result = try exec(allocator, env_map, &.{
1866 const result = try exec(allocator, env_map, null, &.{
18861867 zig_exe, "build-obj", "--show-builtin",
18871868 });
18881869 return result.stdout;
lib/std/Build.zig+4
......@@ -539,6 +539,8 @@ pub const TestOptions = struct {
539539 optimize: std.builtin.Mode = .Debug,
540540 version: ?std.builtin.Version = null,
541541 max_rss: usize = 0,
542 filter: ?[]const u8 = null,
543 test_runner: ?[]const u8 = null,
542544};
543545
544546pub fn addTest(b: *Build, options: TestOptions) *CompileStep {
......@@ -549,6 +551,8 @@ pub fn addTest(b: *Build, options: TestOptions) *CompileStep {
549551 .target = options.target,
550552 .optimize = options.optimize,
551553 .max_rss = options.max_rss,
554 .filter = options.filter,
555 .test_runner = options.test_runner,
552556 });
553557}
554558
lib/std/Build/CompileStep.zig+48-105
......@@ -97,13 +97,10 @@ out_lib_filename: []const u8,
9797out_pdb_filename: []const u8,
9898modules: std.StringArrayHashMap(*Module),
9999
100object_src: []const u8,
101
102100link_objects: ArrayList(LinkObject),
103101include_dirs: ArrayList(IncludeDir),
104102c_macros: ArrayList([]const u8),
105103installed_headers: ArrayList(*Step),
106output_dir: ?[]const u8,
107104is_linking_libc: bool = false,
108105is_linking_libcpp: bool = false,
109106vcpkg_bin_path: ?[]const u8 = null,
......@@ -288,6 +285,8 @@ pub const Options = struct {
288285 linkage: ?Linkage = null,
289286 version: ?std.builtin.Version = null,
290287 max_rss: usize = 0,
288 filter: ?[]const u8 = null,
289 test_runner: ?[]const u8 = null,
291290};
292291
293292pub const Kind = enum {
......@@ -340,6 +339,23 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
340339 options.target.zigTriple(owner.allocator) catch @panic("OOM"),
341340 });
342341
342 const target_info = NativeTargetInfo.detect(options.target) catch @panic("unhandled error");
343
344 const out_filename = std.zig.binNameAlloc(owner.allocator, .{
345 .root_name = name,
346 .target = target_info.target,
347 .output_mode = switch (options.kind) {
348 .lib => .Lib,
349 .obj => .Obj,
350 .exe, .@"test" => .Exe,
351 },
352 .link_mode = if (options.linkage) |some| @as(std.builtin.LinkMode, switch (some) {
353 .dynamic => .Dynamic,
354 .static => .Static,
355 }) else null,
356 .version = options.version,
357 }) catch @panic("OOM");
358
343359 const self = owner.allocator.create(CompileStep) catch @panic("OOM");
344360 self.* = CompileStep{
345361 .strip = null,
......@@ -361,7 +377,7 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
361377 .max_rss = options.max_rss,
362378 }),
363379 .version = options.version,
364 .out_filename = undefined,
380 .out_filename = out_filename,
365381 .out_h_filename = owner.fmt("{s}.h", .{name}),
366382 .out_lib_filename = undefined,
367383 .out_pdb_filename = owner.fmt("{s}.pdb", .{name}),
......@@ -375,18 +391,16 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
375391 .rpaths = ArrayList(FileSource).init(owner.allocator),
376392 .framework_dirs = ArrayList(FileSource).init(owner.allocator),
377393 .installed_headers = ArrayList(*Step).init(owner.allocator),
378 .object_src = undefined,
379394 .c_std = std.Build.CStd.C99,
380395 .zig_lib_dir = null,
381396 .main_pkg_path = null,
382397 .exec_cmd_args = null,
383 .filter = null,
384 .test_runner = null,
398 .filter = options.filter,
399 .test_runner = options.test_runner,
385400 .disable_stack_probing = false,
386401 .disable_sanitize_c = false,
387402 .sanitize_thread = false,
388403 .rdynamic = false,
389 .output_dir = null,
390404 .override_dest_dir = null,
391405 .installed_path = null,
392406 .force_undefined_symbols = StringHashMap(void).init(owner.allocator),
......@@ -397,70 +411,41 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
397411 .output_pdb_path_source = GeneratedFile{ .step = &self.step },
398412 .output_dirname_source = GeneratedFile{ .step = &self.step },
399413
400 .target_info = NativeTargetInfo.detect(self.target) catch @panic("unhandled error"),
414 .target_info = target_info,
401415 };
402 self.computeOutFileNames();
403 if (root_src) |rs| rs.addStepDependencies(&self.step);
404 return self;
405}
406
407fn computeOutFileNames(self: *CompileStep) void {
408 const b = self.step.owner;
409 const target = self.target_info.target;
410
411 self.out_filename = std.zig.binNameAlloc(b.allocator, .{
412 .root_name = self.name,
413 .target = target,
414 .output_mode = switch (self.kind) {
415 .lib => .Lib,
416 .obj => .Obj,
417 .exe, .@"test" => .Exe,
418 },
419 .link_mode = if (self.linkage) |some| @as(std.builtin.LinkMode, switch (some) {
420 .dynamic => .Dynamic,
421 .static => .Static,
422 }) else null,
423 .version = self.version,
424 }) catch @panic("OOM");
425416
426417 if (self.kind == .lib) {
427418 if (self.linkage != null and self.linkage.? == .static) {
428419 self.out_lib_filename = self.out_filename;
429420 } else if (self.version) |version| {
430 if (target.isDarwin()) {
431 self.major_only_filename = b.fmt("lib{s}.{d}.dylib", .{
421 if (target_info.target.isDarwin()) {
422 self.major_only_filename = owner.fmt("lib{s}.{d}.dylib", .{
432423 self.name,
433424 version.major,
434425 });
435 self.name_only_filename = b.fmt("lib{s}.dylib", .{self.name});
426 self.name_only_filename = owner.fmt("lib{s}.dylib", .{self.name});
436427 self.out_lib_filename = self.out_filename;
437 } else if (target.os.tag == .windows) {
438 self.out_lib_filename = b.fmt("{s}.lib", .{self.name});
428 } else if (target_info.target.os.tag == .windows) {
429 self.out_lib_filename = owner.fmt("{s}.lib", .{self.name});
439430 } else {
440 self.major_only_filename = b.fmt("lib{s}.so.{d}", .{ self.name, version.major });
441 self.name_only_filename = b.fmt("lib{s}.so", .{self.name});
431 self.major_only_filename = owner.fmt("lib{s}.so.{d}", .{ self.name, version.major });
432 self.name_only_filename = owner.fmt("lib{s}.so", .{self.name});
442433 self.out_lib_filename = self.out_filename;
443434 }
444435 } else {
445 if (target.isDarwin()) {
436 if (target_info.target.isDarwin()) {
446437 self.out_lib_filename = self.out_filename;
447 } else if (target.os.tag == .windows) {
448 self.out_lib_filename = b.fmt("{s}.lib", .{self.name});
438 } else if (target_info.target.os.tag == .windows) {
439 self.out_lib_filename = owner.fmt("{s}.lib", .{self.name});
449440 } else {
450441 self.out_lib_filename = self.out_filename;
451442 }
452443 }
453 if (self.output_dir != null) {
454 self.output_lib_path_source.path = b.pathJoin(
455 &.{ self.output_dir.?, self.out_lib_filename },
456 );
457 }
458444 }
459}
460445
461pub fn setOutputDir(self: *CompileStep, dir: []const u8) void {
462 const b = self.step.owner;
463 self.output_dir = b.dupePath(dir);
446 if (root_src) |rs| rs.addStepDependencies(&self.step);
447
448 return self;
464449}
465450
466451pub 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 {
853838 }) catch @panic("OOM");
854839}
855840
856pub fn setName(self: *CompileStep, text: []const u8) void {
857 const b = self.step.owner;
858 assert(self.kind == .@"test");
859 self.name = b.dupe(text);
860}
861
862pub fn setFilter(self: *CompileStep, text: ?[]const u8) void {
863 const b = self.step.owner;
864 assert(self.kind == .@"test");
865 self.filter = if (text) |t| b.dupe(t) else null;
866}
867
868pub fn setTestRunner(self: *CompileStep, path: ?[]const u8) void {
869 const b = self.step.owner;
870 assert(self.kind == .@"test");
871 self.test_runner = if (path) |p| b.dupePath(p) else null;
872}
873
874841/// Handy when you have many C/C++ source files and want them all to have the same flags.
875842pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []const []const u8) void {
876843 const b = self.step.owner;
......@@ -1864,7 +1831,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
18641831 });
18651832 }
18661833
1867 try zig_args.append("--enable-cache");
18681834 try zig_args.append("--listen=-");
18691835
18701836 // 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 {
19321898 },
19331899 else => |e| return e,
19341900 };
1935 const build_output_dir = fs.path.dirname(output_bin_path).?;
1936
1937 if (self.output_dir) |output_dir| {
1938 var src_dir = try fs.cwd().openIterableDir(build_output_dir, .{});
1939 defer src_dir.close();
1940
1941 // Create the output directory if it doesn't exist.
1942 try fs.cwd().makePath(output_dir);
1943
1944 var dest_dir = try fs.cwd().openDir(output_dir, .{});
1945 defer dest_dir.close();
1946
1947 var it = src_dir.iterate();
1948 while (try it.next()) |entry| {
1949 // The compiler can put these files into the same directory, but we don't
1950 // want to copy them over.
1951 if (mem.eql(u8, entry.name, "llvm-ar.id") or
1952 mem.eql(u8, entry.name, "libs.txt") or
1953 mem.eql(u8, entry.name, "builtin.zig") or
1954 mem.eql(u8, entry.name, "zld.id") or
1955 mem.eql(u8, entry.name, "lld.id")) continue;
1956
1957 _ = try src_dir.dir.updateFile(entry.name, dest_dir, entry.name, .{});
1958 }
1959 } else {
1960 self.output_dir = build_output_dir;
1961 }
1962
1963 // This will ensure all output filenames will now have the output_dir available!
1964 self.computeOutFileNames();
1901 const output_dir = fs.path.dirname(output_bin_path).?;
19651902
19661903 // Update generated files
1967 if (self.output_dir != null) {
1968 self.output_dirname_source.path = self.output_dir.?;
1904 {
1905 self.output_dirname_source.path = output_dir;
19691906
19701907 self.output_path_source.path = b.pathJoin(
1971 &.{ self.output_dir.?, self.out_filename },
1908 &.{ output_dir, self.out_filename },
19721909 );
19731910
1911 if (self.kind == .lib) {
1912 self.output_lib_path_source.path = b.pathJoin(
1913 &.{ output_dir, self.out_lib_filename },
1914 );
1915 }
1916
19741917 if (self.emit_h) {
19751918 self.output_h_path_source.path = b.pathJoin(
1976 &.{ self.output_dir.?, self.out_h_filename },
1919 &.{ output_dir, self.out_h_filename },
19771920 );
19781921 }
19791922
19801923 if (self.target.isWindows() or self.target.isUefi()) {
19811924 self.output_pdb_path_source.path = b.pathJoin(
1982 &.{ self.output_dir.?, self.out_pdb_filename },
1925 &.{ output_dir, self.out_pdb_filename },
19831926 );
19841927 }
19851928 }
lib/std/Build/TranslateCStep.zig-1
......@@ -100,7 +100,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
100100 try argv_list.append("translate-c");
101101 try argv_list.append("-lc");
102102
103 try argv_list.append("--enable-cache");
104103 try argv_list.append("--listen=-");
105104
106105 if (!self.target.isNative()) {
src/main.zig+6-71
......@@ -386,7 +386,6 @@ const usage_build_generic =
386386 \\ --cache-dir [path] Override the local cache directory
387387 \\ --global-cache-dir [path] Override the global cache directory
388388 \\ --zig-lib-dir [path] Override path to Zig installation lib directory
389 \\ --enable-cache Output to cache directory; print path to stdout
390389 \\
391390 \\Compile Options:
392391 \\ -target [name] <arch><sub>-<os>-<abi> see the targets command
......@@ -756,7 +755,6 @@ fn buildOutputType(
756755 var link_libcpp = false;
757756 var link_libunwind = false;
758757 var want_native_include_dirs = false;
759 var enable_cache: ?bool = null;
760758 var want_pic: ?bool = null;
761759 var want_pie: ?bool = null;
762760 var want_lto: ?bool = null;
......@@ -1203,8 +1201,6 @@ fn buildOutputType(
12031201 build_id = true;
12041202 } else if (mem.eql(u8, arg, "-fno-build-id")) {
12051203 build_id = false;
1206 } else if (mem.eql(u8, arg, "--enable-cache")) {
1207 enable_cache = true;
12081204 } else if (mem.eql(u8, arg, "--test-cmd-bin")) {
12091205 try test_exec_args.append(null);
12101206 } else if (mem.eql(u8, arg, "--test-evented-io")) {
......@@ -2641,7 +2637,7 @@ fn buildOutputType(
26412637 var cleanup_emit_bin_dir: ?fs.Dir = null;
26422638 defer if (cleanup_emit_bin_dir) |*dir| dir.close();
26432639
2644 const have_enable_cache = enable_cache orelse false;
2640 const output_to_cache = listen != .none;
26452641 const optional_version = if (have_version) version else null;
26462642
26472643 const resolved_soname: ?[]const u8 = switch (soname) {
......@@ -2668,7 +2664,7 @@ fn buildOutputType(
26682664 switch (arg_mode) {
26692665 .run, .zig_test => break :blk null,
26702666 else => {
2671 if (have_enable_cache) {
2667 if (output_to_cache) {
26722668 break :blk null;
26732669 } else {
26742670 break :blk .{ .path = null, .handle = fs.cwd() };
......@@ -2686,12 +2682,6 @@ fn buildOutputType(
26862682 },
26872683 .yes => |full_path| b: {
26882684 const basename = fs.path.basename(full_path);
2689 if (have_enable_cache) {
2690 break :b Compilation.EmitLoc{
2691 .basename = basename,
2692 .directory = null,
2693 };
2694 }
26952685 if (fs.path.dirname(full_path)) |dirname| {
26962686 const handle = fs.cwd().openDir(dirname, .{}) catch |err| {
26972687 fatal("unable to open output directory '{s}': {s}", .{ dirname, @errorName(err) });
......@@ -3145,7 +3135,7 @@ fn buildOutputType(
31453135 .test_filter = test_filter,
31463136 .test_name_prefix = test_name_prefix,
31473137 .test_runner_path = test_runner_path,
3148 .disable_lld_caching = !have_enable_cache,
3138 .disable_lld_caching = !output_to_cache,
31493139 .subsystem = subsystem,
31503140 .wasi_exec_model = wasi_exec_model,
31513141 .debug_compile_errors = debug_compile_errors,
......@@ -3240,19 +3230,7 @@ fn buildOutputType(
32403230 return cmdTranslateC(comp, arena, null);
32413231 }
32423232
3243 const hook: AfterUpdateHook = blk: {
3244 if (!have_enable_cache)
3245 break :blk .none;
3246
3247 switch (emit_bin) {
3248 .no => break :blk .none,
3249 .yes_default_path => break :blk .print_emit_bin_dir_path,
3250 .yes => |full_path| break :blk .{ .update = full_path },
3251 .yes_a_out => break :blk .{ .update = a_out_basename },
3252 }
3253 };
3254
3255 updateModule(gpa, comp, hook) catch |err| switch (err) {
3233 updateModule(comp) catch |err| switch (err) {
32563234 error.SemanticAnalyzeFail => if (listen == .none) process.exit(1),
32573235 else => |e| return e,
32583236 };
......@@ -3800,13 +3778,7 @@ fn runOrTestHotSwap(
38003778 }
38013779}
38023780
3803const AfterUpdateHook = union(enum) {
3804 none,
3805 print_emit_bin_dir_path,
3806 update: []const u8,
3807};
3808
3809fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void {
3781fn updateModule(comp: *Compilation) !void {
38103782 {
38113783 // If the terminal is dumb, we dont want to show the user all the output.
38123784 var progress: std.Progress = .{ .dont_print_on_dumb = true };
......@@ -3832,43 +3804,6 @@ fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void
38323804 if (errors.errorMessageCount() > 0) {
38333805 errors.renderToStdErr(renderOptions(comp.color));
38343806 return error.SemanticAnalyzeFail;
3835 } else switch (hook) {
3836 .none => {},
3837 .print_emit_bin_dir_path => {
3838 const emit = comp.bin_file.options.emit.?;
3839 const full_path = try emit.directory.join(gpa, &.{emit.sub_path});
3840 defer gpa.free(full_path);
3841 const dir_path = fs.path.dirname(full_path).?;
3842 try io.getStdOut().writer().print("{s}\n", .{dir_path});
3843 },
3844 .update => |full_path| {
3845 const bin_sub_path = comp.bin_file.options.emit.?.sub_path;
3846 const cwd = fs.cwd();
3847 const cache_dir = comp.bin_file.options.emit.?.directory.handle;
3848 _ = try cache_dir.updateFile(bin_sub_path, cwd, full_path, .{});
3849
3850 // If a .pdb file is part of the expected output, we must also copy
3851 // it into place here.
3852 const is_coff = comp.bin_file.options.target.ofmt == .coff;
3853 const have_pdb = is_coff and !comp.bin_file.options.strip;
3854 if (have_pdb) {
3855 // Replace `.out` or `.exe` with `.pdb` on both the source and destination
3856 const src_bin_ext = fs.path.extension(bin_sub_path);
3857 const dst_bin_ext = fs.path.extension(full_path);
3858
3859 const src_pdb_path = try std.fmt.allocPrint(gpa, "{s}.pdb", .{
3860 bin_sub_path[0 .. bin_sub_path.len - src_bin_ext.len],
3861 });
3862 defer gpa.free(src_pdb_path);
3863
3864 const dst_pdb_path = try std.fmt.allocPrint(gpa, "{s}.pdb", .{
3865 full_path[0 .. full_path.len - dst_bin_ext.len],
3866 });
3867 defer gpa.free(dst_pdb_path);
3868
3869 _ = try cache_dir.updateFile(src_pdb_path, cwd, dst_pdb_path, .{});
3870 }
3871 },
38723807 }
38733808}
38743809
......@@ -4499,7 +4434,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi
44994434 };
45004435 defer comp.destroy();
45014436
4502 updateModule(gpa, comp, .none) catch |err| switch (err) {
4437 updateModule(comp) catch |err| switch (err) {
45034438 error.SemanticAnalyzeFail => process.exit(2),
45044439 else => |e| return e,
45054440 };
test/standalone/issue_13970/build.zig+3-3
......@@ -6,16 +6,16 @@ pub fn build(b: *std.Build) void {
66
77 const test1 = b.addTest(.{
88 .root_source_file = .{ .path = "test_root/empty.zig" },
9 .test_runner = "src/main.zig",
910 });
1011 const test2 = b.addTest(.{
1112 .root_source_file = .{ .path = "src/empty.zig" },
13 .test_runner = "src/main.zig",
1214 });
1315 const test3 = b.addTest(.{
1416 .root_source_file = .{ .path = "empty.zig" },
17 .test_runner = "src/main.zig",
1518 });
16 test1.setTestRunner("src/main.zig");
17 test2.setTestRunner("src/main.zig");
18 test3.setTestRunner("src/main.zig");
1919
2020 test_step.dependOn(&b.addRunArtifact(test1).step);
2121 test_step.dependOn(&b.addRunArtifact(test2).step);
test/standalone/test_runner_module_imports/build.zig+1-1
......@@ -3,8 +3,8 @@ const std = @import("std");
33pub fn build(b: *std.Build) void {
44 const t = b.addTest(.{
55 .root_source_file = .{ .path = "src/main.zig" },
6 .test_runner = "test_runner/main.zig",
67 });
7 t.setTestRunner("test_runner/main.zig");
88
99 const module1 = b.createModule(.{ .source_file = .{ .path = "module1/main.zig" } });
1010 const module2 = b.createModule(.{
test/tests.zig+6-6
......@@ -977,11 +977,11 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step {
977977 .optimize = test_target.optimize_mode,
978978 .target = test_target.target,
979979 .max_rss = max_rss,
980 .filter = options.test_filter,
980981 });
981982 const single_threaded_txt = if (test_target.single_threaded) "single" else "multi";
982983 const backend_txt = if (test_target.backend) |backend| @tagName(backend) else "default";
983984 these_tests.single_threaded = test_target.single_threaded;
984 these_tests.setFilter(options.test_filter);
985985 if (test_target.link_libc) {
986986 these_tests.linkSystemLibrary("c");
987987 }
......@@ -1037,10 +1037,15 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S
10371037 continue;
10381038 }
10391039
1040 const triple_prefix = c_abi_target.zigTriple(b.allocator) catch @panic("OOM");
1041
10401042 const test_step = b.addTest(.{
10411043 .root_source_file = .{ .path = "test/c_abi/main.zig" },
10421044 .optimize = optimize_mode,
10431045 .target = c_abi_target,
1046 .name = b.fmt("test-c-abi-{s}-{s}", .{
1047 triple_prefix, @tagName(optimize_mode),
1048 }),
10441049 });
10451050 if (c_abi_target.abi != null and c_abi_target.abi.?.isMusl()) {
10461051 // 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
10571062 test_step.want_lto = false;
10581063 }
10591064
1060 const triple_prefix = c_abi_target.zigTriple(b.allocator) catch @panic("OOM");
1061 test_step.setName(b.fmt("test-c-abi-{s}-{s} ", .{
1062 triple_prefix, @tagName(optimize_mode),
1063 }));
1064
10651065 const run = b.addRunArtifact(test_step);
10661066 run.skip_foreign_checks = true;
10671067 step.dependOn(&run.step);