authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-28 18:09:33-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-28 18:09:33-05:00
logaa13f339d4d91f8e39f005821c172290e1a0227f
treee356ff138d61d7f5318f374e27fc714d64424d75
parent8691d3c50d65c3e9e399c83cf2fc1a1173acb6d2
signaturelock-open Commit is signed but in an unrecognized format.

fix handling of CrossTarget.cpu_model


3 files changed, 21 insertions(+), 15 deletions(-)

lib/std/zig/cross_target.zig+14-2
......@@ -10,8 +10,7 @@ pub const CrossTarget = struct {
1010 /// `null` means native. If this is `null` then `cpu_model` must be `null`.
1111 cpu_arch: ?Target.Cpu.Arch = null,
1212
13 /// `null` means native.
14 /// If this is non-null, `cpu_arch` must be specified.
13 /// `null` means native. If this is non-null, `cpu_arch` must be specified.
1514 cpu_model: ?*const Target.Cpu.Model = null,
1615
1716 /// Sparse set of CPU features to add to the set from `cpu_model`.
......@@ -301,6 +300,10 @@ pub const CrossTarget = struct {
301300 return error.UnknownCpuFeature;
302301 }
303302 }
303 } else if (arch_is_native) {
304 result.cpu_model = null;
305 } else {
306 result.cpu_model = Target.Cpu.Model.baseline(arch);
304307 }
305308
306309 return result;
......@@ -725,6 +728,15 @@ pub const CrossTarget = struct {
725728};
726729
727730test "CrossTarget.parse" {
731 {
732 const cross_target = try CrossTarget.parse(.{
733 .arch_os_abi = "aarch64-linux",
734 .cpu_features = "native",
735 });
736
737 std.testing.expect(cross_target.cpu_arch.? == .aarch64);
738 std.testing.expect(cross_target.cpu_model == null);
739 }
728740 {
729741 const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" });
730742
lib/std/zig/system.zig+6-13
......@@ -192,21 +192,14 @@ pub const NativeTargetInfo = struct {
192192 /// TODO Remove the Allocator requirement from this function.
193193 pub fn detect(allocator: *Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo {
194194 const cpu = blk: {
195 if (cross_target.cpu_arch) |arch| {
196 if (cross_target.cpu_model) |model| {
197 var adjusted_model = model.toCpu(arch);
198 cross_target.updateCpuFeatures(&adjusted_model.features);
199 break :blk adjusted_model;
200 } else {
201 // TODO Detect native CPU model. Until that is implemented we use baseline.
202 var adjusted_baseline = Target.Cpu.baseline(arch);
203 cross_target.updateCpuFeatures(&adjusted_baseline.features);
204 break :blk adjusted_baseline;
205 }
195 const arch = cross_target.getCpuArch();
196 if (cross_target.cpu_model) |model| {
197 var adjusted_model = model.toCpu(arch);
198 cross_target.updateCpuFeatures(&adjusted_model.features);
199 break :blk adjusted_model;
206200 } else {
207 assert(cross_target.cpu_model == null);
208201 // TODO Detect native CPU model & features. Until that is implemented we use baseline.
209 var adjusted_baseline = Target.Cpu.baseline(Target.current.cpu.arch);
202 var adjusted_baseline = Target.Cpu.baseline(arch);
210203 cross_target.updateCpuFeatures(&adjusted_baseline.features);
211204 break :blk adjusted_baseline;
212205 }
src-self-hosted/stage2.zig+1
......@@ -1163,6 +1163,7 @@ fn crossTargetToTarget(cross_target: CrossTarget, dynamic_linker_ptr: *?[*:0]u8)
11631163 const arch = std.Target.current.cpu.arch;
11641164 info.target.cpu = try detectNativeCpuWithLLVM(arch, llvm_cpu_name, llvm_cpu_features);
11651165 cross_target.updateCpuFeatures(&info.target.cpu.features);
1166 info.target.cpu.arch = cross_target.getCpuArch();
11661167 }
11671168 if (info.dynamic_linker.get()) |dl| {
11681169 dynamic_linker_ptr.* = try mem.dupeZ(std.heap.c_allocator, u8, dl);