| ... | ... | @@ -1593,39 +1593,11 @@ fn buildOutputType( |
| 1593 | 1593 | } |
| 1594 | 1594 | }; |
| 1595 | 1595 | |
| 1596 | | var diags: std.zig.CrossTarget.ParseOptions.Diagnostics = .{}; |
| 1597 | | const cross_target = std.zig.CrossTarget.parse(.{ |
| 1596 | const cross_target = try parseCrossTargetOrReportFatalError(arena, .{ |
| 1598 | 1597 | .arch_os_abi = target_arch_os_abi, |
| 1599 | 1598 | .cpu_features = target_mcpu, |
| 1600 | 1599 | .dynamic_linker = target_dynamic_linker, |
| 1601 | | .diagnostics = &diags, |
| 1602 | | }) catch |err| switch (err) { |
| 1603 | | error.UnknownCpuModel => { |
| 1604 | | help: { |
| 1605 | | var help_text = std.ArrayList(u8).init(arena); |
| 1606 | | for (diags.arch.?.allCpuModels()) |cpu| { |
| 1607 | | help_text.writer().print(" {s}\n", .{cpu.name}) catch break :help; |
| 1608 | | } |
| 1609 | | std.log.info("Available CPUs for architecture '{s}':\n{s}", .{ |
| 1610 | | @tagName(diags.arch.?), help_text.items, |
| 1611 | | }); |
| 1612 | | } |
| 1613 | | fatal("Unknown CPU: '{s}'", .{diags.cpu_name.?}); |
| 1614 | | }, |
| 1615 | | error.UnknownCpuFeature => { |
| 1616 | | help: { |
| 1617 | | var help_text = std.ArrayList(u8).init(arena); |
| 1618 | | for (diags.arch.?.allFeaturesList()) |feature| { |
| 1619 | | help_text.writer().print(" {s}: {s}\n", .{ feature.name, feature.description }) catch break :help; |
| 1620 | | } |
| 1621 | | std.log.info("Available CPU features for architecture '{s}':\n{s}", .{ |
| 1622 | | @tagName(diags.arch.?), help_text.items, |
| 1623 | | }); |
| 1624 | | } |
| 1625 | | fatal("Unknown CPU feature: '{s}'", .{diags.unknown_feature_name}); |
| 1626 | | }, |
| 1627 | | else => |e| return e, |
| 1628 | | }; |
| 1600 | }); |
| 1629 | 1601 | |
| 1630 | 1602 | const target_info = try detectNativeTargetInfo(gpa, cross_target); |
| 1631 | 1603 | |
| ... | ... | @@ -1972,7 +1944,7 @@ fn buildOutputType( |
| 1972 | 1944 | defer if (libc_installation) |*l| l.deinit(gpa); |
| 1973 | 1945 | |
| 1974 | 1946 | if (libc_paths_file) |paths_file| { |
| 1975 | | libc_installation = LibCInstallation.parse(gpa, paths_file) catch |err| { |
| 1947 | libc_installation = LibCInstallation.parse(gpa, paths_file, cross_target) catch |err| { |
| 1976 | 1948 | fatal("unable to parse libc paths file at path {s}: {s}", .{ paths_file, @errorName(err) }); |
| 1977 | 1949 | }; |
| 1978 | 1950 | } |
| ... | ... | @@ -2289,6 +2261,43 @@ fn buildOutputType( |
| 2289 | 2261 | return cleanExit(); |
| 2290 | 2262 | } |
| 2291 | 2263 | |
| 2264 | fn parseCrossTargetOrReportFatalError(allocator: *Allocator, opts: std.zig.CrossTarget.ParseOptions) !std.zig.CrossTarget { |
| 2265 | var opts_with_diags = opts; |
| 2266 | var diags: std.zig.CrossTarget.ParseOptions.Diagnostics = .{}; |
| 2267 | if (opts_with_diags.diagnostics == null) { |
| 2268 | opts_with_diags.diagnostics = &diags; |
| 2269 | } |
| 2270 | return std.zig.CrossTarget.parse(opts_with_diags) catch |err| switch (err) { |
| 2271 | error.UnknownCpuModel => { |
| 2272 | help: { |
| 2273 | var help_text = std.ArrayList(u8).init(allocator); |
| 2274 | defer help_text.deinit(); |
| 2275 | for (diags.arch.?.allCpuModels()) |cpu| { |
| 2276 | help_text.writer().print(" {s}\n", .{cpu.name}) catch break :help; |
| 2277 | } |
| 2278 | std.log.info("Available CPUs for architecture '{s}':\n{s}", .{ |
| 2279 | @tagName(diags.arch.?), help_text.items, |
| 2280 | }); |
| 2281 | } |
| 2282 | fatal("Unknown CPU: '{s}'", .{diags.cpu_name.?}); |
| 2283 | }, |
| 2284 | error.UnknownCpuFeature => { |
| 2285 | help: { |
| 2286 | var help_text = std.ArrayList(u8).init(allocator); |
| 2287 | defer help_text.deinit(); |
| 2288 | for (diags.arch.?.allFeaturesList()) |feature| { |
| 2289 | help_text.writer().print(" {s}: {s}\n", .{ feature.name, feature.description }) catch break :help; |
| 2290 | } |
| 2291 | std.log.info("Available CPU features for architecture '{s}':\n{s}", .{ |
| 2292 | @tagName(diags.arch.?), help_text.items, |
| 2293 | }); |
| 2294 | } |
| 2295 | fatal("Unknown CPU feature: '{s}'", .{diags.unknown_feature_name}); |
| 2296 | }, |
| 2297 | else => |e| return e, |
| 2298 | }; |
| 2299 | } |
| 2300 | |
| 2292 | 2301 | fn runOrTest( |
| 2293 | 2302 | comp: *Compilation, |
| 2294 | 2303 | gpa: *Allocator, |
| ... | ... | @@ -2630,10 +2639,15 @@ pub const usage_libc = |
| 2630 | 2639 | \\ |
| 2631 | 2640 | \\ Parse a libc installation text file and validate it. |
| 2632 | 2641 | \\ |
| 2642 | \\Options: |
| 2643 | \\ -h, --help Print this help and exit |
| 2644 | \\ -target [name] <arch><sub>-<os>-<abi> see the targets command |
| 2645 | \\ |
| 2633 | 2646 | ; |
| 2634 | 2647 | |
| 2635 | 2648 | pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void { |
| 2636 | 2649 | var input_file: ?[]const u8 = null; |
| 2650 | var target_arch_os_abi: []const u8 = "native"; |
| 2637 | 2651 | { |
| 2638 | 2652 | var i: usize = 0; |
| 2639 | 2653 | while (i < args.len) : (i += 1) { |
| ... | ... | @@ -2643,6 +2657,10 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void { |
| 2643 | 2657 | const stdout = io.getStdOut().writer(); |
| 2644 | 2658 | try stdout.writeAll(usage_libc); |
| 2645 | 2659 | return cleanExit(); |
| 2660 | } else if (mem.eql(u8, arg, "-target")) { |
| 2661 | if (i + 1 >= args.len) fatal("expected parameter after {s}", .{arg}); |
| 2662 | i += 1; |
| 2663 | target_arch_os_abi = args[i]; |
| 2646 | 2664 | } else { |
| 2647 | 2665 | fatal("unrecognized parameter: '{s}'", .{arg}); |
| 2648 | 2666 | } |
| ... | ... | @@ -2653,12 +2671,21 @@ pub fn cmdLibC(gpa: *Allocator, args: []const []const u8) !void { |
| 2653 | 2671 | } |
| 2654 | 2672 | } |
| 2655 | 2673 | } |
| 2674 | |
| 2675 | const cross_target = try parseCrossTargetOrReportFatalError(gpa, .{ |
| 2676 | .arch_os_abi = target_arch_os_abi, |
| 2677 | }); |
| 2678 | |
| 2656 | 2679 | if (input_file) |libc_file| { |
| 2657 | | var libc = LibCInstallation.parse(gpa, libc_file) catch |err| { |
| 2680 | var libc = LibCInstallation.parse(gpa, libc_file, cross_target) catch |err| { |
| 2658 | 2681 | fatal("unable to parse libc file at path {s}: {s}", .{ libc_file, @errorName(err) }); |
| 2659 | 2682 | }; |
| 2660 | 2683 | defer libc.deinit(gpa); |
| 2661 | 2684 | } else { |
| 2685 | if (!cross_target.isNative()) { |
| 2686 | fatal("unable to detect libc for non-native target", .{}); |
| 2687 | } |
| 2688 | |
| 2662 | 2689 | var libc = LibCInstallation.findNative(.{ |
| 2663 | 2690 | .allocator = gpa, |
| 2664 | 2691 | .verbose = true, |