| ... | ... | @@ -20,6 +20,7 @@ const LibCInstallation = std.zig.LibCInstallation; |
| 20 | 20 | const AstGen = std.zig.AstGen; |
| 21 | 21 | const ZonGen = std.zig.ZonGen; |
| 22 | 22 | const Server = std.zig.Server; |
| 23 | const stringToEnum = std.meta.stringToEnum; |
| 23 | 24 | |
| 24 | 25 | pub const tracy = @import("tracy.zig"); |
| 25 | 26 | const Compilation = @import("Compilation.zig"); |
| ... | ... | @@ -229,8 +230,6 @@ pub fn main(init: std.process.Init.Minimal) anyerror!void { |
| 229 | 230 | return mainArgs(gpa, arena, io, args, &environ_map); |
| 230 | 231 | } |
| 231 | 232 | |
| 232 | | const cmd_map = std.StaticStringMap(Cmd).initEnum(); |
| 233 | | |
| 234 | 233 | const Cmd = enum { |
| 235 | 234 | @"build-exe", |
| 236 | 235 | @"build-lib", |
| ... | ... | @@ -322,7 +321,7 @@ fn mainArgs( |
| 322 | 321 | |
| 323 | 322 | const cmd = args[1]; |
| 324 | 323 | const cmd_args = args[2..]; |
| 325 | | switch (cmd_map.get(cmd) orelse { |
| 324 | switch (stringToEnum.get(Cmd, cmd) orelse { |
| 326 | 325 | std.log.info("{s}", .{usage}); |
| 327 | 326 | fatal("unknown command: {s}", .{args[1]}); |
| 328 | 327 | }) { |
| ... | ... | @@ -1220,7 +1219,7 @@ fn buildOutputType( |
| 1220 | 1219 | const next_arg = args_iter.next() orelse { |
| 1221 | 1220 | fatal("expected [auto|on|off] after --color", .{}); |
| 1222 | 1221 | }; |
| 1223 | | color = std.meta.stringToEnum(Color, next_arg) orelse { |
| 1222 | color = stringToEnum(Color, next_arg) orelse { |
| 1224 | 1223 | fatal("expected [auto|on|off] after --color, found {q}", .{next_arg}); |
| 1225 | 1224 | }; |
| 1226 | 1225 | } else if (mem.cutPrefix(u8, arg, "-j")) |str| { |
| ... | ... | @@ -1264,7 +1263,7 @@ fn buildOutputType( |
| 1264 | 1263 | } else if (mem.eql(u8, arg, "-install_name")) { |
| 1265 | 1264 | install_name = args_iter.nextOrFatal(); |
| 1266 | 1265 | } else if (mem.cutPrefix(u8, arg, "--compress-debug-sections=")) |param| { |
| 1267 | | linker_compress_debug_sections = std.meta.stringToEnum(std.zig.CompressDebugSections, param) orelse { |
| 1266 | linker_compress_debug_sections = stringToEnum(std.zig.CompressDebugSections, param) orelse { |
| 1268 | 1267 | fatal("expected --compress-debug-sections=[none|zlib|zstd], found: {s}", .{param}); |
| 1269 | 1268 | }; |
| 1270 | 1269 | } else if (mem.eql(u8, arg, "--compress-debug-sections")) { |
| ... | ... | @@ -2516,7 +2515,7 @@ fn buildOutputType( |
| 2516 | 2515 | if (it.only_arg.len == 0) { |
| 2517 | 2516 | linker_compress_debug_sections = .zlib; |
| 2518 | 2517 | } else { |
| 2519 | | linker_compress_debug_sections = std.meta.stringToEnum(std.zig.CompressDebugSections, it.only_arg) orelse { |
| 2518 | linker_compress_debug_sections = stringToEnum(std.zig.CompressDebugSections, it.only_arg) orelse { |
| 2520 | 2519 | fatal("expected [none|zlib|zstd] after --compress-debug-sections, found {q}", .{it.only_arg}); |
| 2521 | 2520 | }; |
| 2522 | 2521 | } |
| ... | ... | @@ -2668,7 +2667,7 @@ fn buildOutputType( |
| 2668 | 2667 | linker_print_map = true; |
| 2669 | 2668 | } else if (mem.eql(u8, arg, "--sort-section")) { |
| 2670 | 2669 | const arg1 = linker_args_it.nextOrFatal(); |
| 2671 | | linker_sort_section = std.meta.stringToEnum(link.File.Lld.Elf.SortSection, arg1) orelse { |
| 2670 | linker_sort_section = stringToEnum(link.File.Lld.Elf.SortSection, arg1) orelse { |
| 2672 | 2671 | fatal("expected [name|alignment] after --sort-section, found {q}", .{arg1}); |
| 2673 | 2672 | }; |
| 2674 | 2673 | } else if (mem.eql(u8, arg, "--allow-shlib-undefined") or |
| ... | ... | @@ -2724,7 +2723,7 @@ fn buildOutputType( |
| 2724 | 2723 | } |
| 2725 | 2724 | } else if (mem.eql(u8, arg, "--compress-debug-sections")) { |
| 2726 | 2725 | const arg1 = linker_args_it.nextOrFatal(); |
| 2727 | | linker_compress_debug_sections = std.meta.stringToEnum(std.zig.CompressDebugSections, arg1) orelse { |
| 2726 | linker_compress_debug_sections = stringToEnum(std.zig.CompressDebugSections, arg1) orelse { |
| 2728 | 2727 | fatal("expected [none|zlib|zstd] after --compress-debug-sections, found {q}", .{arg1}); |
| 2729 | 2728 | }; |
| 2730 | 2729 | } else if (mem.cutPrefix(u8, arg, "-z")) |z_rest| { |
| ... | ... | @@ -2935,7 +2934,7 @@ fn buildOutputType( |
| 2935 | 2934 | mem.eql(u8, arg, "--hash-style")) |
| 2936 | 2935 | { |
| 2937 | 2936 | const next_arg = linker_args_it.nextOrFatal(); |
| 2938 | | hash_style = std.meta.stringToEnum(link.File.Lld.Elf.HashStyle, next_arg) orelse { |
| 2937 | hash_style = stringToEnum(link.File.Lld.Elf.HashStyle, next_arg) orelse { |
| 2939 | 2938 | fatal("expected [sysv|gnu|both] after --hash-style, found {q}", .{next_arg}); |
| 2940 | 2939 | }; |
| 2941 | 2940 | } else if (mem.eql(u8, arg, "-wrap")) { |
| ... | ... | @@ -5091,7 +5090,7 @@ fn cmdBuild( |
| 5091 | 5090 | configure_argv.appendAssumeCapacity(arg); // Intentionally "--system" only; not the path. |
| 5092 | 5091 | continue; |
| 5093 | 5092 | } else if (mem.cutPrefix(u8, arg, "--color=")) |rest| { |
| 5094 | | color = std.meta.stringToEnum(Color, rest) orelse |
| 5093 | color = stringToEnum(Color, rest) orelse |
| 5095 | 5094 | fatal("expected --color=[auto|on|off]; found {q}", .{arg}); |
| 5096 | 5095 | |
| 5097 | 5096 | try cached_passthru_configure.append(arena, @intCast(configure_argv.items.len)); |
| ... | ... | @@ -5103,7 +5102,7 @@ fn cmdBuild( |
| 5103 | 5102 | continue; |
| 5104 | 5103 | } else if (mem.cutPrefix(u8, arg, "--cache-poison=")) |rest| { |
| 5105 | 5104 | // Allow the configurer process to report parse failure. |
| 5106 | | if (std.meta.stringToEnum(std.Build.Graph.CachePoison, rest)) |poison| { |
| 5105 | if (stringToEnum(std.Build.Graph.CachePoison, rest)) |poison| { |
| 5107 | 5106 | cache_poison = poison; |
| 5108 | 5107 | } |
| 5109 | 5108 | configure_argv.appendAssumeCapacity(arg); |
| ... | ... | @@ -5155,7 +5154,7 @@ fn cmdBuild( |
| 5155 | 5154 | fetch_only = true; |
| 5156 | 5155 | } else if (mem.cutPrefix(u8, arg, "--fetch=")) |sub_arg| { |
| 5157 | 5156 | fetch_only = true; |
| 5158 | | fetch_mode = std.meta.stringToEnum(Package.Fetch.JobQueue.Mode, sub_arg) orelse |
| 5157 | fetch_mode = stringToEnum(Package.Fetch.JobQueue.Mode, sub_arg) orelse |
| 5159 | 5158 | fatal("expected [needed|all] after \"--fetch=\", found: {s}", .{sub_arg}); |
| 5160 | 5159 | } else if (mem.cutPrefix(u8, arg, "--fork=")) |sub_arg| { |
| 5161 | 5160 | try forks.append(arena, .init(sub_arg)); |
| ... | ... | @@ -6591,7 +6590,7 @@ pub const ClangArgIterator = struct { |
| 6591 | 6590 | }; |
| 6592 | 6591 | |
| 6593 | 6592 | fn parseCodeModel(arg: []const u8) std.lang.CodeModel { |
| 6594 | | return std.meta.stringToEnum(std.lang.CodeModel, arg) orelse |
| 6593 | return stringToEnum(std.lang.CodeModel, arg) orelse |
| 6595 | 6594 | fatal("unsupported machine code model: {q}", .{arg}); |
| 6596 | 6595 | } |
| 6597 | 6596 | |
| ... | ... | @@ -6638,7 +6637,7 @@ fn cmdAstCheck(arena: Allocator, io: Io, args: []const []const u8, environ_map: |
| 6638 | 6637 | } |
| 6639 | 6638 | i += 1; |
| 6640 | 6639 | const next_arg = args[i]; |
| 6641 | | color = std.meta.stringToEnum(Color, next_arg) orelse { |
| 6640 | color = stringToEnum(Color, next_arg) orelse { |
| 6642 | 6641 | fatal("expected [auto|on|off] after --color, found {q}", .{next_arg}); |
| 6643 | 6642 | }; |
| 6644 | 6643 | } else { |
| ... | ... | @@ -7020,7 +7019,7 @@ fn warnAboutForeignBinaries( |
| 7020 | 7019 | } |
| 7021 | 7020 | |
| 7022 | 7021 | fn parseSubsystem(arg: []const u8) !std.zig.Subsystem { |
| 7023 | | return std.meta.stringToEnum(std.zig.Subsystem, arg) orelse |
| 7022 | return stringToEnum(std.zig.Subsystem, arg) orelse |
| 7024 | 7023 | fatal("invalid: --subsystem: {q}. Options are:\n{s}", .{ |
| 7025 | 7024 | arg, |
| 7026 | 7025 | \\ console |
| ... | ... | @@ -7151,7 +7150,7 @@ fn accessFrameworkPath( |
| 7151 | 7150 | } |
| 7152 | 7151 | |
| 7153 | 7152 | fn parseRcIncludes(arg: []const u8) std.zig.RcIncludes { |
| 7154 | | return std.meta.stringToEnum(std.zig.RcIncludes, arg) orelse |
| 7153 | return stringToEnum(std.zig.RcIncludes, arg) orelse |
| 7155 | 7154 | fatal("unsupported rc includes type: {q}", .{arg}); |
| 7156 | 7155 | } |
| 7157 | 7156 | |
| ... | ... | @@ -7817,12 +7816,12 @@ fn findTemplates(gpa: Allocator, arena: Allocator, io: Io) Templates { |
| 7817 | 7816 | } |
| 7818 | 7817 | |
| 7819 | 7818 | fn parseOptimizeMode(s: []const u8) std.lang.OptimizeMode { |
| 7820 | | return std.meta.stringToEnum(std.lang.OptimizeMode, s) orelse |
| 7819 | return stringToEnum(std.lang.OptimizeMode, s) orelse |
| 7821 | 7820 | fatal("unrecognized optimization mode: {q}", .{s}); |
| 7822 | 7821 | } |
| 7823 | 7822 | |
| 7824 | 7823 | fn parseWasiExecModel(s: []const u8) std.lang.WasiExecModel { |
| 7825 | | return std.meta.stringToEnum(std.lang.WasiExecModel, s) orelse |
| 7824 | return stringToEnum(std.lang.WasiExecModel, s) orelse |
| 7826 | 7825 | fatal("expected [command|reactor] for -mexec-mode=[value], found {q}", .{s}); |
| 7827 | 7826 | } |
| 7828 | 7827 | |