Skip to content

Commit 70ca8de

Browse files
committed
mingw: build all CRT libraries
1 parent 9610860 commit 70ca8de

File tree

3 files changed

+811
-956
lines changed

3 files changed

+811
-956
lines changed

src/Compilation.zig

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,7 @@ pub const MiscTask = enum {
364364

365365
@"mingw-w64 crt2.o",
366366
@"mingw-w64 dllcrt2.o",
367-
@"mingw-w64 mingw32.lib",
368-
@"mingw-w64 msvcrt-os.lib",
369-
@"mingw-w64 mingwex.lib",
370-
@"mingw-w64 uuid.lib",
367+
@"mingw-w64 CRT lib",
371368
};
372369

373370
pub const MiscError = struct {
@@ -1684,21 +1681,28 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
16841681
if (comp.wantBuildMinGWFromSource()) {
16851682
if (!target_util.canBuildLibC(target)) return error.LibCUnavailable;
16861683

1687-
const static_lib_jobs = [_]Job{
1688-
.{ .mingw_crt_file = .mingw32_lib },
1689-
.{ .mingw_crt_file = .msvcrt_os_lib },
1690-
.{ .mingw_crt_file = .mingwex_lib },
1691-
.{ .mingw_crt_file = .uuid_lib },
1692-
};
16931684
const crt_job: Job = .{ .mingw_crt_file = if (is_dyn_lib) .dllcrt2_o else .crt2_o };
1694-
try comp.work_queue.ensureUnusedCapacity(static_lib_jobs.len + 1);
1695-
comp.work_queue.writeAssumeCapacity(&static_lib_jobs);
1696-
comp.work_queue.writeItemAssumeCapacity(crt_job);
1685+
try comp.work_queue.writeItem(crt_job);
1686+
1687+
var add_libc = true;
1688+
var it = comp.bin_file.options.system_libs.iterator();
1689+
while (it.next()) |entry| {
1690+
const name = entry.key_ptr.*;
1691+
if (std.mem.startsWith(u8, name, "msvcr") or std.mem.startsWith(u8, name, "ucrt") or std.mem.startsWith(u8, name, "crtdll")) {
1692+
add_libc = false;
1693+
break;
1694+
}
1695+
}
1696+
if (add_libc) {
1697+
try comp.bin_file.options.system_libs.put(comp.gpa, "ucrt", .{});
1698+
}
16971699

16981700
// When linking mingw-w64 there are some import libs we always need.
16991701
for (mingw.always_link_libs) |name| {
17001702
try comp.bin_file.options.system_libs.put(comp.gpa, name, .{});
17011703
}
1704+
1705+
try mingw.processSystemLibs(comp);
17021706
}
17031707
// Generate Windows import libs.
17041708
if (target.os.tag == .windows) {

src/link/Coff/lld.zig

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,10 +402,6 @@ pub fn linkWithLLD(self: *Coff, comp: *Compilation, prog_node: *std.Progress.Nod
402402
try argv.append(try comp.get_libc_crt_file(arena, "crt2.obj"));
403403
}
404404

405-
try argv.append(try comp.get_libc_crt_file(arena, "mingw32.lib"));
406-
try argv.append(try comp.get_libc_crt_file(arena, "mingwex.lib"));
407-
try argv.append(try comp.get_libc_crt_file(arena, "msvcrt-os.lib"));
408-
409405
for (mingw.always_link_libs) |name| {
410406
if (!self.base.options.system_libs.contains(name)) {
411407
const lib_basename = try allocPrint(arena, "{s}.lib", .{name});

0 commit comments

Comments
 (0)