Skip to content

Commit 3c7f030

Browse files
committed
add CrossTarget.getObjectFormat
closes #4588 thanks Michaël Larouche for the suggested fix
1 parent 7e6b68a commit 3c7f030

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/std/target.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,18 +1014,22 @@ pub const Target = struct {
10141014
return libPrefix_cpu_arch_abi(self.cpu.arch, self.abi);
10151015
}
10161016

1017-
pub fn getObjectFormat(self: Target) ObjectFormat {
1018-
if (self.os.tag == .windows or self.os.tag == .uefi) {
1017+
pub fn getObjectFormatSimple(os_tag: Os.Tag, cpu_arch: Cpu.Arch) ObjectFormat {
1018+
if (os_tag == .windows or os_tag == .uefi) {
10191019
return .coff;
1020-
} else if (self.isDarwin()) {
1020+
} else if (os_tag.isDarwin()) {
10211021
return .macho;
10221022
}
1023-
if (self.cpu.arch.isWasm()) {
1023+
if (cpu_arch.isWasm()) {
10241024
return .wasm;
10251025
}
10261026
return .elf;
10271027
}
10281028

1029+
pub fn getObjectFormat(self: Target) ObjectFormat {
1030+
return getObjectFormatSimple(self.os.tag, self.cpu.arch);
1031+
}
1032+
10291033
pub fn isMinGW(self: Target) bool {
10301034
return self.os.tag == .windows and self.isGnu();
10311035
}

lib/std/zig/cross_target.zig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,10 @@ pub const CrossTarget = struct {
645645
self.glibc_version = SemVer{ .major = major, .minor = minor, .patch = patch };
646646
}
647647

648+
pub fn getObjectFormat(self: CrossTarget) ObjectFormat {
649+
return Target.getObjectFormatSimple(self.getOsTag(), self.getCpuArch());
650+
}
651+
648652
fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void {
649653
set.removeFeatureSet(self.cpu_features_sub);
650654
set.addFeatureSet(self.cpu_features_add);

0 commit comments

Comments
 (0)