aboutsummaryrefslogtreecommitdiff
path: root/lib/std/Build/Step.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-01-31 00:19:51 -0700
committerAndrew Kelley <andrew@ziglang.org>2023-01-31 15:09:35 -0700
commit36e2d992dd8c45ca89a51d508c6c413cff5ad2cd (patch)
tree5e8a3244cf44c24b216959a475e0277e1ed424af /lib/std/Build/Step.zig
parent73cf7b64291ed8b5dcb4cb52df103be08f15a347 (diff)
downloadzig-36e2d992dd8c45ca89a51d508c6c413cff5ad2cd.tar.gz
zig-36e2d992dd8c45ca89a51d508c6c413cff5ad2cd.zip
combine std.build and std.build.Builder into std.Build
I've been wanting to do this for along time.
Diffstat (limited to 'lib/std/Build/Step.zig')
-rw-r--r--lib/std/Build/Step.zig97
1 files changed, 97 insertions, 0 deletions
diff --git a/lib/std/Build/Step.zig b/lib/std/Build/Step.zig
new file mode 100644
index 0000000000..86d6645c29
--- /dev/null
+++ b/lib/std/Build/Step.zig
@@ -0,0 +1,97 @@
+id: Id,
+name: []const u8,
+makeFn: *const fn (self: *Step) anyerror!void,
+dependencies: std.ArrayList(*Step),
+loop_flag: bool,
+done_flag: bool,
+
+pub const Id = enum {
+ top_level,
+ lib_exe_obj,
+ install_artifact,
+ install_file,
+ install_dir,
+ log,
+ remove_dir,
+ fmt,
+ translate_c,
+ write_file,
+ run,
+ emulatable_run,
+ check_file,
+ check_object,
+ config_header,
+ install_raw,
+ options,
+ custom,
+
+ pub fn Type(comptime id: Id) type {
+ return switch (id) {
+ .top_level => Build.TopLevelStep,
+ .lib_exe_obj => Build.LibExeObjStep,
+ .install_artifact => Build.InstallArtifactStep,
+ .install_file => Build.InstallFileStep,
+ .install_dir => Build.InstallDirStep,
+ .log => Build.LogStep,
+ .remove_dir => Build.RemoveDirStep,
+ .fmt => Build.FmtStep,
+ .translate_c => Build.TranslateCStep,
+ .write_file => Build.WriteFileStep,
+ .run => Build.RunStep,
+ .emulatable_run => Build.EmulatableRunStep,
+ .check_file => Build.CheckFileStep,
+ .check_object => Build.CheckObjectStep,
+ .config_header => Build.ConfigHeaderStep,
+ .install_raw => Build.InstallRawStep,
+ .options => Build.OptionsStep,
+ .custom => @compileError("no type available for custom step"),
+ };
+ }
+};
+
+pub fn init(
+ id: Id,
+ name: []const u8,
+ allocator: Allocator,
+ makeFn: *const fn (self: *Step) anyerror!void,
+) Step {
+ return Step{
+ .id = id,
+ .name = allocator.dupe(u8, name) catch unreachable,
+ .makeFn = makeFn,
+ .dependencies = std.ArrayList(*Step).init(allocator),
+ .loop_flag = false,
+ .done_flag = false,
+ };
+}
+
+pub fn initNoOp(id: Id, name: []const u8, allocator: Allocator) Step {
+ return init(id, name, allocator, makeNoOp);
+}
+
+pub fn make(self: *Step) !void {
+ if (self.done_flag) return;
+
+ try self.makeFn(self);
+ self.done_flag = true;
+}
+
+pub fn dependOn(self: *Step, other: *Step) void {
+ self.dependencies.append(other) catch unreachable;
+}
+
+fn makeNoOp(self: *Step) anyerror!void {
+ _ = self;
+}
+
+pub fn cast(step: *Step, comptime T: type) ?*T {
+ if (step.id == T.base_id) {
+ return @fieldParentPtr(T, "step", step);
+ }
+ return null;
+}
+
+const Step = @This();
+const std = @import("../std.zig");
+const Build = std.Build;
+const Allocator = std.mem.Allocator;