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

This commit is contained in:
Daniel Hooper 2024-11-05 19:38:01 -08:00 committed by GitHub
parent 7ebfc72186
commit ed04acf90d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 17 additions and 1 deletions

View File

@ -193,6 +193,9 @@ pub const ParseOptions = struct {
/// If error.UnknownCpuFeature is returned, this will be populated.
unknown_feature_name: ?[]const u8 = null,
/// If error.UnknownArchitecture is returned, this will be populated.
unknown_architecture_name: ?[]const u8 = null,
};
};
@ -208,8 +211,10 @@ pub fn parse(args: ParseOptions) !Query {
const arch_name = it.first();
const arch_is_native = mem.eql(u8, arch_name, "native");
if (!arch_is_native) {
result.cpu_arch = std.meta.stringToEnum(Target.Cpu.Arch, arch_name) orelse
result.cpu_arch = std.meta.stringToEnum(Target.Cpu.Arch, arch_name) orelse {
diags.unknown_architecture_name = arch_name;
return error.UnknownArchitecture;
};
}
const arch = result.cpu_arch orelse builtin.cpu.arch;
diags.arch = arch;

View File

@ -660,6 +660,17 @@ pub fn parseTargetQueryOrReportFatalError(
}
fatal("unknown object format: '{s}'", .{opts.object_format.?});
},
error.UnknownArchitecture => {
help: {
var help_text = std.ArrayList(u8).init(allocator);
defer help_text.deinit();
inline for (@typeInfo(std.Target.Cpu.Arch).@"enum".fields) |field| {
help_text.writer().print(" {s}\n", .{field.name}) catch break :help;
}
std.log.info("available architectures:\n{s} native\n", .{help_text.items});
}
fatal("unknown architecture: '{s}'", .{diags.unknown_architecture_name.?});
},
else => |e| fatal("unable to parse target query '{s}': {s}", .{
opts.arch_os_abi, @errorName(e),
}),