mirror of
https://github.com/ziglang/zig.git
synced 2025-12-18 12:13:20 +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`.
|
/// `null` means native. If this is `null` then `cpu_model` must be `null`.
|
||||||
cpu_arch: ?Target.Cpu.Arch = null,
|
cpu_arch: ?Target.Cpu.Arch = null,
|
||||||
|
|
||||||
/// `null` means native.
|
/// `null` means native. If this is non-null, `cpu_arch` must be specified.
|
||||||
/// If this is non-null, `cpu_arch` must be specified.
|
|
||||||
cpu_model: ?*const Target.Cpu.Model = null,
|
cpu_model: ?*const Target.Cpu.Model = null,
|
||||||
|
|
||||||
/// Sparse set of CPU features to add to the set from `cpu_model`.
|
/// Sparse set of CPU features to add to the set from `cpu_model`.
|
||||||
@ -301,6 +300,10 @@ pub const CrossTarget = struct {
|
|||||||
return error.UnknownCpuFeature;
|
return error.UnknownCpuFeature;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (arch_is_native) {
|
||||||
|
result.cpu_model = null;
|
||||||
|
} else {
|
||||||
|
result.cpu_model = Target.Cpu.Model.baseline(arch);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
@ -725,6 +728,15 @@ pub const CrossTarget = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
test "CrossTarget.parse" {
|
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" });
|
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.
|
/// TODO Remove the Allocator requirement from this function.
|
||||||
pub fn detect(allocator: *Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo {
|
pub fn detect(allocator: *Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo {
|
||||||
const cpu = blk: {
|
const cpu = blk: {
|
||||||
if (cross_target.cpu_arch) |arch| {
|
const arch = cross_target.getCpuArch();
|
||||||
if (cross_target.cpu_model) |model| {
|
if (cross_target.cpu_model) |model| {
|
||||||
var adjusted_model = model.toCpu(arch);
|
var adjusted_model = model.toCpu(arch);
|
||||||
cross_target.updateCpuFeatures(&adjusted_model.features);
|
cross_target.updateCpuFeatures(&adjusted_model.features);
|
||||||
break :blk adjusted_model;
|
break :blk adjusted_model;
|
||||||
} else {
|
} 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;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
assert(cross_target.cpu_model == null);
|
|
||||||
// TODO Detect native CPU model & features. Until that is implemented we use baseline.
|
// 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);
|
cross_target.updateCpuFeatures(&adjusted_baseline.features);
|
||||||
break :blk adjusted_baseline;
|
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;
|
const arch = std.Target.current.cpu.arch;
|
||||||
info.target.cpu = try detectNativeCpuWithLLVM(arch, llvm_cpu_name, llvm_cpu_features);
|
info.target.cpu = try detectNativeCpuWithLLVM(arch, llvm_cpu_name, llvm_cpu_features);
|
||||||
cross_target.updateCpuFeatures(&info.target.cpu.features);
|
cross_target.updateCpuFeatures(&info.target.cpu.features);
|
||||||
|
info.target.cpu.arch = cross_target.getCpuArch();
|
||||||
}
|
}
|
||||||
if (info.dynamic_linker.get()) |dl| {
|
if (info.dynamic_linker.get()) |dl| {
|
||||||
dynamic_linker_ptr.* = try mem.dupeZ(std.heap.c_allocator, u8, dl);
|
dynamic_linker_ptr.* = try mem.dupeZ(std.heap.c_allocator, u8, dl);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user