authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-11 11:50:48+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-11 16:01:30+03:00
log4b72b0560d940b05a93078e78366cd5b2efe1f8b
tree76cd5fff8f061e2ed09feccd7185adce014fe819
parent1c1ea2baa7514babb2a39031753ce3a0036c5278

make remaining enums in build.zig snake_case


11 files changed, 201 insertions(+), 196 deletions(-)

build.zig+1-1
......@@ -66,7 +66,7 @@ pub fn build(b: *Builder) !void {
6666 if (!skip_install_lib_files) {
6767 b.installDirectory(InstallDirectoryOptions{
6868 .source_dir = "lib",
69 .install_dir = .Lib,
69 .install_dir = .lib,
7070 .install_subdir = "zig",
7171 .exclude_extensions = &[_][]const u8{
7272 "README.md",
lib/std/build.zig+168-179
......@@ -103,21 +103,23 @@ pub const Builder = struct {
103103 };
104104
105105 const UserValue = union(enum) {
106 Flag: void,
107 Scalar: []const u8,
108 List: ArrayList([]const u8),
106 flag: void,
107 scalar: []const u8,
108 list: ArrayList([]const u8),
109109 };
110110
111111 const TypeId = enum {
112 Bool,
113 Int,
114 Float,
115 Enum,
116 String,
117 List,
112 bool,
113 int,
114 float,
115 @"enum",
116 string,
117 list,
118118 };
119119
120120 const TopLevelStep = struct {
121 pub const base_id = .top_level;
122
121123 step: Step,
122124 description: []const u8,
123125 };
......@@ -163,11 +165,11 @@ pub const Builder = struct {
163165 .dest_dir = env_map.get("DESTDIR"),
164166 .installed_files = ArrayList(InstalledFile).init(allocator),
165167 .install_tls = TopLevelStep{
166 .step = Step.initNoOp(.TopLevel, "install", allocator),
168 .step = Step.initNoOp(.top_level, "install", allocator),
167169 .description = "Copy build artifacts to prefix path",
168170 },
169171 .uninstall_tls = TopLevelStep{
170 .step = Step.init(.TopLevel, "uninstall", allocator, makeUninstall),
172 .step = Step.init(.top_level, "uninstall", allocator, makeUninstall),
171173 .description = "Remove build artifacts from prefix path",
172174 },
173175 .release_mode = null,
......@@ -457,9 +459,9 @@ pub const Builder = struct {
457459 const option_ptr = self.user_input_options.getPtr(name) orelse return null;
458460 option_ptr.used = true;
459461 switch (type_id) {
460 .Bool => switch (option_ptr.value) {
461 .Flag => return true,
462 .Scalar => |s| {
462 .bool => switch (option_ptr.value) {
463 .flag => return true,
464 .scalar => |s| {
463465 if (mem.eql(u8, s, "true")) {
464466 return true;
465467 } else if (mem.eql(u8, s, "false")) {
......@@ -470,19 +472,19 @@ pub const Builder = struct {
470472 return null;
471473 }
472474 },
473 .List => {
475 .list => {
474476 warn("Expected -D{s} to be a boolean, but received a list.\n\n", .{name});
475477 self.markInvalidUserInput();
476478 return null;
477479 },
478480 },
479 .Int => switch (option_ptr.value) {
480 .Flag => {
481 .int => switch (option_ptr.value) {
482 .flag => {
481483 warn("Expected -D{s} to be an integer, but received a boolean.\n\n", .{name});
482484 self.markInvalidUserInput();
483485 return null;
484486 },
485 .Scalar => |s| {
487 .scalar => |s| {
486488 const n = std.fmt.parseInt(T, s, 10) catch |err| switch (err) {
487489 error.Overflow => {
488490 warn("-D{s} value {s} cannot fit into type {s}.\n\n", .{ name, s, @typeName(T) });
......@@ -497,19 +499,19 @@ pub const Builder = struct {
497499 };
498500 return n;
499501 },
500 .List => {
502 .list => {
501503 warn("Expected -D{s} to be an integer, but received a list.\n\n", .{name});
502504 self.markInvalidUserInput();
503505 return null;
504506 },
505507 },
506 .Float => switch (option_ptr.value) {
507 .Flag => {
508 .float => switch (option_ptr.value) {
509 .flag => {
508510 warn("Expected -D{s} to be a float, but received a boolean.\n\n", .{name});
509511 self.markInvalidUserInput();
510512 return null;
511513 },
512 .Scalar => |s| {
514 .scalar => |s| {
513515 const n = std.fmt.parseFloat(T, s) catch |err| {
514516 warn("Expected -D{s} to be a float of type {s}.\n\n", .{ name, @typeName(T) });
515517 self.markInvalidUserInput();
......@@ -517,19 +519,19 @@ pub const Builder = struct {
517519 };
518520 return n;
519521 },
520 .List => {
522 .list => {
521523 warn("Expected -D{s} to be a float, but received a list.\n\n", .{name});
522524 self.markInvalidUserInput();
523525 return null;
524526 },
525527 },
526 .Enum => switch (option_ptr.value) {
527 .Flag => {
528 .@"enum" => switch (option_ptr.value) {
529 .flag => {
528530 warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name});
529531 self.markInvalidUserInput();
530532 return null;
531533 },
532 .Scalar => |s| {
534 .scalar => |s| {
533535 if (std.meta.stringToEnum(T, s)) |enum_lit| {
534536 return enum_lit;
535537 } else {
......@@ -538,35 +540,35 @@ pub const Builder = struct {
538540 return null;
539541 }
540542 },
541 .List => {
543 .list => {
542544 warn("Expected -D{s} to be a string, but received a list.\n\n", .{name});
543545 self.markInvalidUserInput();
544546 return null;
545547 },
546548 },
547 .String => switch (option_ptr.value) {
548 .Flag => {
549 .string => switch (option_ptr.value) {
550 .flag => {
549551 warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name});
550552 self.markInvalidUserInput();
551553 return null;
552554 },
553 .List => {
555 .list => {
554556 warn("Expected -D{s} to be a string, but received a list.\n\n", .{name});
555557 self.markInvalidUserInput();
556558 return null;
557559 },
558 .Scalar => |s| return s,
560 .scalar => |s| return s,
559561 },
560 .List => switch (option_ptr.value) {
561 .Flag => {
562 .list => switch (option_ptr.value) {
563 .flag => {
562564 warn("Expected -D{s} to be a list, but received a boolean.\n\n", .{name});
563565 self.markInvalidUserInput();
564566 return null;
565567 },
566 .Scalar => |s| {
568 .scalar => |s| {
567569 return self.allocator.dupe([]const u8, &[_][]const u8{s}) catch unreachable;
568570 },
569 .List => |lst| return lst.items,
571 .list => |lst| return lst.items,
570572 },
571573 }
572574 }
......@@ -574,7 +576,7 @@ pub const Builder = struct {
574576 pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step {
575577 const step_info = self.allocator.create(TopLevelStep) catch unreachable;
576578 step_info.* = TopLevelStep{
577 .step = Step.initNoOp(.TopLevel, name, self.allocator),
579 .step = Step.initNoOp(.top_level, name, self.allocator),
578580 .description = self.dupe(description),
579581 };
580582 self.top_level_steps.append(step_info) catch unreachable;
......@@ -721,7 +723,7 @@ pub const Builder = struct {
721723 if (!gop.found_existing) {
722724 gop.value_ptr.* = UserInputOption{
723725 .name = name,
724 .value = UserValue{ .Scalar = value },
726 .value = .{ .scalar = value },
725727 .used = false,
726728 };
727729 return false;
......@@ -729,27 +731,27 @@ pub const Builder = struct {
729731
730732 // option already exists
731733 switch (gop.value_ptr.value) {
732 UserValue.Scalar => |s| {
734 .scalar => |s| {
733735 // turn it into a list
734736 var list = ArrayList([]const u8).init(self.allocator);
735737 list.append(s) catch unreachable;
736738 list.append(value) catch unreachable;
737 self.user_input_options.put(name, UserInputOption{
739 self.user_input_options.put(name, .{
738740 .name = name,
739 .value = UserValue{ .List = list },
741 .value = .{ .list = list },
740742 .used = false,
741743 }) catch unreachable;
742744 },
743 UserValue.List => |*list| {
745 .list => |*list| {
744746 // append to the list
745747 list.append(value) catch unreachable;
746 self.user_input_options.put(name, UserInputOption{
748 self.user_input_options.put(name, .{
747749 .name = name,
748 .value = UserValue{ .List = list.* },
750 .value = .{ .list = list.* },
749751 .used = false,
750752 }) catch unreachable;
751753 },
752 UserValue.Flag => {
754 .flag => {
753755 warn("Option '-D{s}={s}' conflicts with flag '-D{s}'.\n", .{ name, value, name });
754756 return true;
755757 },
......@@ -761,9 +763,9 @@ pub const Builder = struct {
761763 const name = self.dupe(name_raw);
762764 const gop = try self.user_input_options.getOrPut(name);
763765 if (!gop.found_existing) {
764 gop.value_ptr.* = UserInputOption{
766 gop.value_ptr.* = .{
765767 .name = name,
766 .value = UserValue{ .Flag = {} },
768 .value = .{ .flag = {} },
767769 .used = false,
768770 };
769771 return false;
......@@ -771,28 +773,28 @@ pub const Builder = struct {
771773
772774 // option already exists
773775 switch (gop.value_ptr.value) {
774 UserValue.Scalar => |s| {
776 .scalar => |s| {
775777 warn("Flag '-D{s}' conflicts with option '-D{s}={s}'.\n", .{ name, name, s });
776778 return true;
777779 },
778 UserValue.List => {
780 .list => {
779781 warn("Flag '-D{s}' conflicts with multiple options of the same name.\n", .{name});
780782 return true;
781783 },
782 UserValue.Flag => {},
784 .flag => {},
783785 }
784786 return false;
785787 }
786788
787789 fn typeToEnum(comptime T: type) TypeId {
788790 return switch (@typeInfo(T)) {
789 .Int => .Int,
790 .Float => .Float,
791 .Bool => .Bool,
792 .Enum => .Enum,
791 .Int => .int,
792 .Float => .float,
793 .Bool => .bool,
794 .Enum => .@"enum",
793795 else => switch (T) {
794 []const u8 => .String,
795 []const []const u8 => .List,
796 []const u8 => .string,
797 []const []const u8 => .list,
796798 else => @compileError("Unsupported type: " ++ @typeName(T)),
797799 },
798800 };
......@@ -802,17 +804,6 @@ pub const Builder = struct {
802804 self.invalid_user_input = true;
803805 }
804806
805 pub fn typeIdName(id: TypeId) []const u8 {
806 return switch (id) {
807 .Bool => "bool",
808 .Int => "int",
809 .Float => "float",
810 .Enum => "enum",
811 .String => "string",
812 .List => "list",
813 };
814 }
815
816807 pub fn validateUserInputDidItFail(self: *Builder) bool {
817808 // make sure all args are used
818809 var it = self.user_input_options.iterator();
......@@ -888,7 +879,7 @@ pub const Builder = struct {
888879
889880 ///`dest_rel_path` is relative to prefix path
890881 pub fn installFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void {
891 self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .Prefix, dest_rel_path).step);
882 self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .prefix, dest_rel_path).step);
892883 }
893884
894885 pub fn installDirectory(self: *Builder, options: InstallDirectoryOptions) void {
......@@ -897,12 +888,12 @@ pub const Builder = struct {
897888
898889 ///`dest_rel_path` is relative to bin path
899890 pub fn installBinFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void {
900 self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .Bin, dest_rel_path).step);
891 self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .bin, dest_rel_path).step);
901892 }
902893
903894 ///`dest_rel_path` is relative to lib path
904895 pub fn installLibFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void {
905 self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .Lib, dest_rel_path).step);
896 self.getInstallStep().dependOn(&self.addInstallFileWithDir(.{ .path = src_path }, .lib, dest_rel_path).step);
906897 }
907898
908899 pub fn installRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) void {
......@@ -911,17 +902,17 @@ pub const Builder = struct {
911902
912903 ///`dest_rel_path` is relative to install prefix path
913904 pub fn addInstallFile(self: *Builder, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {
914 return self.addInstallFileWithDir(source.dupe(self), .Prefix, dest_rel_path);
905 return self.addInstallFileWithDir(source.dupe(self), .prefix, dest_rel_path);
915906 }
916907
917908 ///`dest_rel_path` is relative to bin path
918909 pub fn addInstallBinFile(self: *Builder, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {
919 return self.addInstallFileWithDir(source.dupe(self), .Bin, dest_rel_path);
910 return self.addInstallFileWithDir(source.dupe(self), .bin, dest_rel_path);
920911 }
921912
922913 ///`dest_rel_path` is relative to lib path
923914 pub fn addInstallLibFile(self: *Builder, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {
924 return self.addInstallFileWithDir(source.dupe(self), .Lib, dest_rel_path);
915 return self.addInstallFileWithDir(source.dupe(self), .lib, dest_rel_path);
925916 }
926917
927918 pub fn addInstallRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {
......@@ -1119,11 +1110,11 @@ pub const Builder = struct {
11191110 pub fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
11201111 assert(!fs.path.isAbsolute(dest_rel_path)); // Install paths must be relative to the prefix
11211112 const base_dir = switch (dir) {
1122 .Prefix => self.install_path,
1123 .Bin => self.exe_dir,
1124 .Lib => self.lib_dir,
1125 .Header => self.h_dir,
1126 .Custom => |path| fs.path.join(self.allocator, &[_][]const u8{ self.install_path, path }) catch unreachable,
1113 .prefix => self.install_path,
1114 .bin => self.exe_dir,
1115 .lib => self.lib_dir,
1116 .header => self.h_dir,
1117 .custom => |path| fs.path.join(self.allocator, &[_][]const u8{ self.install_path, path }) catch unreachable,
11271118 };
11281119 return fs.path.resolve(
11291120 self.allocator,
......@@ -1315,6 +1306,8 @@ const BuildOptionFileSourceArg = struct {
13151306};
13161307
13171308pub const LibExeObjStep = struct {
1309 pub const base_id = .lib_exe_obj;
1310
13181311 step: Step,
13191312 builder: *Builder,
13201313 name: []const u8,
......@@ -1451,10 +1444,10 @@ pub const LibExeObjStep = struct {
14511444 };
14521445
14531446 const Kind = enum {
1454 Exe,
1455 Lib,
1456 Obj,
1457 Test,
1447 exe,
1448 lib,
1449 obj,
1450 @"test",
14581451 };
14591452
14601453 const SharedLibKind = union(enum) {
......@@ -1465,26 +1458,26 @@ pub const LibExeObjStep = struct {
14651458 pub const Linkage = enum { dynamic, static };
14661459
14671460 pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource, kind: SharedLibKind) *LibExeObjStep {
1468 return initExtraArgs(builder, name, root_src, Kind.Lib, .dynamic, switch (kind) {
1461 return initExtraArgs(builder, name, root_src, .lib, .dynamic, switch (kind) {
14691462 .versioned => |ver| ver,
14701463 .unversioned => null,
14711464 });
14721465 }
14731466
14741467 pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep {
1475 return initExtraArgs(builder, name, root_src, Kind.Lib, .static, null);
1468 return initExtraArgs(builder, name, root_src, .lib, .static, null);
14761469 }
14771470
14781471 pub fn createObject(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep {
1479 return initExtraArgs(builder, name, root_src, Kind.Obj, .static, null);
1472 return initExtraArgs(builder, name, root_src, .obj, .static, null);
14801473 }
14811474
14821475 pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?FileSource, linkage: Linkage) *LibExeObjStep {
1483 return initExtraArgs(builder, name, root_src, Kind.Exe, linkage, null);
1476 return initExtraArgs(builder, name, root_src, .exe, linkage, null);
14841477 }
14851478
14861479 pub fn createTest(builder: *Builder, name: []const u8, root_src: FileSource) *LibExeObjStep {
1487 return initExtraArgs(builder, name, root_src, Kind.Test, .static, null);
1480 return initExtraArgs(builder, name, root_src, .@"test", .static, null);
14881481 }
14891482
14901483 fn initExtraArgs(
......@@ -1513,7 +1506,7 @@ pub const LibExeObjStep = struct {
15131506 .root_src = root_src,
15141507 .name = name,
15151508 .frameworks = BufSet.init(builder.allocator),
1516 .step = Step.init(.LibExeObj, name, builder.allocator, make),
1509 .step = Step.init(base_id, name, builder.allocator, make),
15171510 .version = ver,
15181511 .out_filename = undefined,
15191512 .out_h_filename = builder.fmt("{s}.h", .{name}),
......@@ -1568,18 +1561,18 @@ pub const LibExeObjStep = struct {
15681561 .root_name = self.name,
15691562 .target = target,
15701563 .output_mode = switch (self.kind) {
1571 .Lib => .Lib,
1572 .Obj => .Obj,
1573 .Exe, .Test => .Exe,
1564 .lib => .Lib,
1565 .obj => .Obj,
1566 .exe, .@"test" => .Exe,
15741567 },
15751568 .link_mode = switch (self.linkage) {
1576 .dynamic => std.builtin.LinkMode.Dynamic,
1577 .static => std.builtin.LinkMode.Static,
1569 .dynamic => .Dynamic,
1570 .static => .Static,
15781571 },
15791572 .version = self.version,
15801573 }) catch unreachable;
15811574
1582 if (self.kind == .Lib) {
1575 if (self.kind == .lib) {
15831576 if (self.linkage == .static) {
15841577 self.out_lib_filename = self.out_filename;
15851578 } else if (self.version) |version| {
......@@ -1636,7 +1629,7 @@ pub const LibExeObjStep = struct {
16361629 /// Creates a `RunStep` with an executable built with `addExecutable`.
16371630 /// Add command line arguments with `addArg`.
16381631 pub fn run(exe: *LibExeObjStep) *RunStep {
1639 assert(exe.kind == Kind.Exe);
1632 assert(exe.kind == .exe);
16401633
16411634 // It doesn't have to be native. We catch that if you actually try to run it.
16421635 // Consider that this is declarative; the run step may not be run unless a user
......@@ -1679,31 +1672,31 @@ pub const LibExeObjStep = struct {
16791672 }
16801673
16811674 pub fn linkLibrary(self: *LibExeObjStep, lib: *LibExeObjStep) void {
1682 assert(lib.kind == Kind.Lib);
1675 assert(lib.kind == .lib);
16831676 self.linkLibraryOrObject(lib);
16841677 }
16851678
16861679 pub fn isDynamicLibrary(self: *LibExeObjStep) bool {
1687 return self.kind == Kind.Lib and self.linkage == .dynamic;
1680 return self.kind == .lib and self.linkage == .dynamic;
16881681 }
16891682
16901683 pub fn producesPdbFile(self: *LibExeObjStep) bool {
16911684 if (!self.target.isWindows() and !self.target.isUefi()) return false;
16921685 if (self.strip) return false;
1693 return self.isDynamicLibrary() or self.kind == .Exe;
1686 return self.isDynamicLibrary() or self.kind == .exe;
16941687 }
16951688
16961689 pub fn linkLibC(self: *LibExeObjStep) void {
16971690 if (!self.is_linking_libc) {
16981691 self.is_linking_libc = true;
1699 self.link_objects.append(LinkObject{ .system_lib = "c" }) catch unreachable;
1692 self.link_objects.append(.{ .system_lib = "c" }) catch unreachable;
17001693 }
17011694 }
17021695
17031696 pub fn linkLibCpp(self: *LibExeObjStep) void {
17041697 if (!self.is_linking_libcpp) {
17051698 self.is_linking_libcpp = true;
1706 self.link_objects.append(LinkObject{ .SystemLib = "c++" }) catch unreachable;
1699 self.link_objects.append(.{ .system_lib = "c++" }) catch unreachable;
17071700 }
17081701 }
17091702
......@@ -1715,7 +1708,7 @@ pub const LibExeObjStep = struct {
17151708 /// This one has no integration with anything, it just puts -lname on the command line.
17161709 /// Prefer to use `linkSystemLibrary` instead.
17171710 pub fn linkSystemLibraryName(self: *LibExeObjStep, name: []const u8) void {
1718 self.link_objects.append(LinkObject{ .system_lib = self.builder.dupe(name) }) catch unreachable;
1711 self.link_objects.append(.{ .system_lib = self.builder.dupe(name) }) catch unreachable;
17191712 }
17201713
17211714 /// This links against a system library, exclusively using pkg-config to find the library.
......@@ -1835,12 +1828,12 @@ pub const LibExeObjStep = struct {
18351828 }
18361829
18371830 pub fn setNamePrefix(self: *LibExeObjStep, text: []const u8) void {
1838 assert(self.kind == Kind.Test);
1831 assert(self.kind == .@"test");
18391832 self.name_prefix = self.builder.dupe(text);
18401833 }
18411834
18421835 pub fn setFilter(self: *LibExeObjStep, text: ?[]const u8) void {
1843 assert(self.kind == Kind.Test);
1836 assert(self.kind == .@"test");
18441837 self.filter = if (text) |t| self.builder.dupe(t) else null;
18451838 }
18461839
......@@ -1855,7 +1848,7 @@ pub const LibExeObjStep = struct {
18551848 .files = files_copy,
18561849 .flags = flags_copy,
18571850 };
1858 self.link_objects.append(LinkObject{ .c_source_files = c_source_files }) catch unreachable;
1851 self.link_objects.append(.{ .c_source_files = c_source_files }) catch unreachable;
18591852 }
18601853
18611854 pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, flags: []const []const u8) void {
......@@ -1868,7 +1861,7 @@ pub const LibExeObjStep = struct {
18681861 pub fn addCSourceFileSource(self: *LibExeObjStep, source: CSourceFile) void {
18691862 const c_source_file = self.builder.allocator.create(CSourceFile) catch unreachable;
18701863 c_source_file.* = source.dupe(self.builder);
1871 self.link_objects.append(LinkObject{ .c_source_file = c_source_file }) catch unreachable;
1864 self.link_objects.append(.{ .c_source_file = c_source_file }) catch unreachable;
18721865 source.source.addStepDependencies(&self.step);
18731866 }
18741867
......@@ -1904,14 +1897,14 @@ pub const LibExeObjStep = struct {
19041897
19051898 /// Returns the generated import library. This function can only be called for libraries.
19061899 pub fn getOutputLibSource(self: *LibExeObjStep) FileSource {
1907 assert(self.kind == Kind.Lib);
1900 assert(self.kind == .lib);
19081901 return FileSource{ .generated = &self.output_lib_path_source };
19091902 }
19101903
19111904 /// Returns the generated header file.
19121905 /// This function can only be called for libraries or object files which have `emit_h` set.
19131906 pub fn getOutputHSource(self: *LibExeObjStep) FileSource {
1914 assert(self.kind != Kind.Exe);
1907 assert(self.kind != .exe);
19151908 assert(self.emit_h);
19161909 return FileSource{ .generated = &self.output_h_path_source };
19171910 }
......@@ -1924,14 +1917,14 @@ pub const LibExeObjStep = struct {
19241917 }
19251918
19261919 pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {
1927 self.link_objects.append(LinkObject{
1920 self.link_objects.append(.{
19281921 .assembly_file = .{ .path = self.builder.dupe(path) },
19291922 }) catch unreachable;
19301923 }
19311924
19321925 pub fn addAssemblyFileSource(self: *LibExeObjStep, source: FileSource) void {
19331926 const source_duped = source.dupe(self.builder);
1934 self.link_objects.append(LinkObject{ .assembly_file = source_duped }) catch unreachable;
1927 self.link_objects.append(.{ .assembly_file = source_duped }) catch unreachable;
19351928 source_duped.addStepDependencies(&self.step);
19361929 }
19371930
......@@ -1940,12 +1933,12 @@ pub const LibExeObjStep = struct {
19401933 }
19411934
19421935 pub fn addObjectFileSource(self: *LibExeObjStep, source: FileSource) void {
1943 self.link_objects.append(LinkObject{ .static_path = source.dupe(self.builder) }) catch unreachable;
1936 self.link_objects.append(.{ .static_path = source.dupe(self.builder) }) catch unreachable;
19441937 source.addStepDependencies(&self.step);
19451938 }
19461939
19471940 pub fn addObject(self: *LibExeObjStep, obj: *LibExeObjStep) void {
1948 assert(obj.kind == Kind.Obj);
1941 assert(obj.kind == .obj);
19491942 self.linkLibraryOrObject(obj);
19501943 }
19511944
......@@ -2105,7 +2098,7 @@ pub const LibExeObjStep = struct {
21052098
21062099 /// If Vcpkg was found on the system, it will be added to include and lib
21072100 /// paths for the specified target.
2108 pub fn addVcpkgPaths(self: *LibExeObjStep, linkage: VcpkgLinkage) !void {
2101 pub fn addVcpkgPaths(self: *LibExeObjStep, linkage: LibExeObjStep.Linkage) !void {
21092102 // Ideally in the Unattempted case we would call the function recursively
21102103 // after findVcpkgRoot and have only one switch statement, but the compiler
21112104 // cannot resolve the error set.
......@@ -2125,7 +2118,7 @@ pub const LibExeObjStep = struct {
21252118 .not_found => return error.VcpkgNotFound,
21262119 .found => |root| {
21272120 const allocator = self.builder.allocator;
2128 const triplet = try self.target.vcpkgTriplet(allocator, linkage);
2121 const triplet = try self.target.vcpkgTriplet(allocator, if (linkage == .static) .Static else .Dynamic);
21292122 defer self.builder.allocator.free(triplet);
21302123
21312124 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
......@@ -2141,7 +2134,7 @@ pub const LibExeObjStep = struct {
21412134 }
21422135
21432136 pub fn setExecCmd(self: *LibExeObjStep, args: []const ?[]const u8) void {
2144 assert(self.kind == Kind.Test);
2137 assert(self.kind == .@"test");
21452138 const duped_args = self.builder.allocator.alloc(?[]u8, args.len) catch unreachable;
21462139 for (args) |arg, i| {
21472140 duped_args[i] = if (arg) |a| self.builder.dupe(a) else null;
......@@ -2151,8 +2144,8 @@ pub const LibExeObjStep = struct {
21512144
21522145 fn linkLibraryOrObject(self: *LibExeObjStep, other: *LibExeObjStep) void {
21532146 self.step.dependOn(&other.step);
2154 self.link_objects.append(LinkObject{ .other_step = other }) catch unreachable;
2155 self.include_dirs.append(IncludeDir{ .other_step = other }) catch unreachable;
2147 self.link_objects.append(.{ .other_step = other }) catch unreachable;
2148 self.include_dirs.append(.{ .other_step = other }) catch unreachable;
21562149
21572150 // BUG: The following code introduces a order-of-call dependency:
21582151 // var lib = addSharedLibrary(...);
......@@ -2208,10 +2201,10 @@ pub const LibExeObjStep = struct {
22082201 zig_args.append(builder.zig_exe) catch unreachable;
22092202
22102203 const cmd = switch (self.kind) {
2211 .Lib => "build-lib",
2212 .Exe => "build-exe",
2213 .Obj => "build-obj",
2214 .Test => "test",
2204 .lib => "build-lib",
2205 .exe => "build-exe",
2206 .obj => "build-obj",
2207 .@"test" => "test",
22152208 };
22162209 zig_args.append(cmd) catch unreachable;
22172210
......@@ -2233,12 +2226,12 @@ pub const LibExeObjStep = struct {
22332226 .static_path => |static_path| try zig_args.append(static_path.getPath(builder)),
22342227
22352228 .other_step => |other| switch (other.kind) {
2236 .Exe => unreachable,
2237 .Test => unreachable,
2238 .Obj => {
2229 .exe => unreachable,
2230 .@"test" => unreachable,
2231 .obj => {
22392232 try zig_args.append(other.getOutputSource().getPath(builder));
22402233 },
2241 .Lib => {
2234 .lib => {
22422235 const full_path_lib = other.getOutputLibSource().getPath(builder);
22432236 try zig_args.append(full_path_lib);
22442237
......@@ -2408,7 +2401,7 @@ pub const LibExeObjStep = struct {
24082401 zig_args.append("--name") catch unreachable;
24092402 zig_args.append(self.name) catch unreachable;
24102403
2411 if (self.kind == Kind.Lib and self.linkage == .dynamic) {
2404 if (self.kind == .lib and self.linkage == .dynamic) {
24122405 if (self.version) |version| {
24132406 zig_args.append("--version") catch unreachable;
24142407 zig_args.append(builder.fmt("{}", .{version})) catch unreachable;
......@@ -2682,7 +2675,7 @@ pub const LibExeObjStep = struct {
26822675 });
26832676 }
26842677
2685 if (self.kind == Kind.Test) {
2678 if (self.kind == .@"test") {
26862679 try builder.spawnChild(zig_args.items);
26872680 } else {
26882681 try zig_args.append("--enable-cache");
......@@ -2745,13 +2738,15 @@ pub const LibExeObjStep = struct {
27452738 }
27462739 }
27472740
2748 if (self.kind == .Lib and self.linkage == .dynamic and self.version != null and self.target.wantSharedLibSymLinks()) {
2741 if (self.kind == .lib and self.linkage == .dynamic and self.version != null and self.target.wantSharedLibSymLinks()) {
27492742 try doAtomicSymLinks(builder.allocator, self.getOutputSource().getPath(builder), self.major_only_filename.?, self.name_only_filename.?);
27502743 }
27512744 }
27522745};
27532746
27542747pub const InstallArtifactStep = struct {
2748 pub const base_id = .install_artifact;
2749
27552750 step: Step,
27562751 builder: *Builder,
27572752 artifact: *LibExeObjStep,
......@@ -2767,22 +2762,22 @@ pub const InstallArtifactStep = struct {
27672762 const self = builder.allocator.create(Self) catch unreachable;
27682763 self.* = Self{
27692764 .builder = builder,
2770 .step = Step.init(.InstallArtifact, builder.fmt("install {s}", .{artifact.step.name}), builder.allocator, make),
2765 .step = Step.init(.install_artifact, builder.fmt("install {s}", .{artifact.step.name}), builder.allocator, make),
27712766 .artifact = artifact,
27722767 .dest_dir = artifact.override_dest_dir orelse switch (artifact.kind) {
2773 .Obj => unreachable,
2774 .Test => unreachable,
2775 .Exe => InstallDir{ .Bin = {} },
2776 .Lib => InstallDir{ .Lib = {} },
2768 .obj => unreachable,
2769 .@"test" => unreachable,
2770 .exe => InstallDir{ .bin = {} },
2771 .lib => InstallDir{ .lib = {} },
27772772 },
27782773 .pdb_dir = if (artifact.producesPdbFile()) blk: {
2779 if (artifact.kind == .Exe) {
2780 break :blk InstallDir{ .Bin = {} };
2774 if (artifact.kind == .exe) {
2775 break :blk InstallDir{ .bin = {} };
27812776 } else {
2782 break :blk InstallDir{ .Lib = {} };
2777 break :blk InstallDir{ .lib = {} };
27832778 }
27842779 } else null,
2785 .h_dir = if (artifact.kind == .Lib and artifact.emit_h) .Header else null,
2780 .h_dir = if (artifact.kind == .lib and artifact.emit_h) .header else null,
27862781 };
27872782 self.step.dependOn(&artifact.step);
27882783 artifact.install_step = self;
......@@ -2790,13 +2785,13 @@ pub const InstallArtifactStep = struct {
27902785 builder.pushInstalledFile(self.dest_dir, artifact.out_filename);
27912786 if (self.artifact.isDynamicLibrary()) {
27922787 if (artifact.major_only_filename) |name| {
2793 builder.pushInstalledFile(.Lib, name);
2788 builder.pushInstalledFile(.lib, name);
27942789 }
27952790 if (artifact.name_only_filename) |name| {
2796 builder.pushInstalledFile(.Lib, name);
2791 builder.pushInstalledFile(.lib, name);
27972792 }
27982793 if (self.artifact.target.isWindows()) {
2799 builder.pushInstalledFile(.Lib, artifact.out_lib_filename);
2794 builder.pushInstalledFile(.lib, artifact.out_lib_filename);
28002795 }
28012796 }
28022797 if (self.pdb_dir) |pdb_dir| {
......@@ -2830,6 +2825,8 @@ pub const InstallArtifactStep = struct {
28302825};
28312826
28322827pub const InstallFileStep = struct {
2828 pub const base_id = .install_file;
2829
28332830 step: Step,
28342831 builder: *Builder,
28352832 source: FileSource,
......@@ -2845,7 +2842,7 @@ pub const InstallFileStep = struct {
28452842 builder.pushInstalledFile(dir, dest_rel_path);
28462843 return InstallFileStep{
28472844 .builder = builder,
2848 .step = Step.init(.InstallFile, builder.fmt("install {s} to {s}", .{ source.getDisplayName(), dest_rel_path }), builder.allocator, make),
2845 .step = Step.init(.install_file, builder.fmt("install {s} to {s}", .{ source.getDisplayName(), dest_rel_path }), builder.allocator, make),
28492846 .source = source.dupe(builder),
28502847 .dir = dir.dupe(builder),
28512848 .dest_rel_path = builder.dupePath(dest_rel_path),
......@@ -2886,6 +2883,8 @@ pub const InstallDirectoryOptions = struct {
28862883};
28872884
28882885pub const InstallDirStep = struct {
2886 pub const base_id = .install_dir;
2887
28892888 step: Step,
28902889 builder: *Builder,
28912890 options: InstallDirectoryOptions,
......@@ -2897,7 +2896,7 @@ pub const InstallDirStep = struct {
28972896 builder.pushInstalledFile(options.install_dir, options.install_subdir);
28982897 return InstallDirStep{
28992898 .builder = builder,
2900 .step = Step.init(.InstallDir, builder.fmt("install {s}/", .{options.source_dir}), builder.allocator, make),
2899 .step = Step.init(.install_dir, builder.fmt("install {s}/", .{options.source_dir}), builder.allocator, make),
29012900 .options = options.dupe(builder),
29022901 };
29032902 }
......@@ -2938,6 +2937,8 @@ pub const InstallDirStep = struct {
29382937};
29392938
29402939pub const LogStep = struct {
2940 pub const base_id = .log;
2941
29412942 step: Step,
29422943 builder: *Builder,
29432944 data: []const u8,
......@@ -2945,7 +2946,7 @@ pub const LogStep = struct {
29452946 pub fn init(builder: *Builder, data: []const u8) LogStep {
29462947 return LogStep{
29472948 .builder = builder,
2948 .step = Step.init(.Log, builder.fmt("log {s}", .{data}), builder.allocator, make),
2949 .step = Step.init(.log, builder.fmt("log {s}", .{data}), builder.allocator, make),
29492950 .data = builder.dupe(data),
29502951 };
29512952 }
......@@ -2957,6 +2958,8 @@ pub const LogStep = struct {
29572958};
29582959
29592960pub const RemoveDirStep = struct {
2961 pub const base_id = .remove_dir;
2962
29602963 step: Step,
29612964 builder: *Builder,
29622965 dir_path: []const u8,
......@@ -2964,7 +2967,7 @@ pub const RemoveDirStep = struct {
29642967 pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {
29652968 return RemoveDirStep{
29662969 .builder = builder,
2967 .step = Step.init(.RemoveDir, builder.fmt("RemoveDir {s}", .{dir_path}), builder.allocator, make),
2970 .step = Step.init(.remove_dir, builder.fmt("RemoveDir {s}", .{dir_path}), builder.allocator, make),
29682971 .dir_path = builder.dupePath(dir_path),
29692972 };
29702973 }
......@@ -2990,20 +2993,20 @@ pub const Step = struct {
29902993 done_flag: bool,
29912994
29922995 pub const Id = enum {
2993 TopLevel,
2994 LibExeObj,
2995 InstallArtifact,
2996 InstallFile,
2997 InstallDir,
2998 Log,
2999 RemoveDir,
3000 Fmt,
3001 TranslateC,
3002 WriteFile,
3003 Run,
3004 CheckFile,
3005 InstallRaw,
3006 Custom,
2996 top_level,
2997 lib_exe_obj,
2998 install_artifact,
2999 install_file,
3000 install_dir,
3001 log,
3002 remove_dir,
3003 fmt,
3004 translate_c,
3005 write_file,
3006 run,
3007 check_file,
3008 install_raw,
3009 custom,
30073010 };
30083011
30093012 pub fn init(id: Id, name: []const u8, allocator: *Allocator, makeFn: fn (*Step) anyerror!void) Step {
......@@ -3034,23 +3037,11 @@ pub const Step = struct {
30343037 fn makeNoOp(self: *Step) anyerror!void {}
30353038
30363039 pub fn cast(step: *Step, comptime T: type) ?*T {
3037 if (step.id == comptime typeToId(T)) {
3040 if (step.id == T.base_id) {
30383041 return @fieldParentPtr(T, "step", step);
30393042 }
30403043 return null;
30413044 }
3042
3043 fn typeToId(comptime T: type) Id {
3044 inline for (@typeInfo(Id).Enum.fields) |f| {
3045 if (std.mem.eql(u8, f.name, "TopLevel") or
3046 std.mem.eql(u8, f.name, "Custom")) continue;
3047
3048 if (T == @field(ThisModule, f.name ++ "Step")) {
3049 return @field(Id, f.name);
3050 }
3051 }
3052 unreachable;
3053 }
30543045};
30553046
30563047fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void {
......@@ -3107,21 +3098,19 @@ const VcpkgRootStatus = enum {
31073098 found,
31083099};
31093100
3110pub const VcpkgLinkage = std.builtin.LinkMode;
3111
31123101pub const InstallDir = union(enum) {
3113 Prefix: void,
3114 Lib: void,
3115 Bin: void,
3116 Header: void,
3102 prefix: void,
3103 lib: void,
3104 bin: void,
3105 header: void,
31173106 /// A path relative to the prefix
3118 Custom: []const u8,
3107 custom: []const u8,
31193108
31203109 fn dupe(self: InstallDir, builder: *Builder) InstallDir {
3121 if (self == .Custom) {
3110 if (self == .custom) {
31223111 // Written with this temporary to avoid RLS problems
3123 const duped_path = builder.dupe(self.Custom);
3124 return .{ .Custom = duped_path };
3112 const duped_path = builder.dupe(self.custom);
3113 return .{ .custom = duped_path };
31253114 } else {
31263115 return self;
31273116 }
lib/std/build/CheckFileStep.zig+3-1
......@@ -13,6 +13,8 @@ const warn = std.debug.warn;
1313
1414const CheckFileStep = @This();
1515
16pub const base_id = .check_file;
17
1618step: Step,
1719builder: *Builder,
1820expected_matches: []const []const u8,
......@@ -27,7 +29,7 @@ pub fn create(
2729 const self = builder.allocator.create(CheckFileStep) catch unreachable;
2830 self.* = CheckFileStep{
2931 .builder = builder,
30 .step = Step.init(.CheckFile, "CheckFile", builder.allocator, make),
32 .step = Step.init(.check_file, "CheckFile", builder.allocator, make),
3133 .source = source.dupe(builder),
3234 .expected_matches = builder.dupeStrings(expected_matches),
3335 };
lib/std/build/FmtStep.zig+3-1
......@@ -12,6 +12,8 @@ const mem = std.mem;
1212
1313const FmtStep = @This();
1414
15pub const base_id = .fmt;
16
1517step: Step,
1618builder: *Builder,
1719argv: [][]const u8,
......@@ -20,7 +22,7 @@ pub fn create(builder: *Builder, paths: []const []const u8) *FmtStep {
2022 const self = builder.allocator.create(FmtStep) catch unreachable;
2123 const name = "zig fmt";
2224 self.* = FmtStep{
23 .step = Step.init(.Fmt, name, builder.allocator, make),
25 .step = Step.init(.fmt, name, builder.allocator, make),
2426 .builder = builder,
2527 .argv = builder.allocator.alloc([]u8, paths.len + 2) catch unreachable,
2628 };
lib/std/build/InstallRawStep.zig+7-5
......@@ -179,6 +179,8 @@ fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8) !v
179179
180180const InstallRawStep = @This();
181181
182pub const base_id = .install_raw;
183
182184step: Step,
183185builder: *Builder,
184186artifact: *LibExeObjStep,
......@@ -188,14 +190,14 @@ dest_filename: []const u8,
188190pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {
189191 const self = builder.allocator.create(InstallRawStep) catch unreachable;
190192 self.* = InstallRawStep{
191 .step = Step.init(.InstallRaw, builder.fmt("install raw binary {s}", .{artifact.step.name}), builder.allocator, make),
193 .step = Step.init(.install_raw, builder.fmt("install raw binary {s}", .{artifact.step.name}), builder.allocator, make),
192194 .builder = builder,
193195 .artifact = artifact,
194196 .dest_dir = switch (artifact.kind) {
195 .Obj => unreachable,
196 .Test => unreachable,
197 .Exe => .Bin,
198 .Lib => unreachable,
197 .obj => unreachable,
198 .@"test" => unreachable,
199 .exe => .bin,
200 .lib => unreachable,
199201 },
200202 .dest_filename = dest_filename,
201203 };
lib/std/build/RunStep.zig+3-1
......@@ -21,6 +21,8 @@ const max_stdout_size = 1 * 1024 * 1024; // 1 MiB
2121
2222const RunStep = @This();
2323
24pub const base_id = .run;
25
2426step: Step,
2527builder: *Builder,
2628
......@@ -57,7 +59,7 @@ pub fn create(builder: *Builder, name: []const u8) *RunStep {
5759 const self = builder.allocator.create(RunStep) catch unreachable;
5860 self.* = RunStep{
5961 .builder = builder,
60 .step = Step.init(.Run, name, builder.allocator, make),
62 .step = Step.init(.run, name, builder.allocator, make),
6163 .argv = ArrayList(Arg).init(builder.allocator),
6264 .cwd = null,
6365 .env_map = null,
lib/std/build/TranslateCStep.zig+3-1
......@@ -15,6 +15,8 @@ const CrossTarget = std.zig.CrossTarget;
1515
1616const TranslateCStep = @This();
1717
18pub const base_id = .translate_c;
19
1820step: Step,
1921builder: *Builder,
2022source: build.FileSource,
......@@ -27,7 +29,7 @@ output_file: build.GeneratedFile,
2729pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
2830 const self = builder.allocator.create(TranslateCStep) catch unreachable;
2931 self.* = TranslateCStep{
30 .step = Step.init(.TranslateC, "translate-c", builder.allocator, make),
32 .step = Step.init(.translate_c, "translate-c", builder.allocator, make),
3133 .builder = builder,
3234 .source = source,
3335 .include_dirs = std.ArrayList([]const u8).init(builder.allocator),
lib/std/build/WriteFileStep.zig+3-1
......@@ -13,6 +13,8 @@ const ArrayList = std.ArrayList;
1313
1414const WriteFileStep = @This();
1515
16pub const base_id = .write_file;
17
1618step: Step,
1719builder: *Builder,
1820output_dir: []const u8,
......@@ -27,7 +29,7 @@ pub const File = struct {
2729pub fn init(builder: *Builder) WriteFileStep {
2830 return WriteFileStep{
2931 .builder = builder,
30 .step = Step.init(.WriteFile, "writefile", builder.allocator, make),
32 .step = Step.init(.write_file, "writefile", builder.allocator, make),
3133 .files = .{},
3234 .output_dir = undefined,
3335 };
lib/std/special/build_runner.zig+1-1
......@@ -202,7 +202,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
202202 for (builder.available_options_list.items) |option| {
203203 const name = try fmt.allocPrint(allocator, " -D{s}=[{s}]", .{
204204 option.name,
205 Builder.typeIdName(option.type_id),
205 @tagName(option.type_id),
206206 });
207207 defer allocator.free(name);
208208 try out_stream.print("{s:<29} {s}\n", .{ name, option.description });
test/src/compare_output.zig+2-2
......@@ -126,7 +126,7 @@ pub const CompareOutputContext = struct {
126126 }
127127
128128 const basename = case.sources.items[0].filename;
129 const exe = b.addExecutableSource("test", write_src.getFileSource(basename).?, false);
129 const exe = b.addExecutableSource("test", write_src.getFileSource(basename).?, .static);
130130 exe.setBuildMode(mode);
131131 if (case.link_libc) {
132132 exe.linkSystemLibrary("c");
......@@ -147,7 +147,7 @@ pub const CompareOutputContext = struct {
147147 }
148148
149149 const basename = case.sources.items[0].filename;
150 const exe = b.addExecutableSource("test", write_src.getFileSource(basename).?, false);
150 const exe = b.addExecutableSource("test", write_src.getFileSource(basename).?, .static);
151151 if (case.link_libc) {
152152 exe.linkSystemLibrary("c");
153153 }
test/tests.zig+7-3
......@@ -656,7 +656,7 @@ pub const StackTracesContext = struct {
656656 const b = self.b;
657657 const src_basename = "source.zig";
658658 const write_src = b.addWriteFile(src_basename, source);
659 const exe = b.addExecutableSource("test", write_src.getFileSource(src_basename).?, false);
659 const exe = b.addExecutableSource("test", write_src.getFileSource(src_basename).?, .static);
660660 exe.setBuildMode(mode);
661661
662662 const run_and_compare = RunAndCompareStep.create(
......@@ -672,6 +672,8 @@ pub const StackTracesContext = struct {
672672
673673
674674 const RunAndCompareStep = struct {
675 pub const base_id = .custom;
676
675677 step: build.Step,
676678 context: *StackTracesContext,
677679 exe: *LibExeObjStep,
......@@ -690,7 +692,7 @@ pub const StackTracesContext = struct {
690692 const allocator = context.b.allocator;
691693 const ptr = allocator.create(RunAndCompareStep) catch unreachable;
692694 ptr.* = RunAndCompareStep{
693 .step = build.Step.init(.Custom, "StackTraceCompareOutputStep", allocator, make),
695 .step = build.Step.init(.custom, "StackTraceCompareOutputStep", allocator, make),
694696 .context = context,
695697 .exe = exe,
696698 .name = name,
......@@ -875,6 +877,8 @@ pub const CompileErrorContext = struct {
875877 };
876878
877879 const CompileCmpOutputStep = struct {
880 pub const base_id = .custom;
881
878882 step: build.Step,
879883 context: *CompileErrorContext,
880884 name: []const u8,
......@@ -911,7 +915,7 @@ pub const CompileErrorContext = struct {
911915 const allocator = context.b.allocator;
912916 const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
913917 ptr.* = CompileCmpOutputStep{
914 .step = build.Step.init(.Custom, "CompileCmpOutput", allocator, make),
918 .step = build.Step.init(.custom, "CompileCmpOutput", allocator, make),
915919 .context = context,
916920 .name = name,
917921 .test_index = context.test_index,