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 {...@@ -66,7 +66,7 @@ pub fn build(b: *Builder) !void {
66 if (!skip_install_lib_files) {66 if (!skip_install_lib_files) {
67 b.installDirectory(InstallDirectoryOptions{67 b.installDirectory(InstallDirectoryOptions{
68 .source_dir = "lib",68 .source_dir = "lib",
69 .install_dir = .Lib,69 .install_dir = .lib,
70 .install_subdir = "zig",70 .install_subdir = "zig",
71 .exclude_extensions = &[_][]const u8{71 .exclude_extensions = &[_][]const u8{
72 "README.md",72 "README.md",
lib/std/build.zig+168-179
...@@ -103,21 +103,23 @@ pub const Builder = struct {...@@ -103,21 +103,23 @@ pub const Builder = struct {
103 };103 };
104104
105 const UserValue = union(enum) {105 const UserValue = union(enum) {
106 Flag: void,106 flag: void,
107 Scalar: []const u8,107 scalar: []const u8,
108 List: ArrayList([]const u8),108 list: ArrayList([]const u8),
109 };109 };
110110
111 const TypeId = enum {111 const TypeId = enum {
112 Bool,112 bool,
113 Int,113 int,
114 Float,114 float,
115 Enum,115 @"enum",
116 String,116 string,
117 List,117 list,
118 };118 };
119119
120 const TopLevelStep = struct {120 const TopLevelStep = struct {
121 pub const base_id = .top_level;
122
121 step: Step,123 step: Step,
122 description: []const u8,124 description: []const u8,
123 };125 };
...@@ -163,11 +165,11 @@ pub const Builder = struct {...@@ -163,11 +165,11 @@ pub const Builder = struct {
163 .dest_dir = env_map.get("DESTDIR"),165 .dest_dir = env_map.get("DESTDIR"),
164 .installed_files = ArrayList(InstalledFile).init(allocator),166 .installed_files = ArrayList(InstalledFile).init(allocator),
165 .install_tls = TopLevelStep{167 .install_tls = TopLevelStep{
166 .step = Step.initNoOp(.TopLevel, "install", allocator),168 .step = Step.initNoOp(.top_level, "install", allocator),
167 .description = "Copy build artifacts to prefix path",169 .description = "Copy build artifacts to prefix path",
168 },170 },
169 .uninstall_tls = TopLevelStep{171 .uninstall_tls = TopLevelStep{
170 .step = Step.init(.TopLevel, "uninstall", allocator, makeUninstall),172 .step = Step.init(.top_level, "uninstall", allocator, makeUninstall),
171 .description = "Remove build artifacts from prefix path",173 .description = "Remove build artifacts from prefix path",
172 },174 },
173 .release_mode = null,175 .release_mode = null,
...@@ -457,9 +459,9 @@ pub const Builder = struct {...@@ -457,9 +459,9 @@ pub const Builder = struct {
457 const option_ptr = self.user_input_options.getPtr(name) orelse return null;459 const option_ptr = self.user_input_options.getPtr(name) orelse return null;
458 option_ptr.used = true;460 option_ptr.used = true;
459 switch (type_id) {461 switch (type_id) {
460 .Bool => switch (option_ptr.value) {462 .bool => switch (option_ptr.value) {
461 .Flag => return true,463 .flag => return true,
462 .Scalar => |s| {464 .scalar => |s| {
463 if (mem.eql(u8, s, "true")) {465 if (mem.eql(u8, s, "true")) {
464 return true;466 return true;
465 } else if (mem.eql(u8, s, "false")) {467 } else if (mem.eql(u8, s, "false")) {
...@@ -470,19 +472,19 @@ pub const Builder = struct {...@@ -470,19 +472,19 @@ pub const Builder = struct {
470 return null;472 return null;
471 }473 }
472 },474 },
473 .List => {475 .list => {
474 warn("Expected -D{s} to be a boolean, but received a list.\n\n", .{name});476 warn("Expected -D{s} to be a boolean, but received a list.\n\n", .{name});
475 self.markInvalidUserInput();477 self.markInvalidUserInput();
476 return null;478 return null;
477 },479 },
478 },480 },
479 .Int => switch (option_ptr.value) {481 .int => switch (option_ptr.value) {
480 .Flag => {482 .flag => {
481 warn("Expected -D{s} to be an integer, but received a boolean.\n\n", .{name});483 warn("Expected -D{s} to be an integer, but received a boolean.\n\n", .{name});
482 self.markInvalidUserInput();484 self.markInvalidUserInput();
483 return null;485 return null;
484 },486 },
485 .Scalar => |s| {487 .scalar => |s| {
486 const n = std.fmt.parseInt(T, s, 10) catch |err| switch (err) {488 const n = std.fmt.parseInt(T, s, 10) catch |err| switch (err) {
487 error.Overflow => {489 error.Overflow => {
488 warn("-D{s} value {s} cannot fit into type {s}.\n\n", .{ name, s, @typeName(T) });490 warn("-D{s} value {s} cannot fit into type {s}.\n\n", .{ name, s, @typeName(T) });
...@@ -497,19 +499,19 @@ pub const Builder = struct {...@@ -497,19 +499,19 @@ pub const Builder = struct {
497 };499 };
498 return n;500 return n;
499 },501 },
500 .List => {502 .list => {
501 warn("Expected -D{s} to be an integer, but received a list.\n\n", .{name});503 warn("Expected -D{s} to be an integer, but received a list.\n\n", .{name});
502 self.markInvalidUserInput();504 self.markInvalidUserInput();
503 return null;505 return null;
504 },506 },
505 },507 },
506 .Float => switch (option_ptr.value) {508 .float => switch (option_ptr.value) {
507 .Flag => {509 .flag => {
508 warn("Expected -D{s} to be a float, but received a boolean.\n\n", .{name});510 warn("Expected -D{s} to be a float, but received a boolean.\n\n", .{name});
509 self.markInvalidUserInput();511 self.markInvalidUserInput();
510 return null;512 return null;
511 },513 },
512 .Scalar => |s| {514 .scalar => |s| {
513 const n = std.fmt.parseFloat(T, s) catch |err| {515 const n = std.fmt.parseFloat(T, s) catch |err| {
514 warn("Expected -D{s} to be a float of type {s}.\n\n", .{ name, @typeName(T) });516 warn("Expected -D{s} to be a float of type {s}.\n\n", .{ name, @typeName(T) });
515 self.markInvalidUserInput();517 self.markInvalidUserInput();
...@@ -517,19 +519,19 @@ pub const Builder = struct {...@@ -517,19 +519,19 @@ pub const Builder = struct {
517 };519 };
518 return n;520 return n;
519 },521 },
520 .List => {522 .list => {
521 warn("Expected -D{s} to be a float, but received a list.\n\n", .{name});523 warn("Expected -D{s} to be a float, but received a list.\n\n", .{name});
522 self.markInvalidUserInput();524 self.markInvalidUserInput();
523 return null;525 return null;
524 },526 },
525 },527 },
526 .Enum => switch (option_ptr.value) {528 .@"enum" => switch (option_ptr.value) {
527 .Flag => {529 .flag => {
528 warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name});530 warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name});
529 self.markInvalidUserInput();531 self.markInvalidUserInput();
530 return null;532 return null;
531 },533 },
532 .Scalar => |s| {534 .scalar => |s| {
533 if (std.meta.stringToEnum(T, s)) |enum_lit| {535 if (std.meta.stringToEnum(T, s)) |enum_lit| {
534 return enum_lit;536 return enum_lit;
535 } else {537 } else {
...@@ -538,35 +540,35 @@ pub const Builder = struct {...@@ -538,35 +540,35 @@ pub const Builder = struct {
538 return null;540 return null;
539 }541 }
540 },542 },
541 .List => {543 .list => {
542 warn("Expected -D{s} to be a string, but received a list.\n\n", .{name});544 warn("Expected -D{s} to be a string, but received a list.\n\n", .{name});
543 self.markInvalidUserInput();545 self.markInvalidUserInput();
544 return null;546 return null;
545 },547 },
546 },548 },
547 .String => switch (option_ptr.value) {549 .string => switch (option_ptr.value) {
548 .Flag => {550 .flag => {
549 warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name});551 warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name});
550 self.markInvalidUserInput();552 self.markInvalidUserInput();
551 return null;553 return null;
552 },554 },
553 .List => {555 .list => {
554 warn("Expected -D{s} to be a string, but received a list.\n\n", .{name});556 warn("Expected -D{s} to be a string, but received a list.\n\n", .{name});
555 self.markInvalidUserInput();557 self.markInvalidUserInput();
556 return null;558 return null;
557 },559 },
558 .Scalar => |s| return s,560 .scalar => |s| return s,
559 },561 },
560 .List => switch (option_ptr.value) {562 .list => switch (option_ptr.value) {
561 .Flag => {563 .flag => {
562 warn("Expected -D{s} to be a list, but received a boolean.\n\n", .{name});564 warn("Expected -D{s} to be a list, but received a boolean.\n\n", .{name});
563 self.markInvalidUserInput();565 self.markInvalidUserInput();
564 return null;566 return null;
565 },567 },
566 .Scalar => |s| {568 .scalar => |s| {
567 return self.allocator.dupe([]const u8, &[_][]const u8{s}) catch unreachable;569 return self.allocator.dupe([]const u8, &[_][]const u8{s}) catch unreachable;
568 },570 },
569 .List => |lst| return lst.items,571 .list => |lst| return lst.items,
570 },572 },
571 }573 }
572 }574 }
...@@ -574,7 +576,7 @@ pub const Builder = struct {...@@ -574,7 +576,7 @@ pub const Builder = struct {
574 pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step {576 pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step {
575 const step_info = self.allocator.create(TopLevelStep) catch unreachable;577 const step_info = self.allocator.create(TopLevelStep) catch unreachable;
576 step_info.* = TopLevelStep{578 step_info.* = TopLevelStep{
577 .step = Step.initNoOp(.TopLevel, name, self.allocator),579 .step = Step.initNoOp(.top_level, name, self.allocator),
578 .description = self.dupe(description),580 .description = self.dupe(description),
579 };581 };
580 self.top_level_steps.append(step_info) catch unreachable;582 self.top_level_steps.append(step_info) catch unreachable;
...@@ -721,7 +723,7 @@ pub const Builder = struct {...@@ -721,7 +723,7 @@ pub const Builder = struct {
721 if (!gop.found_existing) {723 if (!gop.found_existing) {
722 gop.value_ptr.* = UserInputOption{724 gop.value_ptr.* = UserInputOption{
723 .name = name,725 .name = name,
724 .value = UserValue{ .Scalar = value },726 .value = .{ .scalar = value },
725 .used = false,727 .used = false,
726 };728 };
727 return false;729 return false;
...@@ -729,27 +731,27 @@ pub const Builder = struct {...@@ -729,27 +731,27 @@ pub const Builder = struct {
729731
730 // option already exists732 // option already exists
731 switch (gop.value_ptr.value) {733 switch (gop.value_ptr.value) {
732 UserValue.Scalar => |s| {734 .scalar => |s| {
733 // turn it into a list735 // turn it into a list
734 var list = ArrayList([]const u8).init(self.allocator);736 var list = ArrayList([]const u8).init(self.allocator);
735 list.append(s) catch unreachable;737 list.append(s) catch unreachable;
736 list.append(value) catch unreachable;738 list.append(value) catch unreachable;
737 self.user_input_options.put(name, UserInputOption{739 self.user_input_options.put(name, .{
738 .name = name,740 .name = name,
739 .value = UserValue{ .List = list },741 .value = .{ .list = list },
740 .used = false,742 .used = false,
741 }) catch unreachable;743 }) catch unreachable;
742 },744 },
743 UserValue.List => |*list| {745 .list => |*list| {
744 // append to the list746 // append to the list
745 list.append(value) catch unreachable;747 list.append(value) catch unreachable;
746 self.user_input_options.put(name, UserInputOption{748 self.user_input_options.put(name, .{
747 .name = name,749 .name = name,
748 .value = UserValue{ .List = list.* },750 .value = .{ .list = list.* },
749 .used = false,751 .used = false,
750 }) catch unreachable;752 }) catch unreachable;
751 },753 },
752 UserValue.Flag => {754 .flag => {
753 warn("Option '-D{s}={s}' conflicts with flag '-D{s}'.\n", .{ name, value, name });755 warn("Option '-D{s}={s}' conflicts with flag '-D{s}'.\n", .{ name, value, name });
754 return true;756 return true;
755 },757 },
...@@ -761,9 +763,9 @@ pub const Builder = struct {...@@ -761,9 +763,9 @@ pub const Builder = struct {
761 const name = self.dupe(name_raw);763 const name = self.dupe(name_raw);
762 const gop = try self.user_input_options.getOrPut(name);764 const gop = try self.user_input_options.getOrPut(name);
763 if (!gop.found_existing) {765 if (!gop.found_existing) {
764 gop.value_ptr.* = UserInputOption{766 gop.value_ptr.* = .{
765 .name = name,767 .name = name,
766 .value = UserValue{ .Flag = {} },768 .value = .{ .flag = {} },
767 .used = false,769 .used = false,
768 };770 };
769 return false;771 return false;
...@@ -771,28 +773,28 @@ pub const Builder = struct {...@@ -771,28 +773,28 @@ pub const Builder = struct {
771773
772 // option already exists774 // option already exists
773 switch (gop.value_ptr.value) {775 switch (gop.value_ptr.value) {
774 UserValue.Scalar => |s| {776 .scalar => |s| {
775 warn("Flag '-D{s}' conflicts with option '-D{s}={s}'.\n", .{ name, name, s });777 warn("Flag '-D{s}' conflicts with option '-D{s}={s}'.\n", .{ name, name, s });
776 return true;778 return true;
777 },779 },
778 UserValue.List => {780 .list => {
779 warn("Flag '-D{s}' conflicts with multiple options of the same name.\n", .{name});781 warn("Flag '-D{s}' conflicts with multiple options of the same name.\n", .{name});
780 return true;782 return true;
781 },783 },
782 UserValue.Flag => {},784 .flag => {},
783 }785 }
784 return false;786 return false;
785 }787 }
786788
787 fn typeToEnum(comptime T: type) TypeId {789 fn typeToEnum(comptime T: type) TypeId {
788 return switch (@typeInfo(T)) {790 return switch (@typeInfo(T)) {
789 .Int => .Int,791 .Int => .int,
790 .Float => .Float,792 .Float => .float,
791 .Bool => .Bool,793 .Bool => .bool,
792 .Enum => .Enum,794 .Enum => .@"enum",
793 else => switch (T) {795 else => switch (T) {
794 []const u8 => .String,796 []const u8 => .string,
795 []const []const u8 => .List,797 []const []const u8 => .list,
796 else => @compileError("Unsupported type: " ++ @typeName(T)),798 else => @compileError("Unsupported type: " ++ @typeName(T)),
797 },799 },
798 };800 };
...@@ -802,17 +804,6 @@ pub const Builder = struct {...@@ -802,17 +804,6 @@ pub const Builder = struct {
802 self.invalid_user_input = true;804 self.invalid_user_input = true;
803 }805 }
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
816 pub fn validateUserInputDidItFail(self: *Builder) bool {807 pub fn validateUserInputDidItFail(self: *Builder) bool {
817 // make sure all args are used808 // make sure all args are used
818 var it = self.user_input_options.iterator();809 var it = self.user_input_options.iterator();
...@@ -888,7 +879,7 @@ pub const Builder = struct {...@@ -888,7 +879,7 @@ pub const Builder = struct {
888879
889 ///`dest_rel_path` is relative to prefix path880 ///`dest_rel_path` is relative to prefix path
890 pub fn installFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void {881 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);
892 }883 }
893884
894 pub fn installDirectory(self: *Builder, options: InstallDirectoryOptions) void {885 pub fn installDirectory(self: *Builder, options: InstallDirectoryOptions) void {
...@@ -897,12 +888,12 @@ pub const Builder = struct {...@@ -897,12 +888,12 @@ pub const Builder = struct {
897888
898 ///`dest_rel_path` is relative to bin path889 ///`dest_rel_path` is relative to bin path
899 pub fn installBinFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void {890 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);
901 }892 }
902893
903 ///`dest_rel_path` is relative to lib path894 ///`dest_rel_path` is relative to lib path
904 pub fn installLibFile(self: *Builder, src_path: []const u8, dest_rel_path: []const u8) void {895 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);
906 }897 }
907898
908 pub fn installRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) void {899 pub fn installRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) void {
...@@ -911,17 +902,17 @@ pub const Builder = struct {...@@ -911,17 +902,17 @@ pub const Builder = struct {
911902
912 ///`dest_rel_path` is relative to install prefix path903 ///`dest_rel_path` is relative to install prefix path
913 pub fn addInstallFile(self: *Builder, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {904 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);
915 }906 }
916907
917 ///`dest_rel_path` is relative to bin path908 ///`dest_rel_path` is relative to bin path
918 pub fn addInstallBinFile(self: *Builder, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {909 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);
920 }911 }
921912
922 ///`dest_rel_path` is relative to lib path913 ///`dest_rel_path` is relative to lib path
923 pub fn addInstallLibFile(self: *Builder, source: FileSource, dest_rel_path: []const u8) *InstallFileStep {914 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);
925 }916 }
926917
927 pub fn addInstallRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {918 pub fn addInstallRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {
...@@ -1119,11 +1110,11 @@ pub const Builder = struct {...@@ -1119,11 +1110,11 @@ pub const Builder = struct {
1119 pub fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {1110 pub fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 {
1120 assert(!fs.path.isAbsolute(dest_rel_path)); // Install paths must be relative to the prefix1111 assert(!fs.path.isAbsolute(dest_rel_path)); // Install paths must be relative to the prefix
1121 const base_dir = switch (dir) {1112 const base_dir = switch (dir) {
1122 .Prefix => self.install_path,1113 .prefix => self.install_path,
1123 .Bin => self.exe_dir,1114 .bin => self.exe_dir,
1124 .Lib => self.lib_dir,1115 .lib => self.lib_dir,
1125 .Header => self.h_dir,1116 .header => self.h_dir,
1126 .Custom => |path| fs.path.join(self.allocator, &[_][]const u8{ self.install_path, path }) catch unreachable,1117 .custom => |path| fs.path.join(self.allocator, &[_][]const u8{ self.install_path, path }) catch unreachable,
1127 };1118 };
1128 return fs.path.resolve(1119 return fs.path.resolve(
1129 self.allocator,1120 self.allocator,
...@@ -1315,6 +1306,8 @@ const BuildOptionFileSourceArg = struct {...@@ -1315,6 +1306,8 @@ const BuildOptionFileSourceArg = struct {
1315};1306};
13161307
1317pub const LibExeObjStep = struct {1308pub const LibExeObjStep = struct {
1309 pub const base_id = .lib_exe_obj;
1310
1318 step: Step,1311 step: Step,
1319 builder: *Builder,1312 builder: *Builder,
1320 name: []const u8,1313 name: []const u8,
...@@ -1451,10 +1444,10 @@ pub const LibExeObjStep = struct {...@@ -1451,10 +1444,10 @@ pub const LibExeObjStep = struct {
1451 };1444 };
14521445
1453 const Kind = enum {1446 const Kind = enum {
1454 Exe,1447 exe,
1455 Lib,1448 lib,
1456 Obj,1449 obj,
1457 Test,1450 @"test",
1458 };1451 };
14591452
1460 const SharedLibKind = union(enum) {1453 const SharedLibKind = union(enum) {
...@@ -1465,26 +1458,26 @@ pub const LibExeObjStep = struct {...@@ -1465,26 +1458,26 @@ pub const LibExeObjStep = struct {
1465 pub const Linkage = enum { dynamic, static };1458 pub const Linkage = enum { dynamic, static };
14661459
1467 pub fn createSharedLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource, kind: SharedLibKind) *LibExeObjStep {1460 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) {
1469 .versioned => |ver| ver,1462 .versioned => |ver| ver,
1470 .unversioned => null,1463 .unversioned => null,
1471 });1464 });
1472 }1465 }
14731466
1474 pub fn createStaticLibrary(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep {1467 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);
1476 }1469 }
14771470
1478 pub fn createObject(builder: *Builder, name: []const u8, root_src: ?FileSource) *LibExeObjStep {1471 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);
1480 }1473 }
14811474
1482 pub fn createExecutable(builder: *Builder, name: []const u8, root_src: ?FileSource, linkage: Linkage) *LibExeObjStep {1475 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);
1484 }1477 }
14851478
1486 pub fn createTest(builder: *Builder, name: []const u8, root_src: FileSource) *LibExeObjStep {1479 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);
1488 }1481 }
14891482
1490 fn initExtraArgs(1483 fn initExtraArgs(
...@@ -1513,7 +1506,7 @@ pub const LibExeObjStep = struct {...@@ -1513,7 +1506,7 @@ pub const LibExeObjStep = struct {
1513 .root_src = root_src,1506 .root_src = root_src,
1514 .name = name,1507 .name = name,
1515 .frameworks = BufSet.init(builder.allocator),1508 .frameworks = BufSet.init(builder.allocator),
1516 .step = Step.init(.LibExeObj, name, builder.allocator, make),1509 .step = Step.init(base_id, name, builder.allocator, make),
1517 .version = ver,1510 .version = ver,
1518 .out_filename = undefined,1511 .out_filename = undefined,
1519 .out_h_filename = builder.fmt("{s}.h", .{name}),1512 .out_h_filename = builder.fmt("{s}.h", .{name}),
...@@ -1568,18 +1561,18 @@ pub const LibExeObjStep = struct {...@@ -1568,18 +1561,18 @@ pub const LibExeObjStep = struct {
1568 .root_name = self.name,1561 .root_name = self.name,
1569 .target = target,1562 .target = target,
1570 .output_mode = switch (self.kind) {1563 .output_mode = switch (self.kind) {
1571 .Lib => .Lib,1564 .lib => .Lib,
1572 .Obj => .Obj,1565 .obj => .Obj,
1573 .Exe, .Test => .Exe,1566 .exe, .@"test" => .Exe,
1574 },1567 },
1575 .link_mode = switch (self.linkage) {1568 .link_mode = switch (self.linkage) {
1576 .dynamic => std.builtin.LinkMode.Dynamic,1569 .dynamic => .Dynamic,
1577 .static => std.builtin.LinkMode.Static,1570 .static => .Static,
1578 },1571 },
1579 .version = self.version,1572 .version = self.version,
1580 }) catch unreachable;1573 }) catch unreachable;
15811574
1582 if (self.kind == .Lib) {1575 if (self.kind == .lib) {
1583 if (self.linkage == .static) {1576 if (self.linkage == .static) {
1584 self.out_lib_filename = self.out_filename;1577 self.out_lib_filename = self.out_filename;
1585 } else if (self.version) |version| {1578 } else if (self.version) |version| {
...@@ -1636,7 +1629,7 @@ pub const LibExeObjStep = struct {...@@ -1636,7 +1629,7 @@ pub const LibExeObjStep = struct {
1636 /// Creates a `RunStep` with an executable built with `addExecutable`.1629 /// Creates a `RunStep` with an executable built with `addExecutable`.
1637 /// Add command line arguments with `addArg`.1630 /// Add command line arguments with `addArg`.
1638 pub fn run(exe: *LibExeObjStep) *RunStep {1631 pub fn run(exe: *LibExeObjStep) *RunStep {
1639 assert(exe.kind == Kind.Exe);1632 assert(exe.kind == .exe);
16401633
1641 // It doesn't have to be native. We catch that if you actually try to run it.1634 // It doesn't have to be native. We catch that if you actually try to run it.
1642 // Consider that this is declarative; the run step may not be run unless a user1635 // Consider that this is declarative; the run step may not be run unless a user
...@@ -1679,31 +1672,31 @@ pub const LibExeObjStep = struct {...@@ -1679,31 +1672,31 @@ pub const LibExeObjStep = struct {
1679 }1672 }
16801673
1681 pub fn linkLibrary(self: *LibExeObjStep, lib: *LibExeObjStep) void {1674 pub fn linkLibrary(self: *LibExeObjStep, lib: *LibExeObjStep) void {
1682 assert(lib.kind == Kind.Lib);1675 assert(lib.kind == .lib);
1683 self.linkLibraryOrObject(lib);1676 self.linkLibraryOrObject(lib);
1684 }1677 }
16851678
1686 pub fn isDynamicLibrary(self: *LibExeObjStep) bool {1679 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;
1688 }1681 }
16891682
1690 pub fn producesPdbFile(self: *LibExeObjStep) bool {1683 pub fn producesPdbFile(self: *LibExeObjStep) bool {
1691 if (!self.target.isWindows() and !self.target.isUefi()) return false;1684 if (!self.target.isWindows() and !self.target.isUefi()) return false;
1692 if (self.strip) return false;1685 if (self.strip) return false;
1693 return self.isDynamicLibrary() or self.kind == .Exe;1686 return self.isDynamicLibrary() or self.kind == .exe;
1694 }1687 }
16951688
1696 pub fn linkLibC(self: *LibExeObjStep) void {1689 pub fn linkLibC(self: *LibExeObjStep) void {
1697 if (!self.is_linking_libc) {1690 if (!self.is_linking_libc) {
1698 self.is_linking_libc = true;1691 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;
1700 }1693 }
1701 }1694 }
17021695
1703 pub fn linkLibCpp(self: *LibExeObjStep) void {1696 pub fn linkLibCpp(self: *LibExeObjStep) void {
1704 if (!self.is_linking_libcpp) {1697 if (!self.is_linking_libcpp) {
1705 self.is_linking_libcpp = true;1698 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;
1707 }1700 }
1708 }1701 }
17091702
...@@ -1715,7 +1708,7 @@ pub const LibExeObjStep = struct {...@@ -1715,7 +1708,7 @@ pub const LibExeObjStep = struct {
1715 /// This one has no integration with anything, it just puts -lname on the command line.1708 /// This one has no integration with anything, it just puts -lname on the command line.
1716 /// Prefer to use `linkSystemLibrary` instead.1709 /// Prefer to use `linkSystemLibrary` instead.
1717 pub fn linkSystemLibraryName(self: *LibExeObjStep, name: []const u8) void {1710 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;
1719 }1712 }
17201713
1721 /// This links against a system library, exclusively using pkg-config to find the library.1714 /// This links against a system library, exclusively using pkg-config to find the library.
...@@ -1835,12 +1828,12 @@ pub const LibExeObjStep = struct {...@@ -1835,12 +1828,12 @@ pub const LibExeObjStep = struct {
1835 }1828 }
18361829
1837 pub fn setNamePrefix(self: *LibExeObjStep, text: []const u8) void {1830 pub fn setNamePrefix(self: *LibExeObjStep, text: []const u8) void {
1838 assert(self.kind == Kind.Test);1831 assert(self.kind == .@"test");
1839 self.name_prefix = self.builder.dupe(text);1832 self.name_prefix = self.builder.dupe(text);
1840 }1833 }
18411834
1842 pub fn setFilter(self: *LibExeObjStep, text: ?[]const u8) void {1835 pub fn setFilter(self: *LibExeObjStep, text: ?[]const u8) void {
1843 assert(self.kind == Kind.Test);1836 assert(self.kind == .@"test");
1844 self.filter = if (text) |t| self.builder.dupe(t) else null;1837 self.filter = if (text) |t| self.builder.dupe(t) else null;
1845 }1838 }
18461839
...@@ -1855,7 +1848,7 @@ pub const LibExeObjStep = struct {...@@ -1855,7 +1848,7 @@ pub const LibExeObjStep = struct {
1855 .files = files_copy,1848 .files = files_copy,
1856 .flags = flags_copy,1849 .flags = flags_copy,
1857 };1850 };
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;
1859 }1852 }
18601853
1861 pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, flags: []const []const u8) void {1854 pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, flags: []const []const u8) void {
...@@ -1868,7 +1861,7 @@ pub const LibExeObjStep = struct {...@@ -1868,7 +1861,7 @@ pub const LibExeObjStep = struct {
1868 pub fn addCSourceFileSource(self: *LibExeObjStep, source: CSourceFile) void {1861 pub fn addCSourceFileSource(self: *LibExeObjStep, source: CSourceFile) void {
1869 const c_source_file = self.builder.allocator.create(CSourceFile) catch unreachable;1862 const c_source_file = self.builder.allocator.create(CSourceFile) catch unreachable;
1870 c_source_file.* = source.dupe(self.builder);1863 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;
1872 source.source.addStepDependencies(&self.step);1865 source.source.addStepDependencies(&self.step);
1873 }1866 }
18741867
...@@ -1904,14 +1897,14 @@ pub const LibExeObjStep = struct {...@@ -1904,14 +1897,14 @@ pub const LibExeObjStep = struct {
19041897
1905 /// Returns the generated import library. This function can only be called for libraries.1898 /// Returns the generated import library. This function can only be called for libraries.
1906 pub fn getOutputLibSource(self: *LibExeObjStep) FileSource {1899 pub fn getOutputLibSource(self: *LibExeObjStep) FileSource {
1907 assert(self.kind == Kind.Lib);1900 assert(self.kind == .lib);
1908 return FileSource{ .generated = &self.output_lib_path_source };1901 return FileSource{ .generated = &self.output_lib_path_source };
1909 }1902 }
19101903
1911 /// Returns the generated header file.1904 /// Returns the generated header file.
1912 /// This function can only be called for libraries or object files which have `emit_h` set.1905 /// This function can only be called for libraries or object files which have `emit_h` set.
1913 pub fn getOutputHSource(self: *LibExeObjStep) FileSource {1906 pub fn getOutputHSource(self: *LibExeObjStep) FileSource {
1914 assert(self.kind != Kind.Exe);1907 assert(self.kind != .exe);
1915 assert(self.emit_h);1908 assert(self.emit_h);
1916 return FileSource{ .generated = &self.output_h_path_source };1909 return FileSource{ .generated = &self.output_h_path_source };
1917 }1910 }
...@@ -1924,14 +1917,14 @@ pub const LibExeObjStep = struct {...@@ -1924,14 +1917,14 @@ pub const LibExeObjStep = struct {
1924 }1917 }
19251918
1926 pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {1919 pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void {
1927 self.link_objects.append(LinkObject{1920 self.link_objects.append(.{
1928 .assembly_file = .{ .path = self.builder.dupe(path) },1921 .assembly_file = .{ .path = self.builder.dupe(path) },
1929 }) catch unreachable;1922 }) catch unreachable;
1930 }1923 }
19311924
1932 pub fn addAssemblyFileSource(self: *LibExeObjStep, source: FileSource) void {1925 pub fn addAssemblyFileSource(self: *LibExeObjStep, source: FileSource) void {
1933 const source_duped = source.dupe(self.builder);1926 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;
1935 source_duped.addStepDependencies(&self.step);1928 source_duped.addStepDependencies(&self.step);
1936 }1929 }
19371930
...@@ -1940,12 +1933,12 @@ pub const LibExeObjStep = struct {...@@ -1940,12 +1933,12 @@ pub const LibExeObjStep = struct {
1940 }1933 }
19411934
1942 pub fn addObjectFileSource(self: *LibExeObjStep, source: FileSource) void {1935 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;
1944 source.addStepDependencies(&self.step);1937 source.addStepDependencies(&self.step);
1945 }1938 }
19461939
1947 pub fn addObject(self: *LibExeObjStep, obj: *LibExeObjStep) void {1940 pub fn addObject(self: *LibExeObjStep, obj: *LibExeObjStep) void {
1948 assert(obj.kind == Kind.Obj);1941 assert(obj.kind == .obj);
1949 self.linkLibraryOrObject(obj);1942 self.linkLibraryOrObject(obj);
1950 }1943 }
19511944
...@@ -2105,7 +2098,7 @@ pub const LibExeObjStep = struct {...@@ -2105,7 +2098,7 @@ pub const LibExeObjStep = struct {
21052098
2106 /// If Vcpkg was found on the system, it will be added to include and lib2099 /// If Vcpkg was found on the system, it will be added to include and lib
2107 /// paths for the specified target.2100 /// paths for the specified target.
2108 pub fn addVcpkgPaths(self: *LibExeObjStep, linkage: VcpkgLinkage) !void {2101 pub fn addVcpkgPaths(self: *LibExeObjStep, linkage: LibExeObjStep.Linkage) !void {
2109 // Ideally in the Unattempted case we would call the function recursively2102 // Ideally in the Unattempted case we would call the function recursively
2110 // after findVcpkgRoot and have only one switch statement, but the compiler2103 // after findVcpkgRoot and have only one switch statement, but the compiler
2111 // cannot resolve the error set.2104 // cannot resolve the error set.
...@@ -2125,7 +2118,7 @@ pub const LibExeObjStep = struct {...@@ -2125,7 +2118,7 @@ pub const LibExeObjStep = struct {
2125 .not_found => return error.VcpkgNotFound,2118 .not_found => return error.VcpkgNotFound,
2126 .found => |root| {2119 .found => |root| {
2127 const allocator = self.builder.allocator;2120 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);
2129 defer self.builder.allocator.free(triplet);2122 defer self.builder.allocator.free(triplet);
21302123
2131 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });2124 const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" });
...@@ -2141,7 +2134,7 @@ pub const LibExeObjStep = struct {...@@ -2141,7 +2134,7 @@ pub const LibExeObjStep = struct {
2141 }2134 }
21422135
2143 pub fn setExecCmd(self: *LibExeObjStep, args: []const ?[]const u8) void {2136 pub fn setExecCmd(self: *LibExeObjStep, args: []const ?[]const u8) void {
2144 assert(self.kind == Kind.Test);2137 assert(self.kind == .@"test");
2145 const duped_args = self.builder.allocator.alloc(?[]u8, args.len) catch unreachable;2138 const duped_args = self.builder.allocator.alloc(?[]u8, args.len) catch unreachable;
2146 for (args) |arg, i| {2139 for (args) |arg, i| {
2147 duped_args[i] = if (arg) |a| self.builder.dupe(a) else null;2140 duped_args[i] = if (arg) |a| self.builder.dupe(a) else null;
...@@ -2151,8 +2144,8 @@ pub const LibExeObjStep = struct {...@@ -2151,8 +2144,8 @@ pub const LibExeObjStep = struct {
21512144
2152 fn linkLibraryOrObject(self: *LibExeObjStep, other: *LibExeObjStep) void {2145 fn linkLibraryOrObject(self: *LibExeObjStep, other: *LibExeObjStep) void {
2153 self.step.dependOn(&other.step);2146 self.step.dependOn(&other.step);
2154 self.link_objects.append(LinkObject{ .other_step = other }) catch unreachable;2147 self.link_objects.append(.{ .other_step = other }) catch unreachable;
2155 self.include_dirs.append(IncludeDir{ .other_step = other }) catch unreachable;2148 self.include_dirs.append(.{ .other_step = other }) catch unreachable;
21562149
2157 // BUG: The following code introduces a order-of-call dependency:2150 // BUG: The following code introduces a order-of-call dependency:
2158 // var lib = addSharedLibrary(...);2151 // var lib = addSharedLibrary(...);
...@@ -2208,10 +2201,10 @@ pub const LibExeObjStep = struct {...@@ -2208,10 +2201,10 @@ pub const LibExeObjStep = struct {
2208 zig_args.append(builder.zig_exe) catch unreachable;2201 zig_args.append(builder.zig_exe) catch unreachable;
22092202
2210 const cmd = switch (self.kind) {2203 const cmd = switch (self.kind) {
2211 .Lib => "build-lib",2204 .lib => "build-lib",
2212 .Exe => "build-exe",2205 .exe => "build-exe",
2213 .Obj => "build-obj",2206 .obj => "build-obj",
2214 .Test => "test",2207 .@"test" => "test",
2215 };2208 };
2216 zig_args.append(cmd) catch unreachable;2209 zig_args.append(cmd) catch unreachable;
22172210
...@@ -2233,12 +2226,12 @@ pub const LibExeObjStep = struct {...@@ -2233,12 +2226,12 @@ pub const LibExeObjStep = struct {
2233 .static_path => |static_path| try zig_args.append(static_path.getPath(builder)),2226 .static_path => |static_path| try zig_args.append(static_path.getPath(builder)),
22342227
2235 .other_step => |other| switch (other.kind) {2228 .other_step => |other| switch (other.kind) {
2236 .Exe => unreachable,2229 .exe => unreachable,
2237 .Test => unreachable,2230 .@"test" => unreachable,
2238 .Obj => {2231 .obj => {
2239 try zig_args.append(other.getOutputSource().getPath(builder));2232 try zig_args.append(other.getOutputSource().getPath(builder));
2240 },2233 },
2241 .Lib => {2234 .lib => {
2242 const full_path_lib = other.getOutputLibSource().getPath(builder);2235 const full_path_lib = other.getOutputLibSource().getPath(builder);
2243 try zig_args.append(full_path_lib);2236 try zig_args.append(full_path_lib);
22442237
...@@ -2408,7 +2401,7 @@ pub const LibExeObjStep = struct {...@@ -2408,7 +2401,7 @@ pub const LibExeObjStep = struct {
2408 zig_args.append("--name") catch unreachable;2401 zig_args.append("--name") catch unreachable;
2409 zig_args.append(self.name) catch unreachable;2402 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) {
2412 if (self.version) |version| {2405 if (self.version) |version| {
2413 zig_args.append("--version") catch unreachable;2406 zig_args.append("--version") catch unreachable;
2414 zig_args.append(builder.fmt("{}", .{version})) catch unreachable;2407 zig_args.append(builder.fmt("{}", .{version})) catch unreachable;
...@@ -2682,7 +2675,7 @@ pub const LibExeObjStep = struct {...@@ -2682,7 +2675,7 @@ pub const LibExeObjStep = struct {
2682 });2675 });
2683 }2676 }
26842677
2685 if (self.kind == Kind.Test) {2678 if (self.kind == .@"test") {
2686 try builder.spawnChild(zig_args.items);2679 try builder.spawnChild(zig_args.items);
2687 } else {2680 } else {
2688 try zig_args.append("--enable-cache");2681 try zig_args.append("--enable-cache");
...@@ -2745,13 +2738,15 @@ pub const LibExeObjStep = struct {...@@ -2745,13 +2738,15 @@ pub const LibExeObjStep = struct {
2745 }2738 }
2746 }2739 }
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()) {
2749 try doAtomicSymLinks(builder.allocator, self.getOutputSource().getPath(builder), self.major_only_filename.?, self.name_only_filename.?);2742 try doAtomicSymLinks(builder.allocator, self.getOutputSource().getPath(builder), self.major_only_filename.?, self.name_only_filename.?);
2750 }2743 }
2751 }2744 }
2752};2745};
27532746
2754pub const InstallArtifactStep = struct {2747pub const InstallArtifactStep = struct {
2748 pub const base_id = .install_artifact;
2749
2755 step: Step,2750 step: Step,
2756 builder: *Builder,2751 builder: *Builder,
2757 artifact: *LibExeObjStep,2752 artifact: *LibExeObjStep,
...@@ -2767,22 +2762,22 @@ pub const InstallArtifactStep = struct {...@@ -2767,22 +2762,22 @@ pub const InstallArtifactStep = struct {
2767 const self = builder.allocator.create(Self) catch unreachable;2762 const self = builder.allocator.create(Self) catch unreachable;
2768 self.* = Self{2763 self.* = Self{
2769 .builder = builder,2764 .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),
2771 .artifact = artifact,2766 .artifact = artifact,
2772 .dest_dir = artifact.override_dest_dir orelse switch (artifact.kind) {2767 .dest_dir = artifact.override_dest_dir orelse switch (artifact.kind) {
2773 .Obj => unreachable,2768 .obj => unreachable,
2774 .Test => unreachable,2769 .@"test" => unreachable,
2775 .Exe => InstallDir{ .Bin = {} },2770 .exe => InstallDir{ .bin = {} },
2776 .Lib => InstallDir{ .Lib = {} },2771 .lib => InstallDir{ .lib = {} },
2777 },2772 },
2778 .pdb_dir = if (artifact.producesPdbFile()) blk: {2773 .pdb_dir = if (artifact.producesPdbFile()) blk: {
2779 if (artifact.kind == .Exe) {2774 if (artifact.kind == .exe) {
2780 break :blk InstallDir{ .Bin = {} };2775 break :blk InstallDir{ .bin = {} };
2781 } else {2776 } else {
2782 break :blk InstallDir{ .Lib = {} };2777 break :blk InstallDir{ .lib = {} };
2783 }2778 }
2784 } else null,2779 } 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,
2786 };2781 };
2787 self.step.dependOn(&artifact.step);2782 self.step.dependOn(&artifact.step);
2788 artifact.install_step = self;2783 artifact.install_step = self;
...@@ -2790,13 +2785,13 @@ pub const InstallArtifactStep = struct {...@@ -2790,13 +2785,13 @@ pub const InstallArtifactStep = struct {
2790 builder.pushInstalledFile(self.dest_dir, artifact.out_filename);2785 builder.pushInstalledFile(self.dest_dir, artifact.out_filename);
2791 if (self.artifact.isDynamicLibrary()) {2786 if (self.artifact.isDynamicLibrary()) {
2792 if (artifact.major_only_filename) |name| {2787 if (artifact.major_only_filename) |name| {
2793 builder.pushInstalledFile(.Lib, name);2788 builder.pushInstalledFile(.lib, name);
2794 }2789 }
2795 if (artifact.name_only_filename) |name| {2790 if (artifact.name_only_filename) |name| {
2796 builder.pushInstalledFile(.Lib, name);2791 builder.pushInstalledFile(.lib, name);
2797 }2792 }
2798 if (self.artifact.target.isWindows()) {2793 if (self.artifact.target.isWindows()) {
2799 builder.pushInstalledFile(.Lib, artifact.out_lib_filename);2794 builder.pushInstalledFile(.lib, artifact.out_lib_filename);
2800 }2795 }
2801 }2796 }
2802 if (self.pdb_dir) |pdb_dir| {2797 if (self.pdb_dir) |pdb_dir| {
...@@ -2830,6 +2825,8 @@ pub const InstallArtifactStep = struct {...@@ -2830,6 +2825,8 @@ pub const InstallArtifactStep = struct {
2830};2825};
28312826
2832pub const InstallFileStep = struct {2827pub const InstallFileStep = struct {
2828 pub const base_id = .install_file;
2829
2833 step: Step,2830 step: Step,
2834 builder: *Builder,2831 builder: *Builder,
2835 source: FileSource,2832 source: FileSource,
...@@ -2845,7 +2842,7 @@ pub const InstallFileStep = struct {...@@ -2845,7 +2842,7 @@ pub const InstallFileStep = struct {
2845 builder.pushInstalledFile(dir, dest_rel_path);2842 builder.pushInstalledFile(dir, dest_rel_path);
2846 return InstallFileStep{2843 return InstallFileStep{
2847 .builder = builder,2844 .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),
2849 .source = source.dupe(builder),2846 .source = source.dupe(builder),
2850 .dir = dir.dupe(builder),2847 .dir = dir.dupe(builder),
2851 .dest_rel_path = builder.dupePath(dest_rel_path),2848 .dest_rel_path = builder.dupePath(dest_rel_path),
...@@ -2886,6 +2883,8 @@ pub const InstallDirectoryOptions = struct {...@@ -2886,6 +2883,8 @@ pub const InstallDirectoryOptions = struct {
2886};2883};
28872884
2888pub const InstallDirStep = struct {2885pub const InstallDirStep = struct {
2886 pub const base_id = .install_dir;
2887
2889 step: Step,2888 step: Step,
2890 builder: *Builder,2889 builder: *Builder,
2891 options: InstallDirectoryOptions,2890 options: InstallDirectoryOptions,
...@@ -2897,7 +2896,7 @@ pub const InstallDirStep = struct {...@@ -2897,7 +2896,7 @@ pub const InstallDirStep = struct {
2897 builder.pushInstalledFile(options.install_dir, options.install_subdir);2896 builder.pushInstalledFile(options.install_dir, options.install_subdir);
2898 return InstallDirStep{2897 return InstallDirStep{
2899 .builder = builder,2898 .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),
2901 .options = options.dupe(builder),2900 .options = options.dupe(builder),
2902 };2901 };
2903 }2902 }
...@@ -2938,6 +2937,8 @@ pub const InstallDirStep = struct {...@@ -2938,6 +2937,8 @@ pub const InstallDirStep = struct {
2938};2937};
29392938
2940pub const LogStep = struct {2939pub const LogStep = struct {
2940 pub const base_id = .log;
2941
2941 step: Step,2942 step: Step,
2942 builder: *Builder,2943 builder: *Builder,
2943 data: []const u8,2944 data: []const u8,
...@@ -2945,7 +2946,7 @@ pub const LogStep = struct {...@@ -2945,7 +2946,7 @@ pub const LogStep = struct {
2945 pub fn init(builder: *Builder, data: []const u8) LogStep {2946 pub fn init(builder: *Builder, data: []const u8) LogStep {
2946 return LogStep{2947 return LogStep{
2947 .builder = builder,2948 .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),
2949 .data = builder.dupe(data),2950 .data = builder.dupe(data),
2950 };2951 };
2951 }2952 }
...@@ -2957,6 +2958,8 @@ pub const LogStep = struct {...@@ -2957,6 +2958,8 @@ pub const LogStep = struct {
2957};2958};
29582959
2959pub const RemoveDirStep = struct {2960pub const RemoveDirStep = struct {
2961 pub const base_id = .remove_dir;
2962
2960 step: Step,2963 step: Step,
2961 builder: *Builder,2964 builder: *Builder,
2962 dir_path: []const u8,2965 dir_path: []const u8,
...@@ -2964,7 +2967,7 @@ pub const RemoveDirStep = struct {...@@ -2964,7 +2967,7 @@ pub const RemoveDirStep = struct {
2964 pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {2967 pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep {
2965 return RemoveDirStep{2968 return RemoveDirStep{
2966 .builder = builder,2969 .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),
2968 .dir_path = builder.dupePath(dir_path),2971 .dir_path = builder.dupePath(dir_path),
2969 };2972 };
2970 }2973 }
...@@ -2990,20 +2993,20 @@ pub const Step = struct {...@@ -2990,20 +2993,20 @@ pub const Step = struct {
2990 done_flag: bool,2993 done_flag: bool,
29912994
2992 pub const Id = enum {2995 pub const Id = enum {
2993 TopLevel,2996 top_level,
2994 LibExeObj,2997 lib_exe_obj,
2995 InstallArtifact,2998 install_artifact,
2996 InstallFile,2999 install_file,
2997 InstallDir,3000 install_dir,
2998 Log,3001 log,
2999 RemoveDir,3002 remove_dir,
3000 Fmt,3003 fmt,
3001 TranslateC,3004 translate_c,
3002 WriteFile,3005 write_file,
3003 Run,3006 run,
3004 CheckFile,3007 check_file,
3005 InstallRaw,3008 install_raw,
3006 Custom,3009 custom,
3007 };3010 };
30083011
3009 pub fn init(id: Id, name: []const u8, allocator: *Allocator, makeFn: fn (*Step) anyerror!void) Step {3012 pub fn init(id: Id, name: []const u8, allocator: *Allocator, makeFn: fn (*Step) anyerror!void) Step {
...@@ -3034,23 +3037,11 @@ pub const Step = struct {...@@ -3034,23 +3037,11 @@ pub const Step = struct {
3034 fn makeNoOp(self: *Step) anyerror!void {}3037 fn makeNoOp(self: *Step) anyerror!void {}
30353038
3036 pub fn cast(step: *Step, comptime T: type) ?*T {3039 pub fn cast(step: *Step, comptime T: type) ?*T {
3037 if (step.id == comptime typeToId(T)) {3040 if (step.id == T.base_id) {
3038 return @fieldParentPtr(T, "step", step);3041 return @fieldParentPtr(T, "step", step);
3039 }3042 }
3040 return null;3043 return null;
3041 }3044 }
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 }
3054};3045};
30553046
3056fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void {3047fn 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 {...@@ -3107,21 +3098,19 @@ const VcpkgRootStatus = enum {
3107 found,3098 found,
3108};3099};
31093100
3110pub const VcpkgLinkage = std.builtin.LinkMode;
3111
3112pub const InstallDir = union(enum) {3101pub const InstallDir = union(enum) {
3113 Prefix: void,3102 prefix: void,
3114 Lib: void,3103 lib: void,
3115 Bin: void,3104 bin: void,
3116 Header: void,3105 header: void,
3117 /// A path relative to the prefix3106 /// A path relative to the prefix
3118 Custom: []const u8,3107 custom: []const u8,
31193108
3120 fn dupe(self: InstallDir, builder: *Builder) InstallDir {3109 fn dupe(self: InstallDir, builder: *Builder) InstallDir {
3121 if (self == .Custom) {3110 if (self == .custom) {
3122 // Written with this temporary to avoid RLS problems3111 // Written with this temporary to avoid RLS problems
3123 const duped_path = builder.dupe(self.Custom);3112 const duped_path = builder.dupe(self.custom);
3124 return .{ .Custom = duped_path };3113 return .{ .custom = duped_path };
3125 } else {3114 } else {
3126 return self;3115 return self;
3127 }3116 }
lib/std/build/CheckFileStep.zig+3-1
...@@ -13,6 +13,8 @@ const warn = std.debug.warn;...@@ -13,6 +13,8 @@ const warn = std.debug.warn;
1313
14const CheckFileStep = @This();14const CheckFileStep = @This();
1515
16pub const base_id = .check_file;
17
16step: Step,18step: Step,
17builder: *Builder,19builder: *Builder,
18expected_matches: []const []const u8,20expected_matches: []const []const u8,
...@@ -27,7 +29,7 @@ pub fn create(...@@ -27,7 +29,7 @@ pub fn create(
27 const self = builder.allocator.create(CheckFileStep) catch unreachable;29 const self = builder.allocator.create(CheckFileStep) catch unreachable;
28 self.* = CheckFileStep{30 self.* = CheckFileStep{
29 .builder = builder,31 .builder = builder,
30 .step = Step.init(.CheckFile, "CheckFile", builder.allocator, make),32 .step = Step.init(.check_file, "CheckFile", builder.allocator, make),
31 .source = source.dupe(builder),33 .source = source.dupe(builder),
32 .expected_matches = builder.dupeStrings(expected_matches),34 .expected_matches = builder.dupeStrings(expected_matches),
33 };35 };
lib/std/build/FmtStep.zig+3-1
...@@ -12,6 +12,8 @@ const mem = std.mem;...@@ -12,6 +12,8 @@ const mem = std.mem;
1212
13const FmtStep = @This();13const FmtStep = @This();
1414
15pub const base_id = .fmt;
16
15step: Step,17step: Step,
16builder: *Builder,18builder: *Builder,
17argv: [][]const u8,19argv: [][]const u8,
...@@ -20,7 +22,7 @@ pub fn create(builder: *Builder, paths: []const []const u8) *FmtStep {...@@ -20,7 +22,7 @@ pub fn create(builder: *Builder, paths: []const []const u8) *FmtStep {
20 const self = builder.allocator.create(FmtStep) catch unreachable;22 const self = builder.allocator.create(FmtStep) catch unreachable;
21 const name = "zig fmt";23 const name = "zig fmt";
22 self.* = FmtStep{24 self.* = FmtStep{
23 .step = Step.init(.Fmt, name, builder.allocator, make),25 .step = Step.init(.fmt, name, builder.allocator, make),
24 .builder = builder,26 .builder = builder,
25 .argv = builder.allocator.alloc([]u8, paths.len + 2) catch unreachable,27 .argv = builder.allocator.alloc([]u8, paths.len + 2) catch unreachable,
26 };28 };
lib/std/build/InstallRawStep.zig+7-5
...@@ -179,6 +179,8 @@ fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8) !v...@@ -179,6 +179,8 @@ fn emitRaw(allocator: *Allocator, elf_path: []const u8, raw_path: []const u8) !v
179179
180const InstallRawStep = @This();180const InstallRawStep = @This();
181181
182pub const base_id = .install_raw;
183
182step: Step,184step: Step,
183builder: *Builder,185builder: *Builder,
184artifact: *LibExeObjStep,186artifact: *LibExeObjStep,
...@@ -188,14 +190,14 @@ dest_filename: []const u8,...@@ -188,14 +190,14 @@ dest_filename: []const u8,
188pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {190pub fn create(builder: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep {
189 const self = builder.allocator.create(InstallRawStep) catch unreachable;191 const self = builder.allocator.create(InstallRawStep) catch unreachable;
190 self.* = InstallRawStep{192 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),
192 .builder = builder,194 .builder = builder,
193 .artifact = artifact,195 .artifact = artifact,
194 .dest_dir = switch (artifact.kind) {196 .dest_dir = switch (artifact.kind) {
195 .Obj => unreachable,197 .obj => unreachable,
196 .Test => unreachable,198 .@"test" => unreachable,
197 .Exe => .Bin,199 .exe => .bin,
198 .Lib => unreachable,200 .lib => unreachable,
199 },201 },
200 .dest_filename = dest_filename,202 .dest_filename = dest_filename,
201 };203 };
lib/std/build/RunStep.zig+3-1
...@@ -21,6 +21,8 @@ const max_stdout_size = 1 * 1024 * 1024; // 1 MiB...@@ -21,6 +21,8 @@ const max_stdout_size = 1 * 1024 * 1024; // 1 MiB
2121
22const RunStep = @This();22const RunStep = @This();
2323
24pub const base_id = .run;
25
24step: Step,26step: Step,
25builder: *Builder,27builder: *Builder,
2628
...@@ -57,7 +59,7 @@ pub fn create(builder: *Builder, name: []const u8) *RunStep {...@@ -57,7 +59,7 @@ pub fn create(builder: *Builder, name: []const u8) *RunStep {
57 const self = builder.allocator.create(RunStep) catch unreachable;59 const self = builder.allocator.create(RunStep) catch unreachable;
58 self.* = RunStep{60 self.* = RunStep{
59 .builder = builder,61 .builder = builder,
60 .step = Step.init(.Run, name, builder.allocator, make),62 .step = Step.init(.run, name, builder.allocator, make),
61 .argv = ArrayList(Arg).init(builder.allocator),63 .argv = ArrayList(Arg).init(builder.allocator),
62 .cwd = null,64 .cwd = null,
63 .env_map = null,65 .env_map = null,
lib/std/build/TranslateCStep.zig+3-1
...@@ -15,6 +15,8 @@ const CrossTarget = std.zig.CrossTarget;...@@ -15,6 +15,8 @@ const CrossTarget = std.zig.CrossTarget;
1515
16const TranslateCStep = @This();16const TranslateCStep = @This();
1717
18pub const base_id = .translate_c;
19
18step: Step,20step: Step,
19builder: *Builder,21builder: *Builder,
20source: build.FileSource,22source: build.FileSource,
...@@ -27,7 +29,7 @@ output_file: build.GeneratedFile,...@@ -27,7 +29,7 @@ output_file: build.GeneratedFile,
27pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {29pub fn create(builder: *Builder, source: build.FileSource) *TranslateCStep {
28 const self = builder.allocator.create(TranslateCStep) catch unreachable;30 const self = builder.allocator.create(TranslateCStep) catch unreachable;
29 self.* = TranslateCStep{31 self.* = TranslateCStep{
30 .step = Step.init(.TranslateC, "translate-c", builder.allocator, make),32 .step = Step.init(.translate_c, "translate-c", builder.allocator, make),
31 .builder = builder,33 .builder = builder,
32 .source = source,34 .source = source,
33 .include_dirs = std.ArrayList([]const u8).init(builder.allocator),35 .include_dirs = std.ArrayList([]const u8).init(builder.allocator),
lib/std/build/WriteFileStep.zig+3-1
...@@ -13,6 +13,8 @@ const ArrayList = std.ArrayList;...@@ -13,6 +13,8 @@ const ArrayList = std.ArrayList;
1313
14const WriteFileStep = @This();14const WriteFileStep = @This();
1515
16pub const base_id = .write_file;
17
16step: Step,18step: Step,
17builder: *Builder,19builder: *Builder,
18output_dir: []const u8,20output_dir: []const u8,
...@@ -27,7 +29,7 @@ pub const File = struct {...@@ -27,7 +29,7 @@ pub const File = struct {
27pub fn init(builder: *Builder) WriteFileStep {29pub fn init(builder: *Builder) WriteFileStep {
28 return WriteFileStep{30 return WriteFileStep{
29 .builder = builder,31 .builder = builder,
30 .step = Step.init(.WriteFile, "writefile", builder.allocator, make),32 .step = Step.init(.write_file, "writefile", builder.allocator, make),
31 .files = .{},33 .files = .{},
32 .output_dir = undefined,34 .output_dir = undefined,
33 };35 };
lib/std/special/build_runner.zig+1-1
...@@ -202,7 +202,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void...@@ -202,7 +202,7 @@ fn usage(builder: *Builder, already_ran_build: bool, out_stream: anytype) !void
202 for (builder.available_options_list.items) |option| {202 for (builder.available_options_list.items) |option| {
203 const name = try fmt.allocPrint(allocator, " -D{s}=[{s}]", .{203 const name = try fmt.allocPrint(allocator, " -D{s}=[{s}]", .{
204 option.name,204 option.name,
205 Builder.typeIdName(option.type_id),205 @tagName(option.type_id),
206 });206 });
207 defer allocator.free(name);207 defer allocator.free(name);
208 try out_stream.print("{s:<29} {s}\n", .{ name, option.description });208 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 {...@@ -126,7 +126,7 @@ pub const CompareOutputContext = struct {
126 }126 }
127127
128 const basename = case.sources.items[0].filename;128 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);
130 exe.setBuildMode(mode);130 exe.setBuildMode(mode);
131 if (case.link_libc) {131 if (case.link_libc) {
132 exe.linkSystemLibrary("c");132 exe.linkSystemLibrary("c");
...@@ -147,7 +147,7 @@ pub const CompareOutputContext = struct {...@@ -147,7 +147,7 @@ pub const CompareOutputContext = struct {
147 }147 }
148148
149 const basename = case.sources.items[0].filename;149 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);
151 if (case.link_libc) {151 if (case.link_libc) {
152 exe.linkSystemLibrary("c");152 exe.linkSystemLibrary("c");
153 }153 }
test/tests.zig+7-3
...@@ -656,7 +656,7 @@ pub const StackTracesContext = struct {...@@ -656,7 +656,7 @@ pub const StackTracesContext = struct {
656 const b = self.b;656 const b = self.b;
657 const src_basename = "source.zig";657 const src_basename = "source.zig";
658 const write_src = b.addWriteFile(src_basename, source);658 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);
660 exe.setBuildMode(mode);660 exe.setBuildMode(mode);
661661
662 const run_and_compare = RunAndCompareStep.create(662 const run_and_compare = RunAndCompareStep.create(
...@@ -672,6 +672,8 @@ pub const StackTracesContext = struct {...@@ -672,6 +672,8 @@ pub const StackTracesContext = struct {
672672
673673
674 const RunAndCompareStep = struct {674 const RunAndCompareStep = struct {
675 pub const base_id = .custom;
676
675 step: build.Step,677 step: build.Step,
676 context: *StackTracesContext,678 context: *StackTracesContext,
677 exe: *LibExeObjStep,679 exe: *LibExeObjStep,
...@@ -690,7 +692,7 @@ pub const StackTracesContext = struct {...@@ -690,7 +692,7 @@ pub const StackTracesContext = struct {
690 const allocator = context.b.allocator;692 const allocator = context.b.allocator;
691 const ptr = allocator.create(RunAndCompareStep) catch unreachable;693 const ptr = allocator.create(RunAndCompareStep) catch unreachable;
692 ptr.* = RunAndCompareStep{694 ptr.* = RunAndCompareStep{
693 .step = build.Step.init(.Custom, "StackTraceCompareOutputStep", allocator, make),695 .step = build.Step.init(.custom, "StackTraceCompareOutputStep", allocator, make),
694 .context = context,696 .context = context,
695 .exe = exe,697 .exe = exe,
696 .name = name,698 .name = name,
...@@ -875,6 +877,8 @@ pub const CompileErrorContext = struct {...@@ -875,6 +877,8 @@ pub const CompileErrorContext = struct {
875 };877 };
876878
877 const CompileCmpOutputStep = struct {879 const CompileCmpOutputStep = struct {
880 pub const base_id = .custom;
881
878 step: build.Step,882 step: build.Step,
879 context: *CompileErrorContext,883 context: *CompileErrorContext,
880 name: []const u8,884 name: []const u8,
...@@ -911,7 +915,7 @@ pub const CompileErrorContext = struct {...@@ -911,7 +915,7 @@ pub const CompileErrorContext = struct {
911 const allocator = context.b.allocator;915 const allocator = context.b.allocator;
912 const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;916 const ptr = allocator.create(CompileCmpOutputStep) catch unreachable;
913 ptr.* = CompileCmpOutputStep{917 ptr.* = CompileCmpOutputStep{
914 .step = build.Step.init(.Custom, "CompileCmpOutput", allocator, make),918 .step = build.Step.init(.custom, "CompileCmpOutput", allocator, make),
915 .context = context,919 .context = context,
916 .name = name,920 .name = name,
917 .test_index = context.test_index,921 .test_index = context.test_index,