authorgravatar for mail@isaacfreund.comIsaac Freund <mail@isaacfreund.com> 2021-09-21 21:06:10+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-09-22 00:46:37-04:00
log8c86043178a30a75aa9ff58b4432964237fb52dc
tree353cf610a986a281fd88e02879fdfc18903e308e
parent5913140b6bf96e168a0167906a78e2d4aac5bd9d

std.build: fix handling of -Dcpu

Currently -Dcpu is completely ignored if -Dtarget isn't passed as well. Further, -Dcpu=baseline is ignored even if -Dtarget=native is passed. This patch fixes these 2 issues, always respecting the -Dcpu option if present.

1 files changed, 7 insertions(+), 6 deletions(-)

lib/std/build.zig+7-6
...@@ -684,7 +684,11 @@ pub const Builder = struct {...@@ -684,7 +684,11 @@ pub const Builder = struct {
684 );684 );
685 const mcpu = self.option([]const u8, "cpu", "Target CPU features to add or subtract");685 const mcpu = self.option([]const u8, "cpu", "Target CPU features to add or subtract");
686686
687 const triple = maybe_triple orelse return args.default_target;687 if (maybe_triple == null and mcpu == null) {
688 return args.default_target;
689 }
690
691 const triple = maybe_triple orelse "native";
688692
689 var diags: CrossTarget.ParseOptions.Diagnostics = .{};693 var diags: CrossTarget.ParseOptions.Diagnostics = .{};
690 const selected_target = CrossTarget.parse(.{694 const selected_target = CrossTarget.parse(.{
...@@ -2432,11 +2436,8 @@ pub const LibExeObjStep = struct {...@@ -2432,11 +2436,8 @@ pub const LibExeObjStep = struct {
24322436
2433 if (populated_cpu_features.eql(cross.cpu.features)) {2437 if (populated_cpu_features.eql(cross.cpu.features)) {
2434 // The CPU name alone is sufficient.2438 // The CPU name alone is sufficient.
2435 // If it is the baseline CPU, no command line args are required.2439 try zig_args.append("-mcpu");
2436 if (cross.cpu.model != std.Target.Cpu.baseline(cross.cpu.arch).model) {2440 try zig_args.append(cross.cpu.model.name);
2437 try zig_args.append("-mcpu");
2438 try zig_args.append(cross.cpu.model.name);
2439 }
2440 } else {2441 } else {
2441 var mcpu_buffer = std.ArrayList(u8).init(builder.allocator);2442 var mcpu_buffer = std.ArrayList(u8).init(builder.allocator);
24422443