| author | |
| committer | |
| log | aa13f339d4d91f8e39f005821c172290e1a0227f |
| tree | e356ff138d61d7f5318f374e27fc714d64424d75 |
| parent | 8691d3c50d65c3e9e399c83cf2fc1a1173acb6d2 |
| signature |
3 files changed, 21 insertions(+), 15 deletions(-)
lib/std/zig/cross_target.zig+14-2| ... | @@ -10,8 +10,7 @@ pub const CrossTarget = struct { | ... | @@ -10,8 +10,7 @@ pub const CrossTarget = struct { |
| 10 | /// `null` means native. If this is `null` then `cpu_model` must be `null`. | 10 | /// `null` means native. If this is `null` then `cpu_model` must be `null`. |
| 11 | cpu_arch: ?Target.Cpu.Arch = null, | 11 | cpu_arch: ?Target.Cpu.Arch = null, |
| 12 | 12 | ||
| 13 | /// `null` means native. | 13 | /// `null` means native. If this is non-null, `cpu_arch` must be specified. |
| 14 | /// If this is non-null, `cpu_arch` must be specified. | ||
| 15 | cpu_model: ?*const Target.Cpu.Model = null, | 14 | cpu_model: ?*const Target.Cpu.Model = null, |
| 16 | 15 | ||
| 17 | /// Sparse set of CPU features to add to the set from `cpu_model`. | 16 | /// Sparse set of CPU features to add to the set from `cpu_model`. |
| ... | @@ -301,6 +300,10 @@ pub const CrossTarget = struct { | ... | @@ -301,6 +300,10 @@ pub const CrossTarget = struct { |
| 301 | return error.UnknownCpuFeature; | 300 | return error.UnknownCpuFeature; |
| 302 | } | 301 | } |
| 303 | } | 302 | } |
| 303 | } else if (arch_is_native) { | ||
| 304 | result.cpu_model = null; | ||
| 305 | } else { | ||
| 306 | result.cpu_model = Target.Cpu.Model.baseline(arch); | ||
| 304 | } | 307 | } |
| 305 | 308 | ||
| 306 | return result; | 309 | return result; |
| ... | @@ -725,6 +728,15 @@ pub const CrossTarget = struct { | ... | @@ -725,6 +728,15 @@ pub const CrossTarget = struct { |
| 725 | }; | 728 | }; |
| 726 | 729 | ||
| 727 | test "CrossTarget.parse" { | 730 | test "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 | } | ||
| 728 | { | 740 | { |
| 729 | const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" }); | 741 | const cross_target = try CrossTarget.parse(.{ .arch_os_abi = "native" }); |
| 730 | 742 |
lib/std/zig/system.zig+6-13| ... | @@ -192,21 +192,14 @@ pub const NativeTargetInfo = struct { | ... | @@ -192,21 +192,14 @@ pub const NativeTargetInfo = struct { |
| 192 | /// TODO Remove the Allocator requirement from this function. | 192 | /// TODO Remove the Allocator requirement from this function. |
| 193 | pub fn detect(allocator: *Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo { | 193 | pub fn detect(allocator: *Allocator, cross_target: CrossTarget) DetectError!NativeTargetInfo { |
| 194 | const cpu = blk: { | 194 | const cpu = blk: { |
| 195 | if (cross_target.cpu_arch) |arch| { | 195 | const arch = cross_target.getCpuArch(); |
| 196 | if (cross_target.cpu_model) |model| { | 196 | if (cross_target.cpu_model) |model| { |
| 197 | var adjusted_model = model.toCpu(arch); | 197 | var adjusted_model = model.toCpu(arch); |
| 198 | cross_target.updateCpuFeatures(&adjusted_model.features); | 198 | cross_target.updateCpuFeatures(&adjusted_model.features); |
| 199 | break :blk adjusted_model; | 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 | } | ||
| 206 | } else { | 200 | } else { |
| 207 | assert(cross_target.cpu_model == null); | ||
| 208 | // TODO Detect native CPU model & features. Until that is implemented we use baseline. | 201 | // 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); |
| 210 | cross_target.updateCpuFeatures(&adjusted_baseline.features); | 203 | cross_target.updateCpuFeatures(&adjusted_baseline.features); |
| 211 | break :blk adjusted_baseline; | 204 | break :blk adjusted_baseline; |
| 212 | } | 205 | } |
src-self-hosted/stage2.zig+1| ... | @@ -1163,6 +1163,7 @@ fn crossTargetToTarget(cross_target: CrossTarget, dynamic_linker_ptr: *?[*:0]u8) | ... | @@ -1163,6 +1163,7 @@ fn crossTargetToTarget(cross_target: CrossTarget, dynamic_linker_ptr: *?[*:0]u8) |
| 1163 | const arch = std.Target.current.cpu.arch; | 1163 | const arch = std.Target.current.cpu.arch; |
| 1164 | info.target.cpu = try detectNativeCpuWithLLVM(arch, llvm_cpu_name, llvm_cpu_features); | 1164 | info.target.cpu = try detectNativeCpuWithLLVM(arch, llvm_cpu_name, llvm_cpu_features); |
| 1165 | cross_target.updateCpuFeatures(&info.target.cpu.features); | 1165 | cross_target.updateCpuFeatures(&info.target.cpu.features); |
| 1166 | info.target.cpu.arch = cross_target.getCpuArch(); | ||
| 1166 | } | 1167 | } |
| 1167 | if (info.dynamic_linker.get()) |dl| { | 1168 | if (info.dynamic_linker.get()) |dl| { |
| 1168 | dynamic_linker_ptr.* = try mem.dupeZ(std.heap.c_allocator, u8, dl); | 1169 | dynamic_linker_ptr.* = try mem.dupeZ(std.heap.c_allocator, u8, dl); |