Skip to content

Commit

Permalink
std.build: fix handling of -Dcpu
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ifreund authored and andrewrk committed Sep 22, 2021
1 parent 5913140 commit 8c86043
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/std/build.zig
Expand Up @@ -684,7 +684,11 @@ pub const Builder = struct {
);
const mcpu = self.option([]const u8, "cpu", "Target CPU features to add or subtract");

const triple = maybe_triple orelse return args.default_target;
if (maybe_triple == null and mcpu == null) {
return args.default_target;
}

const triple = maybe_triple orelse "native";

var diags: CrossTarget.ParseOptions.Diagnostics = .{};
const selected_target = CrossTarget.parse(.{
Expand Down Expand Up @@ -2432,11 +2436,8 @@ pub const LibExeObjStep = struct {

if (populated_cpu_features.eql(cross.cpu.features)) {
// The CPU name alone is sufficient.
// If it is the baseline CPU, no command line args are required.
if (cross.cpu.model != std.Target.Cpu.baseline(cross.cpu.arch).model) {
try zig_args.append("-mcpu");
try zig_args.append(cross.cpu.model.name);
}
try zig_args.append("-mcpu");
try zig_args.append(cross.cpu.model.name);
} else {
var mcpu_buffer = std.ArrayList(u8).init(builder.allocator);

Expand Down

0 comments on commit 8c86043

Please sign in to comment.