Commit c1798cb632

Layne Gustafson <lgustaf1@binghamton.edu>
2019-12-22 03:38:39
Add build.zig cpu and feature options
1 parent b3324f1
Changed files (1)
lib
lib/std/build.zig
@@ -1199,6 +1199,9 @@ pub const LibExeObjStep = struct {
 
     subsystem: ?builtin.SubSystem = null,
 
+    cpu: ?[]const u8 = null,
+    features: ?[]const u8 = null,
+
     const LinkObject = union(enum) {
         StaticPath: []const u8,
         OtherStep: *LibExeObjStep,
@@ -1384,6 +1387,23 @@ pub const LibExeObjStep = struct {
         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 {
         self.target_glibc = Version{
             .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| {
             try zig_args.append("-target-glibc");
             try zig_args.append(builder.fmt("{}.{}.{}", .{ ver.major, ver.minor, ver.patch }));