| ... | @@ -103,21 +103,23 @@ pub const Builder = struct { | ... | @@ -103,21 +103,23 @@ pub const Builder = struct { |
| 103 | }; | 103 | }; |
| 104 | | 104 | |
| 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 | }; |
| 110 | | 110 | |
| 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 | }; |
| 119 | | 119 | |
| 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 { |
| 729 | | 731 | |
| 730 | // option already exists | 732 | // 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 list | 735 | // 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 list | 746 | // 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 { |
| 771 | | 773 | |
| 772 | // option already exists | 774 | // 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 | } |
| 786 | | 788 | |
| 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 | } |
| 804 | | 806 | |
| 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 used | 808 | // 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 { |
| 888 | | 879 | |
| 889 | ///`dest_rel_path` is relative to prefix path | 880 | ///`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 | } |
| 893 | | 884 | |
| 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 { |
| 897 | | 888 | |
| 898 | ///`dest_rel_path` is relative to bin path | 889 | ///`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 | } |
| 902 | | 893 | |
| 903 | ///`dest_rel_path` is relative to lib path | 894 | ///`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 | } |
| 907 | | 898 | |
| 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 { |
| 911 | | 902 | |
| 912 | ///`dest_rel_path` is relative to install prefix path | 903 | ///`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 | } |
| 916 | | 907 | |
| 917 | ///`dest_rel_path` is relative to bin path | 908 | ///`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 | } |
| 921 | | 912 | |
| 922 | ///`dest_rel_path` is relative to lib path | 913 | ///`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 | } |
| 926 | | 917 | |
| 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 prefix | 1111 | 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 | }; |
| 1316 | | 1307 | |
| 1317 | pub const LibExeObjStep = struct { | 1308 | pub 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 | }; |
| 1452 | | 1445 | |
| 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 | }; |
| 1459 | | 1452 | |
| 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 }; |
| 1466 | | 1459 | |
| 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 | } |
| 1473 | | 1466 | |
| 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 | } |
| 1477 | | 1470 | |
| 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 | } |
| 1481 | | 1474 | |
| 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 | } |
| 1485 | | 1478 | |
| 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 | } |
| 1489 | | 1482 | |
| 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; |
| 1581 | | 1574 | |
| 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); |
| 1640 | | 1633 | |
| 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 user | 1635 | // 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 | } |
| 1680 | | 1673 | |
| 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 | } |
| 1685 | | 1678 | |
| 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 | } |
| 1689 | | 1682 | |
| 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 | } |
| 1695 | | 1688 | |
| 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 | } |
| 1702 | | 1695 | |
| 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 | } |
| 1709 | | 1702 | |
| ... | @@ -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 | } |
| 1720 | | 1713 | |
| 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 | } |
| 1836 | | 1829 | |
| 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 | } |
| 1841 | | 1834 | |
| 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 | } |
| 1846 | | 1839 | |
| ... | @@ -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 | } |
| 1860 | | 1853 | |
| 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 | } |
| 1874 | | 1867 | |
| ... | @@ -1904,14 +1897,14 @@ pub const LibExeObjStep = struct { | ... | @@ -1904,14 +1897,14 @@ pub const LibExeObjStep = struct { |
| 1904 | | 1897 | |
| 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 | } |
| 1910 | | 1903 | |
| 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 | } |
| 1925 | | 1918 | |
| 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 | } |
| 1931 | | 1924 | |
| 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 | } |
| 1937 | | 1930 | |
| ... | @@ -1940,12 +1933,12 @@ pub const LibExeObjStep = struct { | ... | @@ -1940,12 +1933,12 @@ pub const LibExeObjStep = struct { |
| 1940 | } | 1933 | } |
| 1941 | | 1934 | |
| 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 | } |
| 1946 | | 1939 | |
| 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 | } |
| 1951 | | 1944 | |
| ... | @@ -2105,7 +2098,7 @@ pub const LibExeObjStep = struct { | ... | @@ -2105,7 +2098,7 @@ pub const LibExeObjStep = struct { |
| 2105 | | 2098 | |
| 2106 | /// If Vcpkg was found on the system, it will be added to include and lib | 2099 | /// 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 recursively | 2102 | // Ideally in the Unattempted case we would call the function recursively |
| 2110 | // after findVcpkgRoot and have only one switch statement, but the compiler | 2103 | // 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); |
| 2130 | | 2123 | |
| 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 | } |
| 2142 | | 2135 | |
| 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 { |
| 2151 | | 2144 | |
| 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; |
| 2156 | | 2149 | |
| 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; |
| 2209 | | 2202 | |
| 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; |
| 2217 | | 2210 | |
| ... | @@ -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)), |
| 2234 | | 2227 | |
| 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); |
| 2244 | | 2237 | |
| ... | @@ -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; |
| 2410 | | 2403 | |
| 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 | } |
| 2684 | | 2677 | |
| 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 | } |
| 2747 | | 2740 | |
| 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 | }; |
| 2753 | | 2746 | |
| 2754 | pub const InstallArtifactStep = struct { | 2747 | pub 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 | }; |
| 2831 | | 2826 | |
| 2832 | pub const InstallFileStep = struct { | 2827 | pub 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 | }; |
| 2887 | | 2884 | |
| 2888 | pub const InstallDirStep = struct { | 2885 | pub 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 | }; |
| 2939 | | 2938 | |
| 2940 | pub const LogStep = struct { | 2939 | pub 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 | }; |
| 2958 | | 2959 | |
| 2959 | pub const RemoveDirStep = struct { | 2960 | pub 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, |
| 2991 | | 2994 | |
| 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 | }; |
| 3008 | | 3011 | |
| 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 {} |
| 3035 | | 3038 | |
| 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 | }; |
| 3055 | | 3046 | |
| 3056 | fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_major_only: []const u8, filename_name_only: []const u8) !void { | 3047 | fn 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 | }; |
| 3109 | | 3100 | |
| 3110 | pub const VcpkgLinkage = std.builtin.LinkMode; | | |
| 3111 | | | |
| 3112 | pub const InstallDir = union(enum) { | 3101 | pub 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 prefix | 3106 | /// A path relative to the prefix |
| 3118 | Custom: []const u8, | 3107 | custom: []const u8, |
| 3119 | | 3108 | |
| 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 problems | 3111 | // 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 | } |