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