| ... | ... | @@ -389,7 +389,7 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 389 | 389 | |
| 390 | 390 | const compile = owner.allocator.create(Compile) catch @panic("OOM"); |
| 391 | 391 | compile.* = .{ |
| 392 | | .root_module = undefined, |
| 392 | .root_module = options.root_module, |
| 393 | 393 | .verbose_link = false, |
| 394 | 394 | .verbose_cc = false, |
| 395 | 395 | .linkage = options.linkage, |
| ... | ... | @@ -432,8 +432,6 @@ pub fn create(owner: *std.Build, options: Options) *Compile { |
| 432 | 432 | |
| 433 | 433 | .zig_process = null, |
| 434 | 434 | }; |
| 435 | | options.root_module.init(owner, .{ .existing = options.root_module }, compile); |
| 436 | | compile.root_module = options.root_module; |
| 437 | 435 | |
| 438 | 436 | if (options.zig_lib_dir) |lp| { |
| 439 | 437 | compile.zig_lib_dir = lp.dupe(compile.step.owner); |
| ... | ... | @@ -607,16 +605,17 @@ pub fn dependsOnSystemLibrary(compile: *const Compile, name: []const u8) bool { |
| 607 | 605 | var is_linking_libc = false; |
| 608 | 606 | var is_linking_libcpp = false; |
| 609 | 607 | |
| 610 | | var dep_it = compile.root_module.iterateDependencies(compile, true); |
| 611 | | while (dep_it.next()) |module| { |
| 612 | | for (module.link_objects.items) |link_object| { |
| 613 | | switch (link_object) { |
| 614 | | .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, |
| 615 | | else => continue, |
| 608 | for (compile.getCompileDependencies(true)) |some_compile| { |
| 609 | for (some_compile.root_module.getGraph().modules) |mod| { |
| 610 | for (mod.link_objects.items) |lo| { |
| 611 | switch (lo) { |
| 612 | .system_lib => |lib| if (mem.eql(u8, lib.name, name)) return true, |
| 613 | else => {}, |
| 614 | } |
| 616 | 615 | } |
| 616 | if (mod.link_libc) is_linking_libc = true; |
| 617 | if (mod.link_libcpp) is_linking_libcpp = true; |
| 617 | 618 | } |
| 618 | | is_linking_libc = is_linking_libc or module.link_libc == true; |
| 619 | | is_linking_libcpp = is_linking_libcpp or module.link_libcpp == true; |
| 620 | 619 | } |
| 621 | 620 | |
| 622 | 621 | const target = compile.rootModuleTarget(); |
| ... | ... | @@ -961,23 +960,22 @@ const CliNamedModules = struct { |
| 961 | 960 | .modules = .{}, |
| 962 | 961 | .names = .{}, |
| 963 | 962 | }; |
| 964 | | var dep_it = root_module.iterateDependencies(null, false); |
| 963 | const graph = root_module.getGraph(); |
| 965 | 964 | { |
| 966 | | const item = dep_it.next().?; |
| 967 | | assert(root_module == item.module); |
| 965 | assert(graph.modules[0] == root_module); |
| 968 | 966 | try compile.modules.put(arena, root_module, {}); |
| 969 | 967 | try compile.names.put(arena, "root", {}); |
| 970 | 968 | } |
| 971 | | while (dep_it.next()) |item| { |
| 972 | | var name = item.name; |
| 969 | for (graph.modules[1..], graph.names[1..]) |mod, orig_name| { |
| 970 | var name = orig_name; |
| 973 | 971 | var n: usize = 0; |
| 974 | 972 | while (true) { |
| 975 | 973 | const gop = try compile.names.getOrPut(arena, name); |
| 976 | 974 | if (!gop.found_existing) { |
| 977 | | try compile.modules.putNoClobber(arena, item.module, {}); |
| 975 | try compile.modules.putNoClobber(arena, mod, {}); |
| 978 | 976 | break; |
| 979 | 977 | } |
| 980 | | name = try std.fmt.allocPrint(arena, "{s}{d}", .{ item.name, n }); |
| 978 | name = try std.fmt.allocPrint(arena, "{s}{d}", .{ orig_name, n }); |
| 981 | 979 | n += 1; |
| 982 | 980 | } |
| 983 | 981 | } |
| ... | ... | @@ -1080,13 +1078,12 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 { |
| 1080 | 1078 | // emitted if there is nothing to link. |
| 1081 | 1079 | var total_linker_objects: usize = @intFromBool(compile.root_module.root_source_file != null); |
| 1082 | 1080 | |
| 1083 | | { |
| 1084 | | // Fully recursive iteration including dynamic libraries to detect |
| 1085 | | // libc and libc++ linkage. |
| 1086 | | var dep_it = compile.root_module.iterateDependencies(compile, true); |
| 1087 | | while (dep_it.next()) |key| { |
| 1088 | | if (key.module.link_libc == true) compile.is_linking_libc = true; |
| 1089 | | if (key.module.link_libcpp == true) compile.is_linking_libcpp = true; |
| 1081 | // Fully recursive iteration including dynamic libraries to detect |
| 1082 | // libc and libc++ linkage. |
| 1083 | for (compile.getCompileDependencies(true)) |some_compile| { |
| 1084 | for (some_compile.root_module.getGraph().modules) |mod| { |
| 1085 | if (mod.link_libc == true) compile.is_linking_libc = true; |
| 1086 | if (mod.link_libcpp == true) compile.is_linking_libcpp = true; |
| 1090 | 1087 | } |
| 1091 | 1088 | } |
| 1092 | 1089 | |
| ... | ... | @@ -1094,265 +1091,265 @@ fn getZigArgs(compile: *Compile, fuzz: bool) ![][]const u8 { |
| 1094 | 1091 | |
| 1095 | 1092 | // For this loop, don't chase dynamic libraries because their link |
| 1096 | 1093 | // objects are already linked. |
| 1097 | | var dep_it = compile.root_module.iterateDependencies(compile, false); |
| 1098 | | |
| 1099 | | while (dep_it.next()) |dep| { |
| 1100 | | // While walking transitive dependencies, if a given link object is |
| 1101 | | // already included in a library, it should not redundantly be |
| 1102 | | // placed on the linker line of the dependee. |
| 1103 | | const my_responsibility = dep.compile.? == compile; |
| 1104 | | const already_linked = !my_responsibility and dep.compile.?.isDynamicLibrary(); |
| 1105 | | |
| 1106 | | // Inherit dependencies on darwin frameworks. |
| 1107 | | if (!already_linked) { |
| 1108 | | for (dep.module.frameworks.keys(), dep.module.frameworks.values()) |name, info| { |
| 1109 | | try frameworks.put(arena, name, info); |
| 1094 | for (compile.getCompileDependencies(false)) |dep_compile| { |
| 1095 | for (dep_compile.root_module.getGraph().modules) |mod| { |
| 1096 | // While walking transitive dependencies, if a given link object is |
| 1097 | // already included in a library, it should not redundantly be |
| 1098 | // placed on the linker line of the dependee. |
| 1099 | const my_responsibility = dep_compile == compile; |
| 1100 | const already_linked = !my_responsibility and dep_compile.isDynamicLibrary(); |
| 1101 | |
| 1102 | // Inherit dependencies on darwin frameworks. |
| 1103 | if (!already_linked) { |
| 1104 | for (mod.frameworks.keys(), mod.frameworks.values()) |name, info| { |
| 1105 | try frameworks.put(arena, name, info); |
| 1106 | } |
| 1110 | 1107 | } |
| 1111 | | } |
| 1112 | | |
| 1113 | | // Inherit dependencies on system libraries and static libraries. |
| 1114 | | for (dep.module.link_objects.items) |link_object| { |
| 1115 | | switch (link_object) { |
| 1116 | | .static_path => |static_path| { |
| 1117 | | if (my_responsibility) { |
| 1118 | | try zig_args.append(static_path.getPath2(dep.module.owner, step)); |
| 1119 | | total_linker_objects += 1; |
| 1120 | | } |
| 1121 | | }, |
| 1122 | | .system_lib => |system_lib| { |
| 1123 | | const system_lib_gop = try seen_system_libs.getOrPut(arena, system_lib.name); |
| 1124 | | if (system_lib_gop.found_existing) { |
| 1125 | | try zig_args.appendSlice(system_lib_gop.value_ptr.*); |
| 1126 | | continue; |
| 1127 | | } else { |
| 1128 | | system_lib_gop.value_ptr.* = &.{}; |
| 1129 | | } |
| 1130 | 1108 | |
| 1131 | | if (already_linked) |
| 1132 | | continue; |
| 1133 | | |
| 1134 | | if ((system_lib.search_strategy != prev_search_strategy or |
| 1135 | | system_lib.preferred_link_mode != prev_preferred_link_mode) and |
| 1136 | | compile.linkage != .static) |
| 1137 | | { |
| 1138 | | switch (system_lib.search_strategy) { |
| 1139 | | .no_fallback => switch (system_lib.preferred_link_mode) { |
| 1140 | | .dynamic => try zig_args.append("-search_dylibs_only"), |
| 1141 | | .static => try zig_args.append("-search_static_only"), |
| 1142 | | }, |
| 1143 | | .paths_first => switch (system_lib.preferred_link_mode) { |
| 1144 | | .dynamic => try zig_args.append("-search_paths_first"), |
| 1145 | | .static => try zig_args.append("-search_paths_first_static"), |
| 1146 | | }, |
| 1147 | | .mode_first => switch (system_lib.preferred_link_mode) { |
| 1148 | | .dynamic => try zig_args.append("-search_dylibs_first"), |
| 1149 | | .static => try zig_args.append("-search_static_first"), |
| 1150 | | }, |
| 1109 | // Inherit dependencies on system libraries and static libraries. |
| 1110 | for (mod.link_objects.items) |link_object| { |
| 1111 | switch (link_object) { |
| 1112 | .static_path => |static_path| { |
| 1113 | if (my_responsibility) { |
| 1114 | try zig_args.append(static_path.getPath2(mod.owner, step)); |
| 1115 | total_linker_objects += 1; |
| 1116 | } |
| 1117 | }, |
| 1118 | .system_lib => |system_lib| { |
| 1119 | const system_lib_gop = try seen_system_libs.getOrPut(arena, system_lib.name); |
| 1120 | if (system_lib_gop.found_existing) { |
| 1121 | try zig_args.appendSlice(system_lib_gop.value_ptr.*); |
| 1122 | continue; |
| 1123 | } else { |
| 1124 | system_lib_gop.value_ptr.* = &.{}; |
| 1151 | 1125 | } |
| 1152 | | prev_search_strategy = system_lib.search_strategy; |
| 1153 | | prev_preferred_link_mode = system_lib.preferred_link_mode; |
| 1154 | | } |
| 1155 | 1126 | |
| 1156 | | const prefix: []const u8 = prefix: { |
| 1157 | | if (system_lib.needed) break :prefix "-needed-l"; |
| 1158 | | if (system_lib.weak) break :prefix "-weak-l"; |
| 1159 | | break :prefix "-l"; |
| 1160 | | }; |
| 1161 | | switch (system_lib.use_pkg_config) { |
| 1162 | | .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), |
| 1163 | | .yes, .force => { |
| 1164 | | if (compile.runPkgConfig(system_lib.name)) |result| { |
| 1165 | | try zig_args.appendSlice(result.cflags); |
| 1166 | | try zig_args.appendSlice(result.libs); |
| 1167 | | try seen_system_libs.put(arena, system_lib.name, result.cflags); |
| 1168 | | } else |err| switch (err) { |
| 1169 | | error.PkgConfigInvalidOutput, |
| 1170 | | error.PkgConfigCrashed, |
| 1171 | | error.PkgConfigFailed, |
| 1172 | | error.PkgConfigNotInstalled, |
| 1173 | | error.PackageNotFound, |
| 1174 | | => switch (system_lib.use_pkg_config) { |
| 1175 | | .yes => { |
| 1176 | | // pkg-config failed, so fall back to linking the library |
| 1177 | | // by name directly. |
| 1178 | | try zig_args.append(b.fmt("{s}{s}", .{ |
| 1179 | | prefix, |
| 1180 | | system_lib.name, |
| 1181 | | })); |
| 1182 | | }, |
| 1183 | | .force => { |
| 1184 | | panic("pkg-config failed for library {s}", .{system_lib.name}); |
| 1185 | | }, |
| 1186 | | .no => unreachable, |
| 1127 | if (already_linked) |
| 1128 | continue; |
| 1129 | |
| 1130 | if ((system_lib.search_strategy != prev_search_strategy or |
| 1131 | system_lib.preferred_link_mode != prev_preferred_link_mode) and |
| 1132 | compile.linkage != .static) |
| 1133 | { |
| 1134 | switch (system_lib.search_strategy) { |
| 1135 | .no_fallback => switch (system_lib.preferred_link_mode) { |
| 1136 | .dynamic => try zig_args.append("-search_dylibs_only"), |
| 1137 | .static => try zig_args.append("-search_static_only"), |
| 1138 | }, |
| 1139 | .paths_first => switch (system_lib.preferred_link_mode) { |
| 1140 | .dynamic => try zig_args.append("-search_paths_first"), |
| 1141 | .static => try zig_args.append("-search_paths_first_static"), |
| 1142 | }, |
| 1143 | .mode_first => switch (system_lib.preferred_link_mode) { |
| 1144 | .dynamic => try zig_args.append("-search_dylibs_first"), |
| 1145 | .static => try zig_args.append("-search_static_first"), |
| 1187 | 1146 | }, |
| 1188 | | |
| 1189 | | else => |e| return e, |
| 1190 | | } |
| 1191 | | }, |
| 1192 | | } |
| 1193 | | }, |
| 1194 | | .other_step => |other| { |
| 1195 | | switch (other.kind) { |
| 1196 | | .exe => return step.fail("cannot link with an executable build artifact", .{}), |
| 1197 | | .@"test" => return step.fail("cannot link with a test", .{}), |
| 1198 | | .obj => { |
| 1199 | | const included_in_lib_or_obj = !my_responsibility and |
| 1200 | | (dep.compile.?.kind == .lib or dep.compile.?.kind == .obj); |
| 1201 | | if (!already_linked and !included_in_lib_or_obj) { |
| 1202 | | try zig_args.append(other.getEmittedBin().getPath2(b, step)); |
| 1203 | | total_linker_objects += 1; |
| 1204 | | } |
| 1205 | | }, |
| 1206 | | .lib => l: { |
| 1207 | | const other_produces_implib = other.producesImplib(); |
| 1208 | | const other_is_static = other_produces_implib or other.isStaticLibrary(); |
| 1209 | | |
| 1210 | | if (compile.isStaticLibrary() and other_is_static) { |
| 1211 | | // Avoid putting a static library inside a static library. |
| 1212 | | break :l; |
| 1213 | 1147 | } |
| 1148 | prev_search_strategy = system_lib.search_strategy; |
| 1149 | prev_preferred_link_mode = system_lib.preferred_link_mode; |
| 1150 | } |
| 1214 | 1151 | |
| 1215 | | // For DLLs, we must link against the implib. |
| 1216 | | // For everything else, we directly link |
| 1217 | | // against the library file. |
| 1218 | | const full_path_lib = if (other_produces_implib) |
| 1219 | | other.getGeneratedFilePath("generated_implib", &compile.step) |
| 1220 | | else |
| 1221 | | other.getGeneratedFilePath("generated_bin", &compile.step); |
| 1152 | const prefix: []const u8 = prefix: { |
| 1153 | if (system_lib.needed) break :prefix "-needed-l"; |
| 1154 | if (system_lib.weak) break :prefix "-weak-l"; |
| 1155 | break :prefix "-l"; |
| 1156 | }; |
| 1157 | switch (system_lib.use_pkg_config) { |
| 1158 | .no => try zig_args.append(b.fmt("{s}{s}", .{ prefix, system_lib.name })), |
| 1159 | .yes, .force => { |
| 1160 | if (compile.runPkgConfig(system_lib.name)) |result| { |
| 1161 | try zig_args.appendSlice(result.cflags); |
| 1162 | try zig_args.appendSlice(result.libs); |
| 1163 | try seen_system_libs.put(arena, system_lib.name, result.cflags); |
| 1164 | } else |err| switch (err) { |
| 1165 | error.PkgConfigInvalidOutput, |
| 1166 | error.PkgConfigCrashed, |
| 1167 | error.PkgConfigFailed, |
| 1168 | error.PkgConfigNotInstalled, |
| 1169 | error.PackageNotFound, |
| 1170 | => switch (system_lib.use_pkg_config) { |
| 1171 | .yes => { |
| 1172 | // pkg-config failed, so fall back to linking the library |
| 1173 | // by name directly. |
| 1174 | try zig_args.append(b.fmt("{s}{s}", .{ |
| 1175 | prefix, |
| 1176 | system_lib.name, |
| 1177 | })); |
| 1178 | }, |
| 1179 | .force => { |
| 1180 | panic("pkg-config failed for library {s}", .{system_lib.name}); |
| 1181 | }, |
| 1182 | .no => unreachable, |
| 1183 | }, |
| 1222 | 1184 | |
| 1223 | | try zig_args.append(full_path_lib); |
| 1224 | | total_linker_objects += 1; |
| 1185 | else => |e| return e, |
| 1186 | } |
| 1187 | }, |
| 1188 | } |
| 1189 | }, |
| 1190 | .other_step => |other| { |
| 1191 | switch (other.kind) { |
| 1192 | .exe => return step.fail("cannot link with an executable build artifact", .{}), |
| 1193 | .@"test" => return step.fail("cannot link with a test", .{}), |
| 1194 | .obj => { |
| 1195 | const included_in_lib_or_obj = !my_responsibility and |
| 1196 | (dep_compile.kind == .lib or dep_compile.kind == .obj); |
| 1197 | if (!already_linked and !included_in_lib_or_obj) { |
| 1198 | try zig_args.append(other.getEmittedBin().getPath2(b, step)); |
| 1199 | total_linker_objects += 1; |
| 1200 | } |
| 1201 | }, |
| 1202 | .lib => l: { |
| 1203 | const other_produces_implib = other.producesImplib(); |
| 1204 | const other_is_static = other_produces_implib or other.isStaticLibrary(); |
| 1225 | 1205 | |
| 1226 | | if (other.linkage == .dynamic and |
| 1227 | | compile.rootModuleTarget().os.tag != .windows) |
| 1228 | | { |
| 1229 | | if (fs.path.dirname(full_path_lib)) |dirname| { |
| 1230 | | try zig_args.append("-rpath"); |
| 1231 | | try zig_args.append(dirname); |
| 1206 | if (compile.isStaticLibrary() and other_is_static) { |
| 1207 | // Avoid putting a static library inside a static library. |
| 1208 | break :l; |
| 1232 | 1209 | } |
| 1233 | | } |
| 1234 | | }, |
| 1235 | | } |
| 1236 | | }, |
| 1237 | | .assembly_file => |asm_file| l: { |
| 1238 | | if (!my_responsibility) break :l; |
| 1239 | 1210 | |
| 1240 | | if (prev_has_cflags) { |
| 1241 | | try zig_args.append("-cflags"); |
| 1242 | | try zig_args.append("--"); |
| 1243 | | prev_has_cflags = false; |
| 1244 | | } |
| 1245 | | try zig_args.append(asm_file.getPath2(dep.module.owner, step)); |
| 1246 | | total_linker_objects += 1; |
| 1247 | | }, |
| 1211 | // For DLLs, we must link against the implib. |
| 1212 | // For everything else, we directly link |
| 1213 | // against the library file. |
| 1214 | const full_path_lib = if (other_produces_implib) |
| 1215 | other.getGeneratedFilePath("generated_implib", &compile.step) |
| 1216 | else |
| 1217 | other.getGeneratedFilePath("generated_bin", &compile.step); |
| 1248 | 1218 | |
| 1249 | | .c_source_file => |c_source_file| l: { |
| 1250 | | if (!my_responsibility) break :l; |
| 1219 | try zig_args.append(full_path_lib); |
| 1220 | total_linker_objects += 1; |
| 1221 | |
| 1222 | if (other.linkage == .dynamic and |
| 1223 | compile.rootModuleTarget().os.tag != .windows) |
| 1224 | { |
| 1225 | if (fs.path.dirname(full_path_lib)) |dirname| { |
| 1226 | try zig_args.append("-rpath"); |
| 1227 | try zig_args.append(dirname); |
| 1228 | } |
| 1229 | } |
| 1230 | }, |
| 1231 | } |
| 1232 | }, |
| 1233 | .assembly_file => |asm_file| l: { |
| 1234 | if (!my_responsibility) break :l; |
| 1251 | 1235 | |
| 1252 | | if (c_source_file.flags.len == 0) { |
| 1253 | 1236 | if (prev_has_cflags) { |
| 1254 | 1237 | try zig_args.append("-cflags"); |
| 1255 | 1238 | try zig_args.append("--"); |
| 1256 | 1239 | prev_has_cflags = false; |
| 1257 | 1240 | } |
| 1258 | | } else { |
| 1259 | | try zig_args.append("-cflags"); |
| 1260 | | for (c_source_file.flags) |arg| { |
| 1261 | | try zig_args.append(arg); |
| 1262 | | } |
| 1263 | | try zig_args.append("--"); |
| 1264 | | prev_has_cflags = true; |
| 1265 | | } |
| 1266 | | try zig_args.append(c_source_file.file.getPath2(dep.module.owner, step)); |
| 1267 | | total_linker_objects += 1; |
| 1268 | | }, |
| 1241 | try zig_args.append(asm_file.getPath2(mod.owner, step)); |
| 1242 | total_linker_objects += 1; |
| 1243 | }, |
| 1269 | 1244 | |
| 1270 | | .c_source_files => |c_source_files| l: { |
| 1271 | | if (!my_responsibility) break :l; |
| 1245 | .c_source_file => |c_source_file| l: { |
| 1246 | if (!my_responsibility) break :l; |
| 1272 | 1247 | |
| 1273 | | if (c_source_files.flags.len == 0) { |
| 1274 | | if (prev_has_cflags) { |
| 1248 | if (c_source_file.flags.len == 0) { |
| 1249 | if (prev_has_cflags) { |
| 1250 | try zig_args.append("-cflags"); |
| 1251 | try zig_args.append("--"); |
| 1252 | prev_has_cflags = false; |
| 1253 | } |
| 1254 | } else { |
| 1275 | 1255 | try zig_args.append("-cflags"); |
| 1256 | for (c_source_file.flags) |arg| { |
| 1257 | try zig_args.append(arg); |
| 1258 | } |
| 1276 | 1259 | try zig_args.append("--"); |
| 1277 | | prev_has_cflags = false; |
| 1260 | prev_has_cflags = true; |
| 1278 | 1261 | } |
| 1279 | | } else { |
| 1280 | | try zig_args.append("-cflags"); |
| 1281 | | for (c_source_files.flags) |flag| { |
| 1282 | | try zig_args.append(flag); |
| 1262 | try zig_args.append(c_source_file.file.getPath2(mod.owner, step)); |
| 1263 | total_linker_objects += 1; |
| 1264 | }, |
| 1265 | |
| 1266 | .c_source_files => |c_source_files| l: { |
| 1267 | if (!my_responsibility) break :l; |
| 1268 | |
| 1269 | if (c_source_files.flags.len == 0) { |
| 1270 | if (prev_has_cflags) { |
| 1271 | try zig_args.append("-cflags"); |
| 1272 | try zig_args.append("--"); |
| 1273 | prev_has_cflags = false; |
| 1274 | } |
| 1275 | } else { |
| 1276 | try zig_args.append("-cflags"); |
| 1277 | for (c_source_files.flags) |flag| { |
| 1278 | try zig_args.append(flag); |
| 1279 | } |
| 1280 | try zig_args.append("--"); |
| 1281 | prev_has_cflags = true; |
| 1283 | 1282 | } |
| 1284 | | try zig_args.append("--"); |
| 1285 | | prev_has_cflags = true; |
| 1286 | | } |
| 1287 | 1283 | |
| 1288 | | const root_path = c_source_files.root.getPath2(dep.module.owner, step); |
| 1289 | | for (c_source_files.files) |file| { |
| 1290 | | try zig_args.append(b.pathJoin(&.{ root_path, file })); |
| 1291 | | } |
| 1284 | const root_path = c_source_files.root.getPath2(mod.owner, step); |
| 1285 | for (c_source_files.files) |file| { |
| 1286 | try zig_args.append(b.pathJoin(&.{ root_path, file })); |
| 1287 | } |
| 1292 | 1288 | |
| 1293 | | total_linker_objects += c_source_files.files.len; |
| 1294 | | }, |
| 1289 | total_linker_objects += c_source_files.files.len; |
| 1290 | }, |
| 1295 | 1291 | |
| 1296 | | .win32_resource_file => |rc_source_file| l: { |
| 1297 | | if (!my_responsibility) break :l; |
| 1292 | .win32_resource_file => |rc_source_file| l: { |
| 1293 | if (!my_responsibility) break :l; |
| 1298 | 1294 | |
| 1299 | | if (rc_source_file.flags.len == 0 and rc_source_file.include_paths.len == 0) { |
| 1300 | | if (prev_has_rcflags) { |
| 1295 | if (rc_source_file.flags.len == 0 and rc_source_file.include_paths.len == 0) { |
| 1296 | if (prev_has_rcflags) { |
| 1297 | try zig_args.append("-rcflags"); |
| 1298 | try zig_args.append("--"); |
| 1299 | prev_has_rcflags = false; |
| 1300 | } |
| 1301 | } else { |
| 1301 | 1302 | try zig_args.append("-rcflags"); |
| 1303 | for (rc_source_file.flags) |arg| { |
| 1304 | try zig_args.append(arg); |
| 1305 | } |
| 1306 | for (rc_source_file.include_paths) |include_path| { |
| 1307 | try zig_args.append("/I"); |
| 1308 | try zig_args.append(include_path.getPath2(mod.owner, step)); |
| 1309 | } |
| 1302 | 1310 | try zig_args.append("--"); |
| 1303 | | prev_has_rcflags = false; |
| 1304 | | } |
| 1305 | | } else { |
| 1306 | | try zig_args.append("-rcflags"); |
| 1307 | | for (rc_source_file.flags) |arg| { |
| 1308 | | try zig_args.append(arg); |
| 1309 | | } |
| 1310 | | for (rc_source_file.include_paths) |include_path| { |
| 1311 | | try zig_args.append("/I"); |
| 1312 | | try zig_args.append(include_path.getPath2(dep.module.owner, step)); |
| 1311 | prev_has_rcflags = true; |
| 1313 | 1312 | } |
| 1314 | | try zig_args.append("--"); |
| 1315 | | prev_has_rcflags = true; |
| 1316 | | } |
| 1317 | | try zig_args.append(rc_source_file.file.getPath2(dep.module.owner, step)); |
| 1318 | | total_linker_objects += 1; |
| 1319 | | }, |
| 1313 | try zig_args.append(rc_source_file.file.getPath2(mod.owner, step)); |
| 1314 | total_linker_objects += 1; |
| 1315 | }, |
| 1316 | } |
| 1320 | 1317 | } |
| 1321 | | } |
| 1322 | 1318 | |
| 1323 | | // We need to emit the --mod argument here so that the above link objects |
| 1324 | | // have the correct parent module, but only if the module is part of |
| 1325 | | // this compilation. |
| 1326 | | if (!my_responsibility) continue; |
| 1327 | | if (cli_named_modules.modules.getIndex(dep.module)) |module_cli_index| { |
| 1328 | | const module_cli_name = cli_named_modules.names.keys()[module_cli_index]; |
| 1329 | | try dep.module.appendZigProcessFlags(&zig_args, step); |
| 1330 | | |
| 1331 | | // --dep arguments |
| 1332 | | try zig_args.ensureUnusedCapacity(dep.module.import_table.count() * 2); |
| 1333 | | for (dep.module.import_table.keys(), dep.module.import_table.values()) |name, import| { |
| 1334 | | const import_index = cli_named_modules.modules.getIndex(import).?; |
| 1335 | | const import_cli_name = cli_named_modules.names.keys()[import_index]; |
| 1336 | | zig_args.appendAssumeCapacity("--dep"); |
| 1337 | | if (std.mem.eql(u8, import_cli_name, name)) { |
| 1338 | | zig_args.appendAssumeCapacity(import_cli_name); |
| 1339 | | } else { |
| 1340 | | zig_args.appendAssumeCapacity(b.fmt("{s}={s}", .{ name, import_cli_name })); |
| 1319 | // We need to emit the --mod argument here so that the above link objects |
| 1320 | // have the correct parent module, but only if the module is part of |
| 1321 | // this compilation. |
| 1322 | if (!my_responsibility) continue; |
| 1323 | if (cli_named_modules.modules.getIndex(mod)) |module_cli_index| { |
| 1324 | const module_cli_name = cli_named_modules.names.keys()[module_cli_index]; |
| 1325 | try mod.appendZigProcessFlags(&zig_args, step); |
| 1326 | |
| 1327 | // --dep arguments |
| 1328 | try zig_args.ensureUnusedCapacity(mod.import_table.count() * 2); |
| 1329 | for (mod.import_table.keys(), mod.import_table.values()) |name, import| { |
| 1330 | const import_index = cli_named_modules.modules.getIndex(import).?; |
| 1331 | const import_cli_name = cli_named_modules.names.keys()[import_index]; |
| 1332 | zig_args.appendAssumeCapacity("--dep"); |
| 1333 | if (std.mem.eql(u8, import_cli_name, name)) { |
| 1334 | zig_args.appendAssumeCapacity(import_cli_name); |
| 1335 | } else { |
| 1336 | zig_args.appendAssumeCapacity(b.fmt("{s}={s}", .{ name, import_cli_name })); |
| 1337 | } |
| 1341 | 1338 | } |
| 1342 | | } |
| 1343 | 1339 | |
| 1344 | | // When the CLI sees a -M argument, it determines whether it |
| 1345 | | // implies the existence of a Zig compilation unit based on |
| 1346 | | // whether there is a root source file. If there is no root |
| 1347 | | // source file, then this is not a zig compilation unit - it is |
| 1348 | | // perhaps a set of linker objects, or C source files instead. |
| 1349 | | // Linker objects are added to the CLI globally, while C source |
| 1350 | | // files must have a module parent. |
| 1351 | | if (dep.module.root_source_file) |lp| { |
| 1352 | | const src = lp.getPath2(dep.module.owner, step); |
| 1353 | | try zig_args.append(b.fmt("-M{s}={s}", .{ module_cli_name, src })); |
| 1354 | | } else if (moduleNeedsCliArg(dep.module)) { |
| 1355 | | try zig_args.append(b.fmt("-M{s}", .{module_cli_name})); |
| 1340 | // When the CLI sees a -M argument, it determines whether it |
| 1341 | // implies the existence of a Zig compilation unit based on |
| 1342 | // whether there is a root source file. If there is no root |
| 1343 | // source file, then this is not a zig compilation unit - it is |
| 1344 | // perhaps a set of linker objects, or C source files instead. |
| 1345 | // Linker objects are added to the CLI globally, while C source |
| 1346 | // files must have a module parent. |
| 1347 | if (mod.root_source_file) |lp| { |
| 1348 | const src = lp.getPath2(mod.owner, step); |
| 1349 | try zig_args.append(b.fmt("-M{s}={s}", .{ module_cli_name, src })); |
| 1350 | } else if (moduleNeedsCliArg(mod)) { |
| 1351 | try zig_args.append(b.fmt("-M{s}", .{module_cli_name})); |
| 1352 | } |
| 1356 | 1353 | } |
| 1357 | 1354 | } |
| 1358 | 1355 | } |
| ... | ... | @@ -2064,3 +2061,35 @@ fn moduleNeedsCliArg(mod: *const Module) bool { |
| 2064 | 2061 | else => continue, |
| 2065 | 2062 | } else false; |
| 2066 | 2063 | } |
| 2064 | |
| 2065 | /// Return the full set of `Step.Compile` which `start` depends on, recursively. `start` itself is |
| 2066 | /// always returned as the first element. If `chase_dynamic` is `false`, then dynamic libraries are |
| 2067 | /// not included, and their dependencies are not considered; if `chase_dynamic` is `true`, dynamic |
| 2068 | /// libraries are treated the same as other linked `Compile`s. |
| 2069 | pub fn getCompileDependencies(start: *Compile, chase_dynamic: bool) []const *Compile { |
| 2070 | const arena = start.step.owner.graph.arena; |
| 2071 | |
| 2072 | var compiles: std.AutoArrayHashMapUnmanaged(*Compile, void) = .empty; |
| 2073 | var next_idx: usize = 0; |
| 2074 | |
| 2075 | compiles.putNoClobber(arena, start, {}) catch @panic("OOM"); |
| 2076 | |
| 2077 | while (next_idx < compiles.count()) { |
| 2078 | const compile = compiles.keys()[next_idx]; |
| 2079 | next_idx += 1; |
| 2080 | |
| 2081 | for (compile.root_module.getGraph().modules) |mod| { |
| 2082 | for (mod.link_objects.items) |lo| { |
| 2083 | switch (lo) { |
| 2084 | .other_step => |other_compile| { |
| 2085 | if (!chase_dynamic and other_compile.isDynamicLibrary()) continue; |
| 2086 | compiles.put(arena, other_compile, {}) catch @panic("OOM"); |
| 2087 | }, |
| 2088 | else => {}, |
| 2089 | } |
| 2090 | } |
| 2091 | } |
| 2092 | } |
| 2093 | |
| 2094 | return compiles.keys(); |
| 2095 | } |