Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions lib/std/target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,8 @@ pub const Target = struct {
.netbsd,
.hurd,
.haiku,
=> return .gnu,
.windows,
=> return .gnu,
.uefi,
=> return .msvc,
.linux,
Expand Down Expand Up @@ -1258,15 +1258,18 @@ pub const Target = struct {
return linuxTripleSimple(allocator, self.cpu.arch, self.os.tag, self.abi);
}

pub fn oFileExt_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 {
switch (abi) {
.msvc => return ".obj",
pub fn oFileExt_os_abi(os_tag: Os.Tag, abi: Abi) [:0]const u8 {
if (abi == .msvc) {
return ".obj";
}
switch (os_tag) {
.windows, .uefi => return ".obj",
else => return ".o",
}
}

pub fn oFileExt(self: Target) [:0]const u8 {
return oFileExt_cpu_arch_abi(self.cpu.arch, self.abi);
return oFileExt_os_abi(self.os.tag, self.abi);
}

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

pub fn staticLibSuffix_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 {
switch (abi) {
.msvc => return ".lib",
pub fn staticLibSuffix_os_abi(os_tag: Os.Tag, abi: Abi) [:0]const u8 {
if (abi == .msvc) {
return ".lib";
}
switch (os_tag) {
.windows, .uefi => return ".lib",
else => return ".a",
}
}

pub fn staticLibSuffix(self: Target) [:0]const u8 {
return staticLibSuffix_cpu_arch_abi(self.cpu.arch, self.abi);
return staticLibSuffix_os_abi(self.os.tag, self.abi);
}

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

pub fn libPrefix_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 {
switch (abi) {
.msvc => return "",
pub fn libPrefix_os_abi(os_tag: Os.Tag, abi: Abi) [:0]const u8 {
if (abi == .msvc) {
return "";
}
switch (os_tag) {
.windows, .uefi => return "",
else => return "lib",
}
}

pub fn libPrefix(self: Target) [:0]const u8 {
return libPrefix_cpu_arch_abi(self.cpu.arch, self.abi);
return libPrefix_os_abi(self.os.tag, self.abi);
}

pub fn getObjectFormatSimple(os_tag: Os.Tag, cpu_arch: Cpu.Arch) ObjectFormat {
Expand Down
6 changes: 3 additions & 3 deletions lib/std/zig/cross_target.zig
Original file line number Diff line number Diff line change
Expand Up @@ -473,23 +473,23 @@ pub const CrossTarget = struct {
}

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

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

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

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

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

pub fn isNativeCpu(self: CrossTarget) bool {
Expand Down
2 changes: 1 addition & 1 deletion src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3164,7 +3164,7 @@ fn detectLibCIncludeDirs(

// If linking system libraries and targeting the native abi, default to
// using the system libc installation.
if (link_system_libs and is_native_abi) {
if (link_system_libs and is_native_abi and !target.isMinGW()) {
const libc = try arena.create(LibCInstallation);
libc.* = try LibCInstallation.findNative(.{ .allocator = arena, .verbose = true });
return detectLibCFromLibCInstallation(arena, target, libc);
Expand Down
5 changes: 2 additions & 3 deletions src/libc_installation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const build_options = @import("build_options");

const is_darwin = Target.current.isDarwin();
const is_windows = Target.current.os.tag == .windows;
const is_gnu = Target.current.isGnu();
const is_haiku = Target.current.os.tag == .haiku;

const log = std.log.scoped(.libc_installation);
Expand Down Expand Up @@ -100,14 +99,14 @@ pub const LibCInstallation = struct {
log.err("crt_dir may not be empty for {s}\n", .{@tagName(Target.current.os.tag)});
return error.ParseError;
}
if (self.msvc_lib_dir == null and is_windows and !is_gnu) {
if (self.msvc_lib_dir == null and is_windows) {
log.err("msvc_lib_dir may not be empty for {s}-{s}\n", .{
@tagName(Target.current.os.tag),
@tagName(Target.current.abi),
});
return error.ParseError;
}
if (self.kernel32_lib_dir == null and is_windows and !is_gnu) {
if (self.kernel32_lib_dir == null and is_windows) {
log.err("kernel32_lib_dir may not be empty for {s}-{s}\n", .{
@tagName(Target.current.os.tag),
@tagName(Target.current.abi),
Expand Down
4 changes: 2 additions & 2 deletions src/link/Coff.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1137,14 +1137,14 @@ fn linkWithLLD(self: *Coff, comp: *Compilation) !void {
}

if (is_dyn_lib) {
try argv.append(try comp.get_libc_crt_file(arena, "dllcrt2.o"));
try argv.append(try comp.get_libc_crt_file(arena, "dllcrt2.obj"));
if (target.cpu.arch == .i386) {
try argv.append("-ALTERNATENAME:__DllMainCRTStartup@12=_DllMainCRTStartup@12");
} else {
try argv.append("-ALTERNATENAME:_DllMainCRTStartup=DllMainCRTStartup");
}
} else {
try argv.append(try comp.get_libc_crt_file(arena, "crt2.o"));
try argv.append(try comp.get_libc_crt_file(arena, "crt2.obj"));
}

try argv.append(try comp.get_libc_crt_file(arena, "mingw32.lib"));
Expand Down
Loading