mirror of
https://github.com/ziglang/zig.git
synced 2025-12-16 03:03:09 +00:00
fix handling of CrossTarget.cpu_model
This commit is contained in:
parent
8691d3c50d
commit
aa13f339d4
@ -10,8 +10,7 @@ pub const CrossTarget = struct {
|
||||
/// `null` means native. If this is `null` then `cpu_model` must be `null`.
|
||||
cpu_arch: ?Target.Cpu.Arch = null,
|
||||
|
||||
/// `null` means native.
|
||||
/// If this is non-null, `cpu_arch` must be specified.
|
||||
/// `null` means native. If this is non-null, `cpu_arch` must be specified.
|
||||
cpu_model: ?*const Target.Cpu.Model = null,
|
||||
|
||||
/// Sparse set of CPU features to add to the set from `cpu_model`.
|
||||
@ -301,6 +300,10 @@ pub const CrossTarget = struct {
|
||||
return error.UnknownCpuFeature;
|
||||
}
|
||||
}
|
||||
} else if (arch_is_native) {
|
||||
result.cpu_model = null;
|
||||
} else {
|
||||
result.cpu_model = Target.Cpu.Model.baseline(arch);
|
||||
}
|
||||
|
||||
return result;
|
||||
@ -725,6 +728,15 @@ pub const CrossTarget = struct {
|
||||
};
|
||||
|
||||
test "CrossTarget.parse" {
|
||||
{
|
||||
const cross_target = try CrossTarget.parse(.{
|
||||
.arch_os_abi = "aarch64-linux",
|
||||
.cpu_features = "native",
|
||||
});
|
||||
|
||||
std.testing.expect(cross_target.cpu_arch.? == .aarch64);
|
||||
std.testing.expect(cross_target.cpu_model == null);
|
||||
}
|
||||
{
|
||||
const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
|
||||
|
||||
|
||||
@ -192,21 +192,14 @@ pub const NativeTargetInfo = struct {
|
||||
/// TODO Remove the Allocator requirement from this function.
|
||||
pub fn detect(allocator: *Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo {
|
||||
const cpu = blk: {
|
||||
if (cross_target.cpu_arch) |arch| {
|
||||
if (cross_target.cpu_model) |model| {
|
||||
var adjusted_model = model.toCpu(arch);
|
||||
cross_target.updateCpuFeatures(&adjusted_model.features);
|
||||
break :blk adjusted_model;
|
||||
} else {
|
||||
// TODO Detect native CPU model. Until that is implemented we use baseline.
|
||||
var adjusted_baseline = Target.Cpu.baseline(arch);
|
||||
cross_target.updateCpuFeatures(&adjusted_baseline.features);
|
||||
break :blk adjusted_baseline;
|
||||
}
|
||||
const arch = cross_target.getCpuArch();
|
||||
if (cross_target.cpu_model) |model| {
|
||||
var adjusted_model = model.toCpu(arch);
|
||||
cross_target.updateCpuFeatures(&adjusted_model.features);
|
||||
break :blk adjusted_model;
|
||||
} else {
|
||||
assert(cross_target.cpu_model == null);
|
||||
// TODO Detect native CPU model & features. Until that is implemented we use baseline.
|
||||
var adjusted_baseline = Target.Cpu.baseline(Target.current.cpu.arch);
|
||||
var adjusted_baseline = Target.Cpu.baseline(arch);
|
||||
cross_target.updateCpuFeatures(&adjusted_baseline.features);
|
||||
break :blk adjusted_baseline;
|
||||
}
|
||||
|
||||
@ -1163,6 +1163,7 @@ fn crossTargetToTarget(cross_target: CrossTarget, dynamic_linker_ptr: *?[*:0]u8)
|
||||
const arch = std.Target.current.cpu.arch;
|
||||
info.target.cpu = try detectNativeCpuWithLLVM(arch, llvm_cpu_name, llvm_cpu_features);
|
||||
cross_target.updateCpuFeatures(&info.target.cpu.features);
|
||||
info.target.cpu.arch = cross_target.getCpuArch();
|
||||
}
|
||||
if (info.dynamic_linker.get()) |dl| {
|
||||
dynamic_linker_ptr.* = try mem.dupeZ(std.heap.c_allocator, u8, dl);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user