| ... | @@ -1022,10 +1022,9 @@ fn buildOutputType( | ... | @@ -1022,10 +1022,9 @@ fn buildOutputType( |
| 1022 | | 1022 | |
| 1023 | var file_ext: ?Compilation.FileExt = null; | 1023 | var file_ext: ?Compilation.FileExt = null; |
| 1024 | args_loop: while (args_iter.next()) |arg| { | 1024 | args_loop: while (args_iter.next()) |arg| { |
| 1025 | if (mem.startsWith(u8, arg, "@")) { | 1025 | if (mem.cutPrefix(u8, arg, "@")) |resp_file_path| { |
| 1026 | // This is a "compiler response file". We must parse the file and treat its | 1026 | // This is a "compiler response file". We must parse the file and treat its |
| 1027 | // contents as command line parameters. | 1027 | // contents as command line parameters. |
| 1028 | const resp_file_path = arg[1..]; | | |
| 1029 | args_iter.resp_file = initArgIteratorResponseFile(arena, resp_file_path) catch |err| { | 1028 | args_iter.resp_file = initArgIteratorResponseFile(arena, resp_file_path) catch |err| { |
| 1030 | fatal("unable to read response file '{s}': {s}", .{ resp_file_path, @errorName(err) }); | 1029 | fatal("unable to read response file '{s}': {s}", .{ resp_file_path, @errorName(err) }); |
| 1031 | }; | 1030 | }; |
| ... | @@ -1043,9 +1042,8 @@ fn buildOutputType( | ... | @@ -1043,9 +1042,8 @@ fn buildOutputType( |
| 1043 | fatal("unexpected end-of-parameter mark: --", .{}); | 1042 | fatal("unexpected end-of-parameter mark: --", .{}); |
| 1044 | } | 1043 | } |
| 1045 | } else if (mem.eql(u8, arg, "--dep")) { | 1044 | } else if (mem.eql(u8, arg, "--dep")) { |
| 1046 | var it = mem.splitScalar(u8, args_iter.nextOrFatal(), '='); | 1045 | const next_arg = args_iter.nextOrFatal(); |
| 1047 | const key = it.first(); | 1046 | const key, const value = mem.cutScalar(u8, next_arg, '=') orelse .{ next_arg, next_arg }; |
| 1048 | const value = if (it.peek() != null) it.rest() else key; | | |
| 1049 | if (mem.eql(u8, key, "std") and !mem.eql(u8, value, "std")) { | 1047 | if (mem.eql(u8, key, "std") and !mem.eql(u8, value, "std")) { |
| 1050 | fatal("unable to import as '{s}': conflicts with builtin module", .{ | 1048 | fatal("unable to import as '{s}': conflicts with builtin module", .{ |
| 1051 | key, | 1049 | key, |
| ... | @@ -1062,10 +1060,8 @@ fn buildOutputType( | ... | @@ -1062,10 +1060,8 @@ fn buildOutputType( |
| 1062 | .key = key, | 1060 | .key = key, |
| 1063 | .value = value, | 1061 | .value = value, |
| 1064 | }); | 1062 | }); |
| 1065 | } else if (mem.startsWith(u8, arg, "-M")) { | 1063 | } else if (mem.cutPrefix(u8, arg, "-M")) |rest| { |
| 1066 | var it = mem.splitScalar(u8, arg["-M".len..], '='); | 1064 | const mod_name, const root_src_orig = mem.cutScalar(u8, rest, '=') orelse .{ rest, null }; |
| 1067 | const mod_name = it.first(); | | |
| 1068 | const root_src_orig = if (it.peek() != null) it.rest() else null; | | |
| 1069 | try handleModArg( | 1065 | try handleModArg( |
| 1070 | arena, | 1066 | arena, |
| 1071 | mod_name, | 1067 | mod_name, |
| ... | @@ -1096,8 +1092,8 @@ fn buildOutputType( | ... | @@ -1096,8 +1092,8 @@ fn buildOutputType( |
| 1096 | } | 1092 | } |
| 1097 | } else if (mem.eql(u8, arg, "-rcincludes")) { | 1093 | } else if (mem.eql(u8, arg, "-rcincludes")) { |
| 1098 | rc_includes = parseRcIncludes(args_iter.nextOrFatal()); | 1094 | rc_includes = parseRcIncludes(args_iter.nextOrFatal()); |
| 1099 | } else if (mem.startsWith(u8, arg, "-rcincludes=")) { | 1095 | } else if (mem.cutPrefix(u8, arg, "-rcincludes=")) |rest| { |
| 1100 | rc_includes = parseRcIncludes(arg["-rcincludes=".len..]); | 1096 | rc_includes = parseRcIncludes(rest); |
| 1101 | } else if (mem.eql(u8, arg, "-rcflags")) { | 1097 | } else if (mem.eql(u8, arg, "-rcflags")) { |
| 1102 | extra_rcflags.shrinkRetainingCapacity(0); | 1098 | extra_rcflags.shrinkRetainingCapacity(0); |
| 1103 | while (true) { | 1099 | while (true) { |
| ... | @@ -1107,9 +1103,9 @@ fn buildOutputType( | ... | @@ -1107,9 +1103,9 @@ fn buildOutputType( |
| 1107 | if (mem.eql(u8, next_arg, "--")) break; | 1103 | if (mem.eql(u8, next_arg, "--")) break; |
| 1108 | try extra_rcflags.append(arena, next_arg); | 1104 | try extra_rcflags.append(arena, next_arg); |
| 1109 | } | 1105 | } |
| 1110 | } else if (mem.startsWith(u8, arg, "-fstructured-cfg")) { | 1106 | } else if (mem.eql(u8, arg, "-fstructured-cfg")) { |
| 1111 | mod_opts.structured_cfg = true; | 1107 | mod_opts.structured_cfg = true; |
| 1112 | } else if (mem.startsWith(u8, arg, "-fno-structured-cfg")) { | 1108 | } else if (mem.eql(u8, arg, "-fno-structured-cfg")) { |
| 1113 | mod_opts.structured_cfg = false; | 1109 | mod_opts.structured_cfg = false; |
| 1114 | } else if (mem.eql(u8, arg, "--color")) { | 1110 | } else if (mem.eql(u8, arg, "--color")) { |
| 1115 | const next_arg = args_iter.next() orelse { | 1111 | const next_arg = args_iter.next() orelse { |
| ... | @@ -1118,8 +1114,7 @@ fn buildOutputType( | ... | @@ -1118,8 +1114,7 @@ fn buildOutputType( |
| 1118 | color = std.meta.stringToEnum(Color, next_arg) orelse { | 1114 | color = std.meta.stringToEnum(Color, next_arg) orelse { |
| 1119 | fatal("expected [auto|on|off] after --color, found '{s}'", .{next_arg}); | 1115 | fatal("expected [auto|on|off] after --color, found '{s}'", .{next_arg}); |
| 1120 | }; | 1116 | }; |
| 1121 | } else if (mem.startsWith(u8, arg, "-j")) { | 1117 | } else if (mem.cutPrefix(u8, arg, "-j")) |str| { |
| 1122 | const str = arg["-j".len..]; | | |
| 1123 | const num = std.fmt.parseUnsigned(u32, str, 10) catch |err| { | 1118 | const num = std.fmt.parseUnsigned(u32, str, 10) catch |err| { |
| 1124 | fatal("unable to parse jobs count '{s}': {s}", .{ | 1119 | fatal("unable to parse jobs count '{s}': {s}", .{ |
| 1125 | str, @errorName(err), | 1120 | str, @errorName(err), |
| ... | @@ -1133,8 +1128,8 @@ fn buildOutputType( | ... | @@ -1133,8 +1128,8 @@ fn buildOutputType( |
| 1133 | subsystem = try parseSubSystem(args_iter.nextOrFatal()); | 1128 | subsystem = try parseSubSystem(args_iter.nextOrFatal()); |
| 1134 | } else if (mem.eql(u8, arg, "-O")) { | 1129 | } else if (mem.eql(u8, arg, "-O")) { |
| 1135 | mod_opts.optimize_mode = parseOptimizeMode(args_iter.nextOrFatal()); | 1130 | mod_opts.optimize_mode = parseOptimizeMode(args_iter.nextOrFatal()); |
| 1136 | } else if (mem.startsWith(u8, arg, "-fentry=")) { | 1131 | } else if (mem.cutPrefix(u8, arg, "-fentry=")) |rest| { |
| 1137 | entry = .{ .named = arg["-fentry=".len..] }; | 1132 | entry = .{ .named = rest }; |
| 1138 | } else if (mem.eql(u8, arg, "--force_undefined")) { | 1133 | } else if (mem.eql(u8, arg, "--force_undefined")) { |
| 1139 | try force_undefined_symbols.put(arena, args_iter.nextOrFatal(), {}); | 1134 | try force_undefined_symbols.put(arena, args_iter.nextOrFatal(), {}); |
| 1140 | } else if (mem.eql(u8, arg, "--discard-all")) { | 1135 | } else if (mem.eql(u8, arg, "--discard-all")) { |
| ... | @@ -1161,8 +1156,7 @@ fn buildOutputType( | ... | @@ -1161,8 +1156,7 @@ fn buildOutputType( |
| 1161 | try create_module.frameworks.put(arena, args_iter.nextOrFatal(), .{ .needed = true }); | 1156 | try create_module.frameworks.put(arena, args_iter.nextOrFatal(), .{ .needed = true }); |
| 1162 | } else if (mem.eql(u8, arg, "-install_name")) { | 1157 | } else if (mem.eql(u8, arg, "-install_name")) { |
| 1163 | install_name = args_iter.nextOrFatal(); | 1158 | install_name = args_iter.nextOrFatal(); |
| 1164 | } else if (mem.startsWith(u8, arg, "--compress-debug-sections=")) { | 1159 | } else if (mem.cutPrefix(u8, arg, "--compress-debug-sections=")) |param| { |
| 1165 | const param = arg["--compress-debug-sections=".len..]; | | |
| 1166 | linker_compress_debug_sections = std.meta.stringToEnum(link.File.Lld.Elf.CompressDebugSections, param) orelse { | 1160 | linker_compress_debug_sections = std.meta.stringToEnum(link.File.Lld.Elf.CompressDebugSections, param) orelse { |
| 1167 | fatal("expected --compress-debug-sections=[none|zlib|zstd], found '{s}'", .{param}); | 1161 | fatal("expected --compress-debug-sections=[none|zlib|zstd], found '{s}'", .{param}); |
| 1168 | }; | 1162 | }; |
| ... | @@ -1260,8 +1254,8 @@ fn buildOutputType( | ... | @@ -1260,8 +1254,8 @@ fn buildOutputType( |
| 1260 | try cc_argv.appendSlice(arena, &.{ arg, args_iter.nextOrFatal() }); | 1254 | try cc_argv.appendSlice(arena, &.{ arg, args_iter.nextOrFatal() }); |
| 1261 | } else if (mem.eql(u8, arg, "-I")) { | 1255 | } else if (mem.eql(u8, arg, "-I")) { |
| 1262 | try cssan.addIncludePath(arena, &cc_argv, .I, arg, args_iter.nextOrFatal(), false); | 1256 | try cssan.addIncludePath(arena, &cc_argv, .I, arg, args_iter.nextOrFatal(), false); |
| 1263 | } else if (mem.startsWith(u8, arg, "--embed-dir=")) { | 1257 | } else if (mem.cutPrefix(u8, arg, "--embed-dir=")) |rest| { |
| 1264 | try cssan.addIncludePath(arena, &cc_argv, .embed_dir, arg, arg["--embed-dir=".len..], true); | 1258 | try cssan.addIncludePath(arena, &cc_argv, .embed_dir, arg, rest, true); |
| 1265 | } else if (mem.eql(u8, arg, "-isystem")) { | 1259 | } else if (mem.eql(u8, arg, "-isystem")) { |
| 1266 | try cssan.addIncludePath(arena, &cc_argv, .isystem, arg, args_iter.nextOrFatal(), false); | 1260 | try cssan.addIncludePath(arena, &cc_argv, .isystem, arg, args_iter.nextOrFatal(), false); |
| 1267 | } else if (mem.eql(u8, arg, "-iwithsysroot")) { | 1261 | } else if (mem.eql(u8, arg, "-iwithsysroot")) { |
| ... | @@ -1288,14 +1282,14 @@ fn buildOutputType( | ... | @@ -1288,14 +1282,14 @@ fn buildOutputType( |
| 1288 | target_mcpu = args_iter.nextOrFatal(); | 1282 | target_mcpu = args_iter.nextOrFatal(); |
| 1289 | } else if (mem.eql(u8, arg, "-mcmodel")) { | 1283 | } else if (mem.eql(u8, arg, "-mcmodel")) { |
| 1290 | mod_opts.code_model = parseCodeModel(args_iter.nextOrFatal()); | 1284 | mod_opts.code_model = parseCodeModel(args_iter.nextOrFatal()); |
| 1291 | } else if (mem.startsWith(u8, arg, "-mcmodel=")) { | 1285 | } else if (mem.cutPrefix(u8, arg, "-mcmodel=")) |rest| { |
| 1292 | mod_opts.code_model = parseCodeModel(arg["-mcmodel=".len..]); | 1286 | mod_opts.code_model = parseCodeModel(rest); |
| 1293 | } else if (mem.startsWith(u8, arg, "-ofmt=")) { | 1287 | } else if (mem.cutPrefix(u8, arg, "-ofmt=")) |rest| { |
| 1294 | create_module.object_format = arg["-ofmt=".len..]; | 1288 | create_module.object_format = rest; |
| 1295 | } else if (mem.startsWith(u8, arg, "-mcpu=")) { | 1289 | } else if (mem.cutPrefix(u8, arg, "-mcpu=")) |rest| { |
| 1296 | target_mcpu = arg["-mcpu=".len..]; | 1290 | target_mcpu = rest; |
| 1297 | } else if (mem.startsWith(u8, arg, "-O")) { | 1291 | } else if (mem.cutPrefix(u8, arg, "-O")) |rest| { |
| 1298 | mod_opts.optimize_mode = parseOptimizeMode(arg["-O".len..]); | 1292 | mod_opts.optimize_mode = parseOptimizeMode(rest); |
| 1299 | } else if (mem.eql(u8, arg, "--dynamic-linker")) { | 1293 | } else if (mem.eql(u8, arg, "--dynamic-linker")) { |
| 1300 | create_module.dynamic_linker = args_iter.nextOrFatal(); | 1294 | create_module.dynamic_linker = args_iter.nextOrFatal(); |
| 1301 | } else if (mem.eql(u8, arg, "--sysroot")) { | 1295 | } else if (mem.eql(u8, arg, "--sysroot")) { |
| ... | @@ -1331,9 +1325,7 @@ fn buildOutputType( | ... | @@ -1331,9 +1325,7 @@ fn buildOutputType( |
| 1331 | } else { | 1325 | } else { |
| 1332 | dev.check(.network_listen); | 1326 | dev.check(.network_listen); |
| 1333 | // example: --listen 127.0.0.1:9000 | 1327 | // example: --listen 127.0.0.1:9000 |
| 1334 | var it = std.mem.splitScalar(u8, next_arg, ':'); | 1328 | const host, const port_text = mem.cutScalar(u8, next_arg, ':') orelse .{ next_arg, "14735" }; |
| 1335 | const host = it.next().?; | | |
| 1336 | const port_text = it.next() orelse "14735"; | | |
| 1337 | const port = std.fmt.parseInt(u16, port_text, 10) catch |err| | 1329 | const port = std.fmt.parseInt(u16, port_text, 10) catch |err| |
| 1338 | fatal("invalid port number: '{s}': {s}", .{ port_text, @errorName(err) }); | 1330 | fatal("invalid port number: '{s}': {s}", .{ port_text, @errorName(err) }); |
| 1339 | listen = .{ .ip4 = std.net.Ip4Address.parse(host, port) catch |err| | 1331 | listen = .{ .ip4 = std.net.Ip4Address.parse(host, port) catch |err| |
| ... | @@ -1393,8 +1385,7 @@ fn buildOutputType( | ... | @@ -1393,8 +1385,7 @@ fn buildOutputType( |
| 1393 | create_module.opts.pie = false; | 1385 | create_module.opts.pie = false; |
| 1394 | } else if (mem.eql(u8, arg, "-flto")) { | 1386 | } else if (mem.eql(u8, arg, "-flto")) { |
| 1395 | create_module.opts.lto = .full; | 1387 | create_module.opts.lto = .full; |
| 1396 | } else if (mem.startsWith(u8, arg, "-flto=")) { | 1388 | } else if (mem.cutPrefix(u8, arg, "-flto=")) |mode| { |
| 1397 | const mode = arg["-flto=".len..]; | | |
| 1398 | if (mem.eql(u8, mode, "full")) { | 1389 | if (mem.eql(u8, mode, "full")) { |
| 1399 | create_module.opts.lto = .full; | 1390 | create_module.opts.lto = .full; |
| 1400 | } else if (mem.eql(u8, mode, "thin")) { | 1391 | } else if (mem.eql(u8, mode, "thin")) { |
| ... | @@ -1428,8 +1419,7 @@ fn buildOutputType( | ... | @@ -1428,8 +1419,7 @@ fn buildOutputType( |
| 1428 | mod_opts.omit_frame_pointer = false; | 1419 | mod_opts.omit_frame_pointer = false; |
| 1429 | } else if (mem.eql(u8, arg, "-fsanitize-c")) { | 1420 | } else if (mem.eql(u8, arg, "-fsanitize-c")) { |
| 1430 | mod_opts.sanitize_c = .full; | 1421 | mod_opts.sanitize_c = .full; |
| 1431 | } else if (mem.startsWith(u8, arg, "-fsanitize-c=")) { | 1422 | } else if (mem.cutPrefix(u8, arg, "-fsanitize-c=")) |mode| { |
| 1432 | const mode = arg["-fsanitize-c=".len..]; | | |
| 1433 | if (mem.eql(u8, mode, "trap")) { | 1423 | if (mem.eql(u8, mode, "trap")) { |
| 1434 | mod_opts.sanitize_c = .trap; | 1424 | mod_opts.sanitize_c = .trap; |
| 1435 | } else if (mem.eql(u8, mode, "full")) { | 1425 | } else if (mem.eql(u8, mode, "full")) { |
| ... | @@ -1477,8 +1467,7 @@ fn buildOutputType( | ... | @@ -1477,8 +1467,7 @@ fn buildOutputType( |
| 1477 | create_module.opts.san_cov_trace_pc_guard = false; | 1467 | create_module.opts.san_cov_trace_pc_guard = false; |
| 1478 | } else if (mem.eql(u8, arg, "-freference-trace")) { | 1468 | } else if (mem.eql(u8, arg, "-freference-trace")) { |
| 1479 | reference_trace = 256; | 1469 | reference_trace = 256; |
| 1480 | } else if (mem.startsWith(u8, arg, "-freference-trace=")) { | 1470 | } else if (mem.cutPrefix(u8, arg, "-freference-trace=")) |num| { |
| 1481 | const num = arg["-freference-trace=".len..]; | | |
| 1482 | reference_trace = std.fmt.parseUnsigned(u32, num, 10) catch |err| { | 1471 | reference_trace = std.fmt.parseUnsigned(u32, num, 10) catch |err| { |
| 1483 | fatal("unable to parse reference_trace count '{s}': {s}", .{ num, @errorName(err) }); | 1472 | fatal("unable to parse reference_trace count '{s}': {s}", .{ num, @errorName(err) }); |
| 1484 | }; | 1473 | }; |
| ... | @@ -1492,51 +1481,51 @@ fn buildOutputType( | ... | @@ -1492,51 +1481,51 @@ fn buildOutputType( |
| 1492 | create_module.opts.rdynamic = true; | 1481 | create_module.opts.rdynamic = true; |
| 1493 | } else if (mem.eql(u8, arg, "-fsoname")) { | 1482 | } else if (mem.eql(u8, arg, "-fsoname")) { |
| 1494 | soname = .yes_default_value; | 1483 | soname = .yes_default_value; |
| 1495 | } else if (mem.startsWith(u8, arg, "-fsoname=")) { | 1484 | } else if (mem.cutPrefix(u8, arg, "-fsoname=")) |rest| { |
| 1496 | soname = .{ .yes = arg["-fsoname=".len..] }; | 1485 | soname = .{ .yes = rest }; |
| 1497 | } else if (mem.eql(u8, arg, "-fno-soname")) { | 1486 | } else if (mem.eql(u8, arg, "-fno-soname")) { |
| 1498 | soname = .no; | 1487 | soname = .no; |
| 1499 | } else if (mem.eql(u8, arg, "-femit-bin")) { | 1488 | } else if (mem.eql(u8, arg, "-femit-bin")) { |
| 1500 | emit_bin = .yes_default_path; | 1489 | emit_bin = .yes_default_path; |
| 1501 | } else if (mem.startsWith(u8, arg, "-femit-bin=")) { | 1490 | } else if (mem.cutPrefix(u8, arg, "-femit-bin=")) |rest| { |
| 1502 | emit_bin = .{ .yes = arg["-femit-bin=".len..] }; | 1491 | emit_bin = .{ .yes = rest }; |
| 1503 | } else if (mem.eql(u8, arg, "-fno-emit-bin")) { | 1492 | } else if (mem.eql(u8, arg, "-fno-emit-bin")) { |
| 1504 | emit_bin = .no; | 1493 | emit_bin = .no; |
| 1505 | } else if (mem.eql(u8, arg, "-femit-h")) { | 1494 | } else if (mem.eql(u8, arg, "-femit-h")) { |
| 1506 | emit_h = .yes_default_path; | 1495 | emit_h = .yes_default_path; |
| 1507 | } else if (mem.startsWith(u8, arg, "-femit-h=")) { | 1496 | } else if (mem.cutPrefix(u8, arg, "-femit-h=")) |rest| { |
| 1508 | emit_h = .{ .yes = arg["-femit-h=".len..] }; | 1497 | emit_h = .{ .yes = rest }; |
| 1509 | } else if (mem.eql(u8, arg, "-fno-emit-h")) { | 1498 | } else if (mem.eql(u8, arg, "-fno-emit-h")) { |
| 1510 | emit_h = .no; | 1499 | emit_h = .no; |
| 1511 | } else if (mem.eql(u8, arg, "-femit-asm")) { | 1500 | } else if (mem.eql(u8, arg, "-femit-asm")) { |
| 1512 | emit_asm = .yes_default_path; | 1501 | emit_asm = .yes_default_path; |
| 1513 | } else if (mem.startsWith(u8, arg, "-femit-asm=")) { | 1502 | } else if (mem.cutPrefix(u8, arg, "-femit-asm=")) |rest| { |
| 1514 | emit_asm = .{ .yes = arg["-femit-asm=".len..] }; | 1503 | emit_asm = .{ .yes = rest }; |
| 1515 | } else if (mem.eql(u8, arg, "-fno-emit-asm")) { | 1504 | } else if (mem.eql(u8, arg, "-fno-emit-asm")) { |
| 1516 | emit_asm = .no; | 1505 | emit_asm = .no; |
| 1517 | } else if (mem.eql(u8, arg, "-femit-llvm-ir")) { | 1506 | } else if (mem.eql(u8, arg, "-femit-llvm-ir")) { |
| 1518 | emit_llvm_ir = .yes_default_path; | 1507 | emit_llvm_ir = .yes_default_path; |
| 1519 | } else if (mem.startsWith(u8, arg, "-femit-llvm-ir=")) { | 1508 | } else if (mem.cutPrefix(u8, arg, "-femit-llvm-ir=")) |rest| { |
| 1520 | emit_llvm_ir = .{ .yes = arg["-femit-llvm-ir=".len..] }; | 1509 | emit_llvm_ir = .{ .yes = rest }; |
| 1521 | } else if (mem.eql(u8, arg, "-fno-emit-llvm-ir")) { | 1510 | } else if (mem.eql(u8, arg, "-fno-emit-llvm-ir")) { |
| 1522 | emit_llvm_ir = .no; | 1511 | emit_llvm_ir = .no; |
| 1523 | } else if (mem.eql(u8, arg, "-femit-llvm-bc")) { | 1512 | } else if (mem.eql(u8, arg, "-femit-llvm-bc")) { |
| 1524 | emit_llvm_bc = .yes_default_path; | 1513 | emit_llvm_bc = .yes_default_path; |
| 1525 | } else if (mem.startsWith(u8, arg, "-femit-llvm-bc=")) { | 1514 | } else if (mem.cutPrefix(u8, arg, "-femit-llvm-bc=")) |rest| { |
| 1526 | emit_llvm_bc = .{ .yes = arg["-femit-llvm-bc=".len..] }; | 1515 | emit_llvm_bc = .{ .yes = rest }; |
| 1527 | } else if (mem.eql(u8, arg, "-fno-emit-llvm-bc")) { | 1516 | } else if (mem.eql(u8, arg, "-fno-emit-llvm-bc")) { |
| 1528 | emit_llvm_bc = .no; | 1517 | emit_llvm_bc = .no; |
| 1529 | } else if (mem.eql(u8, arg, "-femit-docs")) { | 1518 | } else if (mem.eql(u8, arg, "-femit-docs")) { |
| 1530 | emit_docs = .yes_default_path; | 1519 | emit_docs = .yes_default_path; |
| 1531 | } else if (mem.startsWith(u8, arg, "-femit-docs=")) { | 1520 | } else if (mem.cutPrefix(u8, arg, "-femit-docs=")) |rest| { |
| 1532 | emit_docs = .{ .yes = arg["-femit-docs=".len..] }; | 1521 | emit_docs = .{ .yes = rest }; |
| 1533 | } else if (mem.eql(u8, arg, "-fno-emit-docs")) { | 1522 | } else if (mem.eql(u8, arg, "-fno-emit-docs")) { |
| 1534 | emit_docs = .no; | 1523 | emit_docs = .no; |
| 1535 | } else if (mem.eql(u8, arg, "-femit-implib")) { | 1524 | } else if (mem.eql(u8, arg, "-femit-implib")) { |
| 1536 | emit_implib = .yes_default_path; | 1525 | emit_implib = .yes_default_path; |
| 1537 | emit_implib_arg_provided = true; | 1526 | emit_implib_arg_provided = true; |
| 1538 | } else if (mem.startsWith(u8, arg, "-femit-implib=")) { | 1527 | } else if (mem.cutPrefix(u8, arg, "-femit-implib=")) |rest| { |
| 1539 | emit_implib = .{ .yes = arg["-femit-implib=".len..] }; | 1528 | emit_implib = .{ .yes = rest }; |
| 1540 | emit_implib_arg_provided = true; | 1529 | emit_implib_arg_provided = true; |
| 1541 | } else if (mem.eql(u8, arg, "-fno-emit-implib")) { | 1530 | } else if (mem.eql(u8, arg, "-fno-emit-implib")) { |
| 1542 | emit_implib = .no; | 1531 | emit_implib = .no; |
| ... | @@ -1586,8 +1575,7 @@ fn buildOutputType( | ... | @@ -1586,8 +1575,7 @@ fn buildOutputType( |
| 1586 | mod_opts.no_builtin = false; | 1575 | mod_opts.no_builtin = false; |
| 1587 | } else if (mem.eql(u8, arg, "-fno-builtin")) { | 1576 | } else if (mem.eql(u8, arg, "-fno-builtin")) { |
| 1588 | mod_opts.no_builtin = true; | 1577 | mod_opts.no_builtin = true; |
| 1589 | } else if (mem.startsWith(u8, arg, "-fopt-bisect-limit=")) { | 1578 | } else if (mem.cutPrefix(u8, arg, "-fopt-bisect-limit=")) |next_arg| { |
| 1590 | const next_arg = arg["-fopt-bisect-limit=".len..]; | | |
| 1591 | llvm_opt_bisect_limit = std.fmt.parseInt(c_int, next_arg, 0) catch |err| | 1579 | llvm_opt_bisect_limit = std.fmt.parseInt(c_int, next_arg, 0) catch |err| |
| 1592 | fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) }); | 1580 | fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) }); |
| 1593 | } else if (mem.eql(u8, arg, "--eh-frame-hdr")) { | 1581 | } else if (mem.eql(u8, arg, "--eh-frame-hdr")) { |
| ... | @@ -1630,10 +1618,10 @@ fn buildOutputType( | ... | @@ -1630,10 +1618,10 @@ fn buildOutputType( |
| 1630 | linker_z_relro = true; | 1618 | linker_z_relro = true; |
| 1631 | } else if (mem.eql(u8, z_arg, "norelro")) { | 1619 | } else if (mem.eql(u8, z_arg, "norelro")) { |
| 1632 | linker_z_relro = false; | 1620 | linker_z_relro = false; |
| 1633 | } else if (mem.startsWith(u8, z_arg, "common-page-size=")) { | 1621 | } else if (prefixedIntArg(z_arg, "common-page-size=")) |int| { |
| 1634 | linker_z_common_page_size = parseIntSuffix(z_arg, "common-page-size=".len); | 1622 | linker_z_common_page_size = int; |
| 1635 | } else if (mem.startsWith(u8, z_arg, "max-page-size=")) { | 1623 | } else if (prefixedIntArg(z_arg, "max-page-size=")) |int| { |
| 1636 | linker_z_max_page_size = parseIntSuffix(z_arg, "max-page-size=".len); | 1624 | linker_z_max_page_size = int; |
| 1637 | } else { | 1625 | } else { |
| 1638 | fatal("unsupported linker extension flag: -z {s}", .{z_arg}); | 1626 | fatal("unsupported linker extension flag: -z {s}", .{z_arg}); |
| 1639 | } | 1627 | } |
| ... | @@ -1654,16 +1642,16 @@ fn buildOutputType( | ... | @@ -1654,16 +1642,16 @@ fn buildOutputType( |
| 1654 | linker_import_table = true; | 1642 | linker_import_table = true; |
| 1655 | } else if (mem.eql(u8, arg, "--export-table")) { | 1643 | } else if (mem.eql(u8, arg, "--export-table")) { |
| 1656 | linker_export_table = true; | 1644 | linker_export_table = true; |
| 1657 | } else if (mem.startsWith(u8, arg, "--initial-memory=")) { | 1645 | } else if (prefixedIntArg(arg, "--initial-memory=")) |int| { |
| 1658 | linker_initial_memory = parseIntSuffix(arg, "--initial-memory=".len); | 1646 | linker_initial_memory = int; |
| 1659 | } else if (mem.startsWith(u8, arg, "--max-memory=")) { | 1647 | } else if (prefixedIntArg(arg, "--max-memory=")) |int| { |
| 1660 | linker_max_memory = parseIntSuffix(arg, "--max-memory=".len); | 1648 | linker_max_memory = int; |
| 1661 | } else if (mem.eql(u8, arg, "--shared-memory")) { | 1649 | } else if (mem.eql(u8, arg, "--shared-memory")) { |
| 1662 | create_module.opts.shared_memory = true; | 1650 | create_module.opts.shared_memory = true; |
| 1663 | } else if (mem.startsWith(u8, arg, "--global-base=")) { | 1651 | } else if (prefixedIntArg(arg, "--global-base=")) |int| { |
| 1664 | linker_global_base = parseIntSuffix(arg, "--global-base=".len); | 1652 | linker_global_base = int; |
| 1665 | } else if (mem.startsWith(u8, arg, "--export=")) { | 1653 | } else if (mem.cutPrefix(u8, arg, "--export=")) |rest| { |
| 1666 | try linker_export_symbol_names.append(arena, arg["--export=".len..]); | 1654 | try linker_export_symbol_names.append(arena, rest); |
| 1667 | } else if (mem.eql(u8, arg, "-Bsymbolic")) { | 1655 | } else if (mem.eql(u8, arg, "-Bsymbolic")) { |
| 1668 | linker_bind_global_refs_locally = true; | 1656 | linker_bind_global_refs_locally = true; |
| 1669 | } else if (mem.eql(u8, arg, "--gc-sections")) { | 1657 | } else if (mem.eql(u8, arg, "--gc-sections")) { |
| ... | @@ -1672,8 +1660,7 @@ fn buildOutputType( | ... | @@ -1672,8 +1660,7 @@ fn buildOutputType( |
| 1672 | linker_gc_sections = false; | 1660 | linker_gc_sections = false; |
| 1673 | } else if (mem.eql(u8, arg, "--build-id")) { | 1661 | } else if (mem.eql(u8, arg, "--build-id")) { |
| 1674 | build_id = .fast; | 1662 | build_id = .fast; |
| 1675 | } else if (mem.startsWith(u8, arg, "--build-id=")) { | 1663 | } else if (mem.cutPrefix(u8, arg, "--build-id=")) |style| { |
| 1676 | const style = arg["--build-id=".len..]; | | |
| 1677 | build_id = std.zig.BuildId.parse(style) catch |err| { | 1664 | build_id = std.zig.BuildId.parse(style) catch |err| { |
| 1678 | fatal("unable to parse --build-id style '{s}': {s}", .{ | 1665 | fatal("unable to parse --build-id style '{s}': {s}", .{ |
| 1679 | style, @errorName(err), | 1666 | style, @errorName(err), |
| ... | @@ -1697,26 +1684,26 @@ fn buildOutputType( | ... | @@ -1697,26 +1684,26 @@ fn buildOutputType( |
| 1697 | verbose_generic_instances = true; | 1684 | verbose_generic_instances = true; |
| 1698 | } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) { | 1685 | } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) { |
| 1699 | verbose_llvm_ir = "-"; | 1686 | verbose_llvm_ir = "-"; |
| 1700 | } else if (mem.startsWith(u8, arg, "--verbose-llvm-ir=")) { | 1687 | } else if (mem.cutPrefix(u8, arg, "--verbose-llvm-ir=")) |rest| { |
| 1701 | verbose_llvm_ir = arg["--verbose-llvm-ir=".len..]; | 1688 | verbose_llvm_ir = rest; |
| 1702 | } else if (mem.startsWith(u8, arg, "--verbose-llvm-bc=")) { | 1689 | } else if (mem.cutPrefix(u8, arg, "--verbose-llvm-bc=")) |rest| { |
| 1703 | verbose_llvm_bc = arg["--verbose-llvm-bc=".len..]; | 1690 | verbose_llvm_bc = rest; |
| 1704 | } else if (mem.eql(u8, arg, "--verbose-cimport")) { | 1691 | } else if (mem.eql(u8, arg, "--verbose-cimport")) { |
| 1705 | verbose_cimport = true; | 1692 | verbose_cimport = true; |
| 1706 | } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) { | 1693 | } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) { |
| 1707 | verbose_llvm_cpu_features = true; | 1694 | verbose_llvm_cpu_features = true; |
| 1708 | } else if (mem.startsWith(u8, arg, "-T")) { | 1695 | } else if (mem.cutPrefix(u8, arg, "-T")) |rest| { |
| 1709 | linker_script = arg[2..]; | 1696 | linker_script = rest; |
| 1710 | } else if (mem.startsWith(u8, arg, "-L")) { | 1697 | } else if (mem.cutPrefix(u8, arg, "-L")) |rest| { |
| 1711 | try create_module.lib_dir_args.append(arena, arg[2..]); | 1698 | try create_module.lib_dir_args.append(arena, rest); |
| 1712 | } else if (mem.startsWith(u8, arg, "-F")) { | 1699 | } else if (mem.cutPrefix(u8, arg, "-F")) |rest| { |
| 1713 | try create_module.framework_dirs.append(arena, arg[2..]); | 1700 | try create_module.framework_dirs.append(arena, rest); |
| 1714 | } else if (mem.startsWith(u8, arg, "-l")) { | 1701 | } else if (mem.cutPrefix(u8, arg, "-l")) |name| { |
| 1715 | // We don't know whether this library is part of libc | 1702 | // We don't know whether this library is part of libc |
| 1716 | // or libc++ until we resolve the target, so we append | 1703 | // or libc++ until we resolve the target, so we append |
| 1717 | // to the list for now. | 1704 | // to the list for now. |
| 1718 | try create_module.cli_link_inputs.append(arena, .{ .name_query = .{ | 1705 | try create_module.cli_link_inputs.append(arena, .{ .name_query = .{ |
| 1719 | .name = arg["-l".len..], | 1706 | .name = name, |
| 1720 | .query = .{ | 1707 | .query = .{ |
| 1721 | .needed = false, | 1708 | .needed = false, |
| 1722 | .weak = false, | 1709 | .weak = false, |
| ... | @@ -1725,9 +1712,9 @@ fn buildOutputType( | ... | @@ -1725,9 +1712,9 @@ fn buildOutputType( |
| 1725 | .allow_so_scripts = allow_so_scripts, | 1712 | .allow_so_scripts = allow_so_scripts, |
| 1726 | }, | 1713 | }, |
| 1727 | } }); | 1714 | } }); |
| 1728 | } else if (mem.startsWith(u8, arg, "-needed-l")) { | 1715 | } else if (mem.cutPrefix(u8, arg, "-needed-l")) |name| { |
| 1729 | try create_module.cli_link_inputs.append(arena, .{ .name_query = .{ | 1716 | try create_module.cli_link_inputs.append(arena, .{ .name_query = .{ |
| 1730 | .name = arg["-needed-l".len..], | 1717 | .name = name, |
| 1731 | .query = .{ | 1718 | .query = .{ |
| 1732 | .needed = true, | 1719 | .needed = true, |
| 1733 | .weak = false, | 1720 | .weak = false, |
| ... | @@ -1736,9 +1723,9 @@ fn buildOutputType( | ... | @@ -1736,9 +1723,9 @@ fn buildOutputType( |
| 1736 | .allow_so_scripts = allow_so_scripts, | 1723 | .allow_so_scripts = allow_so_scripts, |
| 1737 | }, | 1724 | }, |
| 1738 | } }); | 1725 | } }); |
| 1739 | } else if (mem.startsWith(u8, arg, "-weak-l")) { | 1726 | } else if (mem.cutPrefix(u8, arg, "-weak-l")) |name| { |
| 1740 | try create_module.cli_link_inputs.append(arena, .{ .name_query = .{ | 1727 | try create_module.cli_link_inputs.append(arena, .{ .name_query = .{ |
| 1741 | .name = arg["-weak-l".len..], | 1728 | .name = name, |
| 1742 | .query = .{ | 1729 | .query = .{ |
| 1743 | .needed = false, | 1730 | .needed = false, |
| 1744 | .weak = true, | 1731 | .weak = true, |
| ... | @@ -1749,13 +1736,10 @@ fn buildOutputType( | ... | @@ -1749,13 +1736,10 @@ fn buildOutputType( |
| 1749 | } }); | 1736 | } }); |
| 1750 | } else if (mem.startsWith(u8, arg, "-D")) { | 1737 | } else if (mem.startsWith(u8, arg, "-D")) { |
| 1751 | try cc_argv.append(arena, arg); | 1738 | try cc_argv.append(arena, arg); |
| 1752 | } else if (mem.startsWith(u8, arg, "-I")) { | 1739 | } else if (mem.cutPrefix(u8, arg, "-I")) |rest| { |
| 1753 | try cssan.addIncludePath(arena, &cc_argv, .I, arg, arg[2..], true); | 1740 | try cssan.addIncludePath(arena, &cc_argv, .I, arg, rest, true); |
| 1754 | } else if (mem.startsWith(u8, arg, "-x")) { | 1741 | } else if (mem.cutPrefix(u8, arg, "-x")) |rest| { |
| 1755 | const lang = if (arg.len == "-x".len) | 1742 | const lang = if (rest.len == 0) args_iter.nextOrFatal() else rest; |
| 1756 | args_iter.nextOrFatal() | | |
| 1757 | else | | |
| 1758 | arg["-x".len..]; | | |
| 1759 | if (mem.eql(u8, lang, "none")) { | 1743 | if (mem.eql(u8, lang, "none")) { |
| 1760 | file_ext = null; | 1744 | file_ext = null; |
| 1761 | } else if (Compilation.LangToExt.get(lang)) |got_ext| { | 1745 | } else if (Compilation.LangToExt.get(lang)) |got_ext| { |
| ... | @@ -1763,8 +1747,8 @@ fn buildOutputType( | ... | @@ -1763,8 +1747,8 @@ fn buildOutputType( |
| 1763 | } else { | 1747 | } else { |
| 1764 | fatal("language not recognized: '{s}'", .{lang}); | 1748 | fatal("language not recognized: '{s}'", .{lang}); |
| 1765 | } | 1749 | } |
| 1766 | } else if (mem.startsWith(u8, arg, "-mexec-model=")) { | 1750 | } else if (mem.cutPrefix(u8, arg, "-mexec-model=")) |rest| { |
| 1767 | create_module.opts.wasi_exec_model = parseWasiExecModel(arg["-mexec-model=".len..]); | 1751 | create_module.opts.wasi_exec_model = parseWasiExecModel(rest); |
| 1768 | } else if (mem.eql(u8, arg, "-municode")) { | 1752 | } else if (mem.eql(u8, arg, "-municode")) { |
| 1769 | mingw_unicode_entry_point = true; | 1753 | mingw_unicode_entry_point = true; |
| 1770 | } else { | 1754 | } else { |
| ... | @@ -2442,8 +2426,8 @@ fn buildOutputType( | ... | @@ -2442,8 +2426,8 @@ fn buildOutputType( |
| 2442 | linker_enable_new_dtags = false; | 2426 | linker_enable_new_dtags = false; |
| 2443 | } else if (mem.eql(u8, arg, "-O")) { | 2427 | } else if (mem.eql(u8, arg, "-O")) { |
| 2444 | linker_optimization = linker_args_it.nextOrFatal(); | 2428 | linker_optimization = linker_args_it.nextOrFatal(); |
| 2445 | } else if (mem.startsWith(u8, arg, "-O")) { | 2429 | } else if (mem.cutPrefix(u8, arg, "-O")) |rest| { |
| 2446 | linker_optimization = arg["-O".len..]; | 2430 | linker_optimization = rest; |
| 2447 | } else if (mem.eql(u8, arg, "-pagezero_size")) { | 2431 | } else if (mem.eql(u8, arg, "-pagezero_size")) { |
| 2448 | const next_arg = linker_args_it.nextOrFatal(); | 2432 | const next_arg = linker_args_it.nextOrFatal(); |
| 2449 | pagezero_size = std.fmt.parseUnsigned(u64, eatIntPrefix(next_arg, 16), 16) catch |err| { | 2433 | pagezero_size = std.fmt.parseUnsigned(u64, eatIntPrefix(next_arg, 16), 16) catch |err| { |
| ... | @@ -2525,11 +2509,8 @@ fn buildOutputType( | ... | @@ -2525,11 +2509,8 @@ fn buildOutputType( |
| 2525 | linker_compress_debug_sections = std.meta.stringToEnum(link.File.Lld.Elf.CompressDebugSections, arg1) orelse { | 2509 | linker_compress_debug_sections = std.meta.stringToEnum(link.File.Lld.Elf.CompressDebugSections, arg1) orelse { |
| 2526 | fatal("expected [none|zlib|zstd] after --compress-debug-sections, found '{s}'", .{arg1}); | 2510 | fatal("expected [none|zlib|zstd] after --compress-debug-sections, found '{s}'", .{arg1}); |
| 2527 | }; | 2511 | }; |
| 2528 | } else if (mem.startsWith(u8, arg, "-z")) { | 2512 | } else if (mem.cutPrefix(u8, arg, "-z")) |z_rest| { |
| 2529 | var z_arg = arg[2..]; | 2513 | const z_arg = if (z_rest.len == 0) linker_args_it.nextOrFatal() else z_rest; |
| 2530 | if (z_arg.len == 0) { | | |
| 2531 | z_arg = linker_args_it.nextOrFatal(); | | |
| 2532 | } | | |
| 2533 | if (mem.eql(u8, z_arg, "nodelete")) { | 2514 | if (mem.eql(u8, z_arg, "nodelete")) { |
| 2534 | linker_z_nodelete = true; | 2515 | linker_z_nodelete = true; |
| 2535 | } else if (mem.eql(u8, z_arg, "notext")) { | 2516 | } else if (mem.eql(u8, z_arg, "notext")) { |
| ... | @@ -2552,12 +2533,12 @@ fn buildOutputType( | ... | @@ -2552,12 +2533,12 @@ fn buildOutputType( |
| 2552 | linker_z_relro = true; | 2533 | linker_z_relro = true; |
| 2553 | } else if (mem.eql(u8, z_arg, "norelro")) { | 2534 | } else if (mem.eql(u8, z_arg, "norelro")) { |
| 2554 | linker_z_relro = false; | 2535 | linker_z_relro = false; |
| 2555 | } else if (mem.startsWith(u8, z_arg, "stack-size=")) { | 2536 | } else if (mem.cutPrefix(u8, z_arg, "stack-size=")) |rest| { |
| 2556 | stack_size = parseStackSize(z_arg["stack-size=".len..]); | 2537 | stack_size = parseStackSize(rest); |
| 2557 | } else if (mem.startsWith(u8, z_arg, "common-page-size=")) { | 2538 | } else if (prefixedIntArg(z_arg, "common-page-size=")) |int| { |
| 2558 | linker_z_common_page_size = parseIntSuffix(z_arg, "common-page-size=".len); | 2539 | linker_z_common_page_size = int; |
| 2559 | } else if (mem.startsWith(u8, z_arg, "max-page-size=")) { | 2540 | } else if (prefixedIntArg(z_arg, "max-page-size=")) |int| { |
| 2560 | linker_z_max_page_size = parseIntSuffix(z_arg, "max-page-size=".len); | 2541 | linker_z_max_page_size = int; |
| 2561 | } else { | 2542 | } else { |
| 2562 | fatal("unsupported linker extension flag: -z {s}", .{z_arg}); | 2543 | fatal("unsupported linker extension flag: -z {s}", .{z_arg}); |
| 2563 | } | 2544 | } |
| ... | @@ -2671,9 +2652,9 @@ fn buildOutputType( | ... | @@ -2671,9 +2652,9 @@ fn buildOutputType( |
| 2671 | .allow_so_scripts = allow_so_scripts, | 2652 | .allow_so_scripts = allow_so_scripts, |
| 2672 | }, | 2653 | }, |
| 2673 | } }); | 2654 | } }); |
| 2674 | } else if (mem.startsWith(u8, arg, "-weak-l")) { | 2655 | } else if (mem.cutPrefix(u8, arg, "-weak-l")) |rest| { |
| 2675 | try create_module.cli_link_inputs.append(arena, .{ .name_query = .{ | 2656 | try create_module.cli_link_inputs.append(arena, .{ .name_query = .{ |
| 2676 | .name = arg["-weak-l".len..], | 2657 | .name = rest, |
| 2677 | .query = .{ | 2658 | .query = .{ |
| 2678 | .weak = true, | 2659 | .weak = true, |
| 2679 | .needed = false, | 2660 | .needed = false, |
| ... | @@ -3768,8 +3749,7 @@ fn createModule( | ... | @@ -3768,8 +3749,7 @@ fn createModule( |
| 3768 | try mcpu_buffer.appendSlice(cli_mod.target_mcpu orelse "baseline"); | 3749 | try mcpu_buffer.appendSlice(cli_mod.target_mcpu orelse "baseline"); |
| 3769 | | 3750 | |
| 3770 | for (create_module.llvm_m_args.items) |llvm_m_arg| { | 3751 | for (create_module.llvm_m_args.items) |llvm_m_arg| { |
| 3771 | if (mem.startsWith(u8, llvm_m_arg, "mno-")) { | 3752 | if (mem.cutPrefix(u8, llvm_m_arg, "mno-")) |llvm_name| { |
| 3772 | const llvm_name = llvm_m_arg["mno-".len..]; | | |
| 3773 | const zig_name = llvm_to_zig_name.get(llvm_name) orelse { | 3753 | const zig_name = llvm_to_zig_name.get(llvm_name) orelse { |
| 3774 | fatal("target architecture {s} has no LLVM CPU feature named '{s}'", .{ | 3754 | fatal("target architecture {s} has no LLVM CPU feature named '{s}'", .{ |
| 3775 | @tagName(cpu_arch), llvm_name, | 3755 | @tagName(cpu_arch), llvm_name, |
| ... | @@ -3777,8 +3757,7 @@ fn createModule( | ... | @@ -3777,8 +3757,7 @@ fn createModule( |
| 3777 | }; | 3757 | }; |
| 3778 | try mcpu_buffer.append('-'); | 3758 | try mcpu_buffer.append('-'); |
| 3779 | try mcpu_buffer.appendSlice(zig_name); | 3759 | try mcpu_buffer.appendSlice(zig_name); |
| 3780 | } else if (mem.startsWith(u8, llvm_m_arg, "m")) { | 3760 | } else if (mem.cutPrefix(u8, llvm_m_arg, "m")) |llvm_name| { |
| 3781 | const llvm_name = llvm_m_arg["m".len..]; | | |
| 3782 | const zig_name = llvm_to_zig_name.get(llvm_name) orelse { | 3761 | const zig_name = llvm_to_zig_name.get(llvm_name) orelse { |
| 3783 | fatal("target architecture {s} has no LLVM CPU feature named '{s}'", .{ | 3762 | fatal("target architecture {s} has no LLVM CPU feature named '{s}'", .{ |
| 3784 | @tagName(cpu_arch), llvm_name, | 3763 | @tagName(cpu_arch), llvm_name, |
| ... | @@ -4850,9 +4829,8 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | ... | @@ -4850,9 +4829,8 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4850 | reference_trace = 256; | 4829 | reference_trace = 256; |
| 4851 | } else if (mem.eql(u8, arg, "--fetch")) { | 4830 | } else if (mem.eql(u8, arg, "--fetch")) { |
| 4852 | fetch_only = true; | 4831 | fetch_only = true; |
| 4853 | } else if (mem.startsWith(u8, arg, "--fetch=")) { | 4832 | } else if (mem.cutPrefix(u8, arg, "--fetch=")) |sub_arg| { |
| 4854 | fetch_only = true; | 4833 | fetch_only = true; |
| 4855 | const sub_arg = arg["--fetch=".len..]; | | |
| 4856 | fetch_mode = std.meta.stringToEnum(Package.Fetch.JobQueue.Mode, sub_arg) orelse | 4834 | fetch_mode = std.meta.stringToEnum(Package.Fetch.JobQueue.Mode, sub_arg) orelse |
| 4857 | fatal("expected [needed|all] after '--fetch=', found '{s}'", .{ | 4835 | fatal("expected [needed|all] after '--fetch=', found '{s}'", .{ |
| 4858 | sub_arg, | 4836 | sub_arg, |
| ... | @@ -4863,8 +4841,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | ... | @@ -4863,8 +4841,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4863 | system_pkg_dir_path = args[i]; | 4841 | system_pkg_dir_path = args[i]; |
| 4864 | try child_argv.append("--system"); | 4842 | try child_argv.append("--system"); |
| 4865 | continue; | 4843 | continue; |
| 4866 | } else if (mem.startsWith(u8, arg, "-freference-trace=")) { | 4844 | } else if (mem.cutPrefix(u8, arg, "-freference-trace=")) |num| { |
| 4867 | const num = arg["-freference-trace=".len..]; | | |
| 4868 | reference_trace = std.fmt.parseUnsigned(u32, num, 10) catch |err| { | 4845 | reference_trace = std.fmt.parseUnsigned(u32, num, 10) catch |err| { |
| 4869 | fatal("unable to parse reference_trace count '{s}': {s}", .{ num, @errorName(err) }); | 4846 | fatal("unable to parse reference_trace count '{s}': {s}", .{ num, @errorName(err) }); |
| 4870 | }; | 4847 | }; |
| ... | @@ -4914,10 +4891,10 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | ... | @@ -4914,10 +4891,10 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4914 | verbose_generic_instances = true; | 4891 | verbose_generic_instances = true; |
| 4915 | } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) { | 4892 | } else if (mem.eql(u8, arg, "--verbose-llvm-ir")) { |
| 4916 | verbose_llvm_ir = "-"; | 4893 | verbose_llvm_ir = "-"; |
| 4917 | } else if (mem.startsWith(u8, arg, "--verbose-llvm-ir=")) { | 4894 | } else if (mem.cutPrefix(u8, arg, "--verbose-llvm-ir=")) |rest| { |
| 4918 | verbose_llvm_ir = arg["--verbose-llvm-ir=".len..]; | 4895 | verbose_llvm_ir = rest; |
| 4919 | } else if (mem.startsWith(u8, arg, "--verbose-llvm-bc=")) { | 4896 | } else if (mem.cutPrefix(u8, arg, "--verbose-llvm-bc=")) |rest| { |
| 4920 | verbose_llvm_bc = arg["--verbose-llvm-bc=".len..]; | 4897 | verbose_llvm_bc = rest; |
| 4921 | } else if (mem.eql(u8, arg, "--verbose-cimport")) { | 4898 | } else if (mem.eql(u8, arg, "--verbose-cimport")) { |
| 4922 | verbose_cimport = true; | 4899 | verbose_cimport = true; |
| 4923 | } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) { | 4900 | } else if (mem.eql(u8, arg, "--verbose-llvm-cpu-features")) { |
| ... | @@ -4930,8 +4907,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { | ... | @@ -4930,8 +4907,7 @@ fn cmdBuild(gpa: Allocator, arena: Allocator, args: []const []const u8) !void { |
| 4930 | }; | 4907 | }; |
| 4931 | try child_argv.appendSlice(&.{ arg, args[i] }); | 4908 | try child_argv.appendSlice(&.{ arg, args[i] }); |
| 4932 | continue; | 4909 | continue; |
| 4933 | } else if (mem.startsWith(u8, arg, "-j")) { | 4910 | } else if (mem.cutPrefix(u8, arg, "-j")) |str| { |
| 4934 | const str = arg["-j".len..]; | | |
| 4935 | const num = std.fmt.parseUnsigned(u32, str, 10) catch |err| { | 4911 | const num = std.fmt.parseUnsigned(u32, str, 10) catch |err| { |
| 4936 | fatal("unable to parse jobs count '{s}': {s}", .{ | 4912 | fatal("unable to parse jobs count '{s}': {s}", .{ |
| 4937 | str, @errorName(err), | 4913 | str, @errorName(err), |
| ... | @@ -6507,10 +6483,9 @@ fn eatIntPrefix(arg: []const u8, base: u8) []const u8 { | ... | @@ -6507,10 +6483,9 @@ fn eatIntPrefix(arg: []const u8, base: u8) []const u8 { |
| 6507 | return arg; | 6483 | return arg; |
| 6508 | } | 6484 | } |
| 6509 | | 6485 | |
| 6510 | fn parseIntSuffix(arg: []const u8, prefix_len: usize) u64 { | 6486 | fn prefixedIntArg(arg: []const u8, prefix: []const u8) ?u64 { |
| 6511 | return std.fmt.parseUnsigned(u64, arg[prefix_len..], 0) catch |err| { | 6487 | const number = mem.cutPrefix(u8, arg, prefix) orelse return null; |
| 6512 | fatal("unable to parse '{s}': {s}", .{ arg, @errorName(err) }); | 6488 | return std.fmt.parseUnsigned(u64, number, 0) catch |err| fatal("unable to parse '{s}': {t}", .{ arg, err }); |
| 6513 | }; | | |
| 6514 | } | 6489 | } |
| 6515 | | 6490 | |
| 6516 | fn warnAboutForeignBinaries( | 6491 | fn warnAboutForeignBinaries( |
| ... | @@ -6837,12 +6812,12 @@ fn cmdFetch( | ... | @@ -6837,12 +6812,12 @@ fn cmdFetch( |
| 6837 | debug_hash = true; | 6812 | debug_hash = true; |
| 6838 | } else if (mem.eql(u8, arg, "--save")) { | 6813 | } else if (mem.eql(u8, arg, "--save")) { |
| 6839 | save = .{ .yes = null }; | 6814 | save = .{ .yes = null }; |
| 6840 | } else if (mem.startsWith(u8, arg, "--save=")) { | 6815 | } else if (mem.cutPrefix(u8, arg, "--save=")) |rest| { |
| 6841 | save = .{ .yes = arg["--save=".len..] }; | 6816 | save = .{ .yes = rest }; |
| 6842 | } else if (mem.eql(u8, arg, "--save-exact")) { | 6817 | } else if (mem.eql(u8, arg, "--save-exact")) { |
| 6843 | save = .{ .exact = null }; | 6818 | save = .{ .exact = null }; |
| 6844 | } else if (mem.startsWith(u8, arg, "--save-exact=")) { | 6819 | } else if (mem.cutPrefix(u8, arg, "--save-exact=")) |rest| { |
| 6845 | save = .{ .exact = arg["--save-exact=".len..] }; | 6820 | save = .{ .exact = rest }; |
| 6846 | } else { | 6821 | } else { |
| 6847 | fatal("unrecognized parameter: '{s}'", .{arg}); | 6822 | fatal("unrecognized parameter: '{s}'", .{arg}); |
| 6848 | } | 6823 | } |