authorgravatar for thejoshwolfe@gmail.comJosh Wolfe <thejoshwolfe@gmail.com> 2020-09-24 21:22:39-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-25 01:53:38-04:00
log1a8669eadaedc50fd7703412389f3c97fdffb913
tree0b99410dcc36f1d86324adddef0b9a3b91a98dac
parentbd89bd6fdbcc0ce5ea7763a8043fd46099022b19

build.zig: addBuildOptionArtifact


1 files changed, 23 insertions(+), 1 deletions(-)

lib/std/build.zig+23-1
......@@ -1165,6 +1165,11 @@ pub const FileSource = union(enum) {
11651165 }
11661166};
11671167
1168const BuildOptionArtifactArg = struct {
1169 name: []const u8,
1170 artifact: *LibExeObjStep,
1171};
1172
11681173pub const LibExeObjStep = struct {
11691174 step: Step,
11701175 builder: *Builder,
......@@ -1210,6 +1215,7 @@ pub const LibExeObjStep = struct {
12101215 out_pdb_filename: []const u8,
12111216 packages: ArrayList(Pkg),
12121217 build_options_contents: std.ArrayList(u8),
1218 build_options_artifact_args: std.ArrayList(BuildOptionArtifactArg),
12131219 system_linker_hack: bool = false,
12141220
12151221 object_src: []const u8,
......@@ -1355,6 +1361,7 @@ pub const LibExeObjStep = struct {
13551361 .framework_dirs = ArrayList([]const u8).init(builder.allocator),
13561362 .object_src = undefined,
13571363 .build_options_contents = std.ArrayList(u8).init(builder.allocator),
1364 .build_options_artifact_args = std.ArrayList(BuildOptionArtifactArg).init(builder.allocator),
13581365 .c_std = Builder.CStd.C99,
13591366 .override_lib_dir = null,
13601367 .main_pkg_path = null,
......@@ -1812,6 +1819,13 @@ pub const LibExeObjStep = struct {
18121819 out.print("pub const {} = {};\n", .{ name, value }) catch unreachable;
18131820 }
18141821
1822 /// The value is the path in the cache dir.
1823 /// Adds a dependency automatically.
1824 pub fn addBuildOptionArtifact(self: *LibExeObjStep, name: []const u8, artifact: *LibExeObjStep) void {
1825 self.build_options_artifact_args.append(.{ .name = name, .artifact = artifact }) catch unreachable;
1826 self.step.dependOn(&artifact.step);
1827 }
1828
18151829 pub fn addSystemIncludeDir(self: *LibExeObjStep, path: []const u8) void {
18161830 self.include_dirs.append(IncludeDir{ .RawPathSystem = self.builder.dupe(path) }) catch unreachable;
18171831 }
......@@ -1995,7 +2009,15 @@ pub const LibExeObjStep = struct {
19952009 }
19962010 }
19972011
1998 if (self.build_options_contents.items.len > 0) {
2012 if (self.build_options_contents.items.len > 0 or self.build_options_artifact_args.items.len > 0) {
2013 // Render build artifact options at the last minute, now that the path is known.
2014 for (self.build_options_artifact_args.items) |item| {
2015 const out = self.build_options_contents.writer();
2016 out.print("pub const {}: []const u8 = ", .{item.name}) catch unreachable;
2017 std.zig.renderStringLiteral(item.artifact.getOutputPath(), out) catch unreachable;
2018 out.writeAll(";\n") catch unreachable;
2019 }
2020
19992021 const build_options_file = try fs.path.join(
20002022 builder.allocator,
20012023 &[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) },