Skip to content

Commit

Permalink
Provide a detailed message for invalid arch in target triple (#21921)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielchasehooper authored Nov 6, 2024
1 parent 7ebfc72 commit ed04acf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/std/Target/Query.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
};

Expand All @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions lib/std/zig.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
Expand Down

0 comments on commit ed04acf

Please sign in to comment.