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(...@@ -533,7 +533,7 @@ fn addCompilerStep(
533 b: *std.Build,533 b: *std.Build,
534 optimize: std.builtin.OptimizeMode,534 optimize: std.builtin.OptimizeMode,
535 target: std.zig.CrossTarget,535 target: std.zig.CrossTarget,
536) *std.Build.CompileStep {536) *std.Build.Step.Compile {
537 const exe = b.addExecutable(.{537 const exe = b.addExecutable(.{
538 .name = "zig",538 .name = "zig",
539 .root_source_file = .{ .path = "src/main.zig" },539 .root_source_file = .{ .path = "src/main.zig" },
...@@ -561,7 +561,7 @@ const exe_cflags = [_][]const u8{...@@ -561,7 +561,7 @@ const exe_cflags = [_][]const u8{
561fn addCmakeCfgOptionsToExe(561fn addCmakeCfgOptionsToExe(
562 b: *std.Build,562 b: *std.Build,
563 cfg: CMakeConfig,563 cfg: CMakeConfig,
564 exe: *std.Build.CompileStep,564 exe: *std.Build.Step.Compile,
565 use_zig_libcxx: bool,565 use_zig_libcxx: bool,
566) !void {566) !void {
567 if (exe.target.isDarwin()) {567 if (exe.target.isDarwin()) {
...@@ -640,7 +640,7 @@ fn addCmakeCfgOptionsToExe(...@@ -640,7 +640,7 @@ fn addCmakeCfgOptionsToExe(
640 }640 }
641}641}
642642
643fn addStaticLlvmOptionsToExe(exe: *std.Build.CompileStep) !void {643fn addStaticLlvmOptionsToExe(exe: *std.Build.Step.Compile) !void {
644 // Adds the Zig C++ sources which both stage1 and stage2 need.644 // Adds the Zig C++ sources which both stage1 and stage2 need.
645 //645 //
646 // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling646 // We need this because otherwise zig_clang_cc1_main.cpp ends up pulling
...@@ -679,7 +679,7 @@ fn addStaticLlvmOptionsToExe(exe: *std.Build.CompileStep) !void {...@@ -679,7 +679,7 @@ fn addStaticLlvmOptionsToExe(exe: *std.Build.CompileStep) !void {
679fn addCxxKnownPath(679fn addCxxKnownPath(
680 b: *std.Build,680 b: *std.Build,
681 ctx: CMakeConfig,681 ctx: CMakeConfig,
682 exe: *std.Build.CompileStep,682 exe: *std.Build.Step.Compile,
683 objname: []const u8,683 objname: []const u8,
684 errtxt: ?[]const u8,684 errtxt: ?[]const u8,
685 need_cpp_includes: bool,685 need_cpp_includes: bool,
...@@ -709,7 +709,7 @@ fn addCxxKnownPath(...@@ -709,7 +709,7 @@ fn addCxxKnownPath(
709 }709 }
710}710}
711711
712fn addCMakeLibraryList(exe: *std.Build.CompileStep, list: []const u8) void {712fn addCMakeLibraryList(exe: *std.Build.Step.Compile, list: []const u8) void {
713 var it = mem.tokenize(u8, list, ";");713 var it = mem.tokenize(u8, list, ";");
714 while (it.next()) |lib| {714 while (it.next()) |lib| {
715 if (mem.startsWith(u8, lib, "-l")) {715 if (mem.startsWith(u8, lib, "-l")) {
...@@ -723,7 +723,7 @@ fn addCMakeLibraryList(exe: *std.Build.CompileStep, list: []const u8) void {...@@ -723,7 +723,7 @@ fn addCMakeLibraryList(exe: *std.Build.CompileStep, list: []const u8) void {
723}723}
724724
725const CMakeConfig = struct {725const CMakeConfig = struct {
726 llvm_linkage: std.Build.CompileStep.Linkage,726 llvm_linkage: std.Build.Step.Compile.Linkage,
727 cmake_binary_dir: []const u8,727 cmake_binary_dir: []const u8,
728 cmake_prefix_path: []const u8,728 cmake_prefix_path: []const u8,
729 cmake_static_library_prefix: []const u8,729 cmake_static_library_prefix: []const u8,
lib/init-exe/build.zig+1-1
...@@ -29,7 +29,7 @@ pub fn build(b: *std.Build) void {...@@ -29,7 +29,7 @@ pub fn build(b: *std.Build) void {
29 // step when running `zig build`).29 // step when running `zig build`).
30 b.installArtifact(exe);30 b.installArtifact(exe);
3131
32 // This *creates* a RunStep in the build graph, to be executed when another32 // This *creates* a Run step in the build graph, to be executed when another
33 // step is evaluated that depends on it. The next line below will establish33 // step is evaluated that depends on it. The next line below will establish
34 // such a dependency.34 // such a dependency.
35 const run_cmd = b.addRunArtifact(exe);35 const run_cmd = b.addRunArtifact(exe);
lib/std/Build.zig+76-74
...@@ -21,27 +21,41 @@ const Build = @This();...@@ -21,27 +21,41 @@ const Build = @This();
2121
22pub const Cache = @import("Build/Cache.zig");22pub const Cache = @import("Build/Cache.zig");
2323
24/// deprecated: use `CompileStep`.24/// deprecated: use `Step.Compile`.
25pub const LibExeObjStep = CompileStep;25pub const LibExeObjStep = Step.Compile;
26/// deprecated: use `Build`.26/// deprecated: use `Build`.
27pub const Builder = Build;27pub const Builder = Build;
28/// deprecated: use `InstallDirStep.Options`28/// deprecated: use `Step.InstallDir.Options`
29pub const InstallDirectoryOptions = InstallDirStep.Options;29pub const InstallDirectoryOptions = Step.InstallDir.Options;
3030
31pub const Step = @import("Build/Step.zig");31pub const Step = @import("Build/Step.zig");
32/// deprecated: use `Step.CheckFile`.
32pub const CheckFileStep = @import("Build/Step/CheckFile.zig");33pub const CheckFileStep = @import("Build/Step/CheckFile.zig");
34/// deprecated: use `Step.CheckObject`.
33pub const CheckObjectStep = @import("Build/Step/CheckObject.zig");35pub const CheckObjectStep = @import("Build/Step/CheckObject.zig");
36/// deprecated: use `Step.ConfigHeader`.
34pub const ConfigHeaderStep = @import("Build/Step/ConfigHeader.zig");37pub const ConfigHeaderStep = @import("Build/Step/ConfigHeader.zig");
38/// deprecated: use `Step.Fmt`.
35pub const FmtStep = @import("Build/Step/Fmt.zig");39pub const FmtStep = @import("Build/Step/Fmt.zig");
40/// deprecated: use `Step.InstallArtifact`.
36pub const InstallArtifactStep = @import("Build/Step/InstallArtifact.zig");41pub const InstallArtifactStep = @import("Build/Step/InstallArtifact.zig");
42/// deprecated: use `Step.InstallDir`.
37pub const InstallDirStep = @import("Build/Step/InstallDir.zig");43pub const InstallDirStep = @import("Build/Step/InstallDir.zig");
44/// deprecated: use `Step.InstallFile`.
38pub const InstallFileStep = @import("Build/Step/InstallFile.zig");45pub const InstallFileStep = @import("Build/Step/InstallFile.zig");
46/// deprecated: use `Step.ObjCopy`.
39pub const ObjCopyStep = @import("Build/Step/ObjCopy.zig");47pub const ObjCopyStep = @import("Build/Step/ObjCopy.zig");
48/// deprecated: use `Step.Compile`.
40pub const CompileStep = @import("Build/Step/Compile.zig");49pub const CompileStep = @import("Build/Step/Compile.zig");
50/// deprecated: use `Step.Options`.
41pub const OptionsStep = @import("Build/Step/Options.zig");51pub const OptionsStep = @import("Build/Step/Options.zig");
52/// deprecated: use `Step.RemoveDir`.
42pub const RemoveDirStep = @import("Build/Step/RemoveDir.zig");53pub const RemoveDirStep = @import("Build/Step/RemoveDir.zig");
54/// deprecated: use `Step.Run`.
43pub const RunStep = @import("Build/Step/Run.zig");55pub const RunStep = @import("Build/Step/Run.zig");
56/// deprecated: use `Step.TranslateC`.
44pub const TranslateCStep = @import("Build/Step/TranslateC.zig");57pub const TranslateCStep = @import("Build/Step/TranslateC.zig");
58/// deprecated: use `Step.WriteFile`.
45pub const WriteFileStep = @import("Build/Step/WriteFile.zig");59pub const WriteFileStep = @import("Build/Step/WriteFile.zig");
4660
47install_tls: TopLevelStep,61install_tls: TopLevelStep,
...@@ -442,8 +456,8 @@ pub fn resolveInstallPrefix(self: *Build, install_prefix: ?[]const u8, dir_list:...@@ -442,8 +456,8 @@ pub fn resolveInstallPrefix(self: *Build, install_prefix: ?[]const u8, dir_list:
442 self.h_dir = self.pathJoin(&h_list);456 self.h_dir = self.pathJoin(&h_list);
443}457}
444458
445pub fn addOptions(self: *Build) *OptionsStep {459pub fn addOptions(self: *Build) *Step.Options {
446 return OptionsStep.create(self);460 return Step.Options.create(self);
447}461}
448462
449pub const ExecutableOptions = struct {463pub const ExecutableOptions = struct {
...@@ -452,7 +466,7 @@ pub const ExecutableOptions = struct {...@@ -452,7 +466,7 @@ pub const ExecutableOptions = struct {
452 version: ?std.builtin.Version = null,466 version: ?std.builtin.Version = null,
453 target: CrossTarget = .{},467 target: CrossTarget = .{},
454 optimize: std.builtin.Mode = .Debug,468 optimize: std.builtin.Mode = .Debug,
455 linkage: ?CompileStep.Linkage = null,469 linkage: ?Step.Compile.Linkage = null,
456 max_rss: usize = 0,470 max_rss: usize = 0,
457 link_libc: ?bool = null,471 link_libc: ?bool = null,
458 single_threaded: ?bool = null,472 single_threaded: ?bool = null,
...@@ -460,8 +474,8 @@ pub const ExecutableOptions = struct {...@@ -460,8 +474,8 @@ pub const ExecutableOptions = struct {
460 use_lld: ?bool = null,474 use_lld: ?bool = null,
461};475};
462476
463pub fn addExecutable(b: *Build, options: ExecutableOptions) *CompileStep {477pub fn addExecutable(b: *Build, options: ExecutableOptions) *Step.Compile {
464 return CompileStep.create(b, .{478 return Step.Compile.create(b, .{
465 .name = options.name,479 .name = options.name,
466 .root_source_file = options.root_source_file,480 .root_source_file = options.root_source_file,
467 .version = options.version,481 .version = options.version,
...@@ -489,8 +503,8 @@ pub const ObjectOptions = struct {...@@ -489,8 +503,8 @@ pub const ObjectOptions = struct {
489 use_lld: ?bool = null,503 use_lld: ?bool = null,
490};504};
491505
492pub fn addObject(b: *Build, options: ObjectOptions) *CompileStep {506pub fn addObject(b: *Build, options: ObjectOptions) *Step.Compile {
493 return CompileStep.create(b, .{507 return Step.Compile.create(b, .{
494 .name = options.name,508 .name = options.name,
495 .root_source_file = options.root_source_file,509 .root_source_file = options.root_source_file,
496 .target = options.target,510 .target = options.target,
...@@ -517,8 +531,8 @@ pub const SharedLibraryOptions = struct {...@@ -517,8 +531,8 @@ pub const SharedLibraryOptions = struct {
517 use_lld: ?bool = null,531 use_lld: ?bool = null,
518};532};
519533
520pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *CompileStep {534pub fn addSharedLibrary(b: *Build, options: SharedLibraryOptions) *Step.Compile {
521 return CompileStep.create(b, .{535 return Step.Compile.create(b, .{
522 .name = options.name,536 .name = options.name,
523 .root_source_file = options.root_source_file,537 .root_source_file = options.root_source_file,
524 .kind = .lib,538 .kind = .lib,
...@@ -547,8 +561,8 @@ pub const StaticLibraryOptions = struct {...@@ -547,8 +561,8 @@ pub const StaticLibraryOptions = struct {
547 use_lld: ?bool = null,561 use_lld: ?bool = null,
548};562};
549563
550pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *CompileStep {564pub fn addStaticLibrary(b: *Build, options: StaticLibraryOptions) *Step.Compile {
551 return CompileStep.create(b, .{565 return Step.Compile.create(b, .{
552 .name = options.name,566 .name = options.name,
553 .root_source_file = options.root_source_file,567 .root_source_file = options.root_source_file,
554 .kind = .lib,568 .kind = .lib,
...@@ -579,8 +593,8 @@ pub const TestOptions = struct {...@@ -579,8 +593,8 @@ pub const TestOptions = struct {
579 use_lld: ?bool = null,593 use_lld: ?bool = null,
580};594};
581595
582pub fn addTest(b: *Build, options: TestOptions) *CompileStep {596pub fn addTest(b: *Build, options: TestOptions) *Step.Compile {
583 return CompileStep.create(b, .{597 return Step.Compile.create(b, .{
584 .name = options.name,598 .name = options.name,
585 .kind = .@"test",599 .kind = .@"test",
586 .root_source_file = options.root_source_file,600 .root_source_file = options.root_source_file,
...@@ -604,8 +618,8 @@ pub const AssemblyOptions = struct {...@@ -604,8 +618,8 @@ pub const AssemblyOptions = struct {
604 max_rss: usize = 0,618 max_rss: usize = 0,
605};619};
606620
607pub fn addAssembly(b: *Build, options: AssemblyOptions) *CompileStep {621pub fn addAssembly(b: *Build, options: AssemblyOptions) *Step.Compile {
608 const obj_step = CompileStep.create(b, .{622 const obj_step = Step.Compile.create(b, .{
609 .name = options.name,623 .name = options.name,
610 .kind = .obj,624 .kind = .obj,
611 .root_source_file = null,625 .root_source_file = null,
...@@ -657,25 +671,25 @@ fn moduleDependenciesToArrayHashMap(arena: Allocator, deps: []const ModuleDepend...@@ -657,25 +671,25 @@ fn moduleDependenciesToArrayHashMap(arena: Allocator, deps: []const ModuleDepend
657 return result;671 return result;
658}672}
659673
660/// Initializes a RunStep with argv, which must at least have the path to the674/// Initializes a `Step.Run` with argv, which must at least have the path to the
661/// executable. More command line arguments can be added with `addArg`,675/// executable. More command line arguments can be added with `addArg`,
662/// `addArgs`, and `addArtifactArg`.676/// `addArgs`, and `addArtifactArg`.
663/// Be careful using this function, as it introduces a system dependency.677/// Be careful using this function, as it introduces a system dependency.
664/// To run an executable built with zig build, see `CompileStep.run`.678/// To run an executable built with zig build, see `Step.Compile.run`.
665pub fn addSystemCommand(self: *Build, argv: []const []const u8) *RunStep {679pub fn addSystemCommand(self: *Build, argv: []const []const u8) *Step.Run {
666 assert(argv.len >= 1);680 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]}));
668 run_step.addArgs(argv);682 run_step.addArgs(argv);
669 return run_step;683 return run_step;
670}684}
671685
672/// Creates a `RunStep` with an executable built with `addExecutable`.686/// Creates a `Step.Run` with an executable built with `addExecutable`.
673/// Add command line arguments with methods of `RunStep`.687/// Add command line arguments with methods of `Step.Run`.
674pub fn addRunArtifact(b: *Build, exe: *CompileStep) *RunStep {688pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run {
675 // It doesn't have to be native. We catch that if you actually try to run it.689 // It doesn't have to be native. We catch that if you actually try to run it.
676 // Consider that this is declarative; the run step may not be run unless a user690 // Consider that this is declarative; the run step may not be run unless a user
677 // option is supplied.691 // 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}));
679 run_step.addArtifactArg(exe);693 run_step.addArtifactArg(exe);
680694
681 if (exe.kind == .@"test") {695 if (exe.kind == .@"test") {
...@@ -696,14 +710,14 @@ pub fn addRunArtifact(b: *Build, exe: *CompileStep) *RunStep {...@@ -696,14 +710,14 @@ pub fn addRunArtifact(b: *Build, exe: *CompileStep) *RunStep {
696/// when an option found in the input file is missing from `values`.710/// when an option found in the input file is missing from `values`.
697pub fn addConfigHeader(711pub fn addConfigHeader(
698 b: *Build,712 b: *Build,
699 options: ConfigHeaderStep.Options,713 options: Step.ConfigHeader.Options,
700 values: anytype,714 values: anytype,
701) *ConfigHeaderStep {715) *Step.ConfigHeader {
702 var options_copy = options;716 var options_copy = options;
703 if (options_copy.first_ret_addr == null)717 if (options_copy.first_ret_addr == null)
704 options_copy.first_ret_addr = @returnAddress();718 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);
707 config_header_step.addValues(values);721 config_header_step.addValues(values);
708 return config_header_step;722 return config_header_step;
709}723}
...@@ -734,28 +748,28 @@ pub fn dupePath(self: *Build, bytes: []const u8) []u8 {...@@ -734,28 +748,28 @@ pub fn dupePath(self: *Build, bytes: []const u8) []u8 {
734 return the_copy;748 return the_copy;
735}749}
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 {
738 const write_file_step = self.addWriteFiles();752 const write_file_step = self.addWriteFiles();
739 write_file_step.add(file_path, data);753 write_file_step.add(file_path, data);
740 return write_file_step;754 return write_file_step;
741}755}
742756
743pub fn addWriteFiles(b: *Build) *WriteFileStep {757pub fn addWriteFiles(b: *Build) *Step.WriteFile {
744 return WriteFileStep.create(b);758 return Step.WriteFile.create(b);
745}759}
746760
747pub fn addRemoveDirTree(self: *Build, dir_path: []const u8) *RemoveDirStep {761pub fn addRemoveDirTree(self: *Build, dir_path: []const u8) *Step.RemoveDir {
748 const remove_dir_step = self.allocator.create(RemoveDirStep) catch @panic("OOM");762 const remove_dir_step = self.allocator.create(Step.RemoveDir) catch @panic("OOM");
749 remove_dir_step.* = RemoveDirStep.init(self, dir_path);763 remove_dir_step.* = Step.RemoveDir.init(self, dir_path);
750 return remove_dir_step;764 return remove_dir_step;
751}765}
752766
753pub fn addFmt(b: *Build, options: FmtStep.Options) *FmtStep {767pub fn addFmt(b: *Build, options: Step.Fmt.Options) *Step.Fmt {
754 return FmtStep.create(b, options);768 return Step.Fmt.create(b, options);
755}769}
756770
757pub fn addTranslateC(self: *Build, options: TranslateCStep.Options) *TranslateCStep {771pub fn addTranslateC(self: *Build, options: Step.TranslateC.Options) *Step.TranslateC {
758 return TranslateCStep.create(self, options);772 return Step.TranslateC.create(self, options);
759}773}
760774
761pub fn getInstallStep(self: *Build) *Step {775pub fn getInstallStep(self: *Build) *Step {
...@@ -1213,12 +1227,12 @@ fn printCmd(ally: Allocator, cwd: ?[]const u8, argv: []const []const u8) void {...@@ -1213,12 +1227,12 @@ fn printCmd(ally: Allocator, cwd: ?[]const u8, argv: []const []const u8) void {
1213 std.debug.print("{s}\n", .{text});1227 std.debug.print("{s}\n", .{text});
1214}1228}
12151229
1216pub fn installArtifact(self: *Build, artifact: *CompileStep) void {1230pub fn installArtifact(self: *Build, artifact: *Step.Compile) void {
1217 self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step);1231 self.getInstallStep().dependOn(&self.addInstallArtifact(artifact).step);
1218}1232}
12191233
1220pub fn addInstallArtifact(self: *Build, artifact: *CompileStep) *InstallArtifactStep {1234pub fn addInstallArtifact(self: *Build, artifact: *Step.Compile) *Step.InstallArtifact {
1221 return InstallArtifactStep.create(self, artifact);1235 return Step.InstallArtifact.create(self, artifact);
1222}1236}
12231237
1224///`dest_rel_path` is relative to prefix path1238///`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...@@ -1240,26 +1254,26 @@ pub fn installLibFile(self: *Build, src_path: []const u8, dest_rel_path: []const
1240 self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .lib, dest_rel_path).step);1254 self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .lib, dest_rel_path).step);
1241}1255}
12421256
1243pub fn addObjCopy(b: *Build, source: FileSource, options: ObjCopyStep.Options) *ObjCopyStep {1257pub fn addObjCopy(b: *Build, source: FileSource, options: Step.ObjCopy.Options) *Step.ObjCopy {
1244 return ObjCopyStep.create(b, source, options);1258 return Step.ObjCopy.create(b, source, options);
1245}1259}
12461260
1247///`dest_rel_path` is relative to install prefix path1261///`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 {
1249 return self.addInstallFileWithDir(source.dupe(self), .prefix, dest_rel_path);1263 return self.addInstallFileWithDir(source.dupe(self), .prefix, dest_rel_path);
1250}1264}
12511265
1252///`dest_rel_path` is relative to bin path1266///`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 {
1254 return self.addInstallFileWithDir(source.dupe(self), .bin, dest_rel_path);1268 return self.addInstallFileWithDir(source.dupe(self), .bin, dest_rel_path);
1255}1269}
12561270
1257///`dest_rel_path` is relative to lib path1271///`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 {
1259 return self.addInstallFileWithDir(source.dupe(self), .lib, dest_rel_path);1273 return self.addInstallFileWithDir(source.dupe(self), .lib, dest_rel_path);
1260}1274}
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 {
1263 return b.addInstallFileWithDir(.{ .path = src_path }, .header, dest_rel_path);1277 return b.addInstallFileWithDir(.{ .path = src_path }, .header, dest_rel_path);
1264}1278}
12651279
...@@ -1268,22 +1282,22 @@ pub fn addInstallFileWithDir(...@@ -1268,22 +1282,22 @@ pub fn addInstallFileWithDir(
1268 source: FileSource,1282 source: FileSource,
1269 install_dir: InstallDir,1283 install_dir: InstallDir,
1270 dest_rel_path: []const u8,1284 dest_rel_path: []const u8,
1271) *InstallFileStep {1285) *Step.InstallFile {
1272 return InstallFileStep.create(self, source.dupe(self), install_dir, dest_rel_path);1286 return Step.InstallFile.create(self, source.dupe(self), install_dir, dest_rel_path);
1273}1287}
12741288
1275pub fn addInstallDirectory(self: *Build, options: InstallDirectoryOptions) *InstallDirStep {1289pub fn addInstallDirectory(self: *Build, options: InstallDirectoryOptions) *Step.InstallDir {
1276 const install_step = self.allocator.create(InstallDirStep) catch @panic("OOM");1290 const install_step = self.allocator.create(Step.InstallDir) catch @panic("OOM");
1277 install_step.* = InstallDirStep.init(self, options);1291 install_step.* = Step.InstallDir.init(self, options);
1278 return install_step;1292 return install_step;
1279}1293}
12801294
1281pub fn addCheckFile(1295pub fn addCheckFile(
1282 b: *Build,1296 b: *Build,
1283 file_source: FileSource,1297 file_source: FileSource,
1284 options: CheckFileStep.Options,1298 options: Step.CheckFile.Options,
1285) *CheckFileStep {1299) *Step.CheckFile {
1286 return CheckFileStep.create(b, file_source, options);1300 return Step.CheckFile.create(b, file_source, options);
1287}1301}
12881302
1289pub fn pushInstalledFile(self: *Build, dir: InstallDir, dest_rel_path: []const u8) void {1303pub 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)...@@ -1453,10 +1467,10 @@ pub fn getInstallPath(self: *Build, dir: InstallDir, dest_rel_path: []const u8)
1453pub const Dependency = struct {1467pub const Dependency = struct {
1454 builder: *Build,1468 builder: *Build,
14551469
1456 pub fn artifact(d: *Dependency, name: []const u8) *CompileStep {1470 pub fn artifact(d: *Dependency, name: []const u8) *Step.Compile {
1457 var found: ?*CompileStep = null;1471 var found: ?*Step.Compile = null;
1458 for (d.builder.install_tls.step.dependencies.items) |dep_step| {1472 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;
1460 if (mem.eql(u8, inst.artifact.name, name)) {1474 if (mem.eql(u8, inst.artifact.name, name)) {
1461 if (found != null) panic("artifact name '{s}' is ambiguous", .{name});1475 if (found != null) panic("artifact name '{s}' is ambiguous", .{name});
1462 found = inst.artifact;1476 found = inst.artifact;
...@@ -1464,7 +1478,7 @@ pub const Dependency = struct {...@@ -1464,7 +1478,7 @@ pub const Dependency = struct {
1464 }1478 }
1465 return found orelse {1479 return found orelse {
1466 for (d.builder.install_tls.step.dependencies.items) |dep_step| {1480 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;
1468 log.info("available artifact: '{s}'", .{inst.artifact.name});1482 log.info("available artifact: '{s}'", .{inst.artifact.name});
1469 }1483 }
1470 panic("unable to find artifact '{s}'", .{name});1484 panic("unable to find artifact '{s}'", .{name});
...@@ -1808,17 +1822,5 @@ pub fn hex64(x: u64) [16]u8 {...@@ -1808,17 +1822,5 @@ pub fn hex64(x: u64) [16]u8 {
1808}1822}
18091823
1810test {1824test {
1811 _ = CheckFileStep;1825 _ = Step;
1812 _ = CheckObjectStep;
1813 _ = FmtStep;
1814 _ = InstallArtifactStep;
1815 _ = InstallDirStep;
1816 _ = InstallFileStep;
1817 _ = ObjCopyStep;
1818 _ = CompileStep;
1819 _ = OptionsStep;
1820 _ = RemoveDirStep;
1821 _ = RunStep;
1822 _ = TranslateCStep;
1823 _ = WriteFileStep;
1824}1826}
lib/std/Build/Step.zig+49-18
...@@ -94,26 +94,41 @@ pub const Id = enum {...@@ -94,26 +94,41 @@ pub const Id = enum {
94 pub fn Type(comptime id: Id) type {94 pub fn Type(comptime id: Id) type {
95 return switch (id) {95 return switch (id) {
96 .top_level => Build.TopLevelStep,96 .top_level => Build.TopLevelStep,
97 .compile => Build.CompileStep,97 .compile => Compile,
98 .install_artifact => Build.InstallArtifactStep,98 .install_artifact => InstallArtifact,
99 .install_file => Build.InstallFileStep,99 .install_file => InstallFile,
100 .install_dir => Build.InstallDirStep,100 .install_dir => InstallDir,
101 .remove_dir => Build.RemoveDirStep,101 .remove_dir => RemoveDir,
102 .fmt => Build.FmtStep,102 .fmt => Fmt,
103 .translate_c => Build.TranslateCStep,103 .translate_c => TranslateC,
104 .write_file => Build.WriteFileStep,104 .write_file => WriteFile,
105 .run => Build.RunStep,105 .run => Run,
106 .check_file => Build.CheckFileStep,106 .check_file => CheckFile,
107 .check_object => Build.CheckObjectStep,107 .check_object => CheckObject,
108 .config_header => Build.ConfigHeaderStep,108 .config_header => ConfigHeader,
109 .objcopy => Build.ObjCopyStep,109 .objcopy => ObjCopy,
110 .options => Build.OptionsStep,110 .options => Options,
111 .custom => @compileError("no type available for custom step"),111 .custom => @compileError("no type available for custom step"),
112 };112 };
113 }113 }
114};114};
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 {
117 id: Id,132 id: Id,
118 name: []const u8,133 name: []const u8,
119 owner: *Build,134 owner: *Build,
...@@ -122,7 +137,7 @@ pub const Options = struct {...@@ -122,7 +137,7 @@ pub const Options = struct {
122 max_rss: usize = 0,137 max_rss: usize = 0,
123};138};
124139
125pub fn init(options: Options) Step {140pub fn init(options: StepOptions) Step {
126 const arena = options.owner.allocator;141 const arena = options.owner.allocator;
127142
128 var addresses = [1]usize{0} ** n_debug_stack_frames;143 var addresses = [1]usize{0} ** n_debug_stack_frames;
...@@ -387,8 +402,8 @@ pub fn evalZigProcess(...@@ -387,8 +402,8 @@ pub fn evalZigProcess(
387 s.result_duration_ns = timer.read();402 s.result_duration_ns = timer.read();
388 s.result_peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0;403 s.result_peak_rss = child.resource_usage_statistics.getMaxRss() orelse 0;
389404
390 // Special handling for CompileStep that is expecting compile errors.405 // Special handling for Compile step that is expecting compile errors.
391 if (s.cast(Build.CompileStep)) |compile| switch (term) {406 if (s.cast(Compile)) |compile| switch (term) {
392 .Exited => {407 .Exited => {
393 // Note that the exit code may be 0 in this case due to the408 // Note that the exit code may be 0 in this case due to the
394 // compiler server protocol.409 // compiler server protocol.
...@@ -535,3 +550,19 @@ pub fn writeManifest(s: *Step, man: *std.Build.Cache.Manifest) !void {...@@ -535,3 +550,19 @@ pub fn writeManifest(s: *Step, man: *std.Build.Cache.Manifest) !void {
535 };550 };
536 }551 }
537}552}
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 @@...@@ -1,8 +1,8 @@
1//! Fail the build step if a file does not match certain checks.1//! Fail the build step if a file does not match certain checks.
2//! TODO: make this more flexible, supporting more kinds of checks.2//! TODO: make this more flexible, supporting more kinds of checks.
3//! TODO: generalize the code in std.testing.expectEqualStrings and make this3//! TODO: generalize the code in std.testing.expectEqualStrings and make this
4//! CheckFileStep produce those helpful diagnostics when there is not a match.4//! CheckFile step produce those helpful diagnostics when there is not a match.
5const CheckFileStep = @This();5const CheckFile = @This();
6const std = @import("std");6const std = @import("std");
7const Step = std.Build.Step;7const Step = std.Build.Step;
8const fs = std.fs;8const fs = std.fs;
...@@ -25,8 +25,8 @@ pub fn create(...@@ -25,8 +25,8 @@ pub fn create(
25 owner: *std.Build,25 owner: *std.Build,
26 source: std.Build.FileSource,26 source: std.Build.FileSource,
27 options: Options,27 options: Options,
28) *CheckFileStep {28) *CheckFile {
29 const self = owner.allocator.create(CheckFileStep) catch @panic("OOM");29 const self = owner.allocator.create(CheckFile) catch @panic("OOM");
30 self.* = .{30 self.* = .{
31 .step = Step.init(.{31 .step = Step.init(.{
32 .id = .check_file,32 .id = .check_file,
...@@ -42,14 +42,14 @@ pub fn create(...@@ -42,14 +42,14 @@ pub fn create(
42 return self;42 return self;
43}43}
4444
45pub fn setName(self: *CheckFileStep, name: []const u8) void {45pub fn setName(self: *CheckFile, name: []const u8) void {
46 self.step.name = name;46 self.step.name = name;
47}47}
4848
49fn make(step: *Step, prog_node: *std.Progress.Node) !void {49fn make(step: *Step, prog_node: *std.Progress.Node) !void {
50 _ = prog_node;50 _ = prog_node;
51 const b = step.owner;51 const b = step.owner;
52 const self = @fieldParentPtr(CheckFileStep, "step", step);52 const self = @fieldParentPtr(CheckFile, "step", step);
5353
54 const src_path = self.source.getPath(b);54 const src_path = self.source.getPath(b);
55 const contents = fs.cwd().readFileAlloc(b.allocator, src_path, self.max_bytes) catch |err| {55 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;...@@ -6,7 +6,7 @@ const math = std.math;
6const mem = std.mem;6const mem = std.mem;
7const testing = std.testing;7const testing = std.testing;
88
9const CheckObjectStep = @This();9const CheckObject = @This();
1010
11const Allocator = mem.Allocator;11const Allocator = mem.Allocator;
12const Step = std.Build.Step;12const Step = std.Build.Step;
...@@ -24,9 +24,9 @@ pub fn create(...@@ -24,9 +24,9 @@ pub fn create(
24 owner: *std.Build,24 owner: *std.Build,
25 source: std.Build.FileSource,25 source: std.Build.FileSource,
26 obj_format: std.Target.ObjectFormat,26 obj_format: std.Target.ObjectFormat,
27) *CheckObjectStep {27) *CheckObject {
28 const gpa = owner.allocator;28 const gpa = owner.allocator;
29 const self = gpa.create(CheckObjectStep) catch @panic("OOM");29 const self = gpa.create(CheckObject) catch @panic("OOM");
30 self.* = .{30 self.* = .{
31 .step = Step.init(.{31 .step = Step.init(.{
32 .id = .check_file,32 .id = .check_file,
...@@ -47,11 +47,11 @@ pub fn create(...@@ -47,11 +47,11 @@ pub fn create(
47/// TODO this doesn't actually compare, and there's no apparent reason for it47/// TODO this doesn't actually compare, and there's no apparent reason for it
48/// to depend on the check object step. I don't see why this function should exist,48/// to depend on the check object step. I don't see why this function should exist,
49/// the caller could just add the run step directly.49/// 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 {
51 const dependencies_len = self.step.dependencies.items.len;51 const dependencies_len = self.step.dependencies.items.len;
52 assert(dependencies_len > 0);52 assert(dependencies_len > 0);
53 const exe_step = self.step.dependencies.items[dependencies_len - 1];53 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).?;
55 const run = self.step.owner.addRunArtifact(exe);55 const run = self.step.owner.addRunArtifact(exe);
56 run.skip_foreign_checks = true;56 run.skip_foreign_checks = true;
57 run.step.dependOn(&self.step);57 run.step.dependOn(&self.step);
...@@ -274,15 +274,15 @@ const Check = struct {...@@ -274,15 +274,15 @@ const Check = struct {
274};274};
275275
276/// Creates a new sequence of actions with `phrase` as the first anchor searched phrase.276/// 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 {
278 var new_check = Check.create(self.step.owner.allocator);278 var new_check = Check.create(self.step.owner.allocator);
279 new_check.match(.{ .string = self.step.owner.dupe(phrase) });279 new_check.match(.{ .string = self.step.owner.dupe(phrase) });
280 self.checks.append(new_check) catch @panic("OOM");280 self.checks.append(new_check) catch @panic("OOM");
281}281}
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(...)`.
284/// Asserts at least one check already exists.284/// 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 {
286 assert(self.checks.items.len > 0);286 assert(self.checks.items.len > 0);
287 const last = &self.checks.items[self.checks.items.len - 1];287 const last = &self.checks.items[self.checks.items.len - 1];
288 last.match(.{ .string = self.step.owner.dupe(phrase) });288 last.match(.{ .string = self.step.owner.dupe(phrase) });
...@@ -291,7 +291,7 @@ pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void {...@@ -291,7 +291,7 @@ pub fn checkNext(self: *CheckObjectStep, phrase: []const u8) void {
291/// Like `checkNext()` but takes an additional argument `FileSource` which will be291/// Like `checkNext()` but takes an additional argument `FileSource` which will be
292/// resolved to a full search query in `make()`.292/// resolved to a full search query in `make()`.
293pub fn checkNextFileSource(293pub fn checkNextFileSource(
294 self: *CheckObjectStep,294 self: *CheckObject,
295 phrase: []const u8,295 phrase: []const u8,
296 file_source: std.Build.FileSource,296 file_source: std.Build.FileSource,
297) void {297) void {
...@@ -300,10 +300,10 @@ pub fn checkNextFileSource(...@@ -300,10 +300,10 @@ pub fn checkNextFileSource(
300 last.match(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source });300 last.match(.{ .string = self.step.owner.dupe(phrase), .file_source = file_source });
301}301}
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(...)`
304/// however ensures there is no matching phrase in the output.304/// however ensures there is no matching phrase in the output.
305/// Asserts at least one check already exists.305/// 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 {
307 assert(self.checks.items.len > 0);307 assert(self.checks.items.len > 0);
308 const last = &self.checks.items[self.checks.items.len - 1];308 const last = &self.checks.items[self.checks.items.len - 1];
309 last.notPresent(.{ .string = self.step.owner.dupe(phrase) });309 last.notPresent(.{ .string = self.step.owner.dupe(phrase) });
...@@ -312,7 +312,7 @@ pub fn checkNotPresent(self: *CheckObjectStep, phrase: []const u8) void {...@@ -312,7 +312,7 @@ pub fn checkNotPresent(self: *CheckObjectStep, phrase: []const u8) void {
312/// Creates a new check checking specifically symbol table parsed and dumped from the object312/// Creates a new check checking specifically symbol table parsed and dumped from the object
313/// file.313/// file.
314/// Issuing this check will force parsing and dumping of the symbol table.314/// Issuing this check will force parsing and dumping of the symbol table.
315pub fn checkInSymtab(self: *CheckObjectStep) void {315pub fn checkInSymtab(self: *CheckObject) void {
316 self.dump_symtab = true;316 self.dump_symtab = true;
317 const symtab_label = switch (self.obj_format) {317 const symtab_label = switch (self.obj_format) {
318 .macho => MachODumper.symtab_label,318 .macho => MachODumper.symtab_label,
...@@ -325,7 +325,7 @@ pub fn checkInSymtab(self: *CheckObjectStep) void {...@@ -325,7 +325,7 @@ pub fn checkInSymtab(self: *CheckObjectStep) void {
325/// on the extracted variables. It will then compare the reduced program with the value of325/// on the extracted variables. It will then compare the reduced program with the value of
326/// the expected variable.326/// the expected variable.
327pub fn checkComputeCompare(327pub fn checkComputeCompare(
328 self: *CheckObjectStep,328 self: *CheckObject,
329 program: []const u8,329 program: []const u8,
330 expected: ComputeCompareExpected,330 expected: ComputeCompareExpected,
331) void {331) void {
...@@ -338,7 +338,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -338,7 +338,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
338 _ = prog_node;338 _ = prog_node;
339 const b = step.owner;339 const b = step.owner;
340 const gpa = b.allocator;340 const gpa = b.allocator;
341 const self = @fieldParentPtr(CheckObjectStep, "step", step);341 const self = @fieldParentPtr(CheckObject, "step", step);
342342
343 const src_path = self.source.getPath(b);343 const src_path = self.source.getPath(b);
344 const contents = fs.cwd().readFileAllocOptions(344 const contents = fs.cwd().readFileAllocOptions(
lib/std/Build/Step/Compile.zig+81-87
...@@ -18,14 +18,8 @@ const ExecError = std.Build.ExecError;...@@ -18,14 +18,8 @@ const ExecError = std.Build.ExecError;
18const Module = std.Build.Module;18const Module = std.Build.Module;
19const VcpkgRoot = std.Build.VcpkgRoot;19const VcpkgRoot = std.Build.VcpkgRoot;
20const InstallDir = std.Build.InstallDir;20const InstallDir = std.Build.InstallDir;
21const InstallArtifactStep = std.Build.InstallArtifactStep;
22const GeneratedFile = std.Build.GeneratedFile;21const GeneratedFile = std.Build.GeneratedFile;
23const ObjCopyStep = std.Build.ObjCopyStep;22const Compile = @This();
24const CheckObjectStep = std.Build.CheckObjectStep;
25const RunStep = std.Build.RunStep;
26const OptionsStep = std.Build.OptionsStep;
27const ConfigHeaderStep = std.Build.ConfigHeaderStep;
28const CompileStep = @This();
2923
30pub const base_id: Step.Id = .compile;24pub const base_id: Step.Id = .compile;
3125
...@@ -211,8 +205,8 @@ want_lto: ?bool = null,...@@ -211,8 +205,8 @@ want_lto: ?bool = null,
211use_llvm: ?bool,205use_llvm: ?bool,
212use_lld: ?bool,206use_lld: ?bool,
213207
214/// This is an advanced setting that can change the intent of this CompileStep.208/// This is an advanced setting that can change the intent of this Compile step.
215/// If this slice has nonzero length, it means that this CompileStep exists to209/// If this slice has nonzero length, it means that this Compile step exists to
216/// check for compile errors and return *success* if they match, and failure210/// check for compile errors and return *success* if they match, and failure
217/// otherwise.211/// otherwise.
218expect_errors: []const []const u8 = &.{},212expect_errors: []const []const u8 = &.{},
...@@ -242,7 +236,7 @@ pub const CSourceFile = struct {...@@ -242,7 +236,7 @@ pub const CSourceFile = struct {
242236
243pub const LinkObject = union(enum) {237pub const LinkObject = union(enum) {
244 static_path: FileSource,238 static_path: FileSource,
245 other_step: *CompileStep,239 other_step: *Compile,
246 system_lib: SystemLib,240 system_lib: SystemLib,
247 assembly_file: FileSource,241 assembly_file: FileSource,
248 c_source_file: *CSourceFile,242 c_source_file: *CSourceFile,
...@@ -273,8 +267,8 @@ const FrameworkLinkInfo = struct {...@@ -273,8 +267,8 @@ const FrameworkLinkInfo = struct {
273pub const IncludeDir = union(enum) {267pub const IncludeDir = union(enum) {
274 raw_path: []const u8,268 raw_path: []const u8,
275 raw_path_system: []const u8,269 raw_path_system: []const u8,
276 other_step: *CompileStep,270 other_step: *Compile,
277 config_header_step: *ConfigHeaderStep,271 config_header_step: *Step.ConfigHeader,
278};272};
279273
280pub const Options = struct {274pub const Options = struct {
...@@ -319,7 +313,7 @@ pub const EmitOption = union(enum) {...@@ -319,7 +313,7 @@ pub const EmitOption = union(enum) {
319 }313 }
320};314};
321315
322pub fn create(owner: *std.Build, options: Options) *CompileStep {316pub fn create(owner: *std.Build, options: Options) *Compile {
323 const name = owner.dupe(options.name);317 const name = owner.dupe(options.name);
324 const root_src: ?FileSource = if (options.root_source_file) |rsrc| rsrc.dupe(owner) else null;318 const root_src: ?FileSource = if (options.root_source_file) |rsrc| rsrc.dupe(owner) else null;
325 if (mem.indexOf(u8, name, "/") != null or mem.indexOf(u8, name, "\\") != null) {319 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 {...@@ -361,8 +355,8 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
361 .version = options.version,355 .version = options.version,
362 }) catch @panic("OOM");356 }) catch @panic("OOM");
363357
364 const self = owner.allocator.create(CompileStep) catch @panic("OOM");358 const self = owner.allocator.create(Compile) catch @panic("OOM");
365 self.* = CompileStep{359 self.* = Compile{
366 .strip = null,360 .strip = null,
367 .unwind_tables = null,361 .unwind_tables = null,
368 .verbose_link = false,362 .verbose_link = false,
...@@ -459,7 +453,7 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {...@@ -459,7 +453,7 @@ pub fn create(owner: *std.Build, options: Options) *CompileStep {
459 return self;453 return self;
460}454}
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 {
463 const b = cs.step.owner;457 const b = cs.step.owner;
464 const install_file = b.addInstallHeaderFile(src_path, dest_rel_path);458 const install_file = b.addInstallHeaderFile(src_path, dest_rel_path);
465 b.getInstallStep().dependOn(&install_file.step);459 b.getInstallStep().dependOn(&install_file.step);
...@@ -472,8 +466,8 @@ pub const InstallConfigHeaderOptions = struct {...@@ -472,8 +466,8 @@ pub const InstallConfigHeaderOptions = struct {
472};466};
473467
474pub fn installConfigHeader(468pub fn installConfigHeader(
475 cs: *CompileStep,469 cs: *Compile,
476 config_header: *ConfigHeaderStep,470 config_header: *Step.ConfigHeader,
477 options: InstallConfigHeaderOptions,471 options: InstallConfigHeaderOptions,
478) void {472) void {
479 const dest_rel_path = options.dest_rel_path orelse config_header.include_path;473 const dest_rel_path = options.dest_rel_path orelse config_header.include_path;
...@@ -489,7 +483,7 @@ pub fn installConfigHeader(...@@ -489,7 +483,7 @@ pub fn installConfigHeader(
489}483}
490484
491pub fn installHeadersDirectory(485pub fn installHeadersDirectory(
492 a: *CompileStep,486 a: *Compile,
493 src_dir_path: []const u8,487 src_dir_path: []const u8,
494 dest_rel_path: []const u8,488 dest_rel_path: []const u8,
495) void {489) void {
...@@ -501,8 +495,8 @@ pub fn installHeadersDirectory(...@@ -501,8 +495,8 @@ pub fn installHeadersDirectory(
501}495}
502496
503pub fn installHeadersDirectoryOptions(497pub fn installHeadersDirectoryOptions(
504 cs: *CompileStep,498 cs: *Compile,
505 options: std.Build.InstallDirStep.Options,499 options: std.Build.Step.InstallDir.Options,
506) void {500) void {
507 const b = cs.step.owner;501 const b = cs.step.owner;
508 const install_dir = b.addInstallDirectory(options);502 const install_dir = b.addInstallDirectory(options);
...@@ -510,7 +504,7 @@ pub fn installHeadersDirectoryOptions(...@@ -510,7 +504,7 @@ pub fn installHeadersDirectoryOptions(
510 cs.installed_headers.append(&install_dir.step) catch @panic("OOM");504 cs.installed_headers.append(&install_dir.step) catch @panic("OOM");
511}505}
512506
513pub fn installLibraryHeaders(cs: *CompileStep, l: *CompileStep) void {507pub fn installLibraryHeaders(cs: *Compile, l: *Compile) void {
514 assert(l.kind == .lib);508 assert(l.kind == .lib);
515 const b = cs.step.owner;509 const b = cs.step.owner;
516 const install_step = b.getInstallStep();510 const install_step = b.getInstallStep();
...@@ -533,7 +527,7 @@ pub fn installLibraryHeaders(cs: *CompileStep, l: *CompileStep) void {...@@ -533,7 +527,7 @@ pub fn installLibraryHeaders(cs: *CompileStep, l: *CompileStep) void {
533 cs.installed_headers.appendSlice(l.installed_headers.items) catch @panic("OOM");527 cs.installed_headers.appendSlice(l.installed_headers.items) catch @panic("OOM");
534}528}
535529
536pub fn addObjCopy(cs: *CompileStep, options: ObjCopyStep.Options) *ObjCopyStep {530pub fn addObjCopy(cs: *Compile, options: Step.ObjCopy.Options) *Step.ObjCopy {
537 const b = cs.step.owner;531 const b = cs.step.owner;
538 var copy = options;532 var copy = options;
539 if (copy.basename == null) {533 if (copy.basename == null) {
...@@ -554,34 +548,34 @@ pub const run = @compileError("deprecated; use std.Build.addRunArtifact");...@@ -554,34 +548,34 @@ pub const run = @compileError("deprecated; use std.Build.addRunArtifact");
554/// which is undesirable when installing an artifact provided by a dependency package.548/// which is undesirable when installing an artifact provided by a dependency package.
555pub const install = @compileError("deprecated; use std.Build.installArtifact");549pub const install = @compileError("deprecated; use std.Build.installArtifact");
556550
557pub fn checkObject(self: *CompileStep) *CheckObjectStep {551pub fn checkObject(self: *Compile) *Step.CheckObject {
558 return CheckObjectStep.create(self.step.owner, self.getOutputSource(), self.target_info.target.ofmt);552 return Step.CheckObject.create(self.step.owner, self.getOutputSource(), self.target_info.target.ofmt);
559}553}
560554
561pub fn setLinkerScriptPath(self: *CompileStep, source: FileSource) void {555pub fn setLinkerScriptPath(self: *Compile, source: FileSource) void {
562 const b = self.step.owner;556 const b = self.step.owner;
563 self.linker_script = source.dupe(b);557 self.linker_script = source.dupe(b);
564 source.addStepDependencies(&self.step);558 source.addStepDependencies(&self.step);
565}559}
566560
567pub fn forceUndefinedSymbol(self: *CompileStep, symbol_name: []const u8) void {561pub fn forceUndefinedSymbol(self: *Compile, symbol_name: []const u8) void {
568 const b = self.step.owner;562 const b = self.step.owner;
569 self.force_undefined_symbols.put(b.dupe(symbol_name), {}) catch @panic("OOM");563 self.force_undefined_symbols.put(b.dupe(symbol_name), {}) catch @panic("OOM");
570}564}
571565
572pub fn linkFramework(self: *CompileStep, framework_name: []const u8) void {566pub fn linkFramework(self: *Compile, framework_name: []const u8) void {
573 const b = self.step.owner;567 const b = self.step.owner;
574 self.frameworks.put(b.dupe(framework_name), .{}) catch @panic("OOM");568 self.frameworks.put(b.dupe(framework_name), .{}) catch @panic("OOM");
575}569}
576570
577pub fn linkFrameworkNeeded(self: *CompileStep, framework_name: []const u8) void {571pub fn linkFrameworkNeeded(self: *Compile, framework_name: []const u8) void {
578 const b = self.step.owner;572 const b = self.step.owner;
579 self.frameworks.put(b.dupe(framework_name), .{573 self.frameworks.put(b.dupe(framework_name), .{
580 .needed = true,574 .needed = true,
581 }) catch @panic("OOM");575 }) catch @panic("OOM");
582}576}
583577
584pub fn linkFrameworkWeak(self: *CompileStep, framework_name: []const u8) void {578pub fn linkFrameworkWeak(self: *Compile, framework_name: []const u8) void {
585 const b = self.step.owner;579 const b = self.step.owner;
586 self.frameworks.put(b.dupe(framework_name), .{580 self.frameworks.put(b.dupe(framework_name), .{
587 .weak = true,581 .weak = true,
...@@ -589,7 +583,7 @@ pub fn linkFrameworkWeak(self: *CompileStep, framework_name: []const u8) void {...@@ -589,7 +583,7 @@ pub fn linkFrameworkWeak(self: *CompileStep, framework_name: []const u8) void {
589}583}
590584
591/// Returns whether the library, executable, or object depends on a particular system library.585/// 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 {
593 if (isLibCLibrary(name)) {587 if (isLibCLibrary(name)) {
594 return self.is_linking_libc;588 return self.is_linking_libc;
595 }589 }
...@@ -605,51 +599,51 @@ pub fn dependsOnSystemLibrary(self: CompileStep, name: []const u8) bool {...@@ -605,51 +599,51 @@ pub fn dependsOnSystemLibrary(self: CompileStep, name: []const u8) bool {
605 return false;599 return false;
606}600}
607601
608pub fn linkLibrary(self: *CompileStep, lib: *CompileStep) void {602pub fn linkLibrary(self: *Compile, lib: *Compile) void {
609 assert(lib.kind == .lib);603 assert(lib.kind == .lib);
610 self.linkLibraryOrObject(lib);604 self.linkLibraryOrObject(lib);
611}605}
612606
613pub fn isDynamicLibrary(self: *CompileStep) bool {607pub fn isDynamicLibrary(self: *Compile) bool {
614 return self.kind == .lib and self.linkage == Linkage.dynamic;608 return self.kind == .lib and self.linkage == Linkage.dynamic;
615}609}
616610
617pub fn isStaticLibrary(self: *CompileStep) bool {611pub fn isStaticLibrary(self: *Compile) bool {
618 return self.kind == .lib and self.linkage != Linkage.dynamic;612 return self.kind == .lib and self.linkage != Linkage.dynamic;
619}613}
620614
621pub fn producesPdbFile(self: *CompileStep) bool {615pub fn producesPdbFile(self: *Compile) bool {
622 if (!self.target.isWindows() and !self.target.isUefi()) return false;616 if (!self.target.isWindows() and !self.target.isUefi()) return false;
623 if (self.target.getObjectFormat() == .c) return false;617 if (self.target.getObjectFormat() == .c) return false;
624 if (self.strip == true) return false;618 if (self.strip == true) return false;
625 return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test";619 return self.isDynamicLibrary() or self.kind == .exe or self.kind == .@"test";
626}620}
627621
628pub fn linkLibC(self: *CompileStep) void {622pub fn linkLibC(self: *Compile) void {
629 self.is_linking_libc = true;623 self.is_linking_libc = true;
630}624}
631625
632pub fn linkLibCpp(self: *CompileStep) void {626pub fn linkLibCpp(self: *Compile) void {
633 self.is_linking_libcpp = true;627 self.is_linking_libcpp = true;
634}628}
635629
636/// If the value is omitted, it is set to 1.630/// If the value is omitted, it is set to 1.
637/// `name` and `value` need not live longer than the function call.631/// `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 {
639 const b = self.step.owner;633 const b = self.step.owner;
640 const macro = std.Build.constructCMacro(b.allocator, name, value);634 const macro = std.Build.constructCMacro(b.allocator, name, value);
641 self.c_macros.append(macro) catch @panic("OOM");635 self.c_macros.append(macro) catch @panic("OOM");
642}636}
643637
644/// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1.638/// 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 {
646 const b = self.step.owner;640 const b = self.step.owner;
647 self.c_macros.append(b.dupe(name_and_value)) catch @panic("OOM");641 self.c_macros.append(b.dupe(name_and_value)) catch @panic("OOM");
648}642}
649643
650/// This one has no integration with anything, it just puts -lname on the command line.644/// This one has no integration with anything, it just puts -lname on the command line.
651/// Prefer to use `linkSystemLibrary` instead.645/// Prefer to use `linkSystemLibrary` instead.
652pub fn linkSystemLibraryName(self: *CompileStep, name: []const u8) void {646pub fn linkSystemLibraryName(self: *Compile, name: []const u8) void {
653 const b = self.step.owner;647 const b = self.step.owner;
654 self.link_objects.append(.{648 self.link_objects.append(.{
655 .system_lib = .{649 .system_lib = .{
...@@ -663,7 +657,7 @@ pub fn linkSystemLibraryName(self: *CompileStep, name: []const u8) void {...@@ -663,7 +657,7 @@ pub fn linkSystemLibraryName(self: *CompileStep, name: []const u8) void {
663657
664/// This one has no integration with anything, it just puts -needed-lname on the command line.658/// This one has no integration with anything, it just puts -needed-lname on the command line.
665/// Prefer to use `linkSystemLibraryNeeded` instead.659/// Prefer to use `linkSystemLibraryNeeded` instead.
666pub fn linkSystemLibraryNeededName(self: *CompileStep, name: []const u8) void {660pub fn linkSystemLibraryNeededName(self: *Compile, name: []const u8) void {
667 const b = self.step.owner;661 const b = self.step.owner;
668 self.link_objects.append(.{662 self.link_objects.append(.{
669 .system_lib = .{663 .system_lib = .{
...@@ -677,7 +671,7 @@ pub fn linkSystemLibraryNeededName(self: *CompileStep, name: []const u8) void {...@@ -677,7 +671,7 @@ pub fn linkSystemLibraryNeededName(self: *CompileStep, name: []const u8) void {
677671
678/// Darwin-only. This one has no integration with anything, it just puts -weak-lname on the672/// Darwin-only. This one has no integration with anything, it just puts -weak-lname on the
679/// command line. Prefer to use `linkSystemLibraryWeak` instead.673/// 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 {
681 const b = self.step.owner;675 const b = self.step.owner;
682 self.link_objects.append(.{676 self.link_objects.append(.{
683 .system_lib = .{677 .system_lib = .{
...@@ -691,7 +685,7 @@ pub fn linkSystemLibraryWeakName(self: *CompileStep, name: []const u8) void {...@@ -691,7 +685,7 @@ pub fn linkSystemLibraryWeakName(self: *CompileStep, name: []const u8) void {
691685
692/// This links against a system library, exclusively using pkg-config to find the library.686/// This links against a system library, exclusively using pkg-config to find the library.
693/// Prefer to use `linkSystemLibrary` instead.687/// 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 {
695 const b = self.step.owner;689 const b = self.step.owner;
696 self.link_objects.append(.{690 self.link_objects.append(.{
697 .system_lib = .{691 .system_lib = .{
...@@ -705,7 +699,7 @@ pub fn linkSystemLibraryPkgConfigOnly(self: *CompileStep, lib_name: []const u8)...@@ -705,7 +699,7 @@ pub fn linkSystemLibraryPkgConfigOnly(self: *CompileStep, lib_name: []const u8)
705699
706/// This links against a system library, exclusively using pkg-config to find the library.700/// This links against a system library, exclusively using pkg-config to find the library.
707/// Prefer to use `linkSystemLibraryNeeded` instead.701/// 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 {
709 const b = self.step.owner;703 const b = self.step.owner;
710 self.link_objects.append(.{704 self.link_objects.append(.{
711 .system_lib = .{705 .system_lib = .{
...@@ -719,7 +713,7 @@ pub fn linkSystemLibraryNeededPkgConfigOnly(self: *CompileStep, lib_name: []cons...@@ -719,7 +713,7 @@ pub fn linkSystemLibraryNeededPkgConfigOnly(self: *CompileStep, lib_name: []cons
719713
720/// Run pkg-config for the given library name and parse the output, returning the arguments714/// Run pkg-config for the given library name and parse the output, returning the arguments
721/// that should be passed to zig to link the given library.715/// 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 {
723 const b = self.step.owner;717 const b = self.step.owner;
724 const pkg_name = match: {718 const pkg_name = match: {
725 // First we have to map the library name to pkg config name. Unfortunately,719 // 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 {...@@ -813,19 +807,19 @@ fn runPkgConfig(self: *CompileStep, lib_name: []const u8) ![]const []const u8 {
813 return zig_args.toOwnedSlice();807 return zig_args.toOwnedSlice();
814}808}
815809
816pub fn linkSystemLibrary(self: *CompileStep, name: []const u8) void {810pub fn linkSystemLibrary(self: *Compile, name: []const u8) void {
817 self.linkSystemLibraryInner(name, .{});811 self.linkSystemLibraryInner(name, .{});
818}812}
819813
820pub fn linkSystemLibraryNeeded(self: *CompileStep, name: []const u8) void {814pub fn linkSystemLibraryNeeded(self: *Compile, name: []const u8) void {
821 self.linkSystemLibraryInner(name, .{ .needed = true });815 self.linkSystemLibraryInner(name, .{ .needed = true });
822}816}
823817
824pub fn linkSystemLibraryWeak(self: *CompileStep, name: []const u8) void {818pub fn linkSystemLibraryWeak(self: *Compile, name: []const u8) void {
825 self.linkSystemLibraryInner(name, .{ .weak = true });819 self.linkSystemLibraryInner(name, .{ .weak = true });
826}820}
827821
828fn linkSystemLibraryInner(self: *CompileStep, name: []const u8, opts: struct {822fn linkSystemLibraryInner(self: *Compile, name: []const u8, opts: struct {
829 needed: bool = false,823 needed: bool = false,
830 weak: bool = false,824 weak: bool = false,
831}) void {825}) void {
...@@ -850,7 +844,7 @@ fn linkSystemLibraryInner(self: *CompileStep, name: []const u8, opts: struct {...@@ -850,7 +844,7 @@ fn linkSystemLibraryInner(self: *CompileStep, name: []const u8, opts: struct {
850}844}
851845
852/// Handy when you have many C/C++ source files and want them all to have the same flags.846/// 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 {
854 const b = self.step.owner;848 const b = self.step.owner;
855 const c_source_files = b.allocator.create(CSourceFiles) catch @panic("OOM");849 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...@@ -864,14 +858,14 @@ pub fn addCSourceFiles(self: *CompileStep, files: []const []const u8, flags: []c
864 self.link_objects.append(.{ .c_source_files = c_source_files }) catch @panic("OOM");858 self.link_objects.append(.{ .c_source_files = c_source_files }) catch @panic("OOM");
865}859}
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 {
868 self.addCSourceFileSource(.{862 self.addCSourceFileSource(.{
869 .args = flags,863 .args = flags,
870 .source = .{ .path = file },864 .source = .{ .path = file },
871 });865 });
872}866}
873867
874pub fn addCSourceFileSource(self: *CompileStep, source: CSourceFile) void {868pub fn addCSourceFileSource(self: *Compile, source: CSourceFile) void {
875 const b = self.step.owner;869 const b = self.step.owner;
876 const c_source_file = b.allocator.create(CSourceFile) catch @panic("OOM");870 const c_source_file = b.allocator.create(CSourceFile) catch @panic("OOM");
877 c_source_file.* = source.dupe(b);871 c_source_file.* = source.dupe(b);
...@@ -879,85 +873,85 @@ pub fn addCSourceFileSource(self: *CompileStep, source: CSourceFile) void {...@@ -879,85 +873,85 @@ pub fn addCSourceFileSource(self: *CompileStep, source: CSourceFile) void {
879 source.source.addStepDependencies(&self.step);873 source.source.addStepDependencies(&self.step);
880}874}
881875
882pub fn setVerboseLink(self: *CompileStep, value: bool) void {876pub fn setVerboseLink(self: *Compile, value: bool) void {
883 self.verbose_link = value;877 self.verbose_link = value;
884}878}
885879
886pub fn setVerboseCC(self: *CompileStep, value: bool) void {880pub fn setVerboseCC(self: *Compile, value: bool) void {
887 self.verbose_cc = value;881 self.verbose_cc = value;
888}882}
889883
890pub fn overrideZigLibDir(self: *CompileStep, dir_path: []const u8) void {884pub fn overrideZigLibDir(self: *Compile, dir_path: []const u8) void {
891 const b = self.step.owner;885 const b = self.step.owner;
892 self.zig_lib_dir = b.dupePath(dir_path);886 self.zig_lib_dir = b.dupePath(dir_path);
893}887}
894888
895pub fn setMainPkgPath(self: *CompileStep, dir_path: []const u8) void {889pub fn setMainPkgPath(self: *Compile, dir_path: []const u8) void {
896 const b = self.step.owner;890 const b = self.step.owner;
897 self.main_pkg_path = b.dupePath(dir_path);891 self.main_pkg_path = b.dupePath(dir_path);
898}892}
899893
900pub fn setLibCFile(self: *CompileStep, libc_file: ?FileSource) void {894pub fn setLibCFile(self: *Compile, libc_file: ?FileSource) void {
901 const b = self.step.owner;895 const b = self.step.owner;
902 self.libc_file = if (libc_file) |f| f.dupe(b) else null;896 self.libc_file = if (libc_file) |f| f.dupe(b) else null;
903}897}
904898
905/// Returns the generated executable, library or object file.899/// Returns the generated executable, library or object file.
906/// To run an executable built with zig build, use `run`, or create an install step and invoke it.900/// 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 {
908 return .{ .generated = &self.output_path_source };902 return .{ .generated = &self.output_path_source };
909}903}
910904
911pub fn getOutputDirectorySource(self: *CompileStep) FileSource {905pub fn getOutputDirectorySource(self: *Compile) FileSource {
912 return .{ .generated = &self.output_dirname_source };906 return .{ .generated = &self.output_dirname_source };
913}907}
914908
915/// Returns the generated import library. This function can only be called for libraries.909/// 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 {
917 assert(self.kind == .lib);911 assert(self.kind == .lib);
918 return .{ .generated = &self.output_lib_path_source };912 return .{ .generated = &self.output_lib_path_source };
919}913}
920914
921/// Returns the generated header file.915/// Returns the generated header file.
922/// This function can only be called for libraries or object files which have `emit_h` set.916/// 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 {
924 assert(self.kind != .exe and self.kind != .@"test");918 assert(self.kind != .exe and self.kind != .@"test");
925 assert(self.emit_h);919 assert(self.emit_h);
926 return .{ .generated = &self.output_h_path_source };920 return .{ .generated = &self.output_h_path_source };
927}921}
928922
929/// Returns the generated PDB file. This function can only be called for Windows and UEFI.923/// 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 {
931 // TODO: Is this right? Isn't PDB for *any* PE/COFF file?925 // TODO: Is this right? Isn't PDB for *any* PE/COFF file?
932 assert(self.target.isWindows() or self.target.isUefi());926 assert(self.target.isWindows() or self.target.isUefi());
933 return .{ .generated = &self.output_pdb_path_source };927 return .{ .generated = &self.output_pdb_path_source };
934}928}
935929
936pub fn addAssemblyFile(self: *CompileStep, path: []const u8) void {930pub fn addAssemblyFile(self: *Compile, path: []const u8) void {
937 const b = self.step.owner;931 const b = self.step.owner;
938 self.link_objects.append(.{932 self.link_objects.append(.{
939 .assembly_file = .{ .path = b.dupe(path) },933 .assembly_file = .{ .path = b.dupe(path) },
940 }) catch @panic("OOM");934 }) catch @panic("OOM");
941}935}
942936
943pub fn addAssemblyFileSource(self: *CompileStep, source: FileSource) void {937pub fn addAssemblyFileSource(self: *Compile, source: FileSource) void {
944 const b = self.step.owner;938 const b = self.step.owner;
945 const source_duped = source.dupe(b);939 const source_duped = source.dupe(b);
946 self.link_objects.append(.{ .assembly_file = source_duped }) catch @panic("OOM");940 self.link_objects.append(.{ .assembly_file = source_duped }) catch @panic("OOM");
947 source_duped.addStepDependencies(&self.step);941 source_duped.addStepDependencies(&self.step);
948}942}
949943
950pub fn addObjectFile(self: *CompileStep, source_file: []const u8) void {944pub fn addObjectFile(self: *Compile, source_file: []const u8) void {
951 self.addObjectFileSource(.{ .path = source_file });945 self.addObjectFileSource(.{ .path = source_file });
952}946}
953947
954pub fn addObjectFileSource(self: *CompileStep, source: FileSource) void {948pub fn addObjectFileSource(self: *Compile, source: FileSource) void {
955 const b = self.step.owner;949 const b = self.step.owner;
956 self.link_objects.append(.{ .static_path = source.dupe(b) }) catch @panic("OOM");950 self.link_objects.append(.{ .static_path = source.dupe(b) }) catch @panic("OOM");
957 source.addStepDependencies(&self.step);951 source.addStepDependencies(&self.step);
958}952}
959953
960pub fn addObject(self: *CompileStep, obj: *CompileStep) void {954pub fn addObject(self: *Compile, obj: *Compile) void {
961 assert(obj.kind == .obj);955 assert(obj.kind == .obj);
962 self.linkLibraryOrObject(obj);956 self.linkLibraryOrObject(obj);
963}957}
...@@ -967,54 +961,54 @@ pub const addIncludeDir = @compileError("deprecated; use addIncludePath");...@@ -967,54 +961,54 @@ pub const addIncludeDir = @compileError("deprecated; use addIncludePath");
967pub const addLibPath = @compileError("deprecated, use addLibraryPath");961pub const addLibPath = @compileError("deprecated, use addLibraryPath");
968pub const addFrameworkDir = @compileError("deprecated, use addFrameworkPath");962pub 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 {
971 const b = self.step.owner;965 const b = self.step.owner;
972 self.include_dirs.append(IncludeDir{ .raw_path_system = b.dupe(path) }) catch @panic("OOM");966 self.include_dirs.append(IncludeDir{ .raw_path_system = b.dupe(path) }) catch @panic("OOM");
973}967}
974968
975pub fn addIncludePath(self: *CompileStep, path: []const u8) void {969pub fn addIncludePath(self: *Compile, path: []const u8) void {
976 const b = self.step.owner;970 const b = self.step.owner;
977 self.include_dirs.append(IncludeDir{ .raw_path = b.dupe(path) }) catch @panic("OOM");971 self.include_dirs.append(IncludeDir{ .raw_path = b.dupe(path) }) catch @panic("OOM");
978}972}
979973
980pub fn addConfigHeader(self: *CompileStep, config_header: *ConfigHeaderStep) void {974pub fn addConfigHeader(self: *Compile, config_header: *Step.ConfigHeader) void {
981 self.step.dependOn(&config_header.step);975 self.step.dependOn(&config_header.step);
982 self.include_dirs.append(.{ .config_header_step = config_header }) catch @panic("OOM");976 self.include_dirs.append(.{ .config_header_step = config_header }) catch @panic("OOM");
983}977}
984978
985pub fn addLibraryPath(self: *CompileStep, path: []const u8) void {979pub fn addLibraryPath(self: *Compile, path: []const u8) void {
986 const b = self.step.owner;980 const b = self.step.owner;
987 self.lib_paths.append(.{ .path = b.dupe(path) }) catch @panic("OOM");981 self.lib_paths.append(.{ .path = b.dupe(path) }) catch @panic("OOM");
988}982}
989983
990pub fn addLibraryPathDirectorySource(self: *CompileStep, directory_source: FileSource) void {984pub fn addLibraryPathDirectorySource(self: *Compile, directory_source: FileSource) void {
991 self.lib_paths.append(directory_source) catch @panic("OOM");985 self.lib_paths.append(directory_source) catch @panic("OOM");
992 directory_source.addStepDependencies(&self.step);986 directory_source.addStepDependencies(&self.step);
993}987}
994988
995pub fn addRPath(self: *CompileStep, path: []const u8) void {989pub fn addRPath(self: *Compile, path: []const u8) void {
996 const b = self.step.owner;990 const b = self.step.owner;
997 self.rpaths.append(.{ .path = b.dupe(path) }) catch @panic("OOM");991 self.rpaths.append(.{ .path = b.dupe(path) }) catch @panic("OOM");
998}992}
999993
1000pub fn addRPathDirectorySource(self: *CompileStep, directory_source: FileSource) void {994pub fn addRPathDirectorySource(self: *Compile, directory_source: FileSource) void {
1001 self.rpaths.append(directory_source) catch @panic("OOM");995 self.rpaths.append(directory_source) catch @panic("OOM");
1002 directory_source.addStepDependencies(&self.step);996 directory_source.addStepDependencies(&self.step);
1003}997}
1004998
1005pub fn addFrameworkPath(self: *CompileStep, dir_path: []const u8) void {999pub fn addFrameworkPath(self: *Compile, dir_path: []const u8) void {
1006 const b = self.step.owner;1000 const b = self.step.owner;
1007 self.framework_dirs.append(.{ .path = b.dupe(dir_path) }) catch @panic("OOM");1001 self.framework_dirs.append(.{ .path = b.dupe(dir_path) }) catch @panic("OOM");
1008}1002}
10091003
1010pub fn addFrameworkPathDirectorySource(self: *CompileStep, directory_source: FileSource) void {1004pub fn addFrameworkPathDirectorySource(self: *Compile, directory_source: FileSource) void {
1011 self.framework_dirs.append(directory_source) catch @panic("OOM");1005 self.framework_dirs.append(directory_source) catch @panic("OOM");
1012 directory_source.addStepDependencies(&self.step);1006 directory_source.addStepDependencies(&self.step);
1013}1007}
10141008
1015/// Adds a module to be used with `@import` and exposing it in the current1009/// Adds a module to be used with `@import` and exposing it in the current
1016/// package's module table using `name`.1010/// 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 {
1018 const b = cs.step.owner;1012 const b = cs.step.owner;
1019 cs.modules.put(b.dupe(name), module) catch @panic("OOM");1013 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 {...@@ -1025,17 +1019,17 @@ pub fn addModule(cs: *CompileStep, name: []const u8, module: *Module) void {
10251019
1026/// Adds a module to be used with `@import` without exposing it in the current1020/// Adds a module to be used with `@import` without exposing it in the current
1027/// package's module table.1021/// 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 {
1029 const b = cs.step.owner;1023 const b = cs.step.owner;
1030 const module = b.createModule(options);1024 const module = b.createModule(options);
1031 return addModule(cs, name, module);1025 return addModule(cs, name, module);
1032}1026}
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 {
1035 addModule(cs, module_name, options.createModule());1029 addModule(cs, module_name, options.createModule());
1036}1030}
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 {
1039 if (done.contains(module)) return;1033 if (done.contains(module)) return;
1040 try done.put(module, {});1034 try done.put(module, {});
1041 module.source_file.addStepDependencies(&cs.step);1035 module.source_file.addStepDependencies(&cs.step);
...@@ -1046,7 +1040,7 @@ fn addRecursiveBuildDeps(cs: *CompileStep, module: *Module, done: *std.AutoHashM...@@ -1046,7 +1040,7 @@ fn addRecursiveBuildDeps(cs: *CompileStep, module: *Module, done: *std.AutoHashM
10461040
1047/// If Vcpkg was found on the system, it will be added to include and lib1041/// If Vcpkg was found on the system, it will be added to include and lib
1048/// paths for the specified target.1042/// paths for the specified target.
1049pub fn addVcpkgPaths(self: *CompileStep, linkage: CompileStep.Linkage) !void {1043pub fn addVcpkgPaths(self: *Compile, linkage: Compile.Linkage) !void {
1050 const b = self.step.owner;1044 const b = self.step.owner;
1051 // Ideally in the Unattempted case we would call the function recursively1045 // Ideally in the Unattempted case we would call the function recursively
1052 // after findVcpkgRoot and have only one switch statement, but the compiler1046 // after findVcpkgRoot and have only one switch statement, but the compiler
...@@ -1082,7 +1076,7 @@ pub fn addVcpkgPaths(self: *CompileStep, linkage: CompileStep.Linkage) !void {...@@ -1082,7 +1076,7 @@ pub fn addVcpkgPaths(self: *CompileStep, linkage: CompileStep.Linkage) !void {
1082 }1076 }
1083}1077}
10841078
1085pub fn setExecCmd(self: *CompileStep, args: []const ?[]const u8) void {1079pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void {
1086 const b = self.step.owner;1080 const b = self.step.owner;
1087 assert(self.kind == .@"test");1081 assert(self.kind == .@"test");
1088 const duped_args = b.allocator.alloc(?[]u8, args.len) catch @panic("OOM");1082 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 {...@@ -1092,7 +1086,7 @@ pub fn setExecCmd(self: *CompileStep, args: []const ?[]const u8) void {
1092 self.exec_cmd_args = duped_args;1086 self.exec_cmd_args = duped_args;
1093}1087}
10941088
1095fn linkLibraryOrObject(self: *CompileStep, other: *CompileStep) void {1089fn linkLibraryOrObject(self: *Compile, other: *Compile) void {
1096 self.step.dependOn(&other.step);1090 self.step.dependOn(&other.step);
1097 self.link_objects.append(.{ .other_step = other }) catch @panic("OOM");1091 self.link_objects.append(.{ .other_step = other }) catch @panic("OOM");
1098 self.include_dirs.append(.{ .other_step = other }) catch @panic("OOM");1092 self.include_dirs.append(.{ .other_step = other }) catch @panic("OOM");
...@@ -1103,7 +1097,7 @@ fn linkLibraryOrObject(self: *CompileStep, other: *CompileStep) void {...@@ -1103,7 +1097,7 @@ fn linkLibraryOrObject(self: *CompileStep, other: *CompileStep) void {
1103}1097}
11041098
1105fn appendModuleArgs(1099fn appendModuleArgs(
1106 cs: *CompileStep,1100 cs: *Compile,
1107 zig_args: *ArrayList([]const u8),1101 zig_args: *ArrayList([]const u8),
1108) error{OutOfMemory}!void {1102) error{OutOfMemory}!void {
1109 const b = cs.step.owner;1103 const b = cs.step.owner;
...@@ -1214,7 +1208,7 @@ fn constructDepString(...@@ -1214,7 +1208,7 @@ fn constructDepString(
12141208
1215fn make(step: *Step, prog_node: *std.Progress.Node) !void {1209fn make(step: *Step, prog_node: *std.Progress.Node) !void {
1216 const b = step.owner;1210 const b = step.owner;
1217 const self = @fieldParentPtr(CompileStep, "step", step);1211 const self = @fieldParentPtr(Compile, "step", step);
12181212
1219 if (self.root_src == null and self.link_objects.items.len == 0) {1213 if (self.root_src == null and self.link_objects.items.len == 0) {
1220 return step.fail("the linker needs one or more objects to link", .{});1214 return step.fail("the linker needs one or more objects to link", .{});
...@@ -2088,7 +2082,7 @@ const TransitiveDeps = struct {...@@ -2088,7 +2082,7 @@ const TransitiveDeps = struct {
2088 }2082 }
2089 }2083 }
20902084
2091 fn addInner(td: *TransitiveDeps, other: *CompileStep, dyn: bool) !void {2085 fn addInner(td: *TransitiveDeps, other: *Compile, dyn: bool) !void {
2092 // Inherit dependency on libc and libc++2086 // Inherit dependency on libc and libc++
2093 td.is_linking_libcpp = td.is_linking_libcpp or other.is_linking_libcpp;2087 td.is_linking_libcpp = td.is_linking_libcpp or other.is_linking_libcpp;
2094 td.is_linking_libc = td.is_linking_libc or other.is_linking_libc;2088 td.is_linking_libc = td.is_linking_libc or other.is_linking_libc;
...@@ -2128,7 +2122,7 @@ const TransitiveDeps = struct {...@@ -2128,7 +2122,7 @@ const TransitiveDeps = struct {
2128 }2122 }
2129};2123};
21302124
2131fn checkCompileErrors(self: *CompileStep) !void {2125fn checkCompileErrors(self: *Compile) !void {
2132 // Clear this field so that it does not get printed by the build runner.2126 // Clear this field so that it does not get printed by the build runner.
2133 const actual_eb = self.step.result_error_bundle;2127 const actual_eb = self.step.result_error_bundle;
2134 self.step.result_error_bundle = std.zig.ErrorBundle.empty;2128 self.step.result_error_bundle = std.zig.ErrorBundle.empty;
lib/std/Build/Step/ConfigHeader.zig+13-13
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1const std = @import("std");1const std = @import("std");
2const ConfigHeaderStep = @This();2const ConfigHeader = @This();
3const Step = std.Build.Step;3const Step = std.Build.Step;
44
5pub const Style = union(enum) {5pub const Style = union(enum) {
...@@ -48,8 +48,8 @@ pub const Options = struct {...@@ -48,8 +48,8 @@ pub const Options = struct {
48 first_ret_addr: ?usize = null,48 first_ret_addr: ?usize = null,
49};49};
5050
51pub fn create(owner: *std.Build, options: Options) *ConfigHeaderStep {51pub fn create(owner: *std.Build, options: Options) *ConfigHeader {
52 const self = owner.allocator.create(ConfigHeaderStep) catch @panic("OOM");52 const self = owner.allocator.create(ConfigHeader) catch @panic("OOM");
5353
54 var include_path: []const u8 = "config.h";54 var include_path: []const u8 = "config.h";
5555
...@@ -93,21 +93,21 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeaderStep {...@@ -93,21 +93,21 @@ pub fn create(owner: *std.Build, options: Options) *ConfigHeaderStep {
93 return self;93 return self;
94}94}
9595
96pub fn addValues(self: *ConfigHeaderStep, values: anytype) void {96pub fn addValues(self: *ConfigHeader, values: anytype) void {
97 return addValuesInner(self, values) catch @panic("OOM");97 return addValuesInner(self, values) catch @panic("OOM");
98}98}
9999
100pub fn getFileSource(self: *ConfigHeaderStep) std.Build.FileSource {100pub fn getFileSource(self: *ConfigHeader) std.Build.FileSource {
101 return .{ .generated = &self.output_file };101 return .{ .generated = &self.output_file };
102}102}
103103
104fn addValuesInner(self: *ConfigHeaderStep, values: anytype) !void {104fn addValuesInner(self: *ConfigHeader, values: anytype) !void {
105 inline for (@typeInfo(@TypeOf(values)).Struct.fields) |field| {105 inline for (@typeInfo(@TypeOf(values)).Struct.fields) |field| {
106 try putValue(self, field.name, field.type, @field(values, field.name));106 try putValue(self, field.name, field.type, @field(values, field.name));
107 }107 }
108}108}
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 {
111 switch (@typeInfo(T)) {111 switch (@typeInfo(T)) {
112 .Null => {112 .Null => {
113 try self.values.put(field_name, .undef);113 try self.values.put(field_name, .undef);
...@@ -151,31 +151,31 @@ fn putValue(self: *ConfigHeaderStep, field_name: []const u8, comptime T: type, v...@@ -151,31 +151,31 @@ fn putValue(self: *ConfigHeaderStep, field_name: []const u8, comptime T: type, v
151 else => {},151 else => {},
152 }152 }
153153
154 @compileError("unsupported ConfigHeaderStep value type: " ++ @typeName(T));154 @compileError("unsupported ConfigHeader value type: " ++ @typeName(T));
155 },155 },
156 else => @compileError("unsupported ConfigHeaderStep value type: " ++ @typeName(T)),156 else => @compileError("unsupported ConfigHeader value type: " ++ @typeName(T)),
157 }157 }
158}158}
159159
160fn make(step: *Step, prog_node: *std.Progress.Node) !void {160fn make(step: *Step, prog_node: *std.Progress.Node) !void {
161 _ = prog_node;161 _ = prog_node;
162 const b = step.owner;162 const b = step.owner;
163 const self = @fieldParentPtr(ConfigHeaderStep, "step", step);163 const self = @fieldParentPtr(ConfigHeader, "step", step);
164 const gpa = b.allocator;164 const gpa = b.allocator;
165 const arena = b.allocator;165 const arena = b.allocator;
166166
167 var man = b.cache.obtain();167 var man = b.cache.obtain();
168 defer man.deinit();168 defer man.deinit();
169169
170 // Random bytes to make ConfigHeaderStep unique. Refresh this with new170 // Random bytes to make ConfigHeader unique. Refresh this with new
171 // random bytes when ConfigHeaderStep implementation is modified in a171 // random bytes when ConfigHeader implementation is modified in a
172 // non-backwards-compatible way.172 // non-backwards-compatible way.
173 man.hash.add(@as(u32, 0xdef08d23));173 man.hash.add(@as(u32, 0xdef08d23));
174174
175 var output = std.ArrayList(u8).init(gpa);175 var output = std.ArrayList(u8).init(gpa);
176 defer output.deinit();176 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.";
179 const c_generated_line = "/* " ++ header_text ++ " */\n";179 const c_generated_line = "/* " ++ header_text ++ " */\n";
180 const asm_generated_line = "; " ++ header_text ++ "\n";180 const asm_generated_line = "; " ++ header_text ++ "\n";
181181
lib/std/Build/Step/Fmt.zig+4-4
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
3//! * Check mode: fail the step if a non-conforming file is found.3//! * Check mode: fail the step if a non-conforming file is found.
4const std = @import("std");4const std = @import("std");
5const Step = std.Build.Step;5const Step = std.Build.Step;
6const FmtStep = @This();6const Fmt = @This();
77
8step: Step,8step: Step,
9paths: []const []const u8,9paths: []const []const u8,
...@@ -19,8 +19,8 @@ pub const Options = struct {...@@ -19,8 +19,8 @@ pub const Options = struct {
19 check: bool = false,19 check: bool = false,
20};20};
2121
22pub fn create(owner: *std.Build, options: Options) *FmtStep {22pub fn create(owner: *std.Build, options: Options) *Fmt {
23 const self = owner.allocator.create(FmtStep) catch @panic("OOM");23 const self = owner.allocator.create(Fmt) catch @panic("OOM");
24 const name = if (options.check) "zig fmt --check" else "zig fmt";24 const name = if (options.check) "zig fmt --check" else "zig fmt";
25 self.* = .{25 self.* = .{
26 .step = Step.init(.{26 .step = Step.init(.{
...@@ -47,7 +47,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -47,7 +47,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
4747
48 const b = step.owner;48 const b = step.owner;
49 const arena = b.allocator;49 const arena = b.allocator;
50 const self = @fieldParentPtr(FmtStep, "step", step);50 const self = @fieldParentPtr(Fmt, "step", step);
5151
52 var argv: std.ArrayListUnmanaged([]const u8) = .{};52 var argv: std.ArrayListUnmanaged([]const u8) = .{};
53 try argv.ensureUnusedCapacity(arena, 2 + 1 + self.paths.len + 2 * self.exclude_paths.len);53 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 @@...@@ -1,24 +1,23 @@
1const std = @import("std");1const std = @import("std");
2const Step = std.Build.Step;2const Step = std.Build.Step;
3const CompileStep = std.Build.CompileStep;
4const InstallDir = std.Build.InstallDir;3const InstallDir = std.Build.InstallDir;
5const InstallArtifactStep = @This();4const InstallArtifact = @This();
6const fs = std.fs;5const fs = std.fs;
76
8pub const base_id = .install_artifact;7pub const base_id = .install_artifact;
98
10step: Step,9step: Step,
11artifact: *CompileStep,10artifact: *Step.Compile,
12dest_dir: InstallDir,11dest_dir: InstallDir,
13pdb_dir: ?InstallDir,12pdb_dir: ?InstallDir,
14h_dir: ?InstallDir,13h_dir: ?InstallDir,
15/// If non-null, adds additional path components relative to dest_dir, and14/// 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.
17dest_sub_path: ?[]const u8,16dest_sub_path: ?[]const u8,
1817
19pub fn create(owner: *std.Build, artifact: *CompileStep) *InstallArtifactStep {18pub fn create(owner: *std.Build, artifact: *Step.Compile) *InstallArtifact {
20 const self = owner.allocator.create(InstallArtifactStep) catch @panic("OOM");19 const self = owner.allocator.create(InstallArtifact) catch @panic("OOM");
21 self.* = InstallArtifactStep{20 self.* = InstallArtifact{
22 .step = Step.init(.{21 .step = Step.init(.{
23 .id = base_id,22 .id = base_id,
24 .name = owner.fmt("install {s}", .{artifact.name}),23 .name = owner.fmt("install {s}", .{artifact.name}),
...@@ -66,7 +65,7 @@ pub fn create(owner: *std.Build, artifact: *CompileStep) *InstallArtifactStep {...@@ -66,7 +65,7 @@ pub fn create(owner: *std.Build, artifact: *CompileStep) *InstallArtifactStep {
6665
67fn make(step: *Step, prog_node: *std.Progress.Node) !void {66fn make(step: *Step, prog_node: *std.Progress.Node) !void {
68 _ = prog_node;67 _ = prog_node;
69 const self = @fieldParentPtr(InstallArtifactStep, "step", step);68 const self = @fieldParentPtr(InstallArtifact, "step", step);
70 const src_builder = self.artifact.step.owner;69 const src_builder = self.artifact.step.owner;
71 const dest_builder = step.owner;70 const dest_builder = step.owner;
7271
...@@ -90,7 +89,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -90,7 +89,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
90 self.artifact.version != null and89 self.artifact.version != null and
91 self.artifact.target.wantSharedLibSymLinks())90 self.artifact.target.wantSharedLibSymLinks())
92 {91 {
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.?);
94 }93 }
95 if (self.artifact.isDynamicLibrary() and94 if (self.artifact.isDynamicLibrary() and
96 self.artifact.target.isWindows() and95 self.artifact.target.isWindows() and
lib/std/Build/Step/InstallFile.zig+4-4
...@@ -2,7 +2,7 @@ const std = @import("std");...@@ -2,7 +2,7 @@ const std = @import("std");
2const Step = std.Build.Step;2const Step = std.Build.Step;
3const FileSource = std.Build.FileSource;3const FileSource = std.Build.FileSource;
4const InstallDir = std.Build.InstallDir;4const InstallDir = std.Build.InstallDir;
5const InstallFileStep = @This();5const InstallFile = @This();
6const assert = std.debug.assert;6const assert = std.debug.assert;
77
8pub const base_id = .install_file;8pub const base_id = .install_file;
...@@ -20,10 +20,10 @@ pub fn create(...@@ -20,10 +20,10 @@ pub fn create(
20 source: FileSource,20 source: FileSource,
21 dir: InstallDir,21 dir: InstallDir,
22 dest_rel_path: []const u8,22 dest_rel_path: []const u8,
23) *InstallFileStep {23) *InstallFile {
24 assert(dest_rel_path.len != 0);24 assert(dest_rel_path.len != 0);
25 owner.pushInstalledFile(dir, dest_rel_path);25 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");
27 self.* = .{27 self.* = .{
28 .step = Step.init(.{28 .step = Step.init(.{
29 .id = base_id,29 .id = base_id,
...@@ -43,7 +43,7 @@ pub fn create(...@@ -43,7 +43,7 @@ pub fn create(
43fn make(step: *Step, prog_node: *std.Progress.Node) !void {43fn make(step: *Step, prog_node: *std.Progress.Node) !void {
44 _ = prog_node;44 _ = prog_node;
45 const src_builder = step.owner;45 const src_builder = step.owner;
46 const self = @fieldParentPtr(InstallFileStep, "step", step);46 const self = @fieldParentPtr(InstallFile, "step", step);
47 const dest_builder = self.dest_builder;47 const dest_builder = self.dest_builder;
48 const full_src_path = self.source.getPath2(src_builder, step);48 const full_src_path = self.source.getPath2(src_builder, step);
49 const full_dest_path = dest_builder.getInstallPath(self.dir, self.dest_rel_path);49 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 @@...@@ -1,12 +1,11 @@
1const std = @import("std");1const std = @import("std");
2const ObjCopyStep = @This();2const ObjCopy = @This();
33
4const Allocator = std.mem.Allocator;4const Allocator = std.mem.Allocator;
5const ArenaAllocator = std.heap.ArenaAllocator;5const ArenaAllocator = std.heap.ArenaAllocator;
6const ArrayListUnmanaged = std.ArrayListUnmanaged;6const ArrayListUnmanaged = std.ArrayListUnmanaged;
7const File = std.fs.File;7const File = std.fs.File;
8const InstallDir = std.Build.InstallDir;8const InstallDir = std.Build.InstallDir;
9const CompileStep = std.Build.CompileStep;
10const Step = std.Build.Step;9const Step = std.Build.Step;
11const elf = std.elf;10const elf = std.elf;
12const fs = std.fs;11const fs = std.fs;
...@@ -40,9 +39,9 @@ pub fn create(...@@ -40,9 +39,9 @@ pub fn create(
40 owner: *std.Build,39 owner: *std.Build,
41 file_source: std.Build.FileSource,40 file_source: std.Build.FileSource,
42 options: Options,41 options: Options,
43) *ObjCopyStep {42) *ObjCopy {
44 const self = owner.allocator.create(ObjCopyStep) catch @panic("OOM");43 const self = owner.allocator.create(ObjCopy) catch @panic("OOM");
45 self.* = ObjCopyStep{44 self.* = ObjCopy{
46 .step = Step.init(.{45 .step = Step.init(.{
47 .id = base_id,46 .id = base_id,
48 .name = owner.fmt("objcopy {s}", .{file_source.getDisplayName()}),47 .name = owner.fmt("objcopy {s}", .{file_source.getDisplayName()}),
...@@ -61,19 +60,19 @@ pub fn create(...@@ -61,19 +60,19 @@ pub fn create(
61 return self;60 return self;
62}61}
6362
64pub fn getOutputSource(self: *const ObjCopyStep) std.Build.FileSource {63pub fn getOutputSource(self: *const ObjCopy) std.Build.FileSource {
65 return .{ .generated = &self.output_file };64 return .{ .generated = &self.output_file };
66}65}
6766
68fn make(step: *Step, prog_node: *std.Progress.Node) !void {67fn make(step: *Step, prog_node: *std.Progress.Node) !void {
69 const b = step.owner;68 const b = step.owner;
70 const self = @fieldParentPtr(ObjCopyStep, "step", step);69 const self = @fieldParentPtr(ObjCopy, "step", step);
7170
72 var man = b.cache.obtain();71 var man = b.cache.obtain();
73 defer man.deinit();72 defer man.deinit();
7473
75 // Random bytes to make ObjCopyStep unique. Refresh this with new random74 // Random bytes to make ObjCopy unique. Refresh this with new random
76 // bytes when ObjCopyStep implementation is modified incompatibly.75 // bytes when ObjCopy implementation is modified incompatibly.
77 man.hash.add(@as(u32, 0xe18b7baf));76 man.hash.add(@as(u32, 0xe18b7baf));
7877
79 const full_src_path = self.file_source.getPath(b);78 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");...@@ -3,10 +3,9 @@ const builtin = @import("builtin");
3const fs = std.fs;3const fs = std.fs;
4const Step = std.Build.Step;4const Step = std.Build.Step;
5const GeneratedFile = std.Build.GeneratedFile;5const GeneratedFile = std.Build.GeneratedFile;
6const CompileStep = std.Build.CompileStep;
7const FileSource = std.Build.FileSource;6const FileSource = std.Build.FileSource;
87
9const OptionsStep = @This();8const Options = @This();
109
11pub const base_id = .options;10pub const base_id = .options;
1211
...@@ -17,8 +16,8 @@ contents: std.ArrayList(u8),...@@ -17,8 +16,8 @@ contents: std.ArrayList(u8),
17artifact_args: std.ArrayList(OptionArtifactArg),16artifact_args: std.ArrayList(OptionArtifactArg),
18file_source_args: std.ArrayList(OptionFileSourceArg),17file_source_args: std.ArrayList(OptionFileSourceArg),
1918
20pub fn create(owner: *std.Build) *OptionsStep {19pub fn create(owner: *std.Build) *Options {
21 const self = owner.allocator.create(OptionsStep) catch @panic("OOM");20 const self = owner.allocator.create(Options) catch @panic("OOM");
22 self.* = .{21 self.* = .{
23 .step = Step.init(.{22 .step = Step.init(.{
24 .id = base_id,23 .id = base_id,
...@@ -36,11 +35,11 @@ pub fn create(owner: *std.Build) *OptionsStep {...@@ -36,11 +35,11 @@ pub fn create(owner: *std.Build) *OptionsStep {
36 return self;35 return self;
37}36}
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 {
40 return addOptionFallible(self, T, name, value) catch @panic("unhandled error");39 return addOptionFallible(self, T, name, value) catch @panic("unhandled error");
41}40}
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 {
44 const out = self.contents.writer();43 const out = self.contents.writer();
45 switch (T) {44 switch (T) {
46 []const []const u8 => {45 []const []const u8 => {
...@@ -189,7 +188,7 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void {...@@ -189,7 +188,7 @@ fn printLiteral(out: anytype, val: anytype, indent: u8) !void {
189/// The value is the path in the cache dir.188/// The value is the path in the cache dir.
190/// Adds a dependency automatically.189/// Adds a dependency automatically.
191pub fn addOptionFileSource(190pub fn addOptionFileSource(
192 self: *OptionsStep,191 self: *Options,
193 name: []const u8,192 name: []const u8,
194 source: FileSource,193 source: FileSource,
195) void {194) void {
...@@ -202,19 +201,19 @@ pub fn addOptionFileSource(...@@ -202,19 +201,19 @@ pub fn addOptionFileSource(
202201
203/// The value is the path in the cache dir.202/// The value is the path in the cache dir.
204/// Adds a dependency automatically.203/// 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 {
206 self.artifact_args.append(.{ .name = self.step.owner.dupe(name), .artifact = artifact }) catch @panic("OOM");205 self.artifact_args.append(.{ .name = self.step.owner.dupe(name), .artifact = artifact }) catch @panic("OOM");
207 self.step.dependOn(&artifact.step);206 self.step.dependOn(&artifact.step);
208}207}
209208
210pub fn createModule(self: *OptionsStep) *std.Build.Module {209pub fn createModule(self: *Options) *std.Build.Module {
211 return self.step.owner.createModule(.{210 return self.step.owner.createModule(.{
212 .source_file = self.getSource(),211 .source_file = self.getSource(),
213 .dependencies = &.{},212 .dependencies = &.{},
214 });213 });
215}214}
216215
217pub fn getSource(self: *OptionsStep) FileSource {216pub fn getSource(self: *Options) FileSource {
218 return .{ .generated = &self.generated_file };217 return .{ .generated = &self.generated_file };
219}218}
220219
...@@ -223,7 +222,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -223,7 +222,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
223 _ = prog_node;222 _ = prog_node;
224223
225 const b = step.owner;224 const b = step.owner;
226 const self = @fieldParentPtr(OptionsStep, "step", step);225 const self = @fieldParentPtr(Options, "step", step);
227226
228 for (self.artifact_args.items) |item| {227 for (self.artifact_args.items) |item| {
229 self.addOption(228 self.addOption(
...@@ -314,7 +313,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -314,7 +313,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
314313
315const OptionArtifactArg = struct {314const OptionArtifactArg = struct {
316 name: []const u8,315 name: []const u8,
317 artifact: *CompileStep,316 artifact: *Step.Compile,
318};317};
319318
320const OptionFileSourceArg = struct {319const OptionFileSourceArg = struct {
...@@ -322,7 +321,7 @@ const OptionFileSourceArg = struct {...@@ -322,7 +321,7 @@ const OptionFileSourceArg = struct {
322 source: FileSource,321 source: FileSource,
323};322};
324323
325test "OptionsStep" {324test Options {
326 if (builtin.os.tag == .wasi) return error.SkipZigTest;325 if (builtin.os.tag == .wasi) return error.SkipZigTest;
327326
328 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);327 var arena = std.heap.ArenaAllocator.init(std.testing.allocator);
lib/std/Build/Step/RemoveDir.zig+4-4
...@@ -1,15 +1,15 @@...@@ -1,15 +1,15 @@
1const std = @import("std");1const std = @import("std");
2const fs = std.fs;2const fs = std.fs;
3const Step = std.Build.Step;3const Step = std.Build.Step;
4const RemoveDirStep = @This();4const RemoveDir = @This();
55
6pub const base_id = .remove_dir;6pub const base_id = .remove_dir;
77
8step: Step,8step: Step,
9dir_path: []const u8,9dir_path: []const u8,
1010
11pub fn init(owner: *std.Build, dir_path: []const u8) RemoveDirStep {11pub fn init(owner: *std.Build, dir_path: []const u8) RemoveDir {
12 return RemoveDirStep{12 return RemoveDir{
13 .step = Step.init(.{13 .step = Step.init(.{
14 .id = .remove_dir,14 .id = .remove_dir,
15 .name = owner.fmt("RemoveDir {s}", .{dir_path}),15 .name = owner.fmt("RemoveDir {s}", .{dir_path}),
...@@ -26,7 +26,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -26,7 +26,7 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
26 _ = prog_node;26 _ = prog_node;
2727
28 const b = step.owner;28 const b = step.owner;
29 const self = @fieldParentPtr(RemoveDirStep, "step", step);29 const self = @fieldParentPtr(RemoveDir, "step", step);
3030
31 b.build_root.handle.deleteTree(self.dir_path) catch |err| {31 b.build_root.handle.deleteTree(self.dir_path) catch |err| {
32 if (b.build_root.path) |base| {32 if (b.build_root.path) |base| {
lib/std/Build/Step/Run.zig+53-55
...@@ -1,8 +1,6 @@...@@ -1,8 +1,6 @@
1const std = @import("std");1const std = @import("std");
2const builtin = @import("builtin");2const builtin = @import("builtin");
3const Step = std.Build.Step;3const Step = std.Build.Step;
4const CompileStep = std.Build.CompileStep;
5const WriteFileStep = std.Build.WriteFileStep;
6const fs = std.fs;4const fs = std.fs;
7const mem = std.mem;5const mem = std.mem;
8const process = std.process;6const process = std.process;
...@@ -12,7 +10,7 @@ const Allocator = mem.Allocator;...@@ -12,7 +10,7 @@ const Allocator = mem.Allocator;
12const ExecError = std.Build.ExecError;10const ExecError = std.Build.ExecError;
13const assert = std.debug.assert;11const assert = std.debug.assert;
1412
15const RunStep = @This();13const Run = @This();
1614
17pub const base_id: Step.Id = .run;15pub const base_id: Step.Id = .run;
1816
...@@ -29,12 +27,12 @@ cwd: ?[]const u8,...@@ -29,12 +27,12 @@ cwd: ?[]const u8,
29/// Override this field to modify the environment, or use setEnvironmentVariable27/// Override this field to modify the environment, or use setEnvironmentVariable
30env_map: ?*EnvMap,28env_map: ?*EnvMap,
3129
32/// Configures whether the RunStep is considered to have side-effects, and also30/// Configures whether the Run step is considered to have side-effects, and also
33/// whether the RunStep will inherit stdio streams, forwarding them to the31/// whether the Run step will inherit stdio streams, forwarding them to the
34/// parent process, in which case will require a global lock to prevent other32/// parent process, in which case will require a global lock to prevent other
35/// steps from interfering with stdio while the subprocess associated with this33/// steps from interfering with stdio while the subprocess associated with this
36/// RunStep is running.34/// Run step is running.
37/// If the RunStep is determined to not have side-effects, then execution will35/// If the Run step is determined to not have side-effects, then execution will
38/// be skipped if all output files are up-to-date and input files are36/// be skipped if all output files are up-to-date and input files are
39/// unchanged.37/// unchanged.
40stdio: StdIo = .infer_from_args,38stdio: StdIo = .infer_from_args,
...@@ -42,9 +40,9 @@ stdio: StdIo = .infer_from_args,...@@ -42,9 +40,9 @@ stdio: StdIo = .infer_from_args,
42stdin: ?[]const u8 = null,40stdin: ?[]const u8 = null,
4341
44/// Additional file paths relative to build.zig that, when modified, indicate42/// Additional file paths relative to build.zig that, when modified, indicate
45/// that the RunStep should be re-executed.43/// that the Run step should be re-executed.
46/// If the RunStep is determined to have side-effects, this field is ignored44/// If the Run step is determined to have side-effects, this field is ignored
47/// and the RunStep is always executed when it appears in the build graph.45/// and the Run step is always executed when it appears in the build graph.
48extra_file_dependencies: []const []const u8 = &.{},46extra_file_dependencies: []const []const u8 = &.{},
4947
50/// After adding an output argument, this step will by default rename itself48/// After adding an output argument, this step will by default rename itself
...@@ -52,14 +50,14 @@ extra_file_dependencies: []const []const u8 = &.{},...@@ -52,14 +50,14 @@ extra_file_dependencies: []const []const u8 = &.{},
52/// This can be disabled by setting this to false.50/// This can be disabled by setting this to false.
53rename_step_with_output_arg: bool = true,51rename_step_with_output_arg: bool = true,
5452
55/// If this is true, a RunStep which is configured to check the output of the53/// If this is true, a Run step which is configured to check the output of the
56/// executed binary will not fail the build if the binary cannot be executed54/// executed binary will not fail the build if the binary cannot be executed
57/// due to being for a foreign binary to the host system which is running the55/// due to being for a foreign binary to the host system which is running the
58/// build graph.56/// build graph.
59/// Command-line arguments such as -fqemu and -fwasmtime may affect whether a57/// Command-line arguments such as -fqemu and -fwasmtime may affect whether a
60/// binary is detected as foreign, as well as system configuration such as58/// binary is detected as foreign, as well as system configuration such as
61/// Rosetta (macOS) and binfmt_misc (Linux).59/// Rosetta (macOS) and binfmt_misc (Linux).
62/// If this RunStep is considered to have side-effects, then this flag does60/// If this Run step is considered to have side-effects, then this flag does
63/// nothing.61/// nothing.
64skip_foreign_checks: bool = false,62skip_foreign_checks: bool = false,
6563
...@@ -73,18 +71,18 @@ captured_stderr: ?*Output = null,...@@ -73,18 +71,18 @@ captured_stderr: ?*Output = null,
73has_side_effects: bool = false,71has_side_effects: bool = false,
7472
75pub const StdIo = union(enum) {73pub const StdIo = union(enum) {
76 /// Whether the RunStep has side-effects will be determined by whether or not one74 /// Whether the Run step has side-effects will be determined by whether or not one
77 /// of the args is an output file (added with `addOutputFileArg`).75 /// 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`.
79 /// The step will fail if the subprocess crashes or returns a non-zero exit code.77 /// The step will fail if the subprocess crashes or returns a non-zero exit code.
80 infer_from_args,78 infer_from_args,
81 /// Causes the RunStep to be considered to have side-effects, and therefore79 /// Causes the Run step to be considered to have side-effects, and therefore
82 /// always execute when it appears in the build graph.80 /// always execute when it appears in the build graph.
83 /// It also means that this step will obtain a global lock to prevent other81 /// It also means that this step will obtain a global lock to prevent other
84 /// steps from running in the meantime.82 /// steps from running in the meantime.
85 /// The step will fail if the subprocess crashes or returns a non-zero exit code.83 /// The step will fail if the subprocess crashes or returns a non-zero exit code.
86 inherit,84 inherit,
87 /// Causes the RunStep to be considered to *not* have side-effects. The85 /// Causes the Run step to be considered to *not* have side-effects. The
88 /// process will be re-executed if any of the input dependencies are86 /// process will be re-executed if any of the input dependencies are
89 /// modified. The exit code and standard I/O streams will be checked for87 /// modified. The exit code and standard I/O streams will be checked for
90 /// certain conditions, and the step will succeed or fail based on these88 /// certain conditions, and the step will succeed or fail based on these
...@@ -92,7 +90,7 @@ pub const StdIo = union(enum) {...@@ -92,7 +90,7 @@ pub const StdIo = union(enum) {
92 /// Note that an explicit check for exit code 0 needs to be added to this90 /// Note that an explicit check for exit code 0 needs to be added to this
93 /// list if such a check is desirable.91 /// list if such a check is desirable.
94 check: std.ArrayList(Check),92 check: std.ArrayList(Check),
95 /// This RunStep is running a zig unit test binary and will communicate93 /// This Run step is running a zig unit test binary and will communicate
96 /// extra metadata over the IPC protocol.94 /// extra metadata over the IPC protocol.
97 zig_test,95 zig_test,
9896
...@@ -106,7 +104,7 @@ pub const StdIo = union(enum) {...@@ -106,7 +104,7 @@ pub const StdIo = union(enum) {
106};104};
107105
108pub const Arg = union(enum) {106pub const Arg = union(enum) {
109 artifact: *CompileStep,107 artifact: *Step.Compile,
110 file_source: std.Build.FileSource,108 file_source: std.Build.FileSource,
111 directory_source: std.Build.FileSource,109 directory_source: std.Build.FileSource,
112 bytes: []u8,110 bytes: []u8,
...@@ -119,8 +117,8 @@ pub const Output = struct {...@@ -119,8 +117,8 @@ pub const Output = struct {
119 basename: []const u8,117 basename: []const u8,
120};118};
121119
122pub fn create(owner: *std.Build, name: []const u8) *RunStep {120pub fn create(owner: *std.Build, name: []const u8) *Run {
123 const self = owner.allocator.create(RunStep) catch @panic("OOM");121 const self = owner.allocator.create(Run) catch @panic("OOM");
124 self.* = .{122 self.* = .{
125 .step = Step.init(.{123 .step = Step.init(.{
126 .id = base_id,124 .id = base_id,
...@@ -135,17 +133,17 @@ pub fn create(owner: *std.Build, name: []const u8) *RunStep {...@@ -135,17 +133,17 @@ pub fn create(owner: *std.Build, name: []const u8) *RunStep {
135 return self;133 return self;
136}134}
137135
138pub fn setName(self: *RunStep, name: []const u8) void {136pub fn setName(self: *Run, name: []const u8) void {
139 self.step.name = name;137 self.step.name = name;
140 self.rename_step_with_output_arg = false;138 self.rename_step_with_output_arg = false;
141}139}
142140
143pub fn enableTestRunnerMode(rs: *RunStep) void {141pub fn enableTestRunnerMode(rs: *Run) void {
144 rs.stdio = .zig_test;142 rs.stdio = .zig_test;
145 rs.addArgs(&.{"--listen=-"});143 rs.addArgs(&.{"--listen=-"});
146}144}
147145
148pub fn addArtifactArg(self: *RunStep, artifact: *CompileStep) void {146pub fn addArtifactArg(self: *Run, artifact: *Step.Compile) void {
149 self.argv.append(Arg{ .artifact = artifact }) catch @panic("OOM");147 self.argv.append(Arg{ .artifact = artifact }) catch @panic("OOM");
150 self.step.dependOn(&artifact.step);148 self.step.dependOn(&artifact.step);
151}149}
...@@ -153,12 +151,12 @@ pub fn addArtifactArg(self: *RunStep, artifact: *CompileStep) void {...@@ -153,12 +151,12 @@ pub fn addArtifactArg(self: *RunStep, artifact: *CompileStep) void {
153/// This provides file path as a command line argument to the command being151/// This provides file path as a command line argument to the command being
154/// run, and returns a FileSource which can be used as inputs to other APIs152/// run, and returns a FileSource which can be used as inputs to other APIs
155/// throughout the build system.153/// 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 {
157 return addPrefixedOutputFileArg(rs, "", basename);155 return addPrefixedOutputFileArg(rs, "", basename);
158}156}
159157
160pub fn addPrefixedOutputFileArg(158pub fn addPrefixedOutputFileArg(
161 rs: *RunStep,159 rs: *Run,
162 prefix: []const u8,160 prefix: []const u8,
163 basename: []const u8,161 basename: []const u8,
164) std.Build.FileSource {162) std.Build.FileSource {
...@@ -179,38 +177,38 @@ pub fn addPrefixedOutputFileArg(...@@ -179,38 +177,38 @@ pub fn addPrefixedOutputFileArg(
179 return .{ .generated = &output.generated_file };177 return .{ .generated = &output.generated_file };
180}178}
181179
182pub fn addFileSourceArg(self: *RunStep, file_source: std.Build.FileSource) void {180pub fn addFileSourceArg(self: *Run, file_source: std.Build.FileSource) void {
183 self.argv.append(.{181 self.argv.append(.{
184 .file_source = file_source.dupe(self.step.owner),182 .file_source = file_source.dupe(self.step.owner),
185 }) catch @panic("OOM");183 }) catch @panic("OOM");
186 file_source.addStepDependencies(&self.step);184 file_source.addStepDependencies(&self.step);
187}185}
188186
189pub fn addDirectorySourceArg(self: *RunStep, directory_source: std.Build.FileSource) void {187pub fn addDirectorySourceArg(self: *Run, directory_source: std.Build.FileSource) void {
190 self.argv.append(.{188 self.argv.append(.{
191 .directory_source = directory_source.dupe(self.step.owner),189 .directory_source = directory_source.dupe(self.step.owner),
192 }) catch @panic("OOM");190 }) catch @panic("OOM");
193 directory_source.addStepDependencies(&self.step);191 directory_source.addStepDependencies(&self.step);
194}192}
195193
196pub fn addArg(self: *RunStep, arg: []const u8) void {194pub fn addArg(self: *Run, arg: []const u8) void {
197 self.argv.append(.{ .bytes = self.step.owner.dupe(arg) }) catch @panic("OOM");195 self.argv.append(.{ .bytes = self.step.owner.dupe(arg) }) catch @panic("OOM");
198}196}
199197
200pub fn addArgs(self: *RunStep, args: []const []const u8) void {198pub fn addArgs(self: *Run, args: []const []const u8) void {
201 for (args) |arg| {199 for (args) |arg| {
202 self.addArg(arg);200 self.addArg(arg);
203 }201 }
204}202}
205203
206pub fn clearEnvironment(self: *RunStep) void {204pub fn clearEnvironment(self: *Run) void {
207 const b = self.step.owner;205 const b = self.step.owner;
208 const new_env_map = b.allocator.create(EnvMap) catch @panic("OOM");206 const new_env_map = b.allocator.create(EnvMap) catch @panic("OOM");
209 new_env_map.* = EnvMap.init(b.allocator);207 new_env_map.* = EnvMap.init(b.allocator);
210 self.env_map = new_env_map;208 self.env_map = new_env_map;
211}209}
212210
213pub fn addPathDir(self: *RunStep, search_path: []const u8) void {211pub fn addPathDir(self: *Run, search_path: []const u8) void {
214 const b = self.step.owner;212 const b = self.step.owner;
215 const env_map = getEnvMapInternal(self);213 const env_map = getEnvMapInternal(self);
216214
...@@ -225,11 +223,11 @@ pub fn addPathDir(self: *RunStep, search_path: []const u8) void {...@@ -225,11 +223,11 @@ pub fn addPathDir(self: *RunStep, search_path: []const u8) void {
225 }223 }
226}224}
227225
228pub fn getEnvMap(self: *RunStep) *EnvMap {226pub fn getEnvMap(self: *Run) *EnvMap {
229 return getEnvMapInternal(self);227 return getEnvMapInternal(self);
230}228}
231229
232fn getEnvMapInternal(self: *RunStep) *EnvMap {230fn getEnvMapInternal(self: *Run) *EnvMap {
233 const arena = self.step.owner.allocator;231 const arena = self.step.owner.allocator;
234 return self.env_map orelse {232 return self.env_map orelse {
235 const env_map = arena.create(EnvMap) catch @panic("OOM");233 const env_map = arena.create(EnvMap) catch @panic("OOM");
...@@ -239,25 +237,25 @@ fn getEnvMapInternal(self: *RunStep) *EnvMap {...@@ -239,25 +237,25 @@ fn getEnvMapInternal(self: *RunStep) *EnvMap {
239 };237 };
240}238}
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 {
243 const b = self.step.owner;241 const b = self.step.owner;
244 const env_map = self.getEnvMap();242 const env_map = self.getEnvMap();
245 env_map.put(b.dupe(key), b.dupe(value)) catch @panic("unhandled error");243 env_map.put(b.dupe(key), b.dupe(value)) catch @panic("unhandled error");
246}244}
247245
248pub fn removeEnvironmentVariable(self: *RunStep, key: []const u8) void {246pub fn removeEnvironmentVariable(self: *Run, key: []const u8) void {
249 self.getEnvMap().remove(key);247 self.getEnvMap().remove(key);
250}248}
251249
252/// Adds a check for exact stderr match. Does not add any other checks.250/// 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 {
254 const new_check: StdIo.Check = .{ .expect_stderr_exact = self.step.owner.dupe(bytes) };252 const new_check: StdIo.Check = .{ .expect_stderr_exact = self.step.owner.dupe(bytes) };
255 self.addCheck(new_check);253 self.addCheck(new_check);
256}254}
257255
258/// Adds a check for exact stdout match as well as a check for exit code 0, if256/// Adds a check for exact stdout match as well as a check for exit code 0, if
259/// there is not already an expected termination check.257/// 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 {
261 const new_check: StdIo.Check = .{ .expect_stdout_exact = self.step.owner.dupe(bytes) };259 const new_check: StdIo.Check = .{ .expect_stdout_exact = self.step.owner.dupe(bytes) };
262 self.addCheck(new_check);260 self.addCheck(new_check);
263 if (!self.hasTermCheck()) {261 if (!self.hasTermCheck()) {
...@@ -265,12 +263,12 @@ pub fn expectStdOutEqual(self: *RunStep, bytes: []const u8) void {...@@ -265,12 +263,12 @@ pub fn expectStdOutEqual(self: *RunStep, bytes: []const u8) void {
265 }263 }
266}264}
267265
268pub fn expectExitCode(self: *RunStep, code: u8) void {266pub fn expectExitCode(self: *Run, code: u8) void {
269 const new_check: StdIo.Check = .{ .expect_term = .{ .Exited = code } };267 const new_check: StdIo.Check = .{ .expect_term = .{ .Exited = code } };
270 self.addCheck(new_check);268 self.addCheck(new_check);
271}269}
272270
273pub fn hasTermCheck(self: RunStep) bool {271pub fn hasTermCheck(self: Run) bool {
274 for (self.stdio.check.items) |check| switch (check) {272 for (self.stdio.check.items) |check| switch (check) {
275 .expect_term => return true,273 .expect_term => return true,
276 else => continue,274 else => continue,
...@@ -278,18 +276,18 @@ pub fn hasTermCheck(self: RunStep) bool {...@@ -278,18 +276,18 @@ pub fn hasTermCheck(self: RunStep) bool {
278 return false;276 return false;
279}277}
280278
281pub fn addCheck(self: *RunStep, new_check: StdIo.Check) void {279pub fn addCheck(self: *Run, new_check: StdIo.Check) void {
282 switch (self.stdio) {280 switch (self.stdio) {
283 .infer_from_args => {281 .infer_from_args => {
284 self.stdio = .{ .check = std.ArrayList(StdIo.Check).init(self.step.owner.allocator) };282 self.stdio = .{ .check = std.ArrayList(StdIo.Check).init(self.step.owner.allocator) };
285 self.stdio.check.append(new_check) catch @panic("OOM");283 self.stdio.check.append(new_check) catch @panic("OOM");
286 },284 },
287 .check => |*checks| checks.append(new_check) catch @panic("OOM"),285 .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"),
289 }287 }
290}288}
291289
292pub fn captureStdErr(self: *RunStep) std.Build.FileSource {290pub fn captureStdErr(self: *Run) std.Build.FileSource {
293 assert(self.stdio != .inherit);291 assert(self.stdio != .inherit);
294292
295 if (self.captured_stderr) |output| return .{ .generated = &output.generated_file };293 if (self.captured_stderr) |output| return .{ .generated = &output.generated_file };
...@@ -304,7 +302,7 @@ pub fn captureStdErr(self: *RunStep) std.Build.FileSource {...@@ -304,7 +302,7 @@ pub fn captureStdErr(self: *RunStep) std.Build.FileSource {
304 return .{ .generated = &output.generated_file };302 return .{ .generated = &output.generated_file };
305}303}
306304
307pub fn captureStdOut(self: *RunStep) std.Build.FileSource {305pub fn captureStdOut(self: *Run) std.Build.FileSource {
308 assert(self.stdio != .inherit);306 assert(self.stdio != .inherit);
309307
310 if (self.captured_stdout) |output| return .{ .generated = &output.generated_file };308 if (self.captured_stdout) |output| return .{ .generated = &output.generated_file };
...@@ -319,8 +317,8 @@ pub fn captureStdOut(self: *RunStep) std.Build.FileSource {...@@ -319,8 +317,8 @@ pub fn captureStdOut(self: *RunStep) std.Build.FileSource {
319 return .{ .generated = &output.generated_file };317 return .{ .generated = &output.generated_file };
320}318}
321319
322/// Returns whether the RunStep has side effects *other than* updating the output arguments.320/// Returns whether the Run step has side effects *other than* updating the output arguments.
323fn hasSideEffects(self: RunStep) bool {321fn hasSideEffects(self: Run) bool {
324 if (self.has_side_effects) return true;322 if (self.has_side_effects) return true;
325 return switch (self.stdio) {323 return switch (self.stdio) {
326 .infer_from_args => !self.hasAnyOutputArgs(),324 .infer_from_args => !self.hasAnyOutputArgs(),
...@@ -330,7 +328,7 @@ fn hasSideEffects(self: RunStep) bool {...@@ -330,7 +328,7 @@ fn hasSideEffects(self: RunStep) bool {
330 };328 };
331}329}
332330
333fn hasAnyOutputArgs(self: RunStep) bool {331fn hasAnyOutputArgs(self: Run) bool {
334 if (self.captured_stdout != null) return true;332 if (self.captured_stdout != null) return true;
335 if (self.captured_stderr != null) return true;333 if (self.captured_stderr != null) return true;
336 for (self.argv.items) |arg| switch (arg) {334 for (self.argv.items) |arg| switch (arg) {
...@@ -371,7 +369,7 @@ fn checksContainStderr(checks: []const StdIo.Check) bool {...@@ -371,7 +369,7 @@ fn checksContainStderr(checks: []const StdIo.Check) bool {
371fn make(step: *Step, prog_node: *std.Progress.Node) !void {369fn make(step: *Step, prog_node: *std.Progress.Node) !void {
372 const b = step.owner;370 const b = step.owner;
373 const arena = b.allocator;371 const arena = b.allocator;
374 const self = @fieldParentPtr(RunStep, "step", step);372 const self = @fieldParentPtr(Run, "step", step);
375 const has_side_effects = self.hasSideEffects();373 const has_side_effects = self.hasSideEffects();
376374
377 var argv_list = ArrayList([]const u8).init(arena);375 var argv_list = ArrayList([]const u8).init(arena);
...@@ -541,7 +539,7 @@ fn termMatches(expected: ?std.process.Child.Term, actual: std.process.Child.Term...@@ -541,7 +539,7 @@ fn termMatches(expected: ?std.process.Child.Term, actual: std.process.Child.Term
541}539}
542540
543fn runCommand(541fn runCommand(
544 self: *RunStep,542 self: *Run,
545 argv: []const []const u8,543 argv: []const []const u8,
546 has_side_effects: bool,544 has_side_effects: bool,
547 digest: ?*const [std.Build.Cache.hex_digest_len]u8,545 digest: ?*const [std.Build.Cache.hex_digest_len]u8,
...@@ -567,7 +565,7 @@ fn runCommand(...@@ -567,7 +565,7 @@ fn runCommand(
567 // FileNotFound: can happen with a wrong dynamic linker path565 // FileNotFound: can happen with a wrong dynamic linker path
568 if (err == error.InvalidExe or err == error.FileNotFound) interpret: {566 if (err == error.InvalidExe or err == error.FileNotFound) interpret: {
569 // TODO: learn the target from the binary directly rather than from567 // TODO: learn the target from the binary directly rather than from
570 // relying on it being a CompileStep. This will make this logic568 // relying on it being a Compile step. This will make this logic
571 // work even for the edge case that the binary was produced by a569 // work even for the edge case that the binary was produced by a
572 // third party.570 // third party.
573 const exe = switch (self.argv.items[0]) {571 const exe = switch (self.argv.items[0]) {
...@@ -862,7 +860,7 @@ const ChildProcResult = struct {...@@ -862,7 +860,7 @@ const ChildProcResult = struct {
862};860};
863861
864fn spawnChildAndCollect(862fn spawnChildAndCollect(
865 self: *RunStep,863 self: *Run,
866 argv: []const []const u8,864 argv: []const []const u8,
867 has_side_effects: bool,865 has_side_effects: bool,
868 prog_node: *std.Progress.Node,866 prog_node: *std.Progress.Node,
...@@ -936,7 +934,7 @@ const StdIoResult = struct {...@@ -936,7 +934,7 @@ const StdIoResult = struct {
936};934};
937935
938fn evalZigTest(936fn evalZigTest(
939 self: *RunStep,937 self: *Run,
940 child: *std.process.Child,938 child: *std.process.Child,
941 prog_node: *std.Progress.Node,939 prog_node: *std.Progress.Node,
942) !StdIoResult {940) !StdIoResult {
...@@ -1121,7 +1119,7 @@ fn sendRunTestMessage(file: std.fs.File, index: u32) !void {...@@ -1121,7 +1119,7 @@ fn sendRunTestMessage(file: std.fs.File, index: u32) !void {
1121 try file.writeAll(full_msg);1119 try file.writeAll(full_msg);
1122}1120}
11231121
1124fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {1122fn evalGeneric(self: *Run, child: *std.process.Child) !StdIoResult {
1125 const arena = self.step.owner.allocator;1123 const arena = self.step.owner.allocator;
11261124
1127 if (self.stdin) |stdin| {1125 if (self.stdin) |stdin| {
...@@ -1188,7 +1186,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {...@@ -1188,7 +1186,7 @@ fn evalGeneric(self: *RunStep, child: *std.process.Child) !StdIoResult {
1188 };1186 };
1189}1187}
11901188
1191fn addPathForDynLibs(self: *RunStep, artifact: *CompileStep) void {1189fn addPathForDynLibs(self: *Run, artifact: *Step.Compile) void {
1192 const b = self.step.owner;1190 const b = self.step.owner;
1193 for (artifact.link_objects.items) |link_object| {1191 for (artifact.link_objects.items) |link_object| {
1194 switch (link_object) {1192 switch (link_object) {
...@@ -1204,10 +1202,10 @@ fn addPathForDynLibs(self: *RunStep, artifact: *CompileStep) void {...@@ -1204,10 +1202,10 @@ fn addPathForDynLibs(self: *RunStep, artifact: *CompileStep) void {
1204}1202}
12051203
1206fn failForeign(1204fn failForeign(
1207 self: *RunStep,1205 self: *Run,
1208 suggested_flag: []const u8,1206 suggested_flag: []const u8,
1209 argv0: []const u8,1207 argv0: []const u8,
1210 exe: *CompileStep,1208 exe: *Step.Compile,
1211) error{ MakeFailed, MakeSkipped, OutOfMemory } {1209) error{ MakeFailed, MakeSkipped, OutOfMemory } {
1212 switch (self.stdio) {1210 switch (self.stdio) {
1213 .check, .zig_test => {1211 .check, .zig_test => {
lib/std/Build/Step/TranslateC.zig+12-14
...@@ -1,12 +1,10 @@...@@ -1,12 +1,10 @@
1const std = @import("std");1const std = @import("std");
2const Step = std.Build.Step;2const Step = std.Build.Step;
3const CompileStep = std.Build.CompileStep;
4const CheckFileStep = std.Build.CheckFileStep;
5const fs = std.fs;3const fs = std.fs;
6const mem = std.mem;4const mem = std.mem;
7const CrossTarget = std.zig.CrossTarget;5const CrossTarget = std.zig.CrossTarget;
86
9const TranslateCStep = @This();7const TranslateC = @This();
108
11pub const base_id = .translate_c;9pub const base_id = .translate_c;
1210
...@@ -25,10 +23,10 @@ pub const Options = struct {...@@ -25,10 +23,10 @@ pub const Options = struct {
25 optimize: std.builtin.OptimizeMode,23 optimize: std.builtin.OptimizeMode,
26};24};
2725
28pub fn create(owner: *std.Build, options: Options) *TranslateCStep {26pub fn create(owner: *std.Build, options: Options) *TranslateC {
29 const self = owner.allocator.create(TranslateCStep) catch @panic("OOM");27 const self = owner.allocator.create(TranslateC) catch @panic("OOM");
30 const source = options.source_file.dupe(owner);28 const source = options.source_file.dupe(owner);
31 self.* = TranslateCStep{29 self.* = TranslateC{
32 .step = Step.init(.{30 .step = Step.init(.{
33 .id = .translate_c,31 .id = .translate_c,
34 .name = "translate-c",32 .name = "translate-c",
...@@ -52,11 +50,11 @@ pub const AddExecutableOptions = struct {...@@ -52,11 +50,11 @@ pub const AddExecutableOptions = struct {
52 version: ?std.builtin.Version = null,50 version: ?std.builtin.Version = null,
53 target: ?CrossTarget = null,51 target: ?CrossTarget = null,
54 optimize: ?std.builtin.Mode = null,52 optimize: ?std.builtin.Mode = null,
55 linkage: ?CompileStep.Linkage = null,53 linkage: ?Step.Compile.Linkage = null,
56};54};
5755
58/// Creates a step to build an executable from the translated source.56/// 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 {
60 return self.step.owner.addExecutable(.{58 return self.step.owner.addExecutable(.{
61 .root_source_file = .{ .generated = &self.output_file },59 .root_source_file = .{ .generated = &self.output_file },
62 .name = options.name orelse "translated_c",60 .name = options.name orelse "translated_c",
...@@ -67,12 +65,12 @@ pub fn addExecutable(self: *TranslateCStep, options: AddExecutableOptions) *Comp...@@ -67,12 +65,12 @@ pub fn addExecutable(self: *TranslateCStep, options: AddExecutableOptions) *Comp
67 });65 });
68}66}
6967
70pub fn addIncludeDir(self: *TranslateCStep, include_dir: []const u8) void {68pub fn addIncludeDir(self: *TranslateC, include_dir: []const u8) void {
71 self.include_dirs.append(self.step.owner.dupePath(include_dir)) catch @panic("OOM");69 self.include_dirs.append(self.step.owner.dupePath(include_dir)) catch @panic("OOM");
72}70}
7371
74pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8) *CheckFileStep {72pub fn addCheckFile(self: *TranslateC, expected_matches: []const []const u8) *Step.CheckFile {
75 return CheckFileStep.create(73 return Step.CheckFile.create(
76 self.step.owner,74 self.step.owner,
77 .{ .generated = &self.output_file },75 .{ .generated = &self.output_file },
78 .{ .expected_matches = expected_matches },76 .{ .expected_matches = expected_matches },
...@@ -81,19 +79,19 @@ pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8)...@@ -81,19 +79,19 @@ pub fn addCheckFile(self: *TranslateCStep, expected_matches: []const []const u8)
8179
82/// If the value is omitted, it is set to 1.80/// If the value is omitted, it is set to 1.
83/// `name` and `value` need not live longer than the function call.81/// `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 {
85 const macro = std.Build.constructCMacro(self.step.owner.allocator, name, value);83 const macro = std.Build.constructCMacro(self.step.owner.allocator, name, value);
86 self.c_macros.append(macro) catch @panic("OOM");84 self.c_macros.append(macro) catch @panic("OOM");
87}85}
8886
89/// name_and_value looks like [name]=[value]. If the value is omitted, it is set to 1.87/// 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 {
91 self.c_macros.append(self.step.owner.dupe(name_and_value)) catch @panic("OOM");89 self.c_macros.append(self.step.owner.dupe(name_and_value)) catch @panic("OOM");
92}90}
9391
94fn make(step: *Step, prog_node: *std.Progress.Node) !void {92fn make(step: *Step, prog_node: *std.Progress.Node) !void {
95 const b = step.owner;93 const b = step.owner;
96 const self = @fieldParentPtr(TranslateCStep, "step", step);94 const self = @fieldParentPtr(TranslateC, "step", step);
9795
98 var argv_list = std.ArrayList([]const u8).init(b.allocator);96 var argv_list = std.ArrayList([]const u8).init(b.allocator);
99 try argv_list.append(b.zig_exe);97 try argv_list.append(b.zig_exe);
lib/std/Build/Step/WriteFile.zig+19-19
...@@ -1,4 +1,4 @@...@@ -1,4 +1,4 @@
1//! WriteFileStep is primarily used to create a directory in an appropriate1//! WriteFile is primarily used to create a directory in an appropriate
2//! location inside the local cache which has a set of files that have either2//! location inside the local cache which has a set of files that have either
3//! been generated during the build, or are copied from the source package.3//! been generated during the build, or are copied from the source package.
4//!4//!
...@@ -12,7 +12,7 @@ const std = @import("std");...@@ -12,7 +12,7 @@ const std = @import("std");
12const Step = std.Build.Step;12const Step = std.Build.Step;
13const fs = std.fs;13const fs = std.fs;
14const ArrayList = std.ArrayList;14const ArrayList = std.ArrayList;
15const WriteFileStep = @This();15const WriteFile = @This();
1616
17step: Step,17step: Step,
18/// The elements here are pointers because we need stable pointers for the18/// The elements here are pointers because we need stable pointers for the
...@@ -39,8 +39,8 @@ pub const Contents = union(enum) {...@@ -39,8 +39,8 @@ pub const Contents = union(enum) {
39 copy: std.Build.FileSource,39 copy: std.Build.FileSource,
40};40};
4141
42pub fn create(owner: *std.Build) *WriteFileStep {42pub fn create(owner: *std.Build) *WriteFile {
43 const wf = owner.allocator.create(WriteFileStep) catch @panic("OOM");43 const wf = owner.allocator.create(WriteFile) catch @panic("OOM");
44 wf.* = .{44 wf.* = .{
45 .step = Step.init(.{45 .step = Step.init(.{
46 .id = .write_file,46 .id = .write_file,
...@@ -55,7 +55,7 @@ pub fn create(owner: *std.Build) *WriteFileStep {...@@ -55,7 +55,7 @@ pub fn create(owner: *std.Build) *WriteFileStep {
55 return wf;55 return wf;
56}56}
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 {
59 const b = wf.step.owner;59 const b = wf.step.owner;
60 const gpa = b.allocator;60 const gpa = b.allocator;
61 const file = gpa.create(File) catch @panic("OOM");61 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 {...@@ -72,11 +72,11 @@ pub fn add(wf: *WriteFileStep, sub_path: []const u8, bytes: []const u8) void {
72/// Place the file into the generated directory within the local cache,72/// Place the file into the generated directory within the local cache,
73/// along with all the rest of the files added to this step. The parameter73/// along with all the rest of the files added to this step. The parameter
74/// here is the destination path relative to the local cache directory74/// here is the destination path relative to the local cache directory
75/// associated with this WriteFileStep. It may be a basename, or it may75/// associated with this WriteFile. It may be a basename, or it may
76/// include sub-directories, in which case this step will ensure the76/// include sub-directories, in which case this step will ensure the
77/// required sub-path exists.77/// required sub-path exists.
78/// This is the option expected to be used most commonly with `addCopyFile`.78/// 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 {
80 const b = wf.step.owner;80 const b = wf.step.owner;
81 const gpa = b.allocator;81 const gpa = b.allocator;
82 const file = gpa.create(File) catch @panic("OOM");82 const file = gpa.create(File) catch @panic("OOM");
...@@ -97,7 +97,7 @@ pub fn addCopyFile(wf: *WriteFileStep, source: std.Build.FileSource, sub_path: [...@@ -97,7 +97,7 @@ pub fn addCopyFile(wf: *WriteFileStep, source: std.Build.FileSource, sub_path: [
97/// run by a developer with intent to modify source files and then commit97/// run by a developer with intent to modify source files and then commit
98/// those changes to version control.98/// those changes to version control.
99/// A file added this way is not available with `getFileSource`.99/// 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 {
101 const b = wf.step.owner;101 const b = wf.step.owner;
102 wf.output_source_files.append(b.allocator, .{102 wf.output_source_files.append(b.allocator, .{
103 .contents = .{ .copy = source },103 .contents = .{ .copy = source },
...@@ -112,7 +112,7 @@ pub fn addCopyFileToSource(wf: *WriteFileStep, source: std.Build.FileSource, sub...@@ -112,7 +112,7 @@ pub fn addCopyFileToSource(wf: *WriteFileStep, source: std.Build.FileSource, sub
112/// run by a developer with intent to modify source files and then commit112/// run by a developer with intent to modify source files and then commit
113/// those changes to version control.113/// those changes to version control.
114/// A file added this way is not available with `getFileSource`.114/// 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 {
116 const b = wf.step.owner;116 const b = wf.step.owner;
117 wf.output_source_files.append(b.allocator, .{117 wf.output_source_files.append(b.allocator, .{
118 .contents = .{ .bytes = bytes },118 .contents = .{ .bytes = bytes },
...@@ -121,7 +121,7 @@ pub fn addBytesToSource(wf: *WriteFileStep, bytes: []const u8, sub_path: []const...@@ -121,7 +121,7 @@ pub fn addBytesToSource(wf: *WriteFileStep, bytes: []const u8, sub_path: []const
121}121}
122122
123/// Gets a file source for the given sub_path. If the file does not exist, returns `null`.123/// 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 {
125 for (wf.files.items) |file| {125 for (wf.files.items) |file| {
126 if (std.mem.eql(u8, file.sub_path, sub_path)) {126 if (std.mem.eql(u8, file.sub_path, sub_path)) {
127 return .{ .generated = &file.generated_file };127 return .{ .generated = &file.generated_file };
...@@ -131,12 +131,12 @@ pub fn getFileSource(wf: *WriteFileStep, sub_path: []const u8) ?std.Build.FileSo...@@ -131,12 +131,12 @@ pub fn getFileSource(wf: *WriteFileStep, sub_path: []const u8) ?std.Build.FileSo
131}131}
132132
133/// Returns a `FileSource` representing the base directory that contains all the133/// Returns a `FileSource` representing the base directory that contains all the
134/// files from this `WriteFileStep`.134/// files from this `WriteFile`.
135pub fn getDirectorySource(wf: *WriteFileStep) std.Build.FileSource {135pub fn getDirectorySource(wf: *WriteFile) std.Build.FileSource {
136 return .{ .generated = &wf.generated_directory };136 return .{ .generated = &wf.generated_directory };
137}137}
138138
139fn maybeUpdateName(wf: *WriteFileStep) void {139fn maybeUpdateName(wf: *WriteFile) void {
140 if (wf.files.items.len == 1) {140 if (wf.files.items.len == 1) {
141 // First time adding a file; update name.141 // First time adding a file; update name.
142 if (std.mem.eql(u8, wf.step.name, "WriteFile")) {142 if (std.mem.eql(u8, wf.step.name, "WriteFile")) {
...@@ -148,10 +148,10 @@ fn maybeUpdateName(wf: *WriteFileStep) void {...@@ -148,10 +148,10 @@ fn maybeUpdateName(wf: *WriteFileStep) void {
148fn make(step: *Step, prog_node: *std.Progress.Node) !void {148fn make(step: *Step, prog_node: *std.Progress.Node) !void {
149 _ = prog_node;149 _ = prog_node;
150 const b = step.owner;150 const b = step.owner;
151 const wf = @fieldParentPtr(WriteFileStep, "step", step);151 const wf = @fieldParentPtr(WriteFile, "step", step);
152152
153 // Writing to source files is kind of an extra capability of this153 // Writing to source files is kind of an extra capability of this
154 // WriteFileStep - arguably it should be a different step. But anyway here154 // WriteFile - arguably it should be a different step. But anyway here
155 // it is, it happens unconditionally and does not interact with the other155 // it is, it happens unconditionally and does not interact with the other
156 // files here.156 // files here.
157 var any_miss = false;157 var any_miss = false;
...@@ -194,14 +194,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {...@@ -194,14 +194,14 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void {
194 // the data to a file would probably be very fast - but as a way to find a canonical194 // the data to a file would probably be very fast - but as a way to find a canonical
195 // location to put build artifacts.195 // location to put build artifacts.
196196
197 // If, for example, a hard-coded path was used as the location to put WriteFileStep197 // If, for example, a hard-coded path was used as the location to put WriteFile
198 // files, then two WriteFileSteps executing in parallel might clobber each other.198 // files, then two WriteFiles executing in parallel might clobber each other.
199199
200 var man = b.cache.obtain();200 var man = b.cache.obtain();
201 defer man.deinit();201 defer man.deinit();
202202
203 // Random bytes to make WriteFileStep unique. Refresh this with203 // Random bytes to make WriteFile unique. Refresh this with
204 // new random bytes when WriteFileStep implementation is modified204 // new random bytes when WriteFile implementation is modified
205 // in a non-backwards-compatible way.205 // in a non-backwards-compatible way.
206 man.hash.add(@as(u32, 0xd767ee59));206 man.hash.add(@as(u32, 0xd767ee59));
207207
test/link/macho/dead_strip/build.zig+1-1
...@@ -42,7 +42,7 @@ fn createScenario(...@@ -42,7 +42,7 @@ fn createScenario(
42 optimize: std.builtin.OptimizeMode,42 optimize: std.builtin.OptimizeMode,
43 target: std.zig.CrossTarget,43 target: std.zig.CrossTarget,
44 name: []const u8,44 name: []const u8,
45) *std.Build.CompileStep {45) *std.Build.Step.Compile {
46 const exe = b.addExecutable(.{46 const exe = b.addExecutable(.{
47 .name = name,47 .name = name,
48 .optimize = optimize,48 .optimize = optimize,
test/link/macho/dead_strip_dylibs/build.zig+1-1
...@@ -46,7 +46,7 @@ fn createScenario(...@@ -46,7 +46,7 @@ fn createScenario(
46 b: *std.Build,46 b: *std.Build,
47 optimize: std.builtin.OptimizeMode,47 optimize: std.builtin.OptimizeMode,
48 name: []const u8,48 name: []const u8,
49) *std.Build.CompileStep {49) *std.Build.Step.Compile {
50 const exe = b.addExecutable(.{50 const exe = b.addExecutable(.{
51 .name = name,51 .name = name,
52 .optimize = optimize,52 .optimize = optimize,
test/link/macho/headerpad/build.zig+1-1
...@@ -104,7 +104,7 @@ fn simpleExe(...@@ -104,7 +104,7 @@ fn simpleExe(
104 b: *std.Build,104 b: *std.Build,
105 optimize: std.builtin.OptimizeMode,105 optimize: std.builtin.OptimizeMode,
106 name: []const u8,106 name: []const u8,
107) *std.Build.CompileStep {107) *std.Build.Step.Compile {
108 const exe = b.addExecutable(.{108 const exe = b.addExecutable(.{
109 .name = name,109 .name = name,
110 .optimize = optimize,110 .optimize = optimize,
test/link/macho/search_strategy/build.zig+1-1
...@@ -46,7 +46,7 @@ fn createScenario(...@@ -46,7 +46,7 @@ fn createScenario(
46 optimize: std.builtin.OptimizeMode,46 optimize: std.builtin.OptimizeMode,
47 target: std.zig.CrossTarget,47 target: std.zig.CrossTarget,
48 name: []const u8,48 name: []const u8,
49) *std.Build.CompileStep {49) *std.Build.Step.Compile {
50 const static = b.addStaticLibrary(.{50 const static = b.addStaticLibrary(.{
51 .name = name,51 .name = name,
52 .optimize = optimize,52 .optimize = optimize,
test/link/macho/unwind_info/build.zig+1-1
...@@ -65,7 +65,7 @@ fn createScenario(...@@ -65,7 +65,7 @@ fn createScenario(
65 optimize: std.builtin.OptimizeMode,65 optimize: std.builtin.OptimizeMode,
66 target: std.zig.CrossTarget,66 target: std.zig.CrossTarget,
67 name: []const u8,67 name: []const u8,
68) *std.Build.CompileStep {68) *std.Build.Step.Compile {
69 const exe = b.addExecutable(.{69 const exe = b.addExecutable(.{
70 .name = name,70 .name = name,
71 .optimize = optimize,71 .optimize = optimize,
test/link/macho/uuid/build.zig+1-2
...@@ -1,5 +1,4 @@...@@ -1,5 +1,4 @@
1const std = @import("std");1const std = @import("std");
2const CompileStep = std.Build.CompileStep;
3const FileSource = std.Build.FileSource;2const FileSource = std.Build.FileSource;
4const Step = std.Build.Step;3const Step = std.Build.Step;
54
...@@ -60,7 +59,7 @@ fn simpleDylib(...@@ -60,7 +59,7 @@ fn simpleDylib(
60 b: *std.Build,59 b: *std.Build,
61 optimize: std.builtin.OptimizeMode,60 optimize: std.builtin.OptimizeMode,
62 target: std.zig.CrossTarget,61 target: std.zig.CrossTarget,
63) *std.Build.CompileStep {62) *std.Build.Step.Compile {
64 const dylib = b.addSharedLibrary(.{63 const dylib = b.addSharedLibrary(.{
65 .name = "test",64 .name = "test",
66 .version = .{ .major = 1, .minor = 0 },65 .version = .{ .major = 1, .minor = 0 },
test/src/Cases.zig+1-1
...@@ -465,7 +465,7 @@ pub fn lowerToBuildSteps(...@@ -465,7 +465,7 @@ pub fn lowerToBuildSteps(
465 parent_step: *std.Build.Step,465 parent_step: *std.Build.Step,
466 opt_test_filter: ?[]const u8,466 opt_test_filter: ?[]const u8,
467 cases_dir_path: []const u8,467 cases_dir_path: []const u8,
468 incremental_exe: *std.Build.CompileStep,468 incremental_exe: *std.Build.Step.Compile,
469) void {469) void {
470 for (self.incremental_cases.items) |incr_case| {470 for (self.incremental_cases.items) |incr_case| {
471 if (opt_test_filter) |test_filter| {471 if (opt_test_filter) |test_filter| {
test/src/StackTrace.zig+1-1
...@@ -3,7 +3,7 @@ step: *Step,...@@ -3,7 +3,7 @@ step: *Step,
3test_index: usize,3test_index: usize,
4test_filter: ?[]const u8,4test_filter: ?[]const u8,
5optimize_modes: []const OptimizeMode,5optimize_modes: []const OptimizeMode,
6check_exe: *std.Build.CompileStep,6check_exe: *std.Build.Step.Compile,
77
8const Expect = [@typeInfo(OptimizeMode).Enum.fields.len][]const u8;8const Expect = [@typeInfo(OptimizeMode).Enum.fields.len][]const u8;
99
test/standalone/install_raw_hex/build.zig-1
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1const builtin = @import("builtin");1const builtin = @import("builtin");
2const std = @import("std");2const std = @import("std");
3const CheckFileStep = std.Build.CheckFileStep;
43
5pub fn build(b: *std.Build) void {4pub fn build(b: *std.Build) void {
6 const test_step = b.step("test", "Test it");5 const test_step = b.step("test", "Test it");
test/tests.zig+1-1
...@@ -1132,7 +1132,7 @@ pub fn addCases(...@@ -1132,7 +1132,7 @@ pub fn addCases(
1132 b: *std.Build,1132 b: *std.Build,
1133 parent_step: *Step,1133 parent_step: *Step,
1134 opt_test_filter: ?[]const u8,1134 opt_test_filter: ?[]const u8,
1135 check_case_exe: *std.Build.CompileStep,1135 check_case_exe: *std.Build.Step.Compile,
1136) !void {1136) !void {
1137 const arena = b.allocator;1137 const arena = b.allocator;
1138 const gpa = b.allocator;1138 const gpa = b.allocator;