aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-02-29 12:27:13 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-02-29 12:27:13 -0500
commit3c7f030a60b038045334788837f40bee0226109c (patch)
tree6de3d50011ed7bf4c7ebe84d1aa8006bc25f1226 /lib
parent7e6b68a534f840d2d08770a5a77896707271e8ea (diff)
downloadzig-3c7f030a60b038045334788837f40bee0226109c.tar.gz
zig-3c7f030a60b038045334788837f40bee0226109c.zip
add CrossTarget.getObjectFormat
closes #4588 thanks Michaƫl Larouche for the suggested fix
Diffstat (limited to 'lib')
-rw-r--r--lib/std/target.zig12
-rw-r--r--lib/std/zig/cross_target.zig4
2 files changed, 12 insertions, 4 deletions
diff --git a/lib/std/target.zig b/lib/std/target.zig
index 0082510505..c810c01ec3 100644
--- a/lib/std/target.zig
+++ b/lib/std/target.zig
@@ -1014,18 +1014,22 @@ pub const Target = struct {
return libPrefix_cpu_arch_abi(self.cpu.arch, self.abi);
}
- pub fn getObjectFormat(self: Target) ObjectFormat {
- if (self.os.tag == .windows or self.os.tag == .uefi) {
+ pub fn getObjectFormatSimple(os_tag: Os.Tag, cpu_arch: Cpu.Arch) ObjectFormat {
+ if (os_tag == .windows or os_tag == .uefi) {
return .coff;
- } else if (self.isDarwin()) {
+ } else if (os_tag.isDarwin()) {
return .macho;
}
- if (self.cpu.arch.isWasm()) {
+ if (cpu_arch.isWasm()) {
return .wasm;
}
return .elf;
}
+ pub fn getObjectFormat(self: Target) ObjectFormat {
+ return getObjectFormatSimple(self.os.tag, self.cpu.arch);
+ }
+
pub fn isMinGW(self: Target) bool {
return self.os.tag == .windows and self.isGnu();
}
diff --git a/lib/std/zig/cross_target.zig b/lib/std/zig/cross_target.zig
index 08a8d21fad..38ce6549f3 100644
--- a/lib/std/zig/cross_target.zig
+++ b/lib/std/zig/cross_target.zig
@@ -645,6 +645,10 @@ pub const CrossTarget = struct {
self.glibc_version = SemVer{ .major = major, .minor = minor, .patch = patch };
}
+ pub fn getObjectFormat(self: CrossTarget) ObjectFormat {
+ return Target.getObjectFormatSimple(self.getOsTag(), self.getCpuArch());
+ }
+
fn updateCpuFeatures(self: CrossTarget, set: *Target.Cpu.Feature.Set) void {
set.removeFeatureSet(self.cpu_features_sub);
set.addFeatureSet(self.cpu_features_add);