| ... | ... | @@ -2515,21 +2515,48 @@ fn buildOutputType( |
| 2515 | 2515 | // Without this, there will be no main module created and no zig |
| 2516 | 2516 | // compilation unit, and therefore also no builtin.zig contents |
| 2517 | 2517 | // created. |
| 2518 | | root_src_file = "dummy.zig"; |
| 2518 | root_src_file = "builtin.zig"; |
| 2519 | 2519 | } |
| 2520 | 2520 | |
| 2521 | | if (root_src_file) |unresolved_src_path| { |
| 2522 | | if (create_module.modules.count() != 0) { |
| 2523 | | fatal("main module provided both by '--mod {s} {}{s}' and by positional argument '{s}'", .{ |
| 2524 | | create_module.modules.keys()[0], |
| 2525 | | create_module.modules.values()[0].paths.root, |
| 2526 | | create_module.modules.values()[0].paths.root_src_path, |
| 2527 | | unresolved_src_path, |
| 2528 | | }); |
| 2529 | | } |
| 2521 | implicit_root_mod: { |
| 2522 | const unresolved_src_path = b: { |
| 2523 | if (root_src_file) |src_path| { |
| 2524 | if (create_module.modules.count() != 0) { |
| 2525 | fatal("main module provided both by '--mod {s} {}{s}' and by positional argument '{s}'", .{ |
| 2526 | create_module.modules.keys()[0], |
| 2527 | create_module.modules.values()[0].paths.root, |
| 2528 | create_module.modules.values()[0].paths.root_src_path, |
| 2529 | src_path, |
| 2530 | }); |
| 2531 | } |
| 2532 | create_module.opts.have_zcu = true; |
| 2533 | break :b src_path; |
| 2534 | } |
| 2535 | |
| 2536 | if (create_module.modules.count() != 0) |
| 2537 | break :implicit_root_mod; |
| 2538 | |
| 2539 | if (create_module.c_source_files.items.len >= 1) |
| 2540 | break :b create_module.c_source_files.items[0].src_path; |
| 2541 | |
| 2542 | if (link_objects.items.len >= 1) |
| 2543 | break :b link_objects.items[0].path; |
| 2544 | |
| 2545 | if (emit_bin == .yes) |
| 2546 | break :b emit_bin.yes; |
| 2547 | |
| 2548 | if (create_module.rc_source_files.items.len >= 1) |
| 2549 | break :b create_module.rc_source_files.items[0].src_path; |
| 2550 | |
| 2551 | if (arg_mode == .run) |
| 2552 | fatal("`zig run` expects at least one positional argument", .{}); |
| 2553 | |
| 2554 | fatal("expected a positional argument, -femit-bin=[path], --show-builtin, or --name [name]", .{}); |
| 2555 | |
| 2556 | break :implicit_root_mod; |
| 2557 | }; |
| 2530 | 2558 | |
| 2531 | 2559 | // See duplicate logic: ModCreationGlobalFlags |
| 2532 | | create_module.opts.have_zcu = true; |
| 2533 | 2560 | if (mod_opts.single_threaded == false) |
| 2534 | 2561 | create_module.opts.any_non_single_threaded = true; |
| 2535 | 2562 | if (mod_opts.sanitize_thread == true) |
| ... | ... | @@ -2542,7 +2569,12 @@ fn buildOutputType( |
| 2542 | 2569 | create_module.opts.any_error_tracing = true; |
| 2543 | 2570 | |
| 2544 | 2571 | const src_path = try introspect.resolvePath(arena, unresolved_src_path); |
| 2545 | | try create_module.modules.put(arena, "main", .{ |
| 2572 | const name = if (arg_mode == .zig_test) |
| 2573 | "test" |
| 2574 | else |
| 2575 | fs.path.stem(fs.path.basename(src_path)); |
| 2576 | |
| 2577 | try create_module.modules.put(arena, name, .{ |
| 2546 | 2578 | .paths = .{ |
| 2547 | 2579 | .root = .{ |
| 2548 | 2580 | .root_dir = Cache.Directory.cwd(), |
| ... | ... | @@ -2718,35 +2750,7 @@ fn buildOutputType( |
| 2718 | 2750 | } |
| 2719 | 2751 | } |
| 2720 | 2752 | |
| 2721 | | const root_name = if (provided_name) |n| n else blk: { |
| 2722 | | if (arg_mode == .zig_test) { |
| 2723 | | break :blk "test"; |
| 2724 | | } else if (root_src_file) |file| { |
| 2725 | | const basename = fs.path.basename(file); |
| 2726 | | break :blk basename[0 .. basename.len - fs.path.extension(basename).len]; |
| 2727 | | } else if (create_module.c_source_files.items.len >= 1) { |
| 2728 | | const basename = fs.path.basename(create_module.c_source_files.items[0].src_path); |
| 2729 | | break :blk basename[0 .. basename.len - fs.path.extension(basename).len]; |
| 2730 | | } else if (link_objects.items.len >= 1) { |
| 2731 | | const basename = fs.path.basename(link_objects.items[0].path); |
| 2732 | | break :blk basename[0 .. basename.len - fs.path.extension(basename).len]; |
| 2733 | | } else if (emit_bin == .yes) { |
| 2734 | | const basename = fs.path.basename(emit_bin.yes); |
| 2735 | | break :blk basename[0 .. basename.len - fs.path.extension(basename).len]; |
| 2736 | | } else if (create_module.rc_source_files.items.len >= 1) { |
| 2737 | | const basename = fs.path.basename(create_module.rc_source_files.items[0].src_path); |
| 2738 | | break :blk basename[0 .. basename.len - fs.path.extension(basename).len]; |
| 2739 | | } else if (show_builtin) { |
| 2740 | | break :blk "builtin"; |
| 2741 | | } else if (arg_mode == .run) { |
| 2742 | | fatal("`zig run` expects at least one positional argument", .{}); |
| 2743 | | // TODO once the attempt to unwrap error: LinkingWithoutZigSourceUnimplemented |
| 2744 | | // is solved, remove the above fatal() and uncomment the `break` below. |
| 2745 | | //break :blk "run"; |
| 2746 | | } else { |
| 2747 | | fatal("expected a positional argument, -femit-bin=[path], --show-builtin, or --name [name]", .{}); |
| 2748 | | } |
| 2749 | | }; |
| 2753 | const root_name = if (provided_name) |n| n else main_mod.fully_qualified_name; |
| 2750 | 2754 | |
| 2751 | 2755 | // Resolve the library path arguments with respect to sysroot. |
| 2752 | 2756 | var lib_dirs: std.ArrayListUnmanaged([]const u8) = .{}; |