authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-18 18:17:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 17:51:20-07:00
log4b667e736201d9fbe2e440863ce1e631a2d3b4e7
treeec54cabd14be4a9767077ff044485a0bba51d375
parentfe87bae7e39657c96015aa7f3c7a35a0b01da1ad

fix compilations without zig compilation units


2 files changed, 46 insertions(+), 42 deletions(-)

src/Compilation.zig+1-1
......@@ -1180,7 +1180,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
11801180 return error.ExportTableAndImportTableConflict;
11811181 }
11821182
1183 const have_zcu = options.root_mod.root_src_path.len != 0;
1183 const have_zcu = options.config.have_zcu;
11841184
11851185 const comp: *Compilation = comp: {
11861186 // For allocations that have the same lifetime as Compilation. This
src/main.zig+45-41
......@@ -2515,21 +2515,48 @@ fn buildOutputType(
25152515 // Without this, there will be no main module created and no zig
25162516 // compilation unit, and therefore also no builtin.zig contents
25172517 // created.
2518 root_src_file = "dummy.zig";
2518 root_src_file = "builtin.zig";
25192519 }
25202520
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 };
25302558
25312559 // See duplicate logic: ModCreationGlobalFlags
2532 create_module.opts.have_zcu = true;
25332560 if (mod_opts.single_threaded == false)
25342561 create_module.opts.any_non_single_threaded = true;
25352562 if (mod_opts.sanitize_thread == true)
......@@ -2542,7 +2569,12 @@ fn buildOutputType(
25422569 create_module.opts.any_error_tracing = true;
25432570
25442571 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, .{
25462578 .paths = .{
25472579 .root = .{
25482580 .root_dir = Cache.Directory.cwd(),
......@@ -2718,35 +2750,7 @@ fn buildOutputType(
27182750 }
27192751 }
27202752
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;
27502754
27512755 // Resolve the library path arguments with respect to sysroot.
27522756 var lib_dirs: std.ArrayListUnmanaged([]const u8) = .{};