Add build.zig cpu and feature options

master
Layne Gustafson 2019-12-21 21:38:39 -05:00 committed by Andrew Kelley
parent b3324f1901
commit c1798cb632
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
1 changed files with 30 additions and 0 deletions

View File

@ -1199,6 +1199,9 @@ pub const LibExeObjStep = struct {
subsystem: ?builtin.SubSystem = null, subsystem: ?builtin.SubSystem = null,
cpu: ?[]const u8 = null,
features: ?[]const u8 = null,
const LinkObject = union(enum) { const LinkObject = union(enum) {
StaticPath: []const u8, StaticPath: []const u8,
OtherStep: *LibExeObjStep, OtherStep: *LibExeObjStep,
@ -1384,6 +1387,23 @@ pub const LibExeObjStep = struct {
self.computeOutFileNames(); self.computeOutFileNames();
} }
pub fn setCpu(self: *LibExeObjStep, cpu: *const std.target.Cpu) void {
self.cpu = cpu.name;
}
pub fn setFeatures(self: *LibExeObjStep, features: []*const std.target.Feature) void {
var features_str_buffer = std.Buffer.init(self.builder.allocator, "") catch unreachable;
defer features_str_buffer.deinit();
for (features) |feature| {
features_str_buffer.append("+") catch unreachable;
features_str_buffer.append(feature.name) catch unreachable;
features_str_buffer.append(",") catch unreachable;
}
self.features = features_str_buffer.toOwnedSlice();
}
pub fn setTargetGLibC(self: *LibExeObjStep, major: u32, minor: u32, patch: u32) void { pub fn setTargetGLibC(self: *LibExeObjStep, major: u32, minor: u32, patch: u32) void {
self.target_glibc = Version{ self.target_glibc = Version{
.major = major, .major = major,
@ -1974,6 +1994,16 @@ pub const LibExeObjStep = struct {
}, },
} }
if (self.cpu) |cpu| {
try zig_args.append("--cpu");
try zig_args.append(cpu);
}
if (self.features) |features| {
try zig_args.append("--features");
try zig_args.append(features);
}
if (self.target_glibc) |ver| { if (self.target_glibc) |ver| {
try zig_args.append("-target-glibc"); try zig_args.append("-target-glibc");
try zig_args.append(builder.fmt("{}.{}.{}", .{ ver.major, ver.minor, ver.patch })); try zig_args.append(builder.fmt("{}.{}.{}", .{ ver.major, ver.minor, ver.patch }));