| author | |
| committer | |
| log | d3a237a98c5a2ccf72a774b5f93425c02fea4bea |
| tree | b440fbaf013ed472c39a60381928c0224e694f5c |
| parent | 1728d92f60d4e9aa10d878e3235fc63764d3909b |
| parent | 3c3cee2cfabc5d03bb83cf6cc6a8ed80f13ee1df |
| signature |
remove --enable-cache option; std.Build.CompileStep: remove output_dir8 files changed, 89 insertions(+), 227 deletions(-)
doc/docgen.zig+21-40| ... | ... | @@ -325,7 +325,6 @@ const Code = struct { |
| 325 | 325 | link_objects: []const []const u8, |
| 326 | 326 | target_str: ?[]const u8, |
| 327 | 327 | link_libc: bool, |
| 328 | backend_stage1: bool, | |
| 329 | 328 | link_mode: ?std.builtin.LinkMode, |
| 330 | 329 | disable_cache: bool, |
| 331 | 330 | verbose_cimport: bool, |
| ... | ... | @@ -596,7 +595,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 596 | 595 | var link_mode: ?std.builtin.LinkMode = null; |
| 597 | 596 | var disable_cache = false; |
| 598 | 597 | var verbose_cimport = false; |
| 599 | var backend_stage1 = false; | |
| 600 | 598 | var additional_options = std.ArrayList([]const u8).init(allocator); |
| 601 | 599 | defer additional_options.deinit(); |
| 602 | 600 | |
| ... | ... | @@ -631,8 +629,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 631 | 629 | link_libc = true; |
| 632 | 630 | } else if (mem.eql(u8, end_tag_name, "link_mode_dynamic")) { |
| 633 | 631 | link_mode = .Dynamic; |
| 634 | } else if (mem.eql(u8, end_tag_name, "backend_stage1")) { | |
| 635 | backend_stage1 = true; | |
| 636 | 632 | } else if (mem.eql(u8, end_tag_name, "additonal_option")) { |
| 637 | 633 | _ = try eatToken(tokenizer, Token.Id.Separator); |
| 638 | 634 | const option = try eatToken(tokenizer, Token.Id.TagContent); |
| ... | ... | @@ -660,7 +656,6 @@ fn genToc(allocator: Allocator, tokenizer: *Tokenizer) !Toc { |
| 660 | 656 | .link_objects = try link_objects.toOwnedSlice(), |
| 661 | 657 | .target_str = target_str, |
| 662 | 658 | .link_libc = link_libc, |
| 663 | .backend_stage1 = backend_stage1, | |
| 664 | 659 | .link_mode = link_mode, |
| 665 | 660 | .disable_cache = disable_cache, |
| 666 | 661 | .verbose_cimport = verbose_cimport, |
| ... | ... | @@ -1380,10 +1375,10 @@ fn genHtml( |
| 1380 | 1375 | var build_args = std.ArrayList([]const u8).init(allocator); |
| 1381 | 1376 | defer build_args.deinit(); |
| 1382 | 1377 | 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, | |
| 1387 | 1382 | }); |
| 1388 | 1383 | if (opt_zig_lib_dir) |zig_lib_dir| { |
| 1389 | 1384 | try build_args.appendSlice(&.{ "--zig-lib-dir", zig_lib_dir }); |
| ... | ... | @@ -1400,21 +1395,13 @@ fn genHtml( |
| 1400 | 1395 | } |
| 1401 | 1396 | for (code.link_objects) |link_object| { |
| 1402 | 1397 | 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); | |
| 1408 | 1399 | try shell_out.print("{s} ", .{name_with_ext}); |
| 1409 | 1400 | } |
| 1410 | 1401 | if (code.link_libc) { |
| 1411 | 1402 | try build_args.append("-lc"); |
| 1412 | 1403 | try shell_out.print("-lc ", .{}); |
| 1413 | 1404 | } |
| 1414 | if (code.backend_stage1) { | |
| 1415 | try build_args.append("-fstage1"); | |
| 1416 | try shell_out.print("-fstage1", .{}); | |
| 1417 | } | |
| 1418 | 1405 | const target = try std.zig.CrossTarget.parse(.{ |
| 1419 | 1406 | .arch_os_abi = code.target_str orelse "native", |
| 1420 | 1407 | }); |
| ... | ... | @@ -1461,7 +1448,7 @@ fn genHtml( |
| 1461 | 1448 | try shell_out.writeAll(colored_stderr); |
| 1462 | 1449 | break :code_block; |
| 1463 | 1450 | } |
| 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 | |
| 1465 | 1452 | return parseError(tokenizer, code.source_token, "example failed to compile", .{}); |
| 1466 | 1453 | |
| 1467 | 1454 | if (code.verbose_cimport) { |
| ... | ... | @@ -1480,15 +1467,10 @@ fn genHtml( |
| 1480 | 1467 | } |
| 1481 | 1468 | } |
| 1482 | 1469 | |
| 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}", .{ | |
| 1485 | 1471 | code.name, |
| 1486 | 1472 | target.exeFileExt(), |
| 1487 | 1473 | }); |
| 1488 | const path_to_exe = try fs.path.join(allocator, &[_][]const u8{ | |
| 1489 | path_to_exe_dir, | |
| 1490 | path_to_exe_basename, | |
| 1491 | }); | |
| 1492 | 1474 | const run_args = &[_][]const u8{path_to_exe}; |
| 1493 | 1475 | |
| 1494 | 1476 | var exited_with_signal = false; |
| ... | ... | @@ -1498,6 +1480,7 @@ fn genHtml( |
| 1498 | 1480 | .allocator = allocator, |
| 1499 | 1481 | .argv = run_args, |
| 1500 | 1482 | .env_map = &env_map, |
| 1483 | .cwd = tmp_dir_name, | |
| 1501 | 1484 | .max_output_bytes = max_doc_file_size, |
| 1502 | 1485 | }); |
| 1503 | 1486 | switch (result.term) { |
| ... | ... | @@ -1514,7 +1497,7 @@ fn genHtml( |
| 1514 | 1497 | } |
| 1515 | 1498 | break :blk result; |
| 1516 | 1499 | } 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", .{}); | |
| 1518 | 1501 | }; |
| 1519 | 1502 | |
| 1520 | 1503 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| ... | ... | @@ -1555,10 +1538,6 @@ fn genHtml( |
| 1555 | 1538 | try test_args.append("-lc"); |
| 1556 | 1539 | try shell_out.print("-lc ", .{}); |
| 1557 | 1540 | } |
| 1558 | if (code.backend_stage1) { | |
| 1559 | try test_args.append("-fstage1"); | |
| 1560 | try shell_out.print("-fstage1", .{}); | |
| 1561 | } | |
| 1562 | 1541 | if (code.target_str) |triple| { |
| 1563 | 1542 | try test_args.appendSlice(&[_][]const u8{ "-target", triple }); |
| 1564 | 1543 | try shell_out.print("-target {s} ", .{triple}); |
| ... | ... | @@ -1579,7 +1558,7 @@ fn genHtml( |
| 1579 | 1558 | }, |
| 1580 | 1559 | } |
| 1581 | 1560 | } |
| 1582 | const result = exec(allocator, &env_map, test_args.items) catch | |
| 1561 | const result = exec(allocator, &env_map, null, test_args.items) catch | |
| 1583 | 1562 | return parseError(tokenizer, code.source_token, "test failed", .{}); |
| 1584 | 1563 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1585 | 1564 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| ... | ... | @@ -1610,10 +1589,6 @@ fn genHtml( |
| 1610 | 1589 | try test_args.append("-lc"); |
| 1611 | 1590 | try shell_out.print("-lc ", .{}); |
| 1612 | 1591 | } |
| 1613 | if (code.backend_stage1) { | |
| 1614 | try test_args.append("-fstage1"); | |
| 1615 | try shell_out.print("-fstage1", .{}); | |
| 1616 | } | |
| 1617 | 1592 | const result = try ChildProcess.exec(.{ |
| 1618 | 1593 | .allocator = allocator, |
| 1619 | 1594 | .argv = test_args.items, |
| ... | ... | @@ -1778,7 +1753,7 @@ fn genHtml( |
| 1778 | 1753 | const colored_stderr = try termColor(allocator, escaped_stderr); |
| 1779 | 1754 | try shell_out.print("\n{s} ", .{colored_stderr}); |
| 1780 | 1755 | } 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", .{}); | |
| 1782 | 1757 | } |
| 1783 | 1758 | try shell_out.writeAll("\n"); |
| 1784 | 1759 | }, |
| ... | ... | @@ -1831,7 +1806,7 @@ fn genHtml( |
| 1831 | 1806 | try test_args.append(option); |
| 1832 | 1807 | try shell_out.print("{s} ", .{option}); |
| 1833 | 1808 | } |
| 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", .{}); | |
| 1835 | 1810 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1836 | 1811 | const escaped_stdout = try escapeHtml(allocator, result.stdout); |
| 1837 | 1812 | try shell_out.print("\n{s}{s}\n", .{ escaped_stderr, escaped_stdout }); |
| ... | ... | @@ -1846,11 +1821,17 @@ fn genHtml( |
| 1846 | 1821 | } |
| 1847 | 1822 | } |
| 1848 | 1823 | |
| 1849 | fn exec(allocator: Allocator, env_map: *process.EnvMap, args: []const []const u8) !ChildProcess.ExecResult { | |
| 1824 | fn exec( | |
| 1825 | allocator: Allocator, | |
| 1826 | env_map: *process.EnvMap, | |
| 1827 | cwd: ?[]const u8, | |
| 1828 | args: []const []const u8, | |
| 1829 | ) !ChildProcess.ExecResult { | |
| 1850 | 1830 | const result = try ChildProcess.exec(.{ |
| 1851 | 1831 | .allocator = allocator, |
| 1852 | 1832 | .argv = args, |
| 1853 | 1833 | .env_map = env_map, |
| 1834 | .cwd = cwd, | |
| 1854 | 1835 | .max_output_bytes = max_doc_file_size, |
| 1855 | 1836 | }); |
| 1856 | 1837 | switch (result.term) { |
| ... | ... | @@ -1877,12 +1858,12 @@ fn getBuiltinCode( |
| 1877 | 1858 | opt_zig_lib_dir: ?[]const u8, |
| 1878 | 1859 | ) ![]const u8 { |
| 1879 | 1860 | 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, &.{ | |
| 1881 | 1862 | zig_exe, "build-obj", "--show-builtin", "--zig-lib-dir", zig_lib_dir, |
| 1882 | 1863 | }); |
| 1883 | 1864 | return result.stdout; |
| 1884 | 1865 | } else { |
| 1885 | const result = try exec(allocator, env_map, &.{ | |
| 1866 | const result = try exec(allocator, env_map, null, &.{ | |
| 1886 | 1867 | zig_exe, "build-obj", "--show-builtin", |
| 1887 | 1868 | }); |
| 1888 | 1869 | return result.stdout; |
lib/std/Build.zig+4| ... | ... | @@ -539,6 +539,8 @@ pub const TestOptions = struct { |
| 539 | 539 | optimize: std.builtin.Mode = .Debug, |
| 540 | 540 | version: ?std.builtin.Version = null, |
| 541 | 541 | max_rss: usize = 0, |
| 542 | filter: ?[]const u8 = null, | |
| 543 | test_runner: ?[]const u8 = null, | |
| 542 | 544 | }; |
| 543 | 545 | |
| 544 | 546 | pub fn addTest(b: *Build, options: TestOptions) *CompileStep { |
| ... | ... | @@ -549,6 +551,8 @@ pub fn addTest(b: *Build, options: TestOptions) *CompileStep { |
| 549 | 551 | .target = options.target, |
| 550 | 552 | .optimize = options.optimize, |
| 551 | 553 | .max_rss = options.max_rss, |
| 554 | .filter = options.filter, | |
| 555 | .test_runner = options.test_runner, | |
| 552 | 556 | }); |
| 553 | 557 | } |
| 554 | 558 |
lib/std/Build/CompileStep.zig+48-105| ... | ... | @@ -97,13 +97,10 @@ out_lib_filename: []const u8, |
| 97 | 97 | out_pdb_filename: []const u8, |
| 98 | 98 | modules: std.StringArrayHashMap(*Module), |
| 99 | 99 | |
| 100 | object_src: []const u8, | |
| 101 | ||
| 102 | 100 | link_objects: ArrayList(LinkObject), |
| 103 | 101 | include_dirs: ArrayList(IncludeDir), |
| 104 | 102 | c_macros: ArrayList([]const u8), |
| 105 | 103 | installed_headers: ArrayList(*Step), |
| 106 | output_dir: ?[]const u8, | |
| 107 | 104 | is_linking_libc: bool = false, |
| 108 | 105 | is_linking_libcpp: bool = false, |
| 109 | 106 | vcpkg_bin_path: ?[]const u8 = null, |
| ... | ... | @@ -288,6 +285,8 @@ pub const Options = struct { |
| 288 | 285 | linkage: ?Linkage = null, |
| 289 | 286 | version: ?std.builtin.Version = null, |
| 290 | 287 | max_rss: usize = 0, |
| 288 | filter: ?[]const u8 = null, | |
| 289 | test_runner: ?[]const u8 = null, | |
| 291 | 290 | }; |
| 292 | 291 | |
| 293 | 292 | pub const Kind = enum { |
| ... | ... | @@ -340,6 +339,23 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 340 | 339 | options.target.zigTriple(owner.allocator) catch @panic("OOM"), |
| 341 | 340 | }); |
| 342 | 341 | |
| 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 | ||
| 343 | 359 | const self = owner.allocator.create(CompileStep) catch @panic("OOM"); |
| 344 | 360 | self.* = CompileStep{ |
| 345 | 361 | .strip = null, |
| ... | ... | @@ -361,7 +377,7 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 361 | 377 | .max_rss = options.max_rss, |
| 362 | 378 | }), |
| 363 | 379 | .version = options.version, |
| 364 | .out_filename = undefined, | |
| 380 | .out_filename = out_filename, | |
| 365 | 381 | .out_h_filename = owner.fmt("{s}.h", .{name}), |
| 366 | 382 | .out_lib_filename = undefined, |
| 367 | 383 | .out_pdb_filename = owner.fmt("{s}.pdb", .{name}), |
| ... | ... | @@ -375,18 +391,16 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 375 | 391 | .rpaths = ArrayList(FileSource).init(owner.allocator), |
| 376 | 392 | .framework_dirs = ArrayList(FileSource).init(owner.allocator), |
| 377 | 393 | .installed_headers = ArrayList(*Step).init(owner.allocator), |
| 378 | .object_src = undefined, | |
| 379 | 394 | .c_std = std.Build.CStd.C99, |
| 380 | 395 | .zig_lib_dir = null, |
| 381 | 396 | .main_pkg_path = null, |
| 382 | 397 | .exec_cmd_args = null, |
| 383 | .filter = null, | |
| 384 | .test_runner = null, | |
| 398 | .filter = options.filter, | |
| 399 | .test_runner = options.test_runner, | |
| 385 | 400 | .disable_stack_probing = false, |
| 386 | 401 | .disable_sanitize_c = false, |
| 387 | 402 | .sanitize_thread = false, |
| 388 | 403 | .rdynamic = false, |
| 389 | .output_dir = null, | |
| 390 | 404 | .override_dest_dir = null, |
| 391 | 405 | .installed_path = null, |
| 392 | 406 | .force_undefined_symbols = StringHashMap(void).init(owner.allocator), |
| ... | ... | @@ -397,70 +411,41 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep { |
| 397 | 411 | .output_pdb_path_source = GeneratedFile{ .step = &self.step }, |
| 398 | 412 | .output_dirname_source = GeneratedFile{ .step = &self.step }, |
| 399 | 413 | |
| 400 | .target_info = NativeTargetInfo.detect(self.target) catch @panic("unhandled error"), | |
| 414 | .target_info = target_info, | |
| 401 | 415 | }; |
| 402 | self.computeOutFileNames(); | |
| 403 | if (root_src) |rs| rs.addStepDependencies(&self.step); | |
| 404 | return self; | |
| 405 | } | |
| 406 | ||
| 407 | fn 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"); | |
| 425 | 416 | |
| 426 | 417 | if (self.kind == .lib) { |
| 427 | 418 | if (self.linkage != null and self.linkage.? == .static) { |
| 428 | 419 | self.out_lib_filename = self.out_filename; |
| 429 | 420 | } 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", .{ | |
| 432 | 423 | self.name, |
| 433 | 424 | version.major, |
| 434 | 425 | }); |
| 435 | self.name_only_filename = b.fmt("lib{s}.dylib", .{self.name}); | |
| 426 | self.name_only_filename = owner.fmt("lib{s}.dylib", .{self.name}); | |
| 436 | 427 | 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}); | |
| 439 | 430 | } 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}); | |
| 442 | 433 | self.out_lib_filename = self.out_filename; |
| 443 | 434 | } |
| 444 | 435 | } else { |
| 445 | if (target.isDarwin()) { | |
| 436 | if (target_info.target.isDarwin()) { | |
| 446 | 437 | 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}); | |
| 449 | 440 | } else { |
| 450 | 441 | self.out_lib_filename = self.out_filename; |
| 451 | 442 | } |
| 452 | 443 | } |
| 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 | } | |
| 458 | 444 | } |
| 459 | } | |
| 460 | 445 | |
| 461 | pub 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; | |
| 464 | 449 | } |
| 465 | 450 | |
| 466 | 451 | 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 { |
| 853 | 838 | }) catch @panic("OOM"); |
| 854 | 839 | } |
| 855 | 840 | |
| 856 | pub 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 | ||
| 862 | pub 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 | ||
| 868 | pub 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 | ||
| 874 | 841 | /// Handy when you have many C/C++ source files and want them all to have the same flags. |
| 875 | 842 | pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []const []const u8) void { |
| 876 | 843 | const b = self.step.owner; |
| ... | ... | @@ -1864,7 +1831,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1864 | 1831 | }); |
| 1865 | 1832 | } |
| 1866 | 1833 | |
| 1867 | try zig_args.append("--enable-cache"); | |
| 1868 | 1834 | try zig_args.append("--listen=-"); |
| 1869 | 1835 | |
| 1870 | 1836 | // 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 { |
| 1932 | 1898 | }, |
| 1933 | 1899 | else => |e| return e, |
| 1934 | 1900 | }; |
| 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).?; | |
| 1965 | 1902 | |
| 1966 | 1903 | // 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; | |
| 1969 | 1906 | |
| 1970 | 1907 | self.output_path_source.path = b.pathJoin( |
| 1971 | &.{ self.output_dir.?, self.out_filename }, | |
| 1908 | &.{ output_dir, self.out_filename }, | |
| 1972 | 1909 | ); |
| 1973 | 1910 | |
| 1911 | if (self.kind == .lib) { | |
| 1912 | self.output_lib_path_source.path = b.pathJoin( | |
| 1913 | &.{ output_dir, self.out_lib_filename }, | |
| 1914 | ); | |
| 1915 | } | |
| 1916 | ||
| 1974 | 1917 | if (self.emit_h) { |
| 1975 | 1918 | self.output_h_path_source.path = b.pathJoin( |
| 1976 | &.{ self.output_dir.?, self.out_h_filename }, | |
| 1919 | &.{ output_dir, self.out_h_filename }, | |
| 1977 | 1920 | ); |
| 1978 | 1921 | } |
| 1979 | 1922 | |
| 1980 | 1923 | if (self.target.isWindows() or self.target.isUefi()) { |
| 1981 | 1924 | self.output_pdb_path_source.path = b.pathJoin( |
| 1982 | &.{ self.output_dir.?, self.out_pdb_filename }, | |
| 1925 | &.{ output_dir, self.out_pdb_filename }, | |
| 1983 | 1926 | ); |
| 1984 | 1927 | } |
| 1985 | 1928 | } |
lib/std/Build/TranslateCStep.zig-1| ... | ... | @@ -100,7 +100,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 100 | 100 | try argv_list.append("translate-c"); |
| 101 | 101 | try argv_list.append("-lc"); |
| 102 | 102 | |
| 103 | try argv_list.append("--enable-cache"); | |
| 104 | 103 | try argv_list.append("--listen=-"); |
| 105 | 104 | |
| 106 | 105 | if (!self.target.isNative()) { |
src/main.zig+6-71| ... | ... | @@ -386,7 +386,6 @@ const usage_build_generic = |
| 386 | 386 | \\ --cache-dir [path] Override the local cache directory |
| 387 | 387 | \\ --global-cache-dir [path] Override the global cache directory |
| 388 | 388 | \\ --zig-lib-dir [path] Override path to Zig installation lib directory |
| 389 | \\ --enable-cache Output to cache directory; print path to stdout | |
| 390 | 389 | \\ |
| 391 | 390 | \\Compile Options: |
| 392 | 391 | \\ -target [name] <arch><sub>-<os>-<abi> see the targets command |
| ... | ... | @@ -756,7 +755,6 @@ fn buildOutputType( |
| 756 | 755 | var link_libcpp = false; |
| 757 | 756 | var link_libunwind = false; |
| 758 | 757 | var want_native_include_dirs = false; |
| 759 | var enable_cache: ?bool = null; | |
| 760 | 758 | var want_pic: ?bool = null; |
| 761 | 759 | var want_pie: ?bool = null; |
| 762 | 760 | var want_lto: ?bool = null; |
| ... | ... | @@ -1203,8 +1201,6 @@ fn buildOutputType( |
| 1203 | 1201 | build_id = true; |
| 1204 | 1202 | } else if (mem.eql(u8, arg, "-fno-build-id")) { |
| 1205 | 1203 | build_id = false; |
| 1206 | } else if (mem.eql(u8, arg, "--enable-cache")) { | |
| 1207 | enable_cache = true; | |
| 1208 | 1204 | } else if (mem.eql(u8, arg, "--test-cmd-bin")) { |
| 1209 | 1205 | try test_exec_args.append(null); |
| 1210 | 1206 | } else if (mem.eql(u8, arg, "--test-evented-io")) { |
| ... | ... | @@ -2641,7 +2637,7 @@ fn buildOutputType( |
| 2641 | 2637 | var cleanup_emit_bin_dir: ?fs.Dir = null; |
| 2642 | 2638 | defer if (cleanup_emit_bin_dir) |*dir| dir.close(); |
| 2643 | 2639 | |
| 2644 | const have_enable_cache = enable_cache orelse false; | |
| 2640 | const output_to_cache = listen != .none; | |
| 2645 | 2641 | const optional_version = if (have_version) version else null; |
| 2646 | 2642 | |
| 2647 | 2643 | const resolved_soname: ?[]const u8 = switch (soname) { |
| ... | ... | @@ -2668,7 +2664,7 @@ fn buildOutputType( |
| 2668 | 2664 | switch (arg_mode) { |
| 2669 | 2665 | .run, .zig_test => break :blk null, |
| 2670 | 2666 | else => { |
| 2671 | if (have_enable_cache) { | |
| 2667 | if (output_to_cache) { | |
| 2672 | 2668 | break :blk null; |
| 2673 | 2669 | } else { |
| 2674 | 2670 | break :blk .{ .path = null, .handle = fs.cwd() }; |
| ... | ... | @@ -2686,12 +2682,6 @@ fn buildOutputType( |
| 2686 | 2682 | }, |
| 2687 | 2683 | .yes => |full_path| b: { |
| 2688 | 2684 | 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 | } | |
| 2695 | 2685 | if (fs.path.dirname(full_path)) |dirname| { |
| 2696 | 2686 | const handle = fs.cwd().openDir(dirname, .{}) catch |err| { |
| 2697 | 2687 | fatal("unable to open output directory '{s}': {s}", .{ dirname, @errorName(err) }); |
| ... | ... | @@ -3145,7 +3135,7 @@ fn buildOutputType( |
| 3145 | 3135 | .test_filter = test_filter, |
| 3146 | 3136 | .test_name_prefix = test_name_prefix, |
| 3147 | 3137 | .test_runner_path = test_runner_path, |
| 3148 | .disable_lld_caching = !have_enable_cache, | |
| 3138 | .disable_lld_caching = !output_to_cache, | |
| 3149 | 3139 | .subsystem = subsystem, |
| 3150 | 3140 | .wasi_exec_model = wasi_exec_model, |
| 3151 | 3141 | .debug_compile_errors = debug_compile_errors, |
| ... | ... | @@ -3240,19 +3230,7 @@ fn buildOutputType( |
| 3240 | 3230 | return cmdTranslateC(comp, arena, null); |
| 3241 | 3231 | } |
| 3242 | 3232 | |
| 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) { | |
| 3256 | 3234 | error.SemanticAnalyzeFail => if (listen == .none) process.exit(1), |
| 3257 | 3235 | else => |e| return e, |
| 3258 | 3236 | }; |
| ... | ... | @@ -3800,13 +3778,7 @@ fn runOrTestHotSwap( |
| 3800 | 3778 | } |
| 3801 | 3779 | } |
| 3802 | 3780 | |
| 3803 | const AfterUpdateHook = union(enum) { | |
| 3804 | none, | |
| 3805 | print_emit_bin_dir_path, | |
| 3806 | update: []const u8, | |
| 3807 | }; | |
| 3808 | ||
| 3809 | fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void { | |
| 3781 | fn updateModule(comp: *Compilation) !void { | |
| 3810 | 3782 | { |
| 3811 | 3783 | // If the terminal is dumb, we dont want to show the user all the output. |
| 3812 | 3784 | var progress: std.Progress = .{ .dont_print_on_dumb = true }; |
| ... | ... | @@ -3832,43 +3804,6 @@ fn updateModule(gpa: Allocator, comp: *Compilation, hook: AfterUpdateHook) !void |
| 3832 | 3804 | if (errors.errorMessageCount() > 0) { |
| 3833 | 3805 | errors.renderToStdErr(renderOptions(comp.color)); |
| 3834 | 3806 | 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 | }, | |
| 3872 | 3807 | } |
| 3873 | 3808 | } |
| 3874 | 3809 | |
| ... | ... | @@ -4499,7 +4434,7 @@ pub fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !voi |
| 4499 | 4434 | }; |
| 4500 | 4435 | defer comp.destroy(); |
| 4501 | 4436 | |
| 4502 | updateModule(gpa, comp, .none) catch |err| switch (err) { | |
| 4437 | updateModule(comp) catch |err| switch (err) { | |
| 4503 | 4438 | error.SemanticAnalyzeFail => process.exit(2), |
| 4504 | 4439 | else => |e| return e, |
| 4505 | 4440 | }; |
test/standalone/issue_13970/build.zig+3-3| ... | ... | @@ -6,16 +6,16 @@ pub fn build(b: *std.Build) void { |
| 6 | 6 | |
| 7 | 7 | const test1 = b.addTest(.{ |
| 8 | 8 | .root_source_file = .{ .path = "test_root/empty.zig" }, |
| 9 | .test_runner = "src/main.zig", | |
| 9 | 10 | }); |
| 10 | 11 | const test2 = b.addTest(.{ |
| 11 | 12 | .root_source_file = .{ .path = "src/empty.zig" }, |
| 13 | .test_runner = "src/main.zig", | |
| 12 | 14 | }); |
| 13 | 15 | const test3 = b.addTest(.{ |
| 14 | 16 | .root_source_file = .{ .path = "empty.zig" }, |
| 17 | .test_runner = "src/main.zig", | |
| 15 | 18 | }); |
| 16 | test1.setTestRunner("src/main.zig"); | |
| 17 | test2.setTestRunner("src/main.zig"); | |
| 18 | test3.setTestRunner("src/main.zig"); | |
| 19 | 19 | |
| 20 | 20 | test_step.dependOn(&b.addRunArtifact(test1).step); |
| 21 | 21 | 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"); |
| 3 | 3 | pub fn build(b: *std.Build) void { |
| 4 | 4 | const t = b.addTest(.{ |
| 5 | 5 | .root_source_file = .{ .path = "src/main.zig" }, |
| 6 | .test_runner = "test_runner/main.zig", | |
| 6 | 7 | }); |
| 7 | t.setTestRunner("test_runner/main.zig"); | |
| 8 | 8 | |
| 9 | 9 | const module1 = b.createModule(.{ .source_file = .{ .path = "module1/main.zig" } }); |
| 10 | 10 | const module2 = b.createModule(.{ |
test/tests.zig+6-6| ... | ... | @@ -977,11 +977,11 @@ pub fn addModuleTests(b: *std.Build, options: ModuleTestOptions) *Step { |
| 977 | 977 | .optimize = test_target.optimize_mode, |
| 978 | 978 | .target = test_target.target, |
| 979 | 979 | .max_rss = max_rss, |
| 980 | .filter = options.test_filter, | |
| 980 | 981 | }); |
| 981 | 982 | const single_threaded_txt = if (test_target.single_threaded) "single" else "multi"; |
| 982 | 983 | const backend_txt = if (test_target.backend) |backend| @tagName(backend) else "default"; |
| 983 | 984 | these_tests.single_threaded = test_target.single_threaded; |
| 984 | these_tests.setFilter(options.test_filter); | |
| 985 | 985 | if (test_target.link_libc) { |
| 986 | 986 | these_tests.linkSystemLibrary("c"); |
| 987 | 987 | } |
| ... | ... | @@ -1037,10 +1037,15 @@ pub fn addCAbiTests(b: *std.Build, skip_non_native: bool, skip_release: bool) *S |
| 1037 | 1037 | continue; |
| 1038 | 1038 | } |
| 1039 | 1039 | |
| 1040 | const triple_prefix = c_abi_target.zigTriple(b.allocator) catch @panic("OOM"); | |
| 1041 | ||
| 1040 | 1042 | const test_step = b.addTest(.{ |
| 1041 | 1043 | .root_source_file = .{ .path = "test/c_abi/main.zig" }, |
| 1042 | 1044 | .optimize = optimize_mode, |
| 1043 | 1045 | .target = c_abi_target, |
| 1046 | .name = b.fmt("test-c-abi-{s}-{s}", .{ | |
| 1047 | triple_prefix, @tagName(optimize_mode), | |
| 1048 | }), | |
| 1044 | 1049 | }); |
| 1045 | 1050 | if (c_abi_target.abi != null and c_abi_target.abi.?.isMusl()) { |
| 1046 | 1051 | // 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 |
| 1057 | 1062 | test_step.want_lto = false; |
| 1058 | 1063 | } |
| 1059 | 1064 | |
| 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 | ||
| 1065 | 1065 | const run = b.addRunArtifact(test_step); |
| 1066 | 1066 | run.skip_foreign_checks = true; |
| 1067 | 1067 | step.dependOn(&run.step); |