authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-12 14:19:17-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-12 14:19:17-07:00
logf77b43dad39a5140f3e39f32e98e9624368c16d6
treeac10a1a65da0f94f119160522841b4be6e4cb502
parent4f9a8b68430b9b44cba78664bd0f60d5c5db5fe3

zig build: add a --debug-target CLI flag

it's not advertised in the usage and only available in debug builds of the compiler. Makes it easier to test changes to the build runner that might affect targets differently.

1 files changed, 30 insertions(+), 5 deletions(-)

src/main.zig+30-5
......@@ -4691,6 +4691,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
46914691 var verbose_llvm_cpu_features = false;
46924692 var fetch_only = false;
46934693 var system_pkg_dir_path: ?[]const u8 = null;
4694 var debug_target: ?[]const u8 = null;
46944695
46954696 const argv_index_exe = child_argv.items.len;
46964697 _ = try child_argv.addOne();
......@@ -4799,6 +4800,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
47994800 } else {
48004801 warn("Zig was compiled without debug extensions. --debug-compile-errors has no effect.", .{});
48014802 }
4803 } else if (mem.eql(u8, arg, "--debug-target")) {
4804 if (i + 1 >= args.len) fatal("expected argument after '{s}'", .{arg});
4805 i += 1;
4806 if (build_options.enable_debug_extensions) {
4807 debug_target = args[i];
4808 } else {
4809 warn("Zig was compiled without debug extensions. --debug-target has no effect.", .{});
4810 }
48024811 } else if (mem.eql(u8, arg, "--verbose-link")) {
48034812 verbose_link = true;
48044813 } else if (mem.eql(u8, arg, "--verbose-cc")) {
......@@ -4857,11 +4866,27 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
48574866 });
48584867 defer root_prog_node.end();
48594868
4860 const target_query: std.Target.Query = .{};
4861 const resolved_target: Package.Module.ResolvedTarget = .{
4862 .result = std.zig.resolveTargetQueryOrFatal(target_query),
4863 .is_native_os = true,
4864 .is_native_abi = true,
4869 // Normally the build runner is compiled for the host target but here is
4870 // some code to help when debugging edits to the build runner so that you
4871 // can make sure it compiles successfully on other targets.
4872 const resolved_target: Package.Module.ResolvedTarget = t: {
4873 if (build_options.enable_debug_extensions) {
4874 if (debug_target) |triple| {
4875 const target_query = try std.Target.Query.parse(.{
4876 .arch_os_abi = triple,
4877 });
4878 break :t .{
4879 .result = std.zig.resolveTargetQueryOrFatal(target_query),
4880 .is_native_os = false,
4881 .is_native_abi = false,
4882 };
4883 }
4884 }
4885 break :t .{
4886 .result = std.zig.resolveTargetQueryOrFatal(.{}),
4887 .is_native_os = true,
4888 .is_native_abi = true,
4889 };
48654890 };
48664891
48674892 const exe_basename = try std.zig.binNameAlloc(arena, .{