| ... | ... | @@ -1220,15 +1220,18 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { |
| 1220 | 1220 | } |
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | | // The CLI assumes if it sees a --mod argument that it is a zig |
| 1224 | | // compilation unit. If there is no root source file, then this |
| 1225 | | // is not a zig compilation unit - it is perhaps a set of |
| 1226 | | // linker objects, or C source files instead. |
| 1227 | | // In such case, there will be only one module, so we can leave |
| 1228 | | // off the naming here. |
| 1223 | // When the CLI sees a -M argument, it determines whether it |
| 1224 | // implies the existence of a Zig compilation unit based on |
| 1225 | // whether there is a root source file. If there is no root |
| 1226 | // source file, then this is not a zig compilation unit - it is |
| 1227 | // perhaps a set of linker objects, or C source files instead. |
| 1228 | // Linker objects are added to the CLI globally, while C source |
| 1229 | // files must have a module parent. |
| 1229 | 1230 | if (module.root_source_file) |lp| { |
| 1230 | 1231 | const src = lp.getPath2(module.owner, step); |
| 1231 | | try zig_args.appendSlice(&.{ "--mod", module_cli_name, src }); |
| 1232 | try zig_args.append(b.fmt("-M{s}={s}", .{ module_cli_name, src })); |
| 1233 | } else if (moduleNeedsCliArg(module)) { |
| 1234 | try zig_args.append(b.fmt("-M{s}", .{module_cli_name})); |
| 1232 | 1235 | } |
| 1233 | 1236 | } |
| 1234 | 1237 | } |
| ... | ... | @@ -1850,3 +1853,10 @@ pub fn rootModuleTarget(c: *Compile) std.Target { |
| 1850 | 1853 | // The root module is always given a target, so we know this to be non-null. |
| 1851 | 1854 | return c.root_module.resolved_target.?.result; |
| 1852 | 1855 | } |
| 1856 | |
| 1857 | fn moduleNeedsCliArg(mod: *const Module) bool { |
| 1858 | return for (mod.link_objects.items) |o| switch (o) { |
| 1859 | .c_source_file, .c_source_files, .assembly_file, .win32_resource_file => break true, |
| 1860 | else => continue, |
| 1861 | } else false; |
| 1862 | } |