authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-05-03 11:49:55+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-03 20:55:29-07:00
log3f3b1a6808113fd5f9b2cec1033009cbb17dc969
tree7893be58b9b8c8edfffdc8127a6b133ec823e141
parent5def162391da5050761beb3e6efb24b99716fc99

std.Build: use Step.* instead of *Step

Follow up to 13eb7251d37759bd47403db304c6120c706fe353

27 files changed, 379 insertions(+), 361 deletions(-)

build.zig+6-6
......@@ -533,7 +533,7 @@ fn addCompilerStep(
533533 b: *std.Build,
534534 optimize: std.builtin.OptimizeMode,
535535 target: std.zig.CrossTarget,
536) *std.Build.CompileStep {
536) *std.Build.Step.Compile {
537537 const exe = b.addExecutable(.{
538538 .name = "zig",
539539 .root_source_file = .{ .path = "src/main.zig" },
......@@ -561,7 +561,7 @@ const exe_cflags = [_][]const u8{
561561fn addCmakeCfgOptionsToExe(
562562 b: *std.Build,
563563 cfg: CMakeConfig,
564 exe: *std.Build.CompileStep,
564 exe: *std.Build.Step.Compile,
565565 use_zig_libcxx: bool,
566566) !void {
567567 if (exe.target.isDarwin()) {
......@@ -640,7 +640,7 @@ fn addCmakeCfgOptionsToExe(
640640 }
641641}
642642
643fn addStaticLlvmOptionsToExe(exe: *std.Build.CompileStep) !void {
643fn addStaticLlvmOptionsToExe(exe: *std.Build.Step.Compile) !void {
644644 // Adds the Zig C++ sources which both stage1 and stage2 need.
645645 //
646646 // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
......@@ -679,7 +679,7 @@ fn addStaticLlvmOptionsToExe(exe: *std.Build.CompileStep) !void {
679679fn addCxxKnownPath(
680680 b: *std.Build,
681681 ctx: CMakeConfig,
682 exe: *std.Build.CompileStep,
682 exe: *std.Build.Step.Compile,
683683 objname: []const u8,
684684 errtxt: ?[]const u8,
685685 need_cpp_includes: bool,
......@@ -709,7 +709,7 @@ fn addCxxKnownPath(
709709 }
710710}
711711
712fn addCMakeLibraryList(exe: *std.Build.CompileStep, list: []const u8) void {
712fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void {
713713 var it = mem.tokenize(u8, list, ";");
714714 while (it.next()) |lib| {
715715 if (mem.startsWith(u8, lib, "-l")) {
......@@ -723,7 +723,7 @@ fn addCMakeLibraryList(exe: *std.Build.CompileStep, list: []const u8) void {
723723}
724724
725725const CMakeConfig = struct {
726 llvm_linkage: std.Build.CompileStep.Linkage,
726 llvm_linkage: std.Build.Step.Compile.Linkage,
727727 cmake_binary_dir: []const u8,
728728 cmake_prefix_path: []const u8,
729729 cmake_static_library_prefix: []const u8,
lib/init-exe/build.zig+1-1
......@@ -29,7 +29,7 @@ pub fn build(b: *std.Build) void {
2929 // step when running `zig build`).
3030 b.installArtifact(exe);
3131
32 // This *creates* a RunStep in the build graph, to be executed when another
32 // This *creates* a Run step in the build graph, to be executed when another
3333 // step is evaluated that depends on it. The next line below will establish
3434 // such a dependency.
3535 const run_cmd = b.addRunArtifact(exe);
lib/std/Build.zig+76-74
......@@ -21,27 +21,41 @@ const Build = @This();
2121
2222pub const Cache = @import("Build/Cache.zig");
2323
24/// deprecated: use `CompileStep`.
25pub const LibExeObjStep = CompileStep;
24/// deprecated: use `Step.Compile`.
25pub const LibExeObjStep = Step.Compile;
2626/// deprecated: use `Build`.
2727pub const Builder = Build;
28/// deprecated: use `InstallDirStep.Options`
29pub const InstallDirectoryOptions = InstallDirStep.Options;
28/// deprecated: use `Step.InstallDir.Options`
29pub const InstallDirectoryOptions = Step.InstallDir.Options;
3030
3131pub const Step = @import("Build/Step.zig");
32/// deprecated: use `Step.CheckFile`.
3233pub const CheckFileStep = @import("Build/Step/CheckFile.zig");
34/// deprecated: use `Step.CheckObject`.
3335pub const CheckObjectStep = @import("Build/Step/CheckObject.zig");
36/// deprecated: use `Step.ConfigHeader`.
3437pub const ConfigHeaderStep = @import("Build/Step/ConfigHeader.zig");
38/// deprecated: use `Step.Fmt`.
3539pub const FmtStep = @import("Build/Step/Fmt.zig");
40/// deprecated: use `Step.InstallArtifact`.
3641pub const InstallArtifactStep = @import("Build/Step/InstallArtifact.zig");
42/// deprecated: use `Step.InstallDir`.
3743pub const InstallDirStep = @import("Build/Step/InstallDir.zig");
44/// deprecated: use `Step.InstallFile`.
3845pub const InstallFileStep = @import("Build/Step/InstallFile.zig");
46/// deprecated: use `Step.ObjCopy`.
3947pub const ObjCopyStep = @import("Build/Step/ObjCopy.zig");
48/// deprecated: use `Step.Compile`.
4049pub const CompileStep = @import("Build/Step/Compile.zig");
50/// deprecated: use `Step.Options`.
4151pub const OptionsStep = @import("Build/Step/Options.zig");
52/// deprecated: use `Step.RemoveDir`.
4253pub const RemoveDirStep = @import("Build/Step/RemoveDir.zig");
54/// deprecated: use `Step.Run`.
4355pub const RunStep = @import("Build/Step/Run.zig");
56/// deprecated: use `Step.TranslateC`.
4457pub const TranslateCStep = @import("Build/Step/TranslateC.zig");
58/// deprecated: use `Step.WriteFile`.
4559pub const WriteFileStep = @import("Build/Step/WriteFile.zig");
4660
4761install_tls: TopLevelStep,
......@@ -442,8 +456,8 @@ pub fn resolveInstallPrefix(self: *Build, install_prefix: ?[]const u8, dir_list:
442456 self.h_dir = self.pathJoin(&h_list);
443457}
444458
445pub fn addOptions(self: *Build) *OptionsStep {
446 return OptionsStep.create(self);
459pub fn addOptions(self: *Build) *Step.Options {
460 return Step.Options.create(self);
447461}
448462
449463pub const ExecutableOptions = struct {
......@@ -452,7 +466,7 @@ pub const ExecutableOptions = struct {
452466 version: ?std.builtin.Version = null,
453467 target: CrossTarget = .{},
454468 optimize: std.builtin.Mode = .Debug,
455 linkage: ?CompileStep.Linkage = null,
469 linkage: ?Step.Compile.Linkage = null,
456470 max_rss: usize = 0,
457471 link_libc: ?bool = null,
458472 single_threaded: ?bool = null,
......@@ -460,8 +474,8 @@ pub const ExecutableOptions = struct {
460474 use_lld: ?bool = null,
461475};
462476
463pub fn addExecutable(b: *Build, options: ExecutableOptions) *CompileStep {
464 return CompileStep.create(b, .{
477pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
478 return Step.Compile.create(b, .{
465479 .name = options.name,
466480 .root_source_file = options.root_source_file,
467481 .version = options.version,
......@@ -489,8 +503,8 @@ pub const ObjectOptions = struct {
489503 use_lld: ?bool = null,
490504};
491505
492pub fn addObject(b: *Build, options: ObjectOptions) *CompileStep {
493 return CompileStep.create(b, .{
506pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
507 return Step.Compile.create(b, .{
494508 .name = options.name,
495509 .root_source_file = options.root_source_file,
496510 .target = options.target,
......@@ -517,8 +531,8 @@ pub const SharedLibraryOptions = struct {
517531 use_lld: ?bool = null,
518532};
519533
520pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *CompileStep {
521 return CompileStep.create(b, .{
534pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile {
535 return Step.Compile.create(b, .{
522536 .name = options.name,
523537 .root_source_file = options.root_source_file,
524538 .kind = .lib,
......@@ -547,8 +561,8 @@ pub const StaticLibraryOptions = struct {
547561 use_lld: ?bool = null,
548562};
549563
550pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *CompileStep {
551 return CompileStep.create(b, .{
564pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile {
565 return Step.Compile.create(b, .{
552566 .name = options.name,
553567 .root_source_file = options.root_source_file,
554568 .kind = .lib,
......@@ -579,8 +593,8 @@ pub const TestOptions = struct {
579593 use_lld: ?bool = null,
580594};
581595
582pub fn addTest(b: *Build, options: TestOptions) *CompileStep {
583 return CompileStep.create(b, .{
596pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
597 return Step.Compile.create(b, .{
584598 .name = options.name,
585599 .kind = .@"test",
586600 .root_source_file = options.root_source_file,
......@@ -604,8 +618,8 @@ pub const AssemblyOptions = struct {
604618 max_rss: usize = 0,
605619};
606620
607pub fn addAssembly(b: *Build, options: AssemblyOptions) *CompileStep {
608 const obj_step = CompileStep.create(b, .{
621pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile {
622 const obj_step = Step.Compile.create(b, .{
609623 .name = options.name,
610624 .kind = .obj,
611625 .root_source_file = null,
......@@ -657,25 +671,25 @@ fn moduleDependenciesToArrayHashMap(arena: Allocator, deps: []const ModuleDepend
657671 return result;
658672}
659673
660/// Initializes a RunStep with argv, which must at least have the path to the
674/// Initializes a `Step.Run` with argv, which must at least have the path to the
661675/// executable. More command line arguments can be added with `addArg`,
662676/// `addArgs`, and `addArtifactArg`.
663677/// Be careful using this function, as it introduces a system dependency.
664/// To run an executable built with zig build, see `CompileStep.run`.
665pub fn addSystemCommand(self: *Build, argv: []const []const u8) *RunStep {
678/// To run an executable built with zig build, see `Step.Compile.run`.
679pub fn addSystemCommand(self: *Build, argv: []const []const u8) *Step.Run {
666680 assert(argv.len >= 1);
667 const run_step = RunStep.create(self, self.fmt("run {s}", .{argv[0]}));
681 const run_step = Step.Run.create(self, self.fmt("run {s}", .{argv[0]}));
668682 run_step.addArgs(argv);
669683 return run_step;
670684}
671685
672/// Creates a `RunStep` with an executable built with `addExecutable`.
673/// Add command line arguments with methods of `RunStep`.
674pub fn addRunArtifact(b: *Build, exe: *CompileStep) *RunStep {
686/// Creates a `Step.Run` with an executable built with `addExecutable`.
687/// Add command line arguments with methods of `Step.Run`.
688pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run {
675689 // It doesn't have to be native. We catch that if you actually try to run it.
676690 // Consider that this is declarative; the run step may not be run unless a user
677691 // option is supplied.
678 const run_step = RunStep.create(b, b.fmt("run {s}", .{exe.name}));
692 const run_step = Step.Run.create(b, b.fmt("run {s}", .{exe.name}));
679693 run_step.addArtifactArg(exe);
680694
681695 if (exe.kind == .@"test") {
......@@ -696,14 +710,14 @@ pub fn addRunArtifact(b: *Build, exe: *CompileStep) *RunStep {
696710/// when an option found in the input file is missing from `values`.
697711pub fn addConfigHeader(
698712 b: *Build,
699 options: ConfigHeaderStep.Options,
713 options: Step.ConfigHeader.Options,
700714 values: anytype,
701) *ConfigHeaderStep {
715) *Step.ConfigHeader {
702716 var options_copy = options;
703717 if (options_copy.first_ret_addr == null)
704718 options_copy.first_ret_addr = @returnAddress();
705719
706 const config_header_step = ConfigHeaderStep.create(b, options_copy);
720 const config_header_step = Step.ConfigHeader.create(b, options_copy);
707721 config_header_step.addValues(values);
708722 return config_header_step;
709723}
......@@ -734,28 +748,28 @@ pub fn dupePath(self: *Build, bytes: []const u8) []u8 {
734748 return the_copy;
735749}
736750
737pub fn addWriteFile(self: *Build, file_path: []const u8, data: []const u8) *WriteFileStep {
751pub fn addWriteFile(self: *Build, file_path: []const u8, data: []const u8) *Step.WriteFile {
738752 const write_file_step = self.addWriteFiles();
739753 write_file_step.add(file_path, data);
740754 return write_file_step;
741755}
742756
743pub fn addWriteFiles(b: *Build) *WriteFileStep {
744 return WriteFileStep.create(b);
757pub fn addWriteFiles(b: *Build) *Step.WriteFile {
758 return Step.WriteFile.create(b);
745759}
746760
747pub fn addRemoveDirTree(self: *Build, dir_path: []const u8) *RemoveDirStep {
748 const remove_dir_step = self.allocator.create(RemoveDirStep) catch @panic("OOM");
749 remove_dir_step.* = RemoveDirStep.init(self, dir_path);
761pub fn addRemoveDirTree(self: *Build, dir_path: []const u8) *Step.RemoveDir {
762 const remove_dir_step = self.allocator.create(Step.RemoveDir) catch @panic("OOM");
763 remove_dir_step.* = Step.RemoveDir.init(self, dir_path);
750764 return remove_dir_step;
751765}
752766
753pub fn addFmt(b: *Build, options: FmtStep.Options) *FmtStep {
754 return FmtStep.create(b, options);
767pub fn addFmt(b: *Build, options: Step.Fmt.Options) *Step.Fmt {
768 return Step.Fmt.create(b, options);
755769}
756770
757pub fn addTranslateC(self: *Build, options: TranslateCStep.Options) *TranslateCStep {
758 return TranslateCStep.create(self, options);
771pub fn addTranslateC(self: *Build, options: Step.TranslateC.Options) *Step.TranslateC {
772 return Step.TranslateC.create(self, options);
759773}
760774
761775pub fn getInstallStep(self: *Build) *Step {
......@@ -1213,12 +1227,12 @@ fn printCmd(ally: Allocator, cwd: ?[]const u8, argv: []const []const u8) void {
12131227 std.debug.print("{s}\n", .{text});
12141228}
12151229
1216pub fn installArtifact(self: *Build, artifact: *CompileStep) void {
1230pub fn installArtifact(self: *Build, artifact: *Step.Compile) void {
12171231 self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step);
12181232}
12191233
1220pub fn addInstallArtifact(self: *Build, artifact: *CompileStep) *InstallArtifactStep {
1221 return InstallArtifactStep.create(self, artifact);
1234pub fn addInstallArtifact(self: *Build, artifact: *Step.Compile) *Step.InstallArtifact {
1235 return Step.InstallArtifact.create(self, artifact);
12221236}
12231237
12241238///`dest_rel_path` is relative to prefix path
......@@ -1240,26 +1254,26 @@ pub fn installLibFile(self: *Build, src_path: []const u8, dest_rel_path: []const
12401254 self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .lib, dest_rel_path).step);
12411255}
12421256
1243pub fn addObjCopy(b: *Build, source: FileSource, options: ObjCopyStep.Options) *ObjCopyStep {
1244 return ObjCopyStep.create(b, source, options);
1257pub fn addObjCopy(b: *Build, source: FileSource, options: Step.ObjCopy.Options) *Step.ObjCopy {
1258 return Step.ObjCopy.create(b, source, options);
12451259}
12461260
12471261///`dest_rel_path` is relative to install prefix path
1248pub fn addInstallFile(self: *Build, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {
1262pub fn addInstallFile(self: *Build, source: FileSource, dest_rel_path: []const u8) *Step.InstallFile {
12491263 return self.addInstallFileWithDir(source.dupe(self), .prefix, dest_rel_path);
12501264}
12511265
12521266///`dest_rel_path` is relative to bin path
1253pub fn addInstallBinFile(self: *Build, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {
1267pub fn addInstallBinFile(self: *Build, source: FileSource, dest_rel_path: []const u8) *Step.InstallFile {
12541268 return self.addInstallFileWithDir(source.dupe(self), .bin, dest_rel_path);
12551269}
12561270
12571271///`dest_rel_path` is relative to lib path
1258pub fn addInstallLibFile(self: *Build, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {
1272pub fn addInstallLibFile(self: *Build, source: FileSource, dest_rel_path: []const u8) *Step.InstallFile {
12591273 return self.addInstallFileWithDir(source.dupe(self), .lib, dest_rel_path);
12601274}
12611275
1262pub fn addInstallHeaderFile(b: *Build, src_path: []const u8, dest_rel_path: []const u8) *InstallFileStep {
1276pub fn addInstallHeaderFile(b: *Build, src_path: []const u8, dest_rel_path: []const u8) *Step.InstallFile {
12631277 return b.addInstallFileWithDir(.{ .path = src_path }, .header, dest_rel_path);
12641278}
12651279
......@@ -1268,22 +1282,22 @@ pub fn addInstallFileWithDir(
12681282 source: FileSource,
12691283 install_dir: InstallDir,
12701284 dest_rel_path: []const u8,
1271) *InstallFileStep {
1272 return InstallFileStep.create(self, source.dupe(self), install_dir, dest_rel_path);
1285) *Step.InstallFile {
1286 return Step.InstallFile.create(self, source.dupe(self), install_dir, dest_rel_path);
12731287}
12741288
1275pub fn addInstallDirectory(self: *Build, options: InstallDirectoryOptions) *InstallDirStep {
1276 const install_step = self.allocator.create(InstallDirStep) catch @panic("OOM");
1277 install_step.* = InstallDirStep.init(self, options);
1289pub fn addInstallDirectory(self: *Build, options: InstallDirectoryOptions) *Step.InstallDir {
1290 const install_step = self.allocator.create(Step.InstallDir) catch @panic("OOM");
1291 install_step.* = Step.InstallDir.init(self, options);
12781292 return install_step;
12791293}
12801294
12811295pub fn addCheckFile(
12821296 b: *Build,
12831297 file_source: FileSource,
1284 options: CheckFileStep.Options,
1285) *CheckFileStep {
1286 return CheckFileStep.create(b, file_source, options);
1298 options: Step.CheckFile.Options,
1299) *Step.CheckFile {
1300 return Step.CheckFile.create(b, file_source, options);
12871301}
12881302
12891303pub fn pushInstalledFile(self: *Build, dir: InstallDir, dest_rel_path: []const u8) void {
......@@ -1453,10 +1467,10 @@ pub fn getInstallPath(self: *Build, dir: InstallDir, dest_rel_path: []const u8)
14531467pub const Dependency = struct {
14541468 builder: *Build,
14551469
1456 pub fn artifact(d: *Dependency, name: []const u8) *CompileStep {
1457 var found: ?*CompileStep = null;
1470 pub fn artifact(d: *Dependency, name: []const u8) *Step.Compile {
1471 var found: ?*Step.Compile = null;
14581472 for (d.builder.install_tls.step.dependencies.items) |dep_step| {
1459 const inst = dep_step.cast(InstallArtifactStep) orelse continue;
1473 const inst = dep_step.cast(Step.InstallArtifact) orelse continue;
14601474 if (mem.eql(u8, inst.artifact.name, name)) {
14611475 if (found != null) panic("artifact name '{s}' is ambiguous", .{name});
14621476 found = inst.artifact;
......@@ -1464,7 +1478,7 @@ pub const Dependency = struct {
14641478 }
14651479 return found orelse {
14661480 for (d.builder.install_tls.step.dependencies.items) |dep_step| {
1467 const inst = dep_step.cast(InstallArtifactStep) orelse continue;
1481 const inst = dep_step.cast(Step.InstallArtifact) orelse continue;
14681482 log.info("available artifact: '{s}'", .{inst.artifact.name});
14691483 }
14701484 panic("unable to find artifact '{s}'", .{name});
......@@ -1808,17 +1822,5 @@ pub fn hex64(x: u64) [16]u8 {
18081822}
18091823
18101824test {
1811 _ = CheckFileStep;
1812 _ = CheckObjectStep;
1813 _ = FmtStep;
1814 _ = InstallArtifactStep;
1815 _ = InstallDirStep;
1816 _ = InstallFileStep;
1817 _ = ObjCopyStep;
1818 _ = CompileStep;
1819 _ = OptionsStep;
1820 _ = RemoveDirStep;
1821 _ = RunStep;
1822 _ = TranslateCStep;
1823 _ = WriteFileStep;
1825 _ = Step;
18241826}
lib/std/Build/Step.zig+49-18
......@@ -94,26 +94,41 @@ pub const Id = enum {
9494 pub fn Type(comptime id: Id) type {
9595 return switch (id) {
9696 .top_level => Build.TopLevelStep,
97 .compile => Build.CompileStep,
98 .install_artifact => Build.InstallArtifactStep,
99 .install_file => Build.InstallFileStep,
100 .install_dir => Build.InstallDirStep,
101 .remove_dir => Build.RemoveDirStep,
102 .fmt => Build.FmtStep,
103 .translate_c => Build.TranslateCStep,
104 .write_file => Build.WriteFileStep,
105 .run => Build.RunStep,
106 .check_file => Build.CheckFileStep,
107 .check_object => Build.CheckObjectStep,
108 .config_header => Build.ConfigHeaderStep,
109 .objcopy => Build.ObjCopyStep,
110 .options => Build.OptionsStep,
97 .compile => Compile,
98 .install_artifact => InstallArtifact,
99 .install_file => InstallFile,
100 .install_dir => InstallDir,
101 .remove_dir => RemoveDir,
102 .fmt => Fmt,
103 .translate_c => TranslateC,
104 .write_file => WriteFile,
105 .run => Run,
106 .check_file => CheckFile,
107 .check_object => CheckObject,
108 .config_header => ConfigHeader,
109 .objcopy => ObjCopy,
110 .options => Options,
111111 .custom => @compileError("no type available for custom step"),
112112 };
113113 }
114114};
115115
116pub const Options = struct {
116pub const CheckFile = @import("Step/CheckFile.zig");
117pub const CheckObject = @import("Step/CheckObject.zig");
118pub const ConfigHeader = @import("Step/ConfigHeader.zig");
119pub const Fmt = @import("Step/Fmt.zig");
120pub const InstallArtifact = @import("Step/InstallArtifact.zig");
121pub const InstallDir = @import("Step/InstallDir.zig");
122pub const InstallFile = @import("Step/InstallFile.zig");
123pub const ObjCopy = @import("Step/ObjCopy.zig");
124pub const Compile = @import("Step/Compile.zig");
125pub const Options = @import("Step/Options.zig");
126pub const RemoveDir = @import("Step/RemoveDir.zig");
127pub const Run = @import("Step/Run.zig");
128pub const TranslateC = @import("Step/TranslateC.zig");
129pub const WriteFile = @import("Step/WriteFile.zig");
130
131pub const StepOptions = struct {
117132 id: Id,
118133 name: []const u8,
119134 owner: *Build,
......@@ -122,7 +137,7 @@ pub const Options = struct {
122137 max_rss: usize = 0,
123138};
124139
125pub fn init(options: Options) Step {
140pub fn init(options: StepOptions) Step {
126141 const arena = options.owner.allocator;
127142
128143 var addresses = [1]usize{0} ** n_debug_stack_frames;
......@@ -387,8 +402,8 @@ pub fn evalZigProcess(
387402 s.result_duration_ns = timer.read();
388403 s.result_peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0;
389404
390 // Special handling for CompileStep that is expecting compile errors.
391 if (s.cast(Build.CompileStep)) |compile| switch (term) {
405 // Special handling for Compile step that is expecting compile errors.
406 if (s.cast(Compile)) |compile| switch (term) {
392407 .Exited => {
393408 // Note that the exit code may be 0 in this case due to the
394409 // compiler server protocol.
......@@ -535,3 +550,19 @@ pub fn writeManifest(s: *Step, man: *std.Build.Cache.Manifest) !void {
535550 };
536551 }
537552}
553
554test {
555 _ = CheckFile;
556 _ = CheckObject;
557 _ = Fmt;
558 _ = InstallArtifact;
559 _ = InstallDir;
560 _ = InstallFile;
561 _ = ObjCopy;
562 _ = Compile;
563 _ = Options;
564 _ = RemoveDir;
565 _ = Run;
566 _ = TranslateC;
567 _ = WriteFile;
568}
lib/std/Build/Step/CheckFile.zig+6-6
......@@ -1,8 +1,8 @@
11//! Fail the build step if a file does not match certain checks.
22//! TODO: make this more flexible, supporting more kinds of checks.
33//! TODO: generalize the code in std.testing.expectEqualStrings and make this
4//! CheckFileStep produce those helpful diagnostics when there is not a match.
5const CheckFileStep = @This();
4//! CheckFile step produce those helpful diagnostics when there is not a match.
5const CheckFile = @This();
66const std = @import("std");
77const Step = std.Build.Step;
88const fs = std.fs;
......@@ -25,8 +25,8 @@ pub fn create(
2525 owner: *std.Build,
2626 source: std.Build.FileSource,
2727 options: Options,
28) *CheckFileStep {
29 const self = owner.allocator.create(CheckFileStep) catch @panic("OOM");
28) *CheckFile {
29 const self = owner.allocator.create(CheckFile) catch @panic("OOM");
3030 self.* = .{
3131 .step = Step.init(.{
3232 .id = .check_file,
......@@ -42,14 +42,14 @@ pub fn create(
4242 return self;
4343}
4444
45pub fn setName(self: *CheckFileStep, name: []const u8) void {
45pub fn setName(self: *CheckFile, name: []const u8) void {
4646 self.step.name = name;
4747}
4848
4949fn make(step: *Step, prog_node: *std.Progress.Node) !void {
5050 _ = prog_node;
5151 const b = step.owner;
52 const self = @fieldParentPtr(CheckFileStep, "step", step);
52 const self = @fieldParentPtr(CheckFile, "step", step);
5353
5454 const src_path = self.source.getPath(b);
5555 const contents = fs.cwd().readFileAlloc(b.allocator, src_path, self.max_bytes) catch |err| {
lib/std/Build/Step/CheckObject.zig+14-14
......@@ -6,7 +6,7 @@ const math = std.math;
66const mem = std.mem;
77const testing = std.testing;
88
9const CheckObjectStep = @This();
9const CheckObject = @This();
1010
1111const Allocator = mem.Allocator;
1212const Step = std.Build.Step;
......@@ -24,9 +24,9 @@ pub fn create(
2424 owner: *std.Build,
2525 source: std.Build.FileSource,
2626 obj_format: std.Target.ObjectFormat,
27) *CheckObjectStep {
27) *CheckObject {
2828 const gpa = owner.allocator;
29 const self = gpa.create(CheckObjectStep) catch @panic("OOM");
29 const self = gpa.create(CheckObject) catch @panic("OOM");
3030 self.* = .{
3131 .step = Step.init(.{
3232 .id = .check_file,
......@@ -47,11 +47,11 @@ pub fn create(
4747/// TODO this doesn't actually compare, and there's no apparent reason for it
4848/// to depend on the check object step. I don't see why this function should exist,
4949/// the caller could just add the run step directly.
50pub fn runAndCompare(self: *CheckObjectStep) *std.Build.RunStep {
50pub fn runAndCompare(self: *CheckObject) *std.Build.Step.Run {
5151 const dependencies_len = self.step.dependencies.items.len;
5252 assert(dependencies_len > 0);
5353 const exe_step = self.step.dependencies.items[dependencies_len - 1];
54 const exe = exe_step.cast(std.Build.CompileStep).?;
54 const exe = exe_step.cast(std.Build.Step.Compile).?;
5555 const run = self.step.owner.addRunArtifact(exe);
5656 run.skip_foreign_checks = true;
5757 run.step.dependOn(&self.step);
......@@ -274,15 +274,15 @@ const Check = struct {
274274};
275275
276276/// Creates a new sequence of actions with `phrase` as the first anchor searched phrase.
277pub fn checkStart(self: *CheckObjectStep, phrase: []const u8) void {
277pub fn checkStart(self: *CheckObject, phrase: []const u8) void {
278278 var new_check = Check.create(self.step.owner.allocator);
279279 new_check.match(.{ .string = self.step.owner.dupe(phrase) });
280280 self.checks.append(new_check) catch @panic("OOM");
281281}
282282
283/// Adds another searched phrase to the latest created Check with `CheckObjectStep.checkStart(...)`.
283/// Adds another searched phrase to the latest created Check with `CheckObject.checkStart(...)`.
284284/// Asserts at least one check already exists.
285pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void {
285pub fn checkNext(self: *CheckObject, phrase: []const u8) void {
286286 assert(self.checks.items.len > 0);
287287 const last = &self.checks.items[self.checks.items.len - 1];
288288 last.match(.{ .string = self.step.owner.dupe(phrase) });
......@@ -291,7 +291,7 @@ pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void {
291291/// Like `checkNext()` but takes an additional argument `FileSource` which will be
292292/// resolved to a full search query in `make()`.
293293pub fn checkNextFileSource(
294 self: *CheckObjectStep,
294 self: *CheckObject,
295295 phrase: []const u8,
296296 file_source: std.Build.FileSource,
297297) void {
......@@ -300,10 +300,10 @@ pub fn checkNextFileSource(
300300 last.match(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source });
301301}
302302
303/// Adds another searched phrase to the latest created Check with `CheckObjectStep.checkStart(...)`
303/// Adds another searched phrase to the latest created Check with `CheckObject.checkStart(...)`
304304/// however ensures there is no matching phrase in the output.
305305/// Asserts at least one check already exists.
306pub fn checkNotPresent(self: *CheckObjectStep, phrase: []const u8) void {
306pub fn checkNotPresent(self: *CheckObject, phrase: []const u8) void {
307307 assert(self.checks.items.len > 0);
308308 const last = &self.checks.items[self.checks.items.len - 1];
309309 last.notPresent(.{ .string = self.step.owner.dupe(phrase) });
......@@ -312,7 +312,7 @@ pub fn checkNotPresent(self: *CheckObjectStep, phrase: []const u8) void {
312312/// Creates a new check checking specifically symbol table parsed and dumped from the object
313313/// file.
314314/// Issuing this check will force parsing and dumping of the symbol table.
315pub fn checkInSymtab(self: *CheckObjectStep) void {
315pub fn checkInSymtab(self: *CheckObject) void {
316316 self.dump_symtab = true;
317317 const symtab_label = switch (self.obj_format) {
318318 .macho => MachODumper.symtab_label,
......@@ -325,7 +325,7 @@ pub fn checkInSymtab(self: *CheckObjectStep) void {
325325/// on the extracted variables. It will then compare the reduced program with the value of
326326/// the expected variable.
327327pub fn checkComputeCompare(
328 self: *CheckObjectStep,
328 self: *CheckObject,
329329 program: []const u8,
330330 expected: ComputeCompareExpected,
331331) void {
......@@ -338,7 +338,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
338338 _ = prog_node;
339339 const b = step.owner;
340340 const gpa = b.allocator;
341 const self = @fieldParentPtr(CheckObjectStep, "step", step);
341 const self = @fieldParentPtr(CheckObject, "step", step);
342342
343343 const src_path = self.source.getPath(b);
344344 const contents = fs.cwd().readFileAllocOptions(
lib/std/Build/Step/Compile.zig+81-87
......@@ -18,14 +18,8 @@ const ExecError = std.Build.ExecError;
1818const Module = std.Build.Module;
1919const VcpkgRoot = std.Build.VcpkgRoot;
2020const InstallDir = std.Build.InstallDir;
21const InstallArtifactStep = std.Build.InstallArtifactStep;
2221const GeneratedFile = std.Build.GeneratedFile;
23const ObjCopyStep = std.Build.ObjCopyStep;
24const CheckObjectStep = std.Build.CheckObjectStep;
25const RunStep = std.Build.RunStep;
26const OptionsStep = std.Build.OptionsStep;
27const ConfigHeaderStep = std.Build.ConfigHeaderStep;
28const CompileStep = @This();
22const Compile = @This();
2923
3024pub const base_id: Step.Id = .compile;
3125
......@@ -211,8 +205,8 @@ want_lto: ?bool = null,
211205use_llvm: ?bool,
212206use_lld: ?bool,
213207
214/// This is an advanced setting that can change the intent of this CompileStep.
215/// If this slice has nonzero length, it means that this CompileStep exists to
208/// This is an advanced setting that can change the intent of this Compile step.
209/// If this slice has nonzero length, it means that this Compile step exists to
216210/// check for compile errors and return *success* if they match, and failure
217211/// otherwise.
218212expect_errors: []const []const u8 = &.{},
......@@ -242,7 +236,7 @@ pub const CSourceFile = struct {
242236
243237pub const LinkObject = union(enum) {
244238 static_path: FileSource,
245 other_step: *CompileStep,
239 other_step: *Compile,
246240 system_lib: SystemLib,
247241 assembly_file: FileSource,
248242 c_source_file: *CSourceFile,
......@@ -273,8 +267,8 @@ const FrameworkLinkInfo = struct {
273267pub const IncludeDir = union(enum) {
274268 raw_path: []const u8,
275269 raw_path_system: []const u8,
276 other_step: *CompileStep,
277 config_header_step: *ConfigHeaderStep,
270 other_step: *Compile,
271 config_header_step: *Step.ConfigHeader,
278272};
279273
280274pub const Options = struct {
......@@ -319,7 +313,7 @@ pub const EmitOption = union(enum) {
319313 }
320314};
321315
322pub fn create(owner: *std.Build, options: Options) *CompileStep {
316pub fn create(owner: *std.Build, options: Options) *Compile {
323317 const name = owner.dupe(options.name);
324318 const root_src: ?FileSource = if (options.root_source_file) |rsrc| rsrc.dupe(owner) else null;
325319 if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {
......@@ -361,8 +355,8 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
361355 .version = options.version,
362356 }) catch @panic("OOM");
363357
364 const self = owner.allocator.create(CompileStep) catch @panic("OOM");
365 self.* = CompileStep{
358 const self = owner.allocator.create(Compile) catch @panic("OOM");
359 self.* = Compile{
366360 .strip = null,
367361 .unwind_tables = null,
368362 .verbose_link = false,
......@@ -459,7 +453,7 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
459453 return self;
460454}
461455
462pub fn installHeader(cs: *CompileStep, src_path: []const u8, dest_rel_path: []const u8) void {
456pub fn installHeader(cs: *Compile, src_path: []const u8, dest_rel_path: []const u8) void {
463457 const b = cs.step.owner;
464458 const install_file = b.addInstallHeaderFile(src_path, dest_rel_path);
465459 b.getInstallStep().dependOn(&install_file.step);
......@@ -472,8 +466,8 @@ pub const InstallConfigHeaderOptions = struct {
472466};
473467
474468pub fn installConfigHeader(
475 cs: *CompileStep,
476 config_header: *ConfigHeaderStep,
469 cs: *Compile,
470 config_header: *Step.ConfigHeader,
477471 options: InstallConfigHeaderOptions,
478472) void {
479473 const dest_rel_path = options.dest_rel_path orelse config_header.include_path;
......@@ -489,7 +483,7 @@ pub fn installConfigHeader(
489483}
490484
491485pub fn installHeadersDirectory(
492 a: *CompileStep,
486 a: *Compile,
493487 src_dir_path: []const u8,
494488 dest_rel_path: []const u8,
495489) void {
......@@ -501,8 +495,8 @@ pub fn installHeadersDirectory(
501495}
502496
503497pub fn installHeadersDirectoryOptions(
504 cs: *CompileStep,
505 options: std.Build.InstallDirStep.Options,
498 cs: *Compile,
499 options: std.Build.Step.InstallDir.Options,
506500) void {
507501 const b = cs.step.owner;
508502 const install_dir = b.addInstallDirectory(options);
......@@ -510,7 +504,7 @@ pub fn installHeadersDirectoryOptions(
510504 cs.installed_headers.append(&install_dir.step) catch @panic("OOM");
511505}
512506
513pub fn installLibraryHeaders(cs: *CompileStep, l: *CompileStep) void {
507pub fn installLibraryHeaders(cs: *Compile, l: *Compile) void {
514508 assert(l.kind == .lib);
515509 const b = cs.step.owner;
516510 const install_step = b.getInstallStep();
......@@ -533,7 +527,7 @@ pub fn installLibraryHeaders(cs: *CompileStep, l: *CompileStep) void {
533527 cs.installed_headers.appendSlice(l.installed_headers.items) catch @panic("OOM");
534528}
535529
536pub fn addObjCopy(cs: *CompileStep, options: ObjCopyStep.Options) *ObjCopyStep {
530pub fn addObjCopy(cs: *Compile, options: Step.ObjCopy.Options) *Step.ObjCopy {
537531 const b = cs.step.owner;
538532 var copy = options;
539533 if (copy.basename == null) {
......@@ -554,34 +548,34 @@ pub const run = @compileError("deprecated; use std.Build.addRunArtifact");
554548/// which is undesirable when installing an artifact provided by a dependency package.
555549pub const install = @compileError("deprecated; use std.Build.installArtifact");
556550
557pub fn checkObject(self: *CompileStep) *CheckObjectStep {
558 return CheckObjectStep.create(self.step.owner, self.getOutputSource(), self.target_info.target.ofmt);
551pub fn checkObject(self: *Compile) *Step.CheckObject {
552 return Step.CheckObject.create(self.step.owner, self.getOutputSource(), self.target_info.target.ofmt);
559553}
560554
561pub fn setLinkerScriptPath(self: *CompileStep, source: FileSource) void {
555pub fn setLinkerScriptPath(self: *Compile, source: FileSource) void {
562556 const b = self.step.owner;
563557 self.linker_script = source.dupe(b);
564558 source.addStepDependencies(&self.step);
565559}
566560
567pub fn forceUndefinedSymbol(self: *CompileStep, symbol_name: []const u8) void {
561pub fn forceUndefinedSymbol(self: *Compile, symbol_name: []const u8) void {
568562 const b = self.step.owner;
569563 self.force_undefined_symbols.put(b.dupe(symbol_name), {}) catch @panic("OOM");
570564}
571565
572pub fn linkFramework(self: *CompileStep, framework_name: []const u8) void {
566pub fn linkFramework(self: *Compile, framework_name: []const u8) void {
573567 const b = self.step.owner;
574568 self.frameworks.put(b.dupe(framework_name), .{}) catch @panic("OOM");
575569}
576570
577pub fn linkFrameworkNeeded(self: *CompileStep, framework_name: []const u8) void {
571pub fn linkFrameworkNeeded(self: *Compile, framework_name: []const u8) void {
578572 const b = self.step.owner;
579573 self.frameworks.put(b.dupe(framework_name), .{
580574 .needed = true,
581575 }) catch @panic("OOM");
582576}
583577
584pub fn linkFrameworkWeak(self: *CompileStep, framework_name: []const u8) void {
578pub fn linkFrameworkWeak(self: *Compile, framework_name: []const u8) void {
585579 const b = self.step.owner;
586580 self.frameworks.put(b.dupe(framework_name), .{
587581 .weak = true,
......@@ -589,7 +583,7 @@ pub fn linkFrameworkWeak(self: *CompileStep, framework_name: []const u8) void {
589583}
590584
591585/// Returns whether the library, executable, or object depends on a particular system library.
592pub fn dependsOnSystemLibrary(self: CompileStep, name: []const u8) bool {
586pub fn dependsOnSystemLibrary(self: Compile, name: []const u8) bool {
593587 if (isLibCLibrary(name)) {
594588 return self.is_linking_libc;
595589 }
......@@ -605,51 +599,51 @@ pub fn dependsOnSystemLibrary(self: CompileStep, name: []const u8) bool {
605599 return false;
606600}
607601
608pub fn linkLibrary(self: *CompileStep, lib: *CompileStep) void {
602pub fn linkLibrary(self: *Compile, lib: *Compile) void {
609603 assert(lib.kind == .lib);
610604 self.linkLibraryOrObject(lib);
611605}
612606
613pub fn isDynamicLibrary(self: *CompileStep) bool {
607pub fn isDynamicLibrary(self: *Compile) bool {
614608 return self.kind == .lib and self.linkage == Linkage.dynamic;
615609}
616610
617pub fn isStaticLibrary(self: *CompileStep) bool {
611pub fn isStaticLibrary(self: *Compile) bool {
618612 return self.kind == .lib and self.linkage != Linkage.dynamic;
619613}
620614
621pub fn producesPdbFile(self: *CompileStep) bool {
615pub fn producesPdbFile(self: *Compile) bool {
622616 if (!self.target.isWindows() and !self.target.isUefi()) return false;
623617 if (self.target.getObjectFormat() == .c) return false;
624618 if (self.strip == true) return false;
625619 return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test";
626620}
627621
628pub fn linkLibC(self: *CompileStep) void {
622pub fn linkLibC(self: *Compile) void {
629623 self.is_linking_libc = true;
630624}
631625
632pub fn linkLibCpp(self: *CompileStep) void {
626pub fn linkLibCpp(self: *Compile) void {
633627 self.is_linking_libcpp = true;
634628}
635629
636630/// If the value is omitted, it is set to 1.
637631/// `name` and `value` need not live longer than the function call.
638pub fn defineCMacro(self: *CompileStep, name: []const u8, value: ?[]const u8) void {
632pub fn defineCMacro(self: *Compile, name: []const u8, value: ?[]const u8) void {
639633 const b = self.step.owner;
640634 const macro = std.Build.constructCMacro(b.allocator, name, value);
641635 self.c_macros.append(macro) catch @panic("OOM");
642636}
643637
644638/// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1.
645pub fn defineCMacroRaw(self: *CompileStep, name_and_value: []const u8) void {
639pub fn defineCMacroRaw(self: *Compile, name_and_value: []const u8) void {
646640 const b = self.step.owner;
647641 self.c_macros.append(b.dupe(name_and_value)) catch @panic("OOM");
648642}
649643
650644/// This one has no integration with anything, it just puts -lname on the command line.
651645/// Prefer to use `linkSystemLibrary` instead.
652pub fn linkSystemLibraryName(self: *CompileStep, name: []const u8) void {
646pub fn linkSystemLibraryName(self: *Compile, name: []const u8) void {
653647 const b = self.step.owner;
654648 self.link_objects.append(.{
655649 .system_lib = .{
......@@ -663,7 +657,7 @@ pub fn linkSystemLibraryName(self: *CompileStep, name: []const u8) void {
663657
664658/// This one has no integration with anything, it just puts -needed-lname on the command line.
665659/// Prefer to use `linkSystemLibraryNeeded` instead.
666pub fn linkSystemLibraryNeededName(self: *CompileStep, name: []const u8) void {
660pub fn linkSystemLibraryNeededName(self: *Compile, name: []const u8) void {
667661 const b = self.step.owner;
668662 self.link_objects.append(.{
669663 .system_lib = .{
......@@ -677,7 +671,7 @@ pub fn linkSystemLibraryNeededName(self: *CompileStep, name: []const u8) void {
677671
678672/// Darwin-only. This one has no integration with anything, it just puts -weak-lname on the
679673/// command line. Prefer to use `linkSystemLibraryWeak` instead.
680pub fn linkSystemLibraryWeakName(self: *CompileStep, name: []const u8) void {
674pub fn linkSystemLibraryWeakName(self: *Compile, name: []const u8) void {
681675 const b = self.step.owner;
682676 self.link_objects.append(.{
683677 .system_lib = .{
......@@ -691,7 +685,7 @@ pub fn linkSystemLibraryWeakName(self: *CompileStep, name: []const u8) void {
691685
692686/// This links against a system library, exclusively using pkg-config to find the library.
693687/// Prefer to use `linkSystemLibrary` instead.
694pub fn linkSystemLibraryPkgConfigOnly(self: *CompileStep, lib_name: []const u8) void {
688pub fn linkSystemLibraryPkgConfigOnly(self: *Compile, lib_name: []const u8) void {
695689 const b = self.step.owner;
696690 self.link_objects.append(.{
697691 .system_lib = .{
......@@ -705,7 +699,7 @@ pub fn linkSystemLibraryPkgConfigOnly(self: *CompileStep, lib_name: []const u8)
705699
706700/// This links against a system library, exclusively using pkg-config to find the library.
707701/// Prefer to use `linkSystemLibraryNeeded` instead.
708pub fn linkSystemLibraryNeededPkgConfigOnly(self: *CompileStep, lib_name: []const u8) void {
702pub fn linkSystemLibraryNeededPkgConfigOnly(self: *Compile, lib_name: []const u8) void {
709703 const b = self.step.owner;
710704 self.link_objects.append(.{
711705 .system_lib = .{
......@@ -719,7 +713,7 @@ pub fn linkSystemLibraryNeededPkgConfigOnly(self: *CompileStep, lib_name: []cons
719713
720714/// Run pkg-config for the given library name and parse the output, returning the arguments
721715/// that should be passed to zig to link the given library.
722fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u8 {
716fn runPkgConfig(self: *Compile, lib_name: []const u8) ![]const []const u8 {
723717 const b = self.step.owner;
724718 const pkg_name = match: {
725719 // First we have to map the library name to pkg config name. Unfortunately,
......@@ -813,19 +807,19 @@ fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u8 {
813807 return zig_args.toOwnedSlice();
814808}
815809
816pub fn linkSystemLibrary(self: *CompileStep, name: []const u8) void {
810pub fn linkSystemLibrary(self: *Compile, name: []const u8) void {
817811 self.linkSystemLibraryInner(name, .{});
818812}
819813
820pub fn linkSystemLibraryNeeded(self: *CompileStep, name: []const u8) void {
814pub fn linkSystemLibraryNeeded(self: *Compile, name: []const u8) void {
821815 self.linkSystemLibraryInner(name, .{ .needed = true });
822816}
823817
824pub fn linkSystemLibraryWeak(self: *CompileStep, name: []const u8) void {
818pub fn linkSystemLibraryWeak(self: *Compile, name: []const u8) void {
825819 self.linkSystemLibraryInner(name, .{ .weak = true });
826820}
827821
828fn linkSystemLibraryInner(self: *CompileStep, name: []const u8, opts: struct {
822fn linkSystemLibraryInner(self: *Compile, name: []const u8, opts: struct {
829823 needed: bool = false,
830824 weak: bool = false,
831825}) void {
......@@ -850,7 +844,7 @@ fn linkSystemLibraryInner(self: *CompileStep, name: []const u8, opts: struct {
850844}
851845
852846/// Handy when you have many C/C++ source files and want them all to have the same flags.
853pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []const []const u8) void {
847pub fn addCSourceFiles(self: *Compile, files: []const []const u8, flags: []const []const u8) void {
854848 const b = self.step.owner;
855849 const c_source_files = b.allocator.create(CSourceFiles) catch @panic("OOM");
856850
......@@ -864,14 +858,14 @@ pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []c
864858 self.link_objects.append(.{ .c_source_files = c_source_files }) catch @panic("OOM");
865859}
866860
867pub fn addCSourceFile(self: *CompileStep, file: []const u8, flags: []const []const u8) void {
861pub fn addCSourceFile(self: *Compile, file: []const u8, flags: []const []const u8) void {
868862 self.addCSourceFileSource(.{
869863 .args = flags,
870864 .source = .{ .path = file },
871865 });
872866}
873867
874pub fn addCSourceFileSource(self: *CompileStep, source: CSourceFile) void {
868pub fn addCSourceFileSource(self: *Compile, source: CSourceFile) void {
875869 const b = self.step.owner;
876870 const c_source_file = b.allocator.create(CSourceFile) catch @panic("OOM");
877871 c_source_file.* = source.dupe(b);
......@@ -879,85 +873,85 @@ pub fn addCSourceFileSource(self: *CompileStep, source: CSourceFile) void {
879873 source.source.addStepDependencies(&self.step);
880874}
881875
882pub fn setVerboseLink(self: *CompileStep, value: bool) void {
876pub fn setVerboseLink(self: *Compile, value: bool) void {
883877 self.verbose_link = value;
884878}
885879
886pub fn setVerboseCC(self: *CompileStep, value: bool) void {
880pub fn setVerboseCC(self: *Compile, value: bool) void {
887881 self.verbose_cc = value;
888882}
889883
890pub fn overrideZigLibDir(self: *CompileStep, dir_path: []const u8) void {
884pub fn overrideZigLibDir(self: *Compile, dir_path: []const u8) void {
891885 const b = self.step.owner;
892886 self.zig_lib_dir = b.dupePath(dir_path);
893887}
894888
895pub fn setMainPkgPath(self: *CompileStep, dir_path: []const u8) void {
889pub fn setMainPkgPath(self: *Compile, dir_path: []const u8) void {
896890 const b = self.step.owner;
897891 self.main_pkg_path = b.dupePath(dir_path);
898892}
899893
900pub fn setLibCFile(self: *CompileStep, libc_file: ?FileSource) void {
894pub fn setLibCFile(self: *Compile, libc_file: ?FileSource) void {
901895 const b = self.step.owner;
902896 self.libc_file = if (libc_file) |f| f.dupe(b) else null;
903897}
904898
905899/// Returns the generated executable, library or object file.
906900/// To run an executable built with zig build, use `run`, or create an install step and invoke it.
907pub fn getOutputSource(self: *CompileStep) FileSource {
901pub fn getOutputSource(self: *Compile) FileSource {
908902 return .{ .generated = &self.output_path_source };
909903}
910904
911pub fn getOutputDirectorySource(self: *CompileStep) FileSource {
905pub fn getOutputDirectorySource(self: *Compile) FileSource {
912906 return .{ .generated = &self.output_dirname_source };
913907}
914908
915909/// Returns the generated import library. This function can only be called for libraries.
916pub fn getOutputLibSource(self: *CompileStep) FileSource {
910pub fn getOutputLibSource(self: *Compile) FileSource {
917911 assert(self.kind == .lib);
918912 return .{ .generated = &self.output_lib_path_source };
919913}
920914
921915/// Returns the generated header file.
922916/// This function can only be called for libraries or object files which have `emit_h` set.
923pub fn getOutputHSource(self: *CompileStep) FileSource {
917pub fn getOutputHSource(self: *Compile) FileSource {
924918 assert(self.kind != .exe and self.kind != .@"test");
925919 assert(self.emit_h);
926920 return .{ .generated = &self.output_h_path_source };
927921}
928922
929923/// Returns the generated PDB file. This function can only be called for Windows and UEFI.
930pub fn getOutputPdbSource(self: *CompileStep) FileSource {
924pub fn getOutputPdbSource(self: *Compile) FileSource {
931925 // TODO: Is this right? Isn't PDB for *any* PE/COFF file?
932926 assert(self.target.isWindows() or self.target.isUefi());
933927 return .{ .generated = &self.output_pdb_path_source };
934928}
935929
936pub fn addAssemblyFile(self: *CompileStep, path: []const u8) void {
930pub fn addAssemblyFile(self: *Compile, path: []const u8) void {
937931 const b = self.step.owner;
938932 self.link_objects.append(.{
939933 .assembly_file = .{ .path = b.dupe(path) },
940934 }) catch @panic("OOM");
941935}
942936
943pub fn addAssemblyFileSource(self: *CompileStep, source: FileSource) void {
937pub fn addAssemblyFileSource(self: *Compile, source: FileSource) void {
944938 const b = self.step.owner;
945939 const source_duped = source.dupe(b);
946940 self.link_objects.append(.{ .assembly_file = source_duped }) catch @panic("OOM");
947941 source_duped.addStepDependencies(&self.step);
948942}
949943
950pub fn addObjectFile(self: *CompileStep, source_file: []const u8) void {
944pub fn addObjectFile(self: *Compile, source_file: []const u8) void {
951945 self.addObjectFileSource(.{ .path = source_file });
952946}
953947
954pub fn addObjectFileSource(self: *CompileStep, source: FileSource) void {
948pub fn addObjectFileSource(self: *Compile, source: FileSource) void {
955949 const b = self.step.owner;
956950 self.link_objects.append(.{ .static_path = source.dupe(b) }) catch @panic("OOM");
957951 source.addStepDependencies(&self.step);
958952}
959953
960pub fn addObject(self: *CompileStep, obj: *CompileStep) void {
954pub fn addObject(self: *Compile, obj: *Compile) void {
961955 assert(obj.kind == .obj);
962956 self.linkLibraryOrObject(obj);
963957}
......@@ -967,54 +961,54 @@ pub const addIncludeDir = @compileError("deprecated; use addIncludePath");
967961pub const addLibPath = @compileError("deprecated, use addLibraryPath");
968962pub const addFrameworkDir = @compileError("deprecated, use addFrameworkPath");
969963
970pub fn addSystemIncludePath(self: *CompileStep, path: []const u8) void {
964pub fn addSystemIncludePath(self: *Compile, path: []const u8) void {
971965 const b = self.step.owner;
972966 self.include_dirs.append(IncludeDir{ .raw_path_system = b.dupe(path) }) catch @panic("OOM");
973967}
974968
975pub fn addIncludePath(self: *CompileStep, path: []const u8) void {
969pub fn addIncludePath(self: *Compile, path: []const u8) void {
976970 const b = self.step.owner;
977971 self.include_dirs.append(IncludeDir{ .raw_path = b.dupe(path) }) catch @panic("OOM");
978972}
979973
980pub fn addConfigHeader(self: *CompileStep, config_header: *ConfigHeaderStep) void {
974pub fn addConfigHeader(self: *Compile, config_header: *Step.ConfigHeader) void {
981975 self.step.dependOn(&config_header.step);
982976 self.include_dirs.append(.{ .config_header_step = config_header }) catch @panic("OOM");
983977}
984978
985pub fn addLibraryPath(self: *CompileStep, path: []const u8) void {
979pub fn addLibraryPath(self: *Compile, path: []const u8) void {
986980 const b = self.step.owner;
987981 self.lib_paths.append(.{ .path = b.dupe(path) }) catch @panic("OOM");
988982}
989983
990pub fn addLibraryPathDirectorySource(self: *CompileStep, directory_source: FileSource) void {
984pub fn addLibraryPathDirectorySource(self: *Compile, directory_source: FileSource) void {
991985 self.lib_paths.append(directory_source) catch @panic("OOM");
992986 directory_source.addStepDependencies(&self.step);
993987}
994988
995pub fn addRPath(self: *CompileStep, path: []const u8) void {
989pub fn addRPath(self: *Compile, path: []const u8) void {
996990 const b = self.step.owner;
997991 self.rpaths.append(.{ .path = b.dupe(path) }) catch @panic("OOM");
998992}
999993
1000pub fn addRPathDirectorySource(self: *CompileStep, directory_source: FileSource) void {
994pub fn addRPathDirectorySource(self: *Compile, directory_source: FileSource) void {
1001995 self.rpaths.append(directory_source) catch @panic("OOM");
1002996 directory_source.addStepDependencies(&self.step);
1003997}
1004998
1005pub fn addFrameworkPath(self: *CompileStep, dir_path: []const u8) void {
999pub fn addFrameworkPath(self: *Compile, dir_path: []const u8) void {
10061000 const b = self.step.owner;
10071001 self.framework_dirs.append(.{ .path = b.dupe(dir_path) }) catch @panic("OOM");
10081002}
10091003
1010pub fn addFrameworkPathDirectorySource(self: *CompileStep, directory_source: FileSource) void {
1004pub fn addFrameworkPathDirectorySource(self: *Compile, directory_source: FileSource) void {
10111005 self.framework_dirs.append(directory_source) catch @panic("OOM");
10121006 directory_source.addStepDependencies(&self.step);
10131007}
10141008
10151009/// Adds a module to be used with `@import` and exposing it in the current
10161010/// package's module table using `name`.
1017pub fn addModule(cs: *CompileStep, name: []const u8, module: *Module) void {
1011pub fn addModule(cs: *Compile, name: []const u8, module: *Module) void {
10181012 const b = cs.step.owner;
10191013 cs.modules.put(b.dupe(name), module) catch @panic("OOM");
10201014
......@@ -1025,17 +1019,17 @@ pub fn addModule(cs: *CompileStep, name: []const u8, module: *Module) void {
10251019
10261020/// Adds a module to be used with `@import` without exposing it in the current
10271021/// package's module table.
1028pub fn addAnonymousModule(cs: *CompileStep, name: []const u8, options: std.Build.CreateModuleOptions) void {
1022pub fn addAnonymousModule(cs: *Compile, name: []const u8, options: std.Build.CreateModuleOptions) void {
10291023 const b = cs.step.owner;
10301024 const module = b.createModule(options);
10311025 return addModule(cs, name, module);
10321026}
10331027
1034pub fn addOptions(cs: *CompileStep, module_name: []const u8, options: *OptionsStep) void {
1028pub fn addOptions(cs: *Compile, module_name: []const u8, options: *Step.Options) void {
10351029 addModule(cs, module_name, options.createModule());
10361030}
10371031
1038fn addRecursiveBuildDeps(cs: *CompileStep, module: *Module, done: *std.AutoHashMap(*Module, void)) !void {
1032fn addRecursiveBuildDeps(cs: *Compile, module: *Module, done: *std.AutoHashMap(*Module, void)) !void {
10391033 if (done.contains(module)) return;
10401034 try done.put(module, {});
10411035 module.source_file.addStepDependencies(&cs.step);
......@@ -1046,7 +1040,7 @@ fn addRecursiveBuildDeps(cs: *CompileStep, module: *Module, done: *std.AutoHashM
10461040
10471041/// If Vcpkg was found on the system, it will be added to include and lib
10481042/// paths for the specified target.
1049pub fn addVcpkgPaths(self: *CompileStep, linkage: CompileStep.Linkage) !void {
1043pub fn addVcpkgPaths(self: *Compile, linkage: Compile.Linkage) !void {
10501044 const b = self.step.owner;
10511045 // Ideally in the Unattempted case we would call the function recursively
10521046 // after findVcpkgRoot and have only one switch statement, but the compiler
......@@ -1082,7 +1076,7 @@ pub fn addVcpkgPaths(self: *CompileStep, linkage: CompileStep.Linkage) !void {
10821076 }
10831077}
10841078
1085pub fn setExecCmd(self: *CompileStep, args: []const ?[]const u8) void {
1079pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void {
10861080 const b = self.step.owner;
10871081 assert(self.kind == .@"test");
10881082 const duped_args = b.allocator.alloc(?[]u8, args.len) catch @panic("OOM");
......@@ -1092,7 +1086,7 @@ pub fn setExecCmd(self: *CompileStep, args: []const ?[]const u8) void {
10921086 self.exec_cmd_args = duped_args;
10931087}
10941088
1095fn linkLibraryOrObject(self: *CompileStep, other: *CompileStep) void {
1089fn linkLibraryOrObject(self: *Compile, other: *Compile) void {
10961090 self.step.dependOn(&other.step);
10971091 self.link_objects.append(.{ .other_step = other }) catch @panic("OOM");
10981092 self.include_dirs.append(.{ .other_step = other }) catch @panic("OOM");
......@@ -1103,7 +1097,7 @@ fn linkLibraryOrObject(self: *CompileStep, other: *CompileStep) void {
11031097}
11041098
11051099fn appendModuleArgs(
1106 cs: *CompileStep,
1100 cs: *Compile,
11071101 zig_args: *ArrayList([]const u8),
11081102) error{OutOfMemory}!void {
11091103 const b = cs.step.owner;
......@@ -1214,7 +1208,7 @@ fn constructDepString(
12141208
12151209fn make(step: *Step, prog_node: *std.Progress.Node) !void {
12161210 const b = step.owner;
1217 const self = @fieldParentPtr(CompileStep, "step", step);
1211 const self = @fieldParentPtr(Compile, "step", step);
12181212
12191213 if (self.root_src == null and self.link_objects.items.len == 0) {
12201214 return step.fail("the linker needs one or more objects to link", .{});
......@@ -2088,7 +2082,7 @@ const TransitiveDeps = struct {
20882082 }
20892083 }
20902084
2091 fn addInner(td: *TransitiveDeps, other: *CompileStep, dyn: bool) !void {
2085 fn addInner(td: *TransitiveDeps, other: *Compile, dyn: bool) !void {
20922086 // Inherit dependency on libc and libc++
20932087 td.is_linking_libcpp = td.is_linking_libcpp or other.is_linking_libcpp;
20942088 td.is_linking_libc = td.is_linking_libc or other.is_linking_libc;
......@@ -2128,7 +2122,7 @@ const TransitiveDeps = struct {
21282122 }
21292123};
21302124
2131fn checkCompileErrors(self: *CompileStep) !void {
2125fn checkCompileErrors(self: *Compile) !void {
21322126 // Clear this field so that it does not get printed by the build runner.
21332127 const actual_eb = self.step.result_error_bundle;
21342128 self.step.result_error_bundle = std.zig.ErrorBundle.empty;
lib/std/Build/Step/ConfigHeader.zig+13-13
......@@ -1,5 +1,5 @@
11const std = @import("std");
2const ConfigHeaderStep = @This();
2const ConfigHeader = @This();
33const Step = std.Build.Step;
44
55pub const Style = union(enum) {
......@@ -48,8 +48,8 @@ pub const Options = struct {
4848 first_ret_addr: ?usize = null,
4949};
5050
51pub fn create(owner: *std.Build, options: Options) *ConfigHeaderStep {
52 const self = owner.allocator.create(ConfigHeaderStep) catch @panic("OOM");
51pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
52 const self = owner.allocator.create(ConfigHeader) catch @panic("OOM");
5353
5454 var include_path: []const u8 = "config.h";
5555
......@@ -93,21 +93,21 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeaderStep {
9393 return self;
9494}
9595
96pub fn addValues(self: *ConfigHeaderStep, values: anytype) void {
96pub fn addValues(self: *ConfigHeader, values: anytype) void {
9797 return addValuesInner(self, values) catch @panic("OOM");
9898}
9999
100pub fn getFileSource(self: *ConfigHeaderStep) std.Build.FileSource {
100pub fn getFileSource(self: *ConfigHeader) std.Build.FileSource {
101101 return .{ .generated = &self.output_file };
102102}
103103
104fn addValuesInner(self: *ConfigHeaderStep, values: anytype) !void {
104fn addValuesInner(self: *ConfigHeader, values: anytype) !void {
105105 inline for (@typeInfo(@TypeOf(values)).Struct.fields) |field| {
106106 try putValue(self, field.name, field.type, @field(values, field.name));
107107 }
108108}
109109
110fn putValue(self: *ConfigHeaderStep, field_name: []const u8, comptime T: type, v: T) !void {
110fn putValue(self: *ConfigHeader, field_name: []const u8, comptime T: type, v: T) !void {
111111 switch (@typeInfo(T)) {
112112 .Null => {
113113 try self.values.put(field_name, .undef);
......@@ -151,31 +151,31 @@ fn putValue(self: *ConfigHeaderStep, field_name: []const u8, comptime T: type, v
151151 else => {},
152152 }
153153
154 @compileError("unsupported ConfigHeaderStep value type: " ++ @typeName(T));
154 @compileError("unsupported ConfigHeader value type: " ++ @typeName(T));
155155 },
156 else => @compileError("unsupported ConfigHeaderStep value type: " ++ @typeName(T)),
156 else => @compileError("unsupported ConfigHeader value type: " ++ @typeName(T)),
157157 }
158158}
159159
160160fn make(step: *Step, prog_node: *std.Progress.Node) !void {
161161 _ = prog_node;
162162 const b = step.owner;
163 const self = @fieldParentPtr(ConfigHeaderStep, "step", step);
163 const self = @fieldParentPtr(ConfigHeader, "step", step);
164164 const gpa = b.allocator;
165165 const arena = b.allocator;
166166
167167 var man = b.cache.obtain();
168168 defer man.deinit();
169169
170 // Random bytes to make ConfigHeaderStep unique. Refresh this with new
171 // random bytes when ConfigHeaderStep implementation is modified in a
170 // Random bytes to make ConfigHeader unique. Refresh this with new
171 // random bytes when ConfigHeader implementation is modified in a
172172 // non-backwards-compatible way.
173173 man.hash.add(@as(u32, 0xdef08d23));
174174
175175 var output = std.ArrayList(u8).init(gpa);
176176 defer output.deinit();
177177
178 const header_text = "This file was generated by ConfigHeaderStep using the Zig Build System.";
178 const header_text = "This file was generated by ConfigHeader using the Zig Build System.";
179179 const c_generated_line = "/* " ++ header_text ++ " */\n";
180180 const asm_generated_line = "; " ++ header_text ++ "\n";
181181
lib/std/Build/Step/Fmt.zig+4-4
......@@ -3,7 +3,7 @@
33//! * Check mode: fail the step if a non-conforming file is found.
44const std = @import("std");
55const Step = std.Build.Step;
6const FmtStep = @This();
6const Fmt = @This();
77
88step: Step,
99paths: []const []const u8,
......@@ -19,8 +19,8 @@ pub const Options = struct {
1919 check: bool = false,
2020};
2121
22pub fn create(owner: *std.Build, options: Options) *FmtStep {
23 const self = owner.allocator.create(FmtStep) catch @panic("OOM");
22pub fn create(owner: *std.Build, options: Options) *Fmt {
23 const self = owner.allocator.create(Fmt) catch @panic("OOM");
2424 const name = if (options.check) "zig fmt --check" else "zig fmt";
2525 self.* = .{
2626 .step = Step.init(.{
......@@ -47,7 +47,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
4747
4848 const b = step.owner;
4949 const arena = b.allocator;
50 const self = @fieldParentPtr(FmtStep, "step", step);
50 const self = @fieldParentPtr(Fmt, "step", step);
5151
5252 var argv: std.ArrayListUnmanaged([]const u8) = .{};
5353 try argv.ensureUnusedCapacity(arena, 2 + 1 + self.paths.len + 2 * self.exclude_paths.len);
lib/std/Build/Step/InstallArtifact.zig+8-9
......@@ -1,24 +1,23 @@
11const std = @import("std");
22const Step = std.Build.Step;
3const CompileStep = std.Build.CompileStep;
43const InstallDir = std.Build.InstallDir;
5const InstallArtifactStep = @This();
4const InstallArtifact = @This();
65const fs = std.fs;
76
87pub const base_id = .install_artifact;
98
109step: Step,
11artifact: *CompileStep,
10artifact: *Step.Compile,
1211dest_dir: InstallDir,
1312pdb_dir: ?InstallDir,
1413h_dir: ?InstallDir,
1514/// If non-null, adds additional path components relative to dest_dir, and
16/// overrides the basename of the CompileStep.
15/// overrides the basename of the Compile step.
1716dest_sub_path: ?[]const u8,
1817
19pub fn create(owner: *std.Build, artifact: *CompileStep) *InstallArtifactStep {
20 const self = owner.allocator.create(InstallArtifactStep) catch @panic("OOM");
21 self.* = InstallArtifactStep{
18pub fn create(owner: *std.Build, artifact: *Step.Compile) *InstallArtifact {
19 const self = owner.allocator.create(InstallArtifact) catch @panic("OOM");
20 self.* = InstallArtifact{
2221 .step = Step.init(.{
2322 .id = base_id,
2423 .name = owner.fmt("install {s}", .{artifact.name}),
......@@ -66,7 +65,7 @@ pub fn create(owner: *std.Build, artifact: *CompileStep) *InstallArtifactStep {
6665
6766fn make(step: *Step, prog_node: *std.Progress.Node) !void {
6867 _ = prog_node;
69 const self = @fieldParentPtr(InstallArtifactStep, "step", step);
68 const self = @fieldParentPtr(InstallArtifact, "step", step);
7069 const src_builder = self.artifact.step.owner;
7170 const dest_builder = step.owner;
7271
......@@ -90,7 +89,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
9089 self.artifact.version != null and
9190 self.artifact.target.wantSharedLibSymLinks())
9291 {
93 try CompileStep.doAtomicSymLinks(step, full_dest_path, self.artifact.major_only_filename.?, self.artifact.name_only_filename.?);
92 try Step.Compile.doAtomicSymLinks(step, full_dest_path, self.artifact.major_only_filename.?, self.artifact.name_only_filename.?);
9493 }
9594 if (self.artifact.isDynamicLibrary() and
9695 self.artifact.target.isWindows() and
lib/std/Build/Step/InstallFile.zig+4-4
......@@ -2,7 +2,7 @@ const std = @import("std");
22const Step = std.Build.Step;
33const FileSource = std.Build.FileSource;
44const InstallDir = std.Build.InstallDir;
5const InstallFileStep = @This();
5const InstallFile = @This();
66const assert = std.debug.assert;
77
88pub const base_id = .install_file;
......@@ -20,10 +20,10 @@ pub fn create(
2020 source: FileSource,
2121 dir: InstallDir,
2222 dest_rel_path: []const u8,
23) *InstallFileStep {
23) *InstallFile {
2424 assert(dest_rel_path.len != 0);
2525 owner.pushInstalledFile(dir, dest_rel_path);
26 const self = owner.allocator.create(InstallFileStep) catch @panic("OOM");
26 const self = owner.allocator.create(InstallFile) catch @panic("OOM");
2727 self.* = .{
2828 .step = Step.init(.{
2929 .id = base_id,
......@@ -43,7 +43,7 @@ pub fn create(
4343fn make(step: *Step, prog_node: *std.Progress.Node) !void {
4444 _ = prog_node;
4545 const src_builder = step.owner;
46 const self = @fieldParentPtr(InstallFileStep, "step", step);
46 const self = @fieldParentPtr(InstallFile, "step", step);
4747 const dest_builder = self.dest_builder;
4848 const full_src_path = self.source.getPath2(src_builder, step);
4949 const full_dest_path = dest_builder.getInstallPath(self.dir, self.dest_rel_path);
lib/std/Build/Step/ObjCopy.zig+8-9
......@@ -1,12 +1,11 @@
11const std = @import("std");
2const ObjCopyStep = @This();
2const ObjCopy = @This();
33
44const Allocator = std.mem.Allocator;
55const ArenaAllocator = std.heap.ArenaAllocator;
66const ArrayListUnmanaged = std.ArrayListUnmanaged;
77const File = std.fs.File;
88const InstallDir = std.Build.InstallDir;
9const CompileStep = std.Build.CompileStep;
109const Step = std.Build.Step;
1110const elf = std.elf;
1211const fs = std.fs;
......@@ -40,9 +39,9 @@ pub fn create(
4039 owner: *std.Build,
4140 file_source: std.Build.FileSource,
4241 options: Options,
43) *ObjCopyStep {
44 const self = owner.allocator.create(ObjCopyStep) catch @panic("OOM");
45 self.* = ObjCopyStep{
42) *ObjCopy {
43 const self = owner.allocator.create(ObjCopy) catch @panic("OOM");
44 self.* = ObjCopy{
4645 .step = Step.init(.{
4746 .id = base_id,
4847 .name = owner.fmt("objcopy {s}", .{file_source.getDisplayName()}),
......@@ -61,19 +60,19 @@ pub fn create(
6160 return self;
6261}
6362
64pub fn getOutputSource(self: *const ObjCopyStep) std.Build.FileSource {
63pub fn getOutputSource(self: *const ObjCopy) std.Build.FileSource {
6564 return .{ .generated = &self.output_file };
6665}
6766
6867fn make(step: *Step, prog_node: *std.Progress.Node) !void {
6968 const b = step.owner;
70 const self = @fieldParentPtr(ObjCopyStep, "step", step);
69 const self = @fieldParentPtr(ObjCopy, "step", step);
7170
7271 var man = b.cache.obtain();
7372 defer man.deinit();
7473
75 // Random bytes to make ObjCopyStep unique. Refresh this with new random
76 // bytes when ObjCopyStep implementation is modified incompatibly.
74 // Random bytes to make ObjCopy unique. Refresh this with new random
75 // bytes when ObjCopy implementation is modified incompatibly.
7776 man.hash.add(@as(u32, 0xe18b7baf));
7877
7978 const full_src_path = self.file_source.getPath(b);
lib/std/Build/Step/Options.zig+12-13
......@@ -3,10 +3,9 @@ const builtin = @import("builtin");
33const fs = std.fs;
44const Step = std.Build.Step;
55const GeneratedFile = std.Build.GeneratedFile;
6const CompileStep = std.Build.CompileStep;
76const FileSource = std.Build.FileSource;
87
9const OptionsStep = @This();
8const Options = @This();
109
1110pub const base_id = .options;
1211
......@@ -17,8 +16,8 @@ contents: std.ArrayList(u8),
1716artifact_args: std.ArrayList(OptionArtifactArg),
1817file_source_args: std.ArrayList(OptionFileSourceArg),
1918
20pub fn create(owner: *std.Build) *OptionsStep {
21 const self = owner.allocator.create(OptionsStep) catch @panic("OOM");
19pub fn create(owner: *std.Build) *Options {
20 const self = owner.allocator.create(Options) catch @panic("OOM");
2221 self.* = .{
2322 .step = Step.init(.{
2423 .id = base_id,
......@@ -36,11 +35,11 @@ pub fn create(owner: *std.Build) *OptionsStep {
3635 return self;
3736}
3837
39pub fn addOption(self: *OptionsStep, comptime T: type, name: []const u8, value: T) void {
38pub fn addOption(self: *Options, comptime T: type, name: []const u8, value: T) void {
4039 return addOptionFallible(self, T, name, value) catch @panic("unhandled error");
4140}
4241
43fn addOptionFallible(self: *OptionsStep, comptime T: type, name: []const u8, value: T) !void {
42fn addOptionFallible(self: *Options, comptime T: type, name: []const u8, value: T) !void {
4443 const out = self.contents.writer();
4544 switch (T) {
4645 []const []const u8 => {
......@@ -189,7 +188,7 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void {
189188/// The value is the path in the cache dir.
190189/// Adds a dependency automatically.
191190pub fn addOptionFileSource(
192 self: *OptionsStep,
191 self: *Options,
193192 name: []const u8,
194193 source: FileSource,
195194) void {
......@@ -202,19 +201,19 @@ pub fn addOptionFileSource(
202201
203202/// The value is the path in the cache dir.
204203/// Adds a dependency automatically.
205pub fn addOptionArtifact(self: *OptionsStep, name: []const u8, artifact: *CompileStep) void {
204pub fn addOptionArtifact(self: *Options, name: []const u8, artifact: *Step.Compile) void {
206205 self.artifact_args.append(.{ .name = self.step.owner.dupe(name), .artifact = artifact }) catch @panic("OOM");
207206 self.step.dependOn(&artifact.step);
208207}
209208
210pub fn createModule(self: *OptionsStep) *std.Build.Module {
209pub fn createModule(self: *Options) *std.Build.Module {
211210 return self.step.owner.createModule(.{
212211 .source_file = self.getSource(),
213212 .dependencies = &.{},
214213 });
215214}
216215
217pub fn getSource(self: *OptionsStep) FileSource {
216pub fn getSource(self: *Options) FileSource {
218217 return .{ .generated = &self.generated_file };
219218}
220219
......@@ -223,7 +222,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
223222 _ = prog_node;
224223
225224 const b = step.owner;
226 const self = @fieldParentPtr(OptionsStep, "step", step);
225 const self = @fieldParentPtr(Options, "step", step);
227226
228227 for (self.artifact_args.items) |item| {
229228 self.addOption(
......@@ -314,7 +313,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
314313
315314const OptionArtifactArg = struct {
316315 name: []const u8,
317 artifact: *CompileStep,
316 artifact: *Step.Compile,
318317};
319318
320319const OptionFileSourceArg = struct {
......@@ -322,7 +321,7 @@ const OptionFileSourceArg = struct {
322321 source: FileSource,
323322};
324323
325test "OptionsStep" {
324test Options {
326325 if (builtin.os.tag == .wasi) return error.SkipZigTest;
327326
328327 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
lib/std/Build/Step/RemoveDir.zig+4-4
......@@ -1,15 +1,15 @@
11const std = @import("std");
22const fs = std.fs;
33const Step = std.Build.Step;
4const RemoveDirStep = @This();
4const RemoveDir = @This();
55
66pub const base_id = .remove_dir;
77
88step: Step,
99dir_path: []const u8,
1010
11pub fn init(owner: *std.Build, dir_path: []const u8) RemoveDirStep {
12 return RemoveDirStep{
11pub fn init(owner: *std.Build, dir_path: []const u8) RemoveDir {
12 return RemoveDir{
1313 .step = Step.init(.{
1414 .id = .remove_dir,
1515 .name = owner.fmt("RemoveDir {s}", .{dir_path}),
......@@ -26,7 +26,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
2626 _ = prog_node;
2727
2828 const b = step.owner;
29 const self = @fieldParentPtr(RemoveDirStep, "step", step);
29 const self = @fieldParentPtr(RemoveDir, "step", step);
3030
3131 b.build_root.handle.deleteTree(self.dir_path) catch |err| {
3232 if (b.build_root.path) |base| {
lib/std/Build/Step/Run.zig+53-55
......@@ -1,8 +1,6 @@
11const std = @import("std");
22const builtin = @import("builtin");
33const Step = std.Build.Step;
4const CompileStep = std.Build.CompileStep;
5const WriteFileStep = std.Build.WriteFileStep;
64const fs = std.fs;
75const mem = std.mem;
86const process = std.process;
......@@ -12,7 +10,7 @@ const Allocator = mem.Allocator;
1210const ExecError = std.Build.ExecError;
1311const assert = std.debug.assert;
1412
15const RunStep = @This();
13const Run = @This();
1614
1715pub const base_id: Step.Id = .run;
1816
......@@ -29,12 +27,12 @@ cwd: ?[]const u8,
2927/// Override this field to modify the environment, or use setEnvironmentVariable
3028env_map: ?*EnvMap,
3129
32/// Configures whether the RunStep is considered to have side-effects, and also
33/// whether the RunStep will inherit stdio streams, forwarding them to the
30/// Configures whether the Run step is considered to have side-effects, and also
31/// whether the Run step will inherit stdio streams, forwarding them to the
3432/// parent process, in which case will require a global lock to prevent other
3533/// steps from interfering with stdio while the subprocess associated with this
36/// RunStep is running.
37/// If the RunStep is determined to not have side-effects, then execution will
34/// Run step is running.
35/// If the Run step is determined to not have side-effects, then execution will
3836/// be skipped if all output files are up-to-date and input files are
3937/// unchanged.
4038stdio: StdIo = .infer_from_args,
......@@ -42,9 +40,9 @@ stdio: StdIo = .infer_from_args,
4240stdin: ?[]const u8 = null,
4341
4442/// Additional file paths relative to build.zig that, when modified, indicate
45/// that the RunStep should be re-executed.
46/// If the RunStep is determined to have side-effects, this field is ignored
47/// and the RunStep is always executed when it appears in the build graph.
43/// that the Run step should be re-executed.
44/// If the Run step is determined to have side-effects, this field is ignored
45/// and the Run step is always executed when it appears in the build graph.
4846extra_file_dependencies: []const []const u8 = &.{},
4947
5048/// After adding an output argument, this step will by default rename itself
......@@ -52,14 +50,14 @@ extra_file_dependencies: []const []const u8 = &.{},
5250/// This can be disabled by setting this to false.
5351rename_step_with_output_arg: bool = true,
5452
55/// If this is true, a RunStep which is configured to check the output of the
53/// If this is true, a Run step which is configured to check the output of the
5654/// executed binary will not fail the build if the binary cannot be executed
5755/// due to being for a foreign binary to the host system which is running the
5856/// build graph.
5957/// Command-line arguments such as -fqemu and -fwasmtime may affect whether a
6058/// binary is detected as foreign, as well as system configuration such as
6159/// Rosetta (macOS) and binfmt_misc (Linux).
62/// If this RunStep is considered to have side-effects, then this flag does
60/// If this Run step is considered to have side-effects, then this flag does
6361/// nothing.
6462skip_foreign_checks: bool = false,
6563
......@@ -73,18 +71,18 @@ captured_stderr: ?*Output = null,
7371has_side_effects: bool = false,
7472
7573pub const StdIo = union(enum) {
76 /// Whether the RunStep has side-effects will be determined by whether or not one
74 /// Whether the Run step has side-effects will be determined by whether or not one
7775 /// of the args is an output file (added with `addOutputFileArg`).
78 /// If the RunStep is determined to have side-effects, this is the same as `inherit`.
76 /// If the Run step is determined to have side-effects, this is the same as `inherit`.
7977 /// The step will fail if the subprocess crashes or returns a non-zero exit code.
8078 infer_from_args,
81 /// Causes the RunStep to be considered to have side-effects, and therefore
79 /// Causes the Run step to be considered to have side-effects, and therefore
8280 /// always execute when it appears in the build graph.
8381 /// It also means that this step will obtain a global lock to prevent other
8482 /// steps from running in the meantime.
8583 /// The step will fail if the subprocess crashes or returns a non-zero exit code.
8684 inherit,
87 /// Causes the RunStep to be considered to *not* have side-effects. The
85 /// Causes the Run step to be considered to *not* have side-effects. The
8886 /// process will be re-executed if any of the input dependencies are
8987 /// modified. The exit code and standard I/O streams will be checked for
9088 /// certain conditions, and the step will succeed or fail based on these
......@@ -92,7 +90,7 @@ pub const StdIo = union(enum) {
9290 /// Note that an explicit check for exit code 0 needs to be added to this
9391 /// list if such a check is desirable.
9492 check: std.ArrayList(Check),
95 /// This RunStep is running a zig unit test binary and will communicate
93 /// This Run step is running a zig unit test binary and will communicate
9694 /// extra metadata over the IPC protocol.
9795 zig_test,
9896
......@@ -106,7 +104,7 @@ pub const StdIo = union(enum) {
106104};
107105
108106pub const Arg = union(enum) {
109 artifact: *CompileStep,
107 artifact: *Step.Compile,
110108 file_source: std.Build.FileSource,
111109 directory_source: std.Build.FileSource,
112110 bytes: []u8,
......@@ -119,8 +117,8 @@ pub const Output = struct {
119117 basename: []const u8,
120118};
121119
122pub fn create(owner: *std.Build, name: []const u8) *RunStep {
123 const self = owner.allocator.create(RunStep) catch @panic("OOM");
120pub fn create(owner: *std.Build, name: []const u8) *Run {
121 const self = owner.allocator.create(Run) catch @panic("OOM");
124122 self.* = .{
125123 .step = Step.init(.{
126124 .id = base_id,
......@@ -135,17 +133,17 @@ pub fn create(owner: *std.Build, name: []const u8) *RunStep {
135133 return self;
136134}
137135
138pub fn setName(self: *RunStep, name: []const u8) void {
136pub fn setName(self: *Run, name: []const u8) void {
139137 self.step.name = name;
140138 self.rename_step_with_output_arg = false;
141139}
142140
143pub fn enableTestRunnerMode(rs: *RunStep) void {
141pub fn enableTestRunnerMode(rs: *Run) void {
144142 rs.stdio = .zig_test;
145143 rs.addArgs(&.{"--listen=-"});
146144}
147145
148pub fn addArtifactArg(self: *RunStep, artifact: *CompileStep) void {
146pub fn addArtifactArg(self: *Run, artifact: *Step.Compile) void {
149147 self.argv.append(Arg{ .artifact = artifact }) catch @panic("OOM");
150148 self.step.dependOn(&artifact.step);
151149}
......@@ -153,12 +151,12 @@ pub fn addArtifactArg(self: *RunStep, artifact: *CompileStep) void {
153151/// This provides file path as a command line argument to the command being
154152/// run, and returns a FileSource which can be used as inputs to other APIs
155153/// throughout the build system.
156pub fn addOutputFileArg(rs: *RunStep, basename: []const u8) std.Build.FileSource {
154pub fn addOutputFileArg(rs: *Run, basename: []const u8) std.Build.FileSource {
157155 return addPrefixedOutputFileArg(rs, "", basename);
158156}
159157
160158pub fn addPrefixedOutputFileArg(
161 rs: *RunStep,
159 rs: *Run,
162160 prefix: []const u8,
163161 basename: []const u8,
164162) std.Build.FileSource {
......@@ -179,38 +177,38 @@ pub fn addPrefixedOutputFileArg(
179177 return .{ .generated = &output.generated_file };
180178}
181179
182pub fn addFileSourceArg(self: *RunStep, file_source: std.Build.FileSource) void {
180pub fn addFileSourceArg(self: *Run, file_source: std.Build.FileSource) void {
183181 self.argv.append(.{
184182 .file_source = file_source.dupe(self.step.owner),
185183 }) catch @panic("OOM");
186184 file_source.addStepDependencies(&self.step);
187185}
188186
189pub fn addDirectorySourceArg(self: *RunStep, directory_source: std.Build.FileSource) void {
187pub fn addDirectorySourceArg(self: *Run, directory_source: std.Build.FileSource) void {
190188 self.argv.append(.{
191189 .directory_source = directory_source.dupe(self.step.owner),
192190 }) catch @panic("OOM");
193191 directory_source.addStepDependencies(&self.step);
194192}
195193
196pub fn addArg(self: *RunStep, arg: []const u8) void {
194pub fn addArg(self: *Run, arg: []const u8) void {
197195 self.argv.append(.{ .bytes = self.step.owner.dupe(arg) }) catch @panic("OOM");
198196}
199197
200pub fn addArgs(self: *RunStep, args: []const []const u8) void {
198pub fn addArgs(self: *Run, args: []const []const u8) void {
201199 for (args) |arg| {
202200 self.addArg(arg);
203201 }
204202}
205203
206pub fn clearEnvironment(self: *RunStep) void {
204pub fn clearEnvironment(self: *Run) void {
207205 const b = self.step.owner;
208206 const new_env_map = b.allocator.create(EnvMap) catch @panic("OOM");
209207 new_env_map.* = EnvMap.init(b.allocator);
210208 self.env_map = new_env_map;
211209}
212210
213pub fn addPathDir(self: *RunStep, search_path: []const u8) void {
211pub fn addPathDir(self: *Run, search_path: []const u8) void {
214212 const b = self.step.owner;
215213 const env_map = getEnvMapInternal(self);
216214
......@@ -225,11 +223,11 @@ pub fn addPathDir(self: *RunStep, search_path: []const u8) void {
225223 }
226224}
227225
228pub fn getEnvMap(self: *RunStep) *EnvMap {
226pub fn getEnvMap(self: *Run) *EnvMap {
229227 return getEnvMapInternal(self);
230228}
231229
232fn getEnvMapInternal(self: *RunStep) *EnvMap {
230fn getEnvMapInternal(self: *Run) *EnvMap {
233231 const arena = self.step.owner.allocator;
234232 return self.env_map orelse {
235233 const env_map = arena.create(EnvMap) catch @panic("OOM");
......@@ -239,25 +237,25 @@ fn getEnvMapInternal(self: *RunStep) *EnvMap {
239237 };
240238}
241239
242pub fn setEnvironmentVariable(self: *RunStep, key: []const u8, value: []const u8) void {
240pub fn setEnvironmentVariable(self: *Run, key: []const u8, value: []const u8) void {
243241 const b = self.step.owner;
244242 const env_map = self.getEnvMap();
245243 env_map.put(b.dupe(key), b.dupe(value)) catch @panic("unhandled error");
246244}
247245
248pub fn removeEnvironmentVariable(self: *RunStep, key: []const u8) void {
246pub fn removeEnvironmentVariable(self: *Run, key: []const u8) void {
249247 self.getEnvMap().remove(key);
250248}
251249
252250/// Adds a check for exact stderr match. Does not add any other checks.
253pub fn expectStdErrEqual(self: *RunStep, bytes: []const u8) void {
251pub fn expectStdErrEqual(self: *Run, bytes: []const u8) void {
254252 const new_check: StdIo.Check = .{ .expect_stderr_exact = self.step.owner.dupe(bytes) };
255253 self.addCheck(new_check);
256254}
257255
258256/// Adds a check for exact stdout match as well as a check for exit code 0, if
259257/// there is not already an expected termination check.
260pub fn expectStdOutEqual(self: *RunStep, bytes: []const u8) void {
258pub fn expectStdOutEqual(self: *Run, bytes: []const u8) void {
261259 const new_check: StdIo.Check = .{ .expect_stdout_exact = self.step.owner.dupe(bytes) };
262260 self.addCheck(new_check);
263261 if (!self.hasTermCheck()) {
......@@ -265,12 +263,12 @@ pub fn expectStdOutEqual(self: *RunStep, bytes: []const u8) void {
265263 }
266264}
267265
268pub fn expectExitCode(self: *RunStep, code: u8) void {
266pub fn expectExitCode(self: *Run, code: u8) void {
269267 const new_check: StdIo.Check = .{ .expect_term = .{ .Exited = code } };
270268 self.addCheck(new_check);
271269}
272270
273pub fn hasTermCheck(self: RunStep) bool {
271pub fn hasTermCheck(self: Run) bool {
274272 for (self.stdio.check.items) |check| switch (check) {
275273 .expect_term => return true,
276274 else => continue,
......@@ -278,18 +276,18 @@ pub fn hasTermCheck(self: RunStep) bool {
278276 return false;
279277}
280278
281pub fn addCheck(self: *RunStep, new_check: StdIo.Check) void {
279pub fn addCheck(self: *Run, new_check: StdIo.Check) void {
282280 switch (self.stdio) {
283281 .infer_from_args => {
284282 self.stdio = .{ .check = std.ArrayList(StdIo.Check).init(self.step.owner.allocator) };
285283 self.stdio.check.append(new_check) catch @panic("OOM");
286284 },
287285 .check => |*checks| checks.append(new_check) catch @panic("OOM"),
288 else => @panic("illegal call to addCheck: conflicting helper method calls. Suggest to directly set stdio field of RunStep instead"),
286 else => @panic("illegal call to addCheck: conflicting helper method calls. Suggest to directly set stdio field of Run instead"),
289287 }
290288}
291289
292pub fn captureStdErr(self: *RunStep) std.Build.FileSource {
290pub fn captureStdErr(self: *Run) std.Build.FileSource {
293291 assert(self.stdio != .inherit);
294292
295293 if (self.captured_stderr) |output| return .{ .generated = &output.generated_file };
......@@ -304,7 +302,7 @@ pub fn captureStdErr(self: *RunStep) std.Build.FileSource {
304302 return .{ .generated = &output.generated_file };
305303}
306304
307pub fn captureStdOut(self: *RunStep) std.Build.FileSource {
305pub fn captureStdOut(self: *Run) std.Build.FileSource {
308306 assert(self.stdio != .inherit);
309307
310308 if (self.captured_stdout) |output| return .{ .generated = &output.generated_file };
......@@ -319,8 +317,8 @@ pub fn captureStdOut(self: *RunStep) std.Build.FileSource {
319317 return .{ .generated = &output.generated_file };
320318}
321319
322/// Returns whether the RunStep has side effects *other than* updating the output arguments.
323fn hasSideEffects(self: RunStep) bool {
320/// Returns whether the Run step has side effects *other than* updating the output arguments.
321fn hasSideEffects(self: Run) bool {
324322 if (self.has_side_effects) return true;
325323 return switch (self.stdio) {
326324 .infer_from_args => !self.hasAnyOutputArgs(),
......@@ -330,7 +328,7 @@ fn hasSideEffects(self: RunStep) bool {
330328 };
331329}
332330
333fn hasAnyOutputArgs(self: RunStep) bool {
331fn hasAnyOutputArgs(self: Run) bool {
334332 if (self.captured_stdout != null) return true;
335333 if (self.captured_stderr != null) return true;
336334 for (self.argv.items) |arg| switch (arg) {
......@@ -371,7 +369,7 @@ fn checksContainStderr(checks: []const StdIo.Check) bool {
371369fn make(step: *Step, prog_node: *std.Progress.Node) !void {
372370 const b = step.owner;
373371 const arena = b.allocator;
374 const self = @fieldParentPtr(RunStep, "step", step);
372 const self = @fieldParentPtr(Run, "step", step);
375373 const has_side_effects = self.hasSideEffects();
376374
377375 var argv_list = ArrayList([]const u8).init(arena);
......@@ -541,7 +539,7 @@ fn termMatches(expected: ?std.process.Child.Term, actual: std.process.Child.Term
541539}
542540
543541fn runCommand(
544 self: *RunStep,
542 self: *Run,
545543 argv: []const []const u8,
546544 has_side_effects: bool,
547545 digest: ?*const [std.Build.Cache.hex_digest_len]u8,
......@@ -567,7 +565,7 @@ fn runCommand(
567565 // FileNotFound: can happen with a wrong dynamic linker path
568566 if (err == error.InvalidExe or err == error.FileNotFound) interpret: {
569567 // TODO: learn the target from the binary directly rather than from
570 // relying on it being a CompileStep. This will make this logic
568 // relying on it being a Compile step. This will make this logic
571569 // work even for the edge case that the binary was produced by a
572570 // third party.
573571 const exe = switch (self.argv.items[0]) {
......@@ -862,7 +860,7 @@ const ChildProcResult = struct {
862860};
863861
864862fn spawnChildAndCollect(
865 self: *RunStep,
863 self: *Run,
866864 argv: []const []const u8,
867865 has_side_effects: bool,
868866 prog_node: *std.Progress.Node,
......@@ -936,7 +934,7 @@ const StdIoResult = struct {
936934};
937935
938936fn evalZigTest(
939 self: *RunStep,
937 self: *Run,
940938 child: *std.process.Child,
941939 prog_node: *std.Progress.Node,
942940) !StdIoResult {
......@@ -1121,7 +1119,7 @@ fn sendRunTestMessage(file: std.fs.File, index: u32) !void {
11211119 try file.writeAll(full_msg);
11221120}
11231121
1124fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {
1122fn evalGeneric(self: *Run, child: *std.process.Child) !StdIoResult {
11251123 const arena = self.step.owner.allocator;
11261124
11271125 if (self.stdin) |stdin| {
......@@ -1188,7 +1186,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {
11881186 };
11891187}
11901188
1191fn addPathForDynLibs(self: *RunStep, artifact: *CompileStep) void {
1189fn addPathForDynLibs(self: *Run, artifact: *Step.Compile) void {
11921190 const b = self.step.owner;
11931191 for (artifact.link_objects.items) |link_object| {
11941192 switch (link_object) {
......@@ -1204,10 +1202,10 @@ fn addPathForDynLibs(self: *RunStep, artifact: *CompileStep) void {
12041202}
12051203
12061204fn failForeign(
1207 self: *RunStep,
1205 self: *Run,
12081206 suggested_flag: []const u8,
12091207 argv0: []const u8,
1210 exe: *CompileStep,
1208 exe: *Step.Compile,
12111209) error{ MakeFailed, MakeSkipped, OutOfMemory } {
12121210 switch (self.stdio) {
12131211 .check, .zig_test => {
lib/std/Build/Step/TranslateC.zig+12-14
......@@ -1,12 +1,10 @@
11const std = @import("std");
22const Step = std.Build.Step;
3const CompileStep = std.Build.CompileStep;
4const CheckFileStep = std.Build.CheckFileStep;
53const fs = std.fs;
64const mem = std.mem;
75const CrossTarget = std.zig.CrossTarget;
86
9const TranslateCStep = @This();
7const TranslateC = @This();
108
119pub const base_id = .translate_c;
1210
......@@ -25,10 +23,10 @@ pub const Options = struct {
2523 optimize: std.builtin.OptimizeMode,
2624};
2725
28pub fn create(owner: *std.Build, options: Options) *TranslateCStep {
29 const self = owner.allocator.create(TranslateCStep) catch @panic("OOM");
26pub fn create(owner: *std.Build, options: Options) *TranslateC {
27 const self = owner.allocator.create(TranslateC) catch @panic("OOM");
3028 const source = options.source_file.dupe(owner);
31 self.* = TranslateCStep{
29 self.* = TranslateC{
3230 .step = Step.init(.{
3331 .id = .translate_c,
3432 .name = "translate-c",
......@@ -52,11 +50,11 @@ pub const AddExecutableOptions = struct {
5250 version: ?std.builtin.Version = null,
5351 target: ?CrossTarget = null,
5452 optimize: ?std.builtin.Mode = null,
55 linkage: ?CompileStep.Linkage = null,
53 linkage: ?Step.Compile.Linkage = null,
5654};
5755
5856/// Creates a step to build an executable from the translated source.
59pub fn addExecutable(self: *TranslateCStep, options: AddExecutableOptions) *CompileStep {
57pub fn addExecutable(self: *TranslateC, options: AddExecutableOptions) *Step.Compile {
6058 return self.step.owner.addExecutable(.{
6159 .root_source_file = .{ .generated = &self.output_file },
6260 .name = options.name orelse "translated_c",
......@@ -67,12 +65,12 @@ pub fn addExecutable(self: *TranslateCStep, options: AddExecutableOptions) *Comp
6765 });
6866}
6967
70pub fn addIncludeDir(self: *TranslateCStep, include_dir: []const u8) void {
68pub fn addIncludeDir(self: *TranslateC, include_dir: []const u8) void {
7169 self.include_dirs.append(self.step.owner.dupePath(include_dir)) catch @panic("OOM");
7270}
7371
74pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8) *CheckFileStep {
75 return CheckFileStep.create(
72pub fn addCheckFile(self: *TranslateC, expected_matches: []const []const u8) *Step.CheckFile {
73 return Step.CheckFile.create(
7674 self.step.owner,
7775 .{ .generated = &self.output_file },
7876 .{ .expected_matches = expected_matches },
......@@ -81,19 +79,19 @@ pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8)
8179
8280/// If the value is omitted, it is set to 1.
8381/// `name` and `value` need not live longer than the function call.
84pub fn defineCMacro(self: *TranslateCStep, name: []const u8, value: ?[]const u8) void {
82pub fn defineCMacro(self: *TranslateC, name: []const u8, value: ?[]const u8) void {
8583 const macro = std.Build.constructCMacro(self.step.owner.allocator, name, value);
8684 self.c_macros.append(macro) catch @panic("OOM");
8785}
8886
8987/// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1.
90pub fn defineCMacroRaw(self: *TranslateCStep, name_and_value: []const u8) void {
88pub fn defineCMacroRaw(self: *TranslateC, name_and_value: []const u8) void {
9189 self.c_macros.append(self.step.owner.dupe(name_and_value)) catch @panic("OOM");
9290}
9391
9492fn make(step: *Step, prog_node: *std.Progress.Node) !void {
9593 const b = step.owner;
96 const self = @fieldParentPtr(TranslateCStep, "step", step);
94 const self = @fieldParentPtr(TranslateC, "step", step);
9795
9896 var argv_list = std.ArrayList([]const u8).init(b.allocator);
9997 try argv_list.append(b.zig_exe);
lib/std/Build/Step/WriteFile.zig+19-19
......@@ -1,4 +1,4 @@
1//! WriteFileStep is primarily used to create a directory in an appropriate
1//! WriteFile is primarily used to create a directory in an appropriate
22//! location inside the local cache which has a set of files that have either
33//! been generated during the build, or are copied from the source package.
44//!
......@@ -12,7 +12,7 @@ const std = @import("std");
1212const Step = std.Build.Step;
1313const fs = std.fs;
1414const ArrayList = std.ArrayList;
15const WriteFileStep = @This();
15const WriteFile = @This();
1616
1717step: Step,
1818/// The elements here are pointers because we need stable pointers for the
......@@ -39,8 +39,8 @@ pub const Contents = union(enum) {
3939 copy: std.Build.FileSource,
4040};
4141
42pub fn create(owner: *std.Build) *WriteFileStep {
43 const wf = owner.allocator.create(WriteFileStep) catch @panic("OOM");
42pub fn create(owner: *std.Build) *WriteFile {
43 const wf = owner.allocator.create(WriteFile) catch @panic("OOM");
4444 wf.* = .{
4545 .step = Step.init(.{
4646 .id = .write_file,
......@@ -55,7 +55,7 @@ pub fn create(owner: *std.Build) *WriteFileStep {
5555 return wf;
5656}
5757
58pub fn add(wf: *WriteFileStep, sub_path: []const u8, bytes: []const u8) void {
58pub fn add(wf: *WriteFile, sub_path: []const u8, bytes: []const u8) void {
5959 const b = wf.step.owner;
6060 const gpa = b.allocator;
6161 const file = gpa.create(File) catch @panic("OOM");
......@@ -72,11 +72,11 @@ pub fn add(wf: *WriteFileStep, sub_path: []const u8, bytes: []const u8) void {
7272/// Place the file into the generated directory within the local cache,
7373/// along with all the rest of the files added to this step. The parameter
7474/// here is the destination path relative to the local cache directory
75/// associated with this WriteFileStep. It may be a basename, or it may
75/// associated with this WriteFile. It may be a basename, or it may
7676/// include sub-directories, in which case this step will ensure the
7777/// required sub-path exists.
7878/// This is the option expected to be used most commonly with `addCopyFile`.
79pub fn addCopyFile(wf: *WriteFileStep, source: std.Build.FileSource, sub_path: []const u8) void {
79pub fn addCopyFile(wf: *WriteFile, source: std.Build.FileSource, sub_path: []const u8) void {
8080 const b = wf.step.owner;
8181 const gpa = b.allocator;
8282 const file = gpa.create(File) catch @panic("OOM");
......@@ -97,7 +97,7 @@ pub fn addCopyFile(wf: *WriteFileStep, source: std.Build.FileSource, sub_path: [
9797/// run by a developer with intent to modify source files and then commit
9898/// those changes to version control.
9999/// A file added this way is not available with `getFileSource`.
100pub fn addCopyFileToSource(wf: *WriteFileStep, source: std.Build.FileSource, sub_path: []const u8) void {
100pub fn addCopyFileToSource(wf: *WriteFile, source: std.Build.FileSource, sub_path: []const u8) void {
101101 const b = wf.step.owner;
102102 wf.output_source_files.append(b.allocator, .{
103103 .contents = .{ .copy = source },
......@@ -112,7 +112,7 @@ pub fn addCopyFileToSource(wf: *WriteFileStep, source: std.Build.FileSource, sub
112112/// run by a developer with intent to modify source files and then commit
113113/// those changes to version control.
114114/// A file added this way is not available with `getFileSource`.
115pub fn addBytesToSource(wf: *WriteFileStep, bytes: []const u8, sub_path: []const u8) void {
115pub fn addBytesToSource(wf: *WriteFile, bytes: []const u8, sub_path: []const u8) void {
116116 const b = wf.step.owner;
117117 wf.output_source_files.append(b.allocator, .{
118118 .contents = .{ .bytes = bytes },
......@@ -121,7 +121,7 @@ pub fn addBytesToSource(wf: *WriteFileStep, bytes: []const u8, sub_path: []const
121121}
122122
123123/// Gets a file source for the given sub_path. If the file does not exist, returns `null`.
124pub fn getFileSource(wf: *WriteFileStep, sub_path: []const u8) ?std.Build.FileSource {
124pub fn getFileSource(wf: *WriteFile, sub_path: []const u8) ?std.Build.FileSource {
125125 for (wf.files.items) |file| {
126126 if (std.mem.eql(u8, file.sub_path, sub_path)) {
127127 return .{ .generated = &file.generated_file };
......@@ -131,12 +131,12 @@ pub fn getFileSource(wf: *WriteFileStep, sub_path: []const u8) ?std.Build.FileSo
131131}
132132
133133/// Returns a `FileSource` representing the base directory that contains all the
134/// files from this `WriteFileStep`.
135pub fn getDirectorySource(wf: *WriteFileStep) std.Build.FileSource {
134/// files from this `WriteFile`.
135pub fn getDirectorySource(wf: *WriteFile) std.Build.FileSource {
136136 return .{ .generated = &wf.generated_directory };
137137}
138138
139fn maybeUpdateName(wf: *WriteFileStep) void {
139fn maybeUpdateName(wf: *WriteFile) void {
140140 if (wf.files.items.len == 1) {
141141 // First time adding a file; update name.
142142 if (std.mem.eql(u8, wf.step.name, "WriteFile")) {
......@@ -148,10 +148,10 @@ fn maybeUpdateName(wf: *WriteFileStep) void {
148148fn make(step: *Step, prog_node: *std.Progress.Node) !void {
149149 _ = prog_node;
150150 const b = step.owner;
151 const wf = @fieldParentPtr(WriteFileStep, "step", step);
151 const wf = @fieldParentPtr(WriteFile, "step", step);
152152
153153 // Writing to source files is kind of an extra capability of this
154 // WriteFileStep - arguably it should be a different step. But anyway here
154 // WriteFile - arguably it should be a different step. But anyway here
155155 // it is, it happens unconditionally and does not interact with the other
156156 // files here.
157157 var any_miss = false;
......@@ -194,14 +194,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
194194 // the data to a file would probably be very fast - but as a way to find a canonical
195195 // location to put build artifacts.
196196
197 // If, for example, a hard-coded path was used as the location to put WriteFileStep
198 // files, then two WriteFileSteps executing in parallel might clobber each other.
197 // If, for example, a hard-coded path was used as the location to put WriteFile
198 // files, then two WriteFiles executing in parallel might clobber each other.
199199
200200 var man = b.cache.obtain();
201201 defer man.deinit();
202202
203 // Random bytes to make WriteFileStep unique. Refresh this with
204 // new random bytes when WriteFileStep implementation is modified
203 // Random bytes to make WriteFile unique. Refresh this with
204 // new random bytes when WriteFile implementation is modified
205205 // in a non-backwards-compatible way.
206206 man.hash.add(@as(u32, 0xd767ee59));
207207
test/link/macho/dead_strip/build.zig+1-1
......@@ -42,7 +42,7 @@ fn createScenario(
4242 optimize: std.builtin.OptimizeMode,
4343 target: std.zig.CrossTarget,
4444 name: []const u8,
45) *std.Build.CompileStep {
45) *std.Build.Step.Compile {
4646 const exe = b.addExecutable(.{
4747 .name = name,
4848 .optimize = optimize,
test/link/macho/dead_strip_dylibs/build.zig+1-1
......@@ -46,7 +46,7 @@ fn createScenario(
4646 b: *std.Build,
4747 optimize: std.builtin.OptimizeMode,
4848 name: []const u8,
49) *std.Build.CompileStep {
49) *std.Build.Step.Compile {
5050 const exe = b.addExecutable(.{
5151 .name = name,
5252 .optimize = optimize,
test/link/macho/headerpad/build.zig+1-1
......@@ -104,7 +104,7 @@ fn simpleExe(
104104 b: *std.Build,
105105 optimize: std.builtin.OptimizeMode,
106106 name: []const u8,
107) *std.Build.CompileStep {
107) *std.Build.Step.Compile {
108108 const exe = b.addExecutable(.{
109109 .name = name,
110110 .optimize = optimize,
test/link/macho/search_strategy/build.zig+1-1
......@@ -46,7 +46,7 @@ fn createScenario(
4646 optimize: std.builtin.OptimizeMode,
4747 target: std.zig.CrossTarget,
4848 name: []const u8,
49) *std.Build.CompileStep {
49) *std.Build.Step.Compile {
5050 const static = b.addStaticLibrary(.{
5151 .name = name,
5252 .optimize = optimize,
test/link/macho/unwind_info/build.zig+1-1
......@@ -65,7 +65,7 @@ fn createScenario(
6565 optimize: std.builtin.OptimizeMode,
6666 target: std.zig.CrossTarget,
6767 name: []const u8,
68) *std.Build.CompileStep {
68) *std.Build.Step.Compile {
6969 const exe = b.addExecutable(.{
7070 .name = name,
7171 .optimize = optimize,
test/link/macho/uuid/build.zig+1-2
......@@ -1,5 +1,4 @@
11const std = @import("std");
2const CompileStep = std.Build.CompileStep;
32const FileSource = std.Build.FileSource;
43const Step = std.Build.Step;
54
......@@ -60,7 +59,7 @@ fn simpleDylib(
6059 b: *std.Build,
6160 optimize: std.builtin.OptimizeMode,
6261 target: std.zig.CrossTarget,
63) *std.Build.CompileStep {
62) *std.Build.Step.Compile {
6463 const dylib = b.addSharedLibrary(.{
6564 .name = "test",
6665 .version = .{ .major = 1, .minor = 0 },
test/src/Cases.zig+1-1
......@@ -465,7 +465,7 @@ pub fn lowerToBuildSteps(
465465 parent_step: *std.Build.Step,
466466 opt_test_filter: ?[]const u8,
467467 cases_dir_path: []const u8,
468 incremental_exe: *std.Build.CompileStep,
468 incremental_exe: *std.Build.Step.Compile,
469469) void {
470470 for (self.incremental_cases.items) |incr_case| {
471471 if (opt_test_filter) |test_filter| {
test/src/StackTrace.zig+1-1
......@@ -3,7 +3,7 @@ step: *Step,
33test_index: usize,
44test_filter: ?[]const u8,
55optimize_modes: []const OptimizeMode,
6check_exe: *std.Build.CompileStep,
6check_exe: *std.Build.Step.Compile,
77
88const Expect = [@typeInfo(OptimizeMode).Enum.fields.len][]const u8;
99
test/standalone/install_raw_hex/build.zig-1
......@@ -1,6 +1,5 @@
11const builtin = @import("builtin");
22const std = @import("std");
3const CheckFileStep = std.Build.CheckFileStep;
43
54pub fn build(b: *std.Build) void {
65 const test_step = b.step("test", "Test it");
test/tests.zig+1-1
......@@ -1132,7 +1132,7 @@ pub fn addCases(
11321132 b: *std.Build,
11331133 parent_step: *Step,
11341134 opt_test_filter: ?[]const u8,
1135 check_case_exe: *std.Build.CompileStep,
1135 check_case_exe: *std.Build.Step.Compile,
11361136) !void {
11371137 const arena = b.allocator;
11381138 const gpa = b.allocator;