Skip to content

Commit 000004b

Browse files
committed
make "gnu" (mingw-w64) the default C ABI on Windows
Closes #6565
1 parent b8f85a8 commit 000004b

File tree

7 files changed

+31
-305
lines changed

7 files changed

+31
-305
lines changed

lib/std/target.zig

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,8 @@ pub const Target = struct {
498498
.netbsd,
499499
.hurd,
500500
.haiku,
501-
=> return .gnu,
502501
.windows,
502+
=> return .gnu,
503503
.uefi,
504504
=> return .msvc,
505505
.linux,
@@ -1258,15 +1258,18 @@ pub const Target = struct {
12581258
return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi);
12591259
}
12601260

1261-
pub fn oFileExt_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 {
1262-
switch (abi) {
1263-
.msvc => return ".obj",
1261+
pub fn oFileExt_os_abi(os_tag: Os.Tag, abi: Abi) [:0]const u8 {
1262+
if (abi == .msvc) {
1263+
return ".obj";
1264+
}
1265+
switch (os_tag) {
1266+
.windows, .uefi => return ".obj",
12641267
else => return ".o",
12651268
}
12661269
}
12671270

12681271
pub fn oFileExt(self: Target) [:0]const u8 {
1269-
return oFileExt_cpu_arch_abi(self.cpu.arch, self.abi);
1272+
return oFileExt_os_abi(self.os.tag, self.abi);
12701273
}
12711274

12721275
pub fn exeFileExtSimple(cpu_arch: Cpu.Arch, os_tag: Os.Tag) [:0]const u8 {
@@ -1285,30 +1288,36 @@ pub const Target = struct {
12851288
return exeFileExtSimple(self.cpu.arch, self.os.tag);
12861289
}
12871290

1288-
pub fn staticLibSuffix_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 {
1289-
switch (abi) {
1290-
.msvc => return ".lib",
1291+
pub fn staticLibSuffix_os_abi(os_tag: Os.Tag, abi: Abi) [:0]const u8 {
1292+
if (abi == .msvc) {
1293+
return ".lib";
1294+
}
1295+
switch (os_tag) {
1296+
.windows, .uefi => return ".lib",
12911297
else => return ".a",
12921298
}
12931299
}
12941300

12951301
pub fn staticLibSuffix(self: Target) [:0]const u8 {
1296-
return staticLibSuffix_cpu_arch_abi(self.cpu.arch, self.abi);
1302+
return staticLibSuffix_os_abi(self.os.tag, self.abi);
12971303
}
12981304

12991305
pub fn dynamicLibSuffix(self: Target) [:0]const u8 {
13001306
return self.os.tag.dynamicLibSuffix();
13011307
}
13021308

1303-
pub fn libPrefix_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 {
1304-
switch (abi) {
1305-
.msvc => return "",
1309+
pub fn libPrefix_os_abi(os_tag: Os.Tag, abi: Abi) [:0]const u8 {
1310+
if (abi == .msvc) {
1311+
return "";
1312+
}
1313+
switch (os_tag) {
1314+
.windows, .uefi => return "",
13061315
else => return "lib",
13071316
}
13081317
}
13091318

13101319
pub fn libPrefix(self: Target) [:0]const u8 {
1311-
return libPrefix_cpu_arch_abi(self.cpu.arch, self.abi);
1320+
return libPrefix_os_abi(self.os.tag, self.abi);
13121321
}
13131322

13141323
pub fn getObjectFormatSimple(os_tag: Os.Tag, cpu_arch: Cpu.Arch) ObjectFormat {

lib/std/zig/cross_target.zig

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -473,23 +473,23 @@ pub const CrossTarget = struct {
473473
}
474474

475475
pub fn oFileExt(self: CrossTarget) [:0]const u8 {
476-
return Target.oFileExt_cpu_arch_abi(self.getCpuArch(), self.getAbi());
476+
return Target.oFileExt_os_abi(self.getOsTag(), self.getAbi());
477477
}
478478

479479
pub fn exeFileExt(self: CrossTarget) [:0]const u8 {
480480
return Target.exeFileExtSimple(self.getCpuArch(), self.getOsTag());
481481
}
482482

483483
pub fn staticLibSuffix(self: CrossTarget) [:0]const u8 {
484-
return Target.staticLibSuffix_cpu_arch_abi(self.getCpuArch(), self.getAbi());
484+
return Target.staticLibSuffix_os_abi(self.getOsTag(), self.getAbi());
485485
}
486486

487487
pub fn dynamicLibSuffix(self: CrossTarget) [:0]const u8 {
488488
return self.getOsTag().dynamicLibSuffix();
489489
}
490490

491491
pub fn libPrefix(self: CrossTarget) [:0]const u8 {
492-
return Target.libPrefix_cpu_arch_abi(self.getCpuArch(), self.getAbi());
492+
return Target.libPrefix_os_abi(self.getOsTag(), self.getAbi());
493493
}
494494

495495
pub fn isNativeCpu(self: CrossTarget) bool {

src/Compilation.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3164,7 +3164,7 @@ fn detectLibCIncludeDirs(
31643164

31653165
// If linking system libraries and targeting the native abi, default to
31663166
// using the system libc installation.
3167-
if (link_system_libs and is_native_abi) {
3167+
if (link_system_libs and is_native_abi and !target.isMinGW()) {
31683168
const libc = try arena.create(LibCInstallation);
31693169
libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true });
31703170
return detectLibCFromLibCInstallation(arena, target, libc);

src/libc_installation.zig

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const build_options = @import("build_options");
88

99
const is_darwin = Target.current.isDarwin();
1010
const is_windows = Target.current.os.tag == .windows;
11-
const is_gnu = Target.current.isGnu();
1211
const is_haiku = Target.current.os.tag == .haiku;
1312

1413
const log = std.log.scoped(.libc_installation);
@@ -100,14 +99,14 @@ pub const LibCInstallation = struct {
10099
log.err("crt_dir may not be empty for {s}\n", .{@tagName(Target.current.os.tag)});
101100
return error.ParseError;
102101
}
103-
if (self.msvc_lib_dir == null and is_windows and !is_gnu) {
102+
if (self.msvc_lib_dir == null and is_windows) {
104103
log.err("msvc_lib_dir may not be empty for {s}-{s}\n", .{
105104
@tagName(Target.current.os.tag),
106105
@tagName(Target.current.abi),
107106
});
108107
return error.ParseError;
109108
}
110-
if (self.kernel32_lib_dir == null and is_windows and !is_gnu) {
109+
if (self.kernel32_lib_dir == null and is_windows) {
111110
log.err("kernel32_lib_dir may not be empty for {s}-{s}\n", .{
112111
@tagName(Target.current.os.tag),
113112
@tagName(Target.current.abi),

src/link/Coff.zig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,14 +1137,14 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
11371137
}
11381138

11391139
if (is_dyn_lib) {
1140-
try argv.append(try comp.get_libc_crt_file(arena, "dllcrt2.o"));
1140+
try argv.append(try comp.get_libc_crt_file(arena, "dllcrt2.obj"));
11411141
if (target.cpu.arch == .i386) {
11421142
try argv.append("-ALTERNATENAME:__DllMainCRTStartup@12=_DllMainCRTStartup@12");
11431143
} else {
11441144
try argv.append("-ALTERNATENAME:_DllMainCRTStartup=DllMainCRTStartup");
11451145
}
11461146
} else {
1147-
try argv.append(try comp.get_libc_crt_file(arena, "crt2.o"));
1147+
try argv.append(try comp.get_libc_crt_file(arena, "crt2.obj"));
11481148
}
11491149

11501150
try argv.append(try comp.get_libc_crt_file(arena, "mingw32.lib"));

0 commit comments

Comments
 (0)