Skip to content

Commit 410b4d9

Browse files
committedJul 8, 2018
builder.addBuildOption
1 parent ced3aae commit 410b4d9

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 

‎std/build.zig

+18
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,7 @@ pub const LibExeObjStep = struct {
814814
out_h_filename: []const u8,
815815
assembly_files: ArrayList([]const u8),
816816
packages: ArrayList(Pkg),
817+
build_options_contents: std.Buffer,
817818

818819
// C only stuff
819820
source_files: ArrayList([]const u8),
@@ -905,6 +906,7 @@ pub const LibExeObjStep = struct {
905906
.lib_paths = ArrayList([]const u8).init(builder.allocator),
906907
.object_src = undefined,
907908
.disable_libc = true,
909+
.build_options_contents = std.Buffer.initSize(builder.allocator, 0) catch unreachable,
908910
};
909911
self.computeOutFileNames();
910912
return self;
@@ -945,6 +947,7 @@ pub const LibExeObjStep = struct {
945947
.out_h_filename = undefined,
946948
.assembly_files = undefined,
947949
.packages = undefined,
950+
.build_options_contents = undefined,
948951
};
949952
self.computeOutFileNames();
950953
return self;
@@ -1096,6 +1099,12 @@ pub const LibExeObjStep = struct {
10961099
self.include_dirs.append(self.builder.cache_root) catch unreachable;
10971100
}
10981101

1102+
pub fn addBuildOption(self: *LibExeObjStep, comptime T: type, name: []const u8, value: T) void {
1103+
assert(self.is_zig);
1104+
const out = &std.io.BufferOutStream.init(&self.build_options_contents).stream;
1105+
out.print("pub const {} = {};\n", name, value) catch unreachable;
1106+
}
1107+
10991108
pub fn addIncludeDir(self: *LibExeObjStep, path: []const u8) void {
11001109
self.include_dirs.append(path) catch unreachable;
11011110
}
@@ -1155,6 +1164,15 @@ pub const LibExeObjStep = struct {
11551164
zig_args.append(builder.pathFromRoot(root_src)) catch unreachable;
11561165
}
11571166

1167+
if (self.build_options_contents.len() > 0) {
1168+
const build_options_file = try os.path.join(builder.allocator, builder.cache_root, builder.fmt("{}_build_options.zig", self.name));
1169+
try std.io.writeFile(builder.allocator, build_options_file, self.build_options_contents.toSliceConst());
1170+
try zig_args.append("--pkg-begin");
1171+
try zig_args.append("build_options");
1172+
try zig_args.append(builder.pathFromRoot(build_options_file));
1173+
try zig_args.append("--pkg-end");
1174+
}
1175+
11581176
for (self.object_files.toSliceConst()) |object_file| {
11591177
zig_args.append("--object") catch unreachable;
11601178
zig_args.append(builder.pathFromRoot(object_file)) catch unreachable;

0 commit comments

Comments
 (0)
Please sign in to comment.