authorgravatar for danielchasehooper@gmail.comDaniel Hooper <danielchasehooper@gmail.com> 2024-11-05 19:38:01-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-11-06 03:38:01+00:00
loged04acf90dad41b24d7e11168a0fdd3316fc6f82
treec62f9980b9aa9c230fae017ab4d9a7ec1a15ecde
parent7ebfc72186bbb70064d08192620bd7cccd965b2e
signaturebadge-check Signed by PGP key B5690EEEBB952194

Provide a detailed message for invalid arch in target triple (#21921)


2 files changed, 17 insertions(+), 1 deletions(-)

lib/std/Target/Query.zig+6-1
...@@ -193,6 +193,9 @@ pub const ParseOptions = struct {...@@ -193,6 +193,9 @@ pub const ParseOptions = struct {
193193
194 /// If error.UnknownCpuFeature is returned, this will be populated.194 /// If error.UnknownCpuFeature is returned, this will be populated.
195 unknown_feature_name: ?[]const u8 = null,195 unknown_feature_name: ?[]const u8 = null,
196
197 /// If error.UnknownArchitecture is returned, this will be populated.
198 unknown_architecture_name: ?[]const u8 = null,
196 };199 };
197};200};
198201
...@@ -208,8 +211,10 @@ pub fn parse(args: ParseOptions) !Query {...@@ -208,8 +211,10 @@ pub fn parse(args: ParseOptions) !Query {
208 const arch_name = it.first();211 const arch_name = it.first();
209 const arch_is_native = mem.eql(u8, arch_name, "native");212 const arch_is_native = mem.eql(u8, arch_name, "native");
210 if (!arch_is_native) {213 if (!arch_is_native) {
211 result.cpu_arch = std.meta.stringToEnum(Target.Cpu.Arch, arch_name) orelse214 result.cpu_arch = std.meta.stringToEnum(Target.Cpu.Arch, arch_name) orelse {
215 diags.unknown_architecture_name = arch_name;
212 return error.UnknownArchitecture;216 return error.UnknownArchitecture;
217 };
213 }218 }
214 const arch = result.cpu_arch orelse builtin.cpu.arch;219 const arch = result.cpu_arch orelse builtin.cpu.arch;
215 diags.arch = arch;220 diags.arch = arch;
lib/std/zig.zig+11
...@@ -660,6 +660,17 @@ pub fn parseTargetQueryOrReportFatalError(...@@ -660,6 +660,17 @@ pub fn parseTargetQueryOrReportFatalError(
660 }660 }
661 fatal("unknown object format: '{s}'", .{opts.object_format.?});661 fatal("unknown object format: '{s}'", .{opts.object_format.?});
662 },662 },
663 error.UnknownArchitecture => {
664 help: {
665 var help_text = std.ArrayList(u8).init(allocator);
666 defer help_text.deinit();
667 inline for (@typeInfo(std.Target.Cpu.Arch).@"enum".fields) |field| {
668 help_text.writer().print(" {s}\n", .{field.name}) catch break :help;
669 }
670 std.log.info("available architectures:\n{s} native\n", .{help_text.items});
671 }
672 fatal("unknown architecture: '{s}'", .{diags.unknown_architecture_name.?});
673 },
663 else => |e| fatal("unable to parse target query '{s}': {s}", .{674 else => |e| fatal("unable to parse target query '{s}': {s}", .{
664 opts.arch_os_abi, @errorName(e),675 opts.arch_os_abi, @errorName(e),
665 }),676 }),