aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJosh Wolfe <thejoshwolfe@gmail.com>2020-09-24 21:22:39 -0400
committerAndrew Kelley <andrew@ziglang.org>2020-09-25 01:53:38 -0400
commit1a8669eadaedc50fd7703412389f3c97fdffb913 (patch)
tree0b99410dcc36f1d86324adddef0b9a3b91a98dac /lib
parentbd89bd6fdbcc0ce5ea7763a8043fd46099022b19 (diff)
downloadzig-1a8669eadaedc50fd7703412389f3c97fdffb913.tar.gz
zig-1a8669eadaedc50fd7703412389f3c97fdffb913.zip
build.zig: addBuildOptionArtifact
Diffstat (limited to 'lib')
-rw-r--r--lib/std/build.zig24
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/std/build.zig b/lib/std/build.zig
index 69f44bad32..c0d7f0b8ed 100644
--- a/lib/std/build.zig
+++ b/lib/std/build.zig
@@ -1165,6 +1165,11 @@ pub const FileSource = union(enum) {
}
};
+const BuildOptionArtifactArg = struct {
+ name: []const u8,
+ artifact: *LibExeObjStep,
+};
+
pub const LibExeObjStep = struct {
step: Step,
builder: *Builder,
@@ -1210,6 +1215,7 @@ pub const LibExeObjStep = struct {
out_pdb_filename: []const u8,
packages: ArrayList(Pkg),
build_options_contents: std.ArrayList(u8),
+ build_options_artifact_args: std.ArrayList(BuildOptionArtifactArg),
system_linker_hack: bool = false,
object_src: []const u8,
@@ -1355,6 +1361,7 @@ pub const LibExeObjStep = struct {
.framework_dirs = ArrayList([]const u8).init(builder.allocator),
.object_src = undefined,
.build_options_contents = std.ArrayList(u8).init(builder.allocator),
+ .build_options_artifact_args = std.ArrayList(BuildOptionArtifactArg).init(builder.allocator),
.c_std = Builder.CStd.C99,
.override_lib_dir = null,
.main_pkg_path = null,
@@ -1812,6 +1819,13 @@ pub const LibExeObjStep = struct {
out.print("pub const {} = {};\n", .{ name, value }) catch unreachable;
}
+ /// The value is the path in the cache dir.
+ /// Adds a dependency automatically.
+ pub fn addBuildOptionArtifact(self: *LibExeObjStep, name: []const u8, artifact: *LibExeObjStep) void {
+ self.build_options_artifact_args.append(.{ .name = name, .artifact = artifact }) catch unreachable;
+ self.step.dependOn(&artifact.step);
+ }
+
pub fn addSystemIncludeDir(self: *LibExeObjStep, path: []const u8) void {
self.include_dirs.append(IncludeDir{ .RawPathSystem = self.builder.dupe(path) }) catch unreachable;
}
@@ -1995,7 +2009,15 @@ pub const LibExeObjStep = struct {
}
}
- if (self.build_options_contents.items.len > 0) {
+ if (self.build_options_contents.items.len > 0 or self.build_options_artifact_args.items.len > 0) {
+ // Render build artifact options at the last minute, now that the path is known.
+ for (self.build_options_artifact_args.items) |item| {
+ const out = self.build_options_contents.writer();
+ out.print("pub const {}: []const u8 = ", .{item.name}) catch unreachable;
+ std.zig.renderStringLiteral(item.artifact.getOutputPath(), out) catch unreachable;
+ out.writeAll(";\n") catch unreachable;
+ }
+
const build_options_file = try fs.path.join(
builder.allocator,
&[_][]const u8{ builder.cache_root, builder.fmt("{}_build_options.zig", .{self.name}) },