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 {...@@ -4691,6 +4691,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4691 var verbose_llvm_cpu_features = false;4691 var verbose_llvm_cpu_features = false;
4692 var fetch_only = false;4692 var fetch_only = false;
4693 var system_pkg_dir_path: ?[]const u8 = null;4693 var system_pkg_dir_path: ?[]const u8 = null;
4694 var debug_target: ?[]const u8 = null;
46944695
4695 const argv_index_exe = child_argv.items.len;4696 const argv_index_exe = child_argv.items.len;
4696 _ = try child_argv.addOne();4697 _ = try child_argv.addOne();
...@@ -4799,6 +4800,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -4799,6 +4800,14 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4799 } else {4800 } else {
4800 warn("Zig was compiled without debug extensions. --debug-compile-errors has no effect.", .{});4801 warn("Zig was compiled without debug extensions. --debug-compile-errors has no effect.", .{});
4801 }4802 }
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 }
4802 } else if (mem.eql(u8, arg, "--verbose-link")) {4811 } else if (mem.eql(u8, arg, "--verbose-link")) {
4803 verbose_link = true;4812 verbose_link = true;
4804 } else if (mem.eql(u8, arg, "--verbose-cc")) {4813 } else if (mem.eql(u8, arg, "--verbose-cc")) {
...@@ -4857,11 +4866,27 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {...@@ -4857,11 +4866,27 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void {
4857 });4866 });
4858 defer root_prog_node.end();4867 defer root_prog_node.end();
48594868
4860 const target_query: std.Target.Query = .{};4869 // Normally the build runner is compiled for the host target but here is
4861 const resolved_target: Package.Module.ResolvedTarget = .{4870 // some code to help when debugging edits to the build runner so that you
4862 .result = std.zig.resolveTargetQueryOrFatal(target_query),4871 // can make sure it compiles successfully on other targets.
4863 .is_native_os = true,4872 const resolved_target: Package.Module.ResolvedTarget = t: {
4864 .is_native_abi = true,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 };
4865 };4890 };
48664891
4867 const exe_basename = try std.zig.binNameAlloc(arena, .{4892 const exe_basename = try std.zig.binNameAlloc(arena, .{