add CrossTarget.getObjectFormat

closes #4588

thanks Michaël Larouche for the suggested fix
This commit is contained in:
Andrew Kelley 2020-02-29 12:27:13 -05:00
parent 7e6b68a534
commit 3c7f030a60
No known key found for this signature in database
GPG key ID: 7C5F548F728501A9
2 changed files with 12 additions and 4 deletions

View file

@ -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();
}

View file

@ -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);