authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-13 16:20:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-05-25 18:54:34-07:00
logb998d71e939c304ba76860077b4483249f670b7d
tree40226d9ce61a12add63d718f256caebc4c01a6f9
parentc60d33f167494afea808dc0ac9c476422efe22c0

maker: finish lowering compile step CLI args


1 files changed, 16 insertions(+), 12 deletions(-)

lib/compiler/Maker/Step/Compile.zig+16-12
......@@ -481,18 +481,21 @@ fn lowerZigArgs(
481481 const module_index = cli_named_modules.modules.keys()[module_cli_index];
482482 try appendModuleFlags(module_index, zig_args, compile_index, maker);
483483
484 if (true) @panic("TODO");
484 const imports = mod.import_table.get(conf).imports.mal;
485485
486486 // --dep arguments
487 try zig_args.ensureUnusedCapacity(gpa, mod.import_table.count() * 2);
488 for (mod.import_table.keys(), mod.import_table.values()) |name, import| {
487 try zig_args.ensureUnusedCapacity(gpa, imports.len * 2);
488 for (imports.items(.name), imports.items(.module)) |name, import| {
489489 const import_index = cli_named_modules.modules.getIndex(import).?;
490490 const import_cli_name = cli_named_modules.names.keys()[import_index];
491491 zig_args.appendAssumeCapacity("--dep");
492 if (std.mem.eql(u8, import_cli_name, name)) {
492 const name_slice = name.slice(conf);
493 if (std.mem.eql(u8, import_cli_name, name_slice)) {
493494 zig_args.appendAssumeCapacity(import_cli_name);
494495 } else {
495 zig_args.appendAssumeCapacity(try allocPrint(arena, "{s}={s}", .{ name, import_cli_name }));
496 zig_args.appendAssumeCapacity(try allocPrint(arena, "{s}={s}", .{
497 name_slice, import_cli_name,
498 }));
496499 }
497500 }
498501
......@@ -503,11 +506,12 @@ fn lowerZigArgs(
503506 // perhaps a set of linker objects, or C source files instead.
504507 // Linker objects are added to the CLI globally, while C source
505508 // files must have a module parent.
506 if (mod.root_source_file) |lp| {
507 const src = lp.getPath2(mod.owner, step);
508 try zig_args.append(gpa, try allocPrint(arena, "-M{s}={s}", .{ module_cli_name, src }));
509 } else if (moduleNeedsCliArg(mod)) {
510 try zig_args.append(gpa, try allocPrint(arena, "-M{s}", .{module_cli_name}));
509 try zig_args.ensureUnusedCapacity(gpa, 1);
510 if (mod.root_source_file.unwrap()) |lp| {
511 const src = try maker.resolveLazyPathIndexAbs(arena, lp, compile_index);
512 zig_args.appendAssumeCapacity(try allocPrint(arena, "-M{s}={s}", .{ module_cli_name, src }));
513 } else if (moduleNeedsCliArg(&mod, conf)) {
514 zig_args.appendAssumeCapacity(try allocPrint(arena, "-M{s}", .{module_cli_name}));
511515 }
512516 }
513517 }
......@@ -1262,8 +1266,8 @@ fn matchCompileError(actual: []const u8, expected: []const u8) bool {
12621266 return false;
12631267}
12641268
1265fn moduleNeedsCliArg(mod: *const Module) bool {
1266 return for (mod.link_objects.items) |o| switch (o) {
1269fn moduleNeedsCliArg(mod: *const Configuration.Module, conf: *const Configuration) bool {
1270 return for (0..mod.link_objects.len) |i| switch (mod.link_objects.tag(conf.extra, i)) {
12671271 .c_source_file, .c_source_files, .assembly_file, .win32_resource_file => break true,
12681272 else => continue,
12691273 } else false;