| ... | ... | @@ -103,21 +103,23 @@ pub const Builder = struct { |
| 103 | 103 | }; |
| 104 | 104 | |
| 105 | 105 | const UserValue = union(enum) { |
| 106 | | Flag: void, |
| 107 | | Scalar: []const u8, |
| 108 | | List: ArrayList([]const u8), |
| 106 | flag: void, |
| 107 | scalar: []const u8, |
| 108 | list: ArrayList([]const u8), |
| 109 | 109 | }; |
| 110 | 110 | |
| 111 | 111 | const TypeId = enum { |
| 112 | | Bool, |
| 113 | | Int, |
| 114 | | Float, |
| 115 | | Enum, |
| 116 | | String, |
| 117 | | List, |
| 112 | bool, |
| 113 | int, |
| 114 | float, |
| 115 | @"enum", |
| 116 | string, |
| 117 | list, |
| 118 | 118 | }; |
| 119 | 119 | |
| 120 | 120 | const TopLevelStep = struct { |
| 121 | pub const base_id = .top_level; |
| 122 | |
| 121 | 123 | step: Step, |
| 122 | 124 | description: []const u8, |
| 123 | 125 | }; |
| ... | ... | @@ -163,11 +165,11 @@ pub const Builder = struct { |
| 163 | 165 | .dest_dir = env_map.get("DESTDIR"), |
| 164 | 166 | .installed_files = ArrayList(InstalledFile).init(allocator), |
| 165 | 167 | .install_tls = TopLevelStep{ |
| 166 | | .step = Step.initNoOp(.TopLevel, "install", allocator), |
| 168 | .step = Step.initNoOp(.top_level, "install", allocator), |
| 167 | 169 | .description = "Copy build artifacts to prefix path", |
| 168 | 170 | }, |
| 169 | 171 | .uninstall_tls = TopLevelStep{ |
| 170 | | .step = Step.init(.TopLevel, "uninstall", allocator, makeUninstall), |
| 172 | .step = Step.init(.top_level, "uninstall", allocator, makeUninstall), |
| 171 | 173 | .description = "Remove build artifacts from prefix path", |
| 172 | 174 | }, |
| 173 | 175 | .release_mode = null, |
| ... | ... | @@ -457,9 +459,9 @@ pub const Builder = struct { |
| 457 | 459 | const option_ptr = self.user_input_options.getPtr(name) orelse return null; |
| 458 | 460 | option_ptr.used = true; |
| 459 | 461 | switch (type_id) { |
| 460 | | .Bool => switch (option_ptr.value) { |
| 461 | | .Flag => return true, |
| 462 | | .Scalar => |s| { |
| 462 | .bool => switch (option_ptr.value) { |
| 463 | .flag => return true, |
| 464 | .scalar => |s| { |
| 463 | 465 | if (mem.eql(u8, s, "true")) { |
| 464 | 466 | return true; |
| 465 | 467 | } else if (mem.eql(u8, s, "false")) { |
| ... | ... | @@ -470,19 +472,19 @@ pub const Builder = struct { |
| 470 | 472 | return null; |
| 471 | 473 | } |
| 472 | 474 | }, |
| 473 | | .List => { |
| 475 | .list => { |
| 474 | 476 | warn("Expected -D{s} to be a boolean, but received a list.\n\n", .{name}); |
| 475 | 477 | self.markInvalidUserInput(); |
| 476 | 478 | return null; |
| 477 | 479 | }, |
| 478 | 480 | }, |
| 479 | | .Int => switch (option_ptr.value) { |
| 480 | | .Flag => { |
| 481 | .int => switch (option_ptr.value) { |
| 482 | .flag => { |
| 481 | 483 | warn("Expected -D{s} to be an integer, but received a boolean.\n\n", .{name}); |
| 482 | 484 | self.markInvalidUserInput(); |
| 483 | 485 | return null; |
| 484 | 486 | }, |
| 485 | | .Scalar => |s| { |
| 487 | .scalar => |s| { |
| 486 | 488 | const n = std.fmt.parseInt(T, s, 10) catch |err| switch (err) { |
| 487 | 489 | error.Overflow => { |
| 488 | 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 | 499 | }; |
| 498 | 500 | return n; |
| 499 | 501 | }, |
| 500 | | .List => { |
| 502 | .list => { |
| 501 | 503 | warn("Expected -D{s} to be an integer, but received a list.\n\n", .{name}); |
| 502 | 504 | self.markInvalidUserInput(); |
| 503 | 505 | return null; |
| 504 | 506 | }, |
| 505 | 507 | }, |
| 506 | | .Float => switch (option_ptr.value) { |
| 507 | | .Flag => { |
| 508 | .float => switch (option_ptr.value) { |
| 509 | .flag => { |
| 508 | 510 | warn("Expected -D{s} to be a float, but received a boolean.\n\n", .{name}); |
| 509 | 511 | self.markInvalidUserInput(); |
| 510 | 512 | return null; |
| 511 | 513 | }, |
| 512 | | .Scalar => |s| { |
| 514 | .scalar => |s| { |
| 513 | 515 | const n = std.fmt.parseFloat(T, s) catch |err| { |
| 514 | 516 | warn("Expected -D{s} to be a float of type {s}.\n\n", .{ name, @typeName(T) }); |
| 515 | 517 | self.markInvalidUserInput(); |
| ... | ... | @@ -517,19 +519,19 @@ pub const Builder = struct { |
| 517 | 519 | }; |
| 518 | 520 | return n; |
| 519 | 521 | }, |
| 520 | | .List => { |
| 522 | .list => { |
| 521 | 523 | warn("Expected -D{s} to be a float, but received a list.\n\n", .{name}); |
| 522 | 524 | self.markInvalidUserInput(); |
| 523 | 525 | return null; |
| 524 | 526 | }, |
| 525 | 527 | }, |
| 526 | | .Enum => switch (option_ptr.value) { |
| 527 | | .Flag => { |
| 528 | .@"enum" => switch (option_ptr.value) { |
| 529 | .flag => { |
| 528 | 530 | warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name}); |
| 529 | 531 | self.markInvalidUserInput(); |
| 530 | 532 | return null; |
| 531 | 533 | }, |
| 532 | | .Scalar => |s| { |
| 534 | .scalar => |s| { |
| 533 | 535 | if (std.meta.stringToEnum(T, s)) |enum_lit| { |
| 534 | 536 | return enum_lit; |
| 535 | 537 | } else { |
| ... | ... | @@ -538,35 +540,35 @@ pub const Builder = struct { |
| 538 | 540 | return null; |
| 539 | 541 | } |
| 540 | 542 | }, |
| 541 | | .List => { |
| 543 | .list => { |
| 542 | 544 | warn("Expected -D{s} to be a string, but received a list.\n\n", .{name}); |
| 543 | 545 | self.markInvalidUserInput(); |
| 544 | 546 | return null; |
| 545 | 547 | }, |
| 546 | 548 | }, |
| 547 | | .String => switch (option_ptr.value) { |
| 548 | | .Flag => { |
| 549 | .string => switch (option_ptr.value) { |
| 550 | .flag => { |
| 549 | 551 | warn("Expected -D{s} to be a string, but received a boolean.\n\n", .{name}); |
| 550 | 552 | self.markInvalidUserInput(); |
| 551 | 553 | return null; |
| 552 | 554 | }, |
| 553 | | .List => { |
| 555 | .list => { |
| 554 | 556 | warn("Expected -D{s} to be a string, but received a list.\n\n", .{name}); |
| 555 | 557 | self.markInvalidUserInput(); |
| 556 | 558 | return null; |
| 557 | 559 | }, |
| 558 | | .Scalar => |s| return s, |
| 560 | .scalar => |s| return s, |
| 559 | 561 | }, |
| 560 | | .List => switch (option_ptr.value) { |
| 561 | | .Flag => { |
| 562 | .list => switch (option_ptr.value) { |
| 563 | .flag => { |
| 562 | 564 | warn("Expected -D{s} to be a list, but received a boolean.\n\n", .{name}); |
| 563 | 565 | self.markInvalidUserInput(); |
| 564 | 566 | return null; |
| 565 | 567 | }, |
| 566 | | .Scalar => |s| { |
| 568 | .scalar => |s| { |
| 567 | 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 | 576 | pub fn step(self: *Builder, name: []const u8, description: []const u8) *Step { |
| 575 | 577 | const step_info = self.allocator.create(TopLevelStep) catch unreachable; |
| 576 | 578 | step_info.* = TopLevelStep{ |
| 577 | | .step = Step.initNoOp(.TopLevel, name, self.allocator), |
| 579 | .step = Step.initNoOp(.top_level, name, self.allocator), |
| 578 | 580 | .description = self.dupe(description), |
| 579 | 581 | }; |
| 580 | 582 | self.top_level_steps.append(step_info) catch unreachable; |
| ... | ... | @@ -721,7 +723,7 @@ pub const Builder = struct { |
| 721 | 723 | if (!gop.found_existing) { |
| 722 | 724 | gop.value_ptr.* = UserInputOption{ |
| 723 | 725 | .name = name, |
| 724 | | .value = UserValue{ .Scalar = value }, |
| 726 | .value = .{ .scalar = value }, |
| 725 | 727 | .used = false, |
| 726 | 728 | }; |
| 727 | 729 | return false; |
| ... | ... | @@ -729,27 +731,27 @@ pub const Builder = struct { |
| 729 | 731 | |
| 730 | 732 | // option already exists |
| 731 | 733 | switch (gop.value_ptr.value) { |
| 732 | | UserValue.Scalar => |s| { |
| 734 | .scalar => |s| { |
| 733 | 735 | // turn it into a list |
| 734 | 736 | var list = ArrayList([]const u8).init(self.allocator); |
| 735 | 737 | list.append(s) catch unreachable; |
| 736 | 738 | list.append(value) catch unreachable; |
| 737 | | self.user_input_options.put(name, UserInputOption{ |
| 739 | self.user_input_options.put(name, .{ |
| 738 | 740 | .name = name, |
| 739 | | .value = UserValue{ .List = list }, |
| 741 | .value = .{ .list = list }, |
| 740 | 742 | .used = false, |
| 741 | 743 | }) catch unreachable; |
| 742 | 744 | }, |
| 743 | | UserValue.List => |*list| { |
| 745 | .list => |*list| { |
| 744 | 746 | // append to the list |
| 745 | 747 | list.append(value) catch unreachable; |
| 746 | | self.user_input_options.put(name, UserInputOption{ |
| 748 | self.user_input_options.put(name, .{ |
| 747 | 749 | .name = name, |
| 748 | | .value = UserValue{ .List = list.* }, |
| 750 | .value = .{ .list = list.* }, |
| 749 | 751 | .used = false, |
| 750 | 752 | }) catch unreachable; |
| 751 | 753 | }, |
| 752 | | UserValue.Flag => { |
| 754 | .flag => { |
| 753 | 755 | warn("Option '-D{s}={s}' conflicts with flag '-D{s}'.\n", .{ name, value, name }); |
| 754 | 756 | return true; |
| 755 | 757 | }, |
| ... | ... | @@ -761,9 +763,9 @@ pub const Builder = struct { |
| 761 | 763 | const name = self.dupe(name_raw); |
| 762 | 764 | const gop = try self.user_input_options.getOrPut(name); |
| 763 | 765 | if (!gop.found_existing) { |
| 764 | | gop.value_ptr.* = UserInputOption{ |
| 766 | gop.value_ptr.* = .{ |
| 765 | 767 | .name = name, |
| 766 | | .value = UserValue{ .Flag = {} }, |
| 768 | .value = .{ .flag = {} }, |
| 767 | 769 | .used = false, |
| 768 | 770 | }; |
| 769 | 771 | return false; |
| ... | ... | @@ -771,28 +773,28 @@ pub const Builder = struct { |
| 771 | 773 | |
| 772 | 774 | // option already exists |
| 773 | 775 | switch (gop.value_ptr.value) { |
| 774 | | UserValue.Scalar => |s| { |
| 776 | .scalar => |s| { |
| 775 | 777 | warn("Flag '-D{s}' conflicts with option '-D{s}={s}'.\n", .{ name, name, s }); |
| 776 | 778 | return true; |
| 777 | 779 | }, |
| 778 | | UserValue.List => { |
| 780 | .list => { |
| 779 | 781 | warn("Flag '-D{s}' conflicts with multiple options of the same name.\n", .{name}); |
| 780 | 782 | return true; |
| 781 | 783 | }, |
| 782 | | UserValue.Flag => {}, |
| 784 | .flag => {}, |
| 783 | 785 | } |
| 784 | 786 | return false; |
| 785 | 787 | } |
| 786 | 788 | |
| 787 | 789 | fn typeToEnum(comptime T: type) TypeId { |
| 788 | 790 | return switch (@typeInfo(T)) { |
| 789 | | .Int => .Int, |
| 790 | | .Float => .Float, |
| 791 | | .Bool => .Bool, |
| 792 | | .Enum => .Enum, |
| 791 | .Int => .int, |
| 792 | .Float => .float, |
| 793 | .Bool => .bool, |
| 794 | .Enum => .@"enum", |
| 793 | 795 | else => switch (T) { |
| 794 | | []const u8 => .String, |
| 795 | | []const []const u8 => .List, |
| 796 | []const u8 => .string, |
| 797 | []const []const u8 => .list, |
| 796 | 798 | else => @compileError("Unsupported type: " ++ @typeName(T)), |
| 797 | 799 | }, |
| 798 | 800 | }; |
| ... | ... | @@ -802,17 +804,6 @@ pub const Builder = struct { |
| 802 | 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 | 807 | pub fn validateUserInputDidItFail(self: *Builder) bool { |
| 817 | 808 | // make sure all args are used |
| 818 | 809 | var it = self.user_input_options.iterator(); |
| ... | ... | @@ -888,7 +879,7 @@ pub const Builder = struct { |
| 888 | 879 | |
| 889 | 880 | ///`dest_rel_path` is relative to prefix path |
| 890 | 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 | 885 | pub fn installDirectory(self: *Builder, options: InstallDirectoryOptions) void { |
| ... | ... | @@ -897,12 +888,12 @@ pub const Builder = struct { |
| 897 | 888 | |
| 898 | 889 | ///`dest_rel_path` is relative to bin path |
| 899 | 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 | 894 | ///`dest_rel_path` is relative to lib path |
| 904 | 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 | 899 | pub fn installRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) void { |
| ... | ... | @@ -911,17 +902,17 @@ pub const Builder = struct { |
| 911 | 902 | |
| 912 | 903 | ///`dest_rel_path` is relative to install prefix path |
| 913 | 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 | 908 | ///`dest_rel_path` is relative to bin path |
| 918 | 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 | 913 | ///`dest_rel_path` is relative to lib path |
| 923 | 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 | 918 | pub fn addInstallRaw(self: *Builder, artifact: *LibExeObjStep, dest_filename: []const u8) *InstallRawStep { |
| ... | ... | @@ -1119,11 +1110,11 @@ pub const Builder = struct { |
| 1119 | 1110 | pub fn getInstallPath(self: *Builder, dir: InstallDir, dest_rel_path: []const u8) []const u8 { |
| 1120 | 1111 | assert(!fs.path.isAbsolute(dest_rel_path)); // Install paths must be relative to the prefix |
| 1121 | 1112 | const base_dir = switch (dir) { |
| 1122 | | .Prefix => self.install_path, |
| 1123 | | .Bin => self.exe_dir, |
| 1124 | | .Lib => self.lib_dir, |
| 1125 | | .Header => self.h_dir, |
| 1126 | | .Custom => |path| fs.path.join(self.allocator, &[_][]const u8{ self.install_path, path }) catch unreachable, |
| 1113 | .prefix => self.install_path, |
| 1114 | .bin => self.exe_dir, |
| 1115 | .lib => self.lib_dir, |
| 1116 | .header => self.h_dir, |
| 1117 | .custom => |path| fs.path.join(self.allocator, &[_][]const u8{ self.install_path, path }) catch unreachable, |
| 1127 | 1118 | }; |
| 1128 | 1119 | return fs.path.resolve( |
| 1129 | 1120 | self.allocator, |
| ... | ... | @@ -1315,6 +1306,8 @@ const BuildOptionFileSourceArg = struct { |
| 1315 | 1306 | }; |
| 1316 | 1307 | |
| 1317 | 1308 | pub const LibExeObjStep = struct { |
| 1309 | pub const base_id = .lib_exe_obj; |
| 1310 | |
| 1318 | 1311 | step: Step, |
| 1319 | 1312 | builder: *Builder, |
| 1320 | 1313 | name: []const u8, |
| ... | ... | @@ -1451,10 +1444,10 @@ pub const LibExeObjStep = struct { |
| 1451 | 1444 | }; |
| 1452 | 1445 | |
| 1453 | 1446 | const Kind = enum { |
| 1454 | | Exe, |
| 1455 | | Lib, |
| 1456 | | Obj, |
| 1457 | | Test, |
| 1447 | exe, |
| 1448 | lib, |
| 1449 | obj, |
| 1450 | @"test", |
| 1458 | 1451 | }; |
| 1459 | 1452 | |
| 1460 | 1453 | const SharedLibKind = union(enum) { |
| ... | ... | @@ -1465,26 +1458,26 @@ pub const LibExeObjStep = struct { |
| 1465 | 1458 | pub const Linkage = enum { dynamic, static }; |
| 1466 | 1459 | |
| 1467 | 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 | 1462 | .versioned => |ver| ver, |
| 1470 | 1463 | .unversioned => null, |
| 1471 | 1464 | }); |
| 1472 | 1465 | } |
| 1473 | 1466 | |
| 1474 | 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 | 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 | 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 | 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 | 1483 | fn initExtraArgs( |
| ... | ... | @@ -1513,7 +1506,7 @@ pub const LibExeObjStep = struct { |
| 1513 | 1506 | .root_src = root_src, |
| 1514 | 1507 | .name = name, |
| 1515 | 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 | 1510 | .version = ver, |
| 1518 | 1511 | .out_filename = undefined, |
| 1519 | 1512 | .out_h_filename = builder.fmt("{s}.h", .{name}), |
| ... | ... | @@ -1568,18 +1561,18 @@ pub const LibExeObjStep = struct { |
| 1568 | 1561 | .root_name = self.name, |
| 1569 | 1562 | .target = target, |
| 1570 | 1563 | .output_mode = switch (self.kind) { |
| 1571 | | .Lib => .Lib, |
| 1572 | | .Obj => .Obj, |
| 1573 | | .Exe, .Test => .Exe, |
| 1564 | .lib => .Lib, |
| 1565 | .obj => .Obj, |
| 1566 | .exe, .@"test" => .Exe, |
| 1574 | 1567 | }, |
| 1575 | 1568 | .link_mode = switch (self.linkage) { |
| 1576 | | .dynamic => std.builtin.LinkMode.Dynamic, |
| 1577 | | .static => std.builtin.LinkMode.Static, |
| 1569 | .dynamic => .Dynamic, |
| 1570 | .static => .Static, |
| 1578 | 1571 | }, |
| 1579 | 1572 | .version = self.version, |
| 1580 | 1573 | }) catch unreachable; |
| 1581 | 1574 | |
| 1582 | | if (self.kind == .Lib) { |
| 1575 | if (self.kind == .lib) { |
| 1583 | 1576 | if (self.linkage == .static) { |
| 1584 | 1577 | self.out_lib_filename = self.out_filename; |
| 1585 | 1578 | } else if (self.version) |version| { |
| ... | ... | @@ -1636,7 +1629,7 @@ pub const LibExeObjStep = struct { |
| 1636 | 1629 | /// Creates a `RunStep` with an executable built with `addExecutable`. |
| 1637 | 1630 | /// Add command line arguments with `addArg`. |
| 1638 | 1631 | pub fn run(exe: *LibExeObjStep) *RunStep { |
| 1639 | | assert(exe.kind == Kind.Exe); |
| 1632 | assert(exe.kind == .exe); |
| 1640 | 1633 | |
| 1641 | 1634 | // It doesn't have to be native. We catch that if you actually try to run it. |
| 1642 | 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 | 1672 | } |
| 1680 | 1673 | |
| 1681 | 1674 | pub fn linkLibrary(self: *LibExeObjStep, lib: *LibExeObjStep) void { |
| 1682 | | assert(lib.kind == Kind.Lib); |
| 1675 | assert(lib.kind == .lib); |
| 1683 | 1676 | self.linkLibraryOrObject(lib); |
| 1684 | 1677 | } |
| 1685 | 1678 | |
| 1686 | 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 | 1683 | pub fn producesPdbFile(self: *LibExeObjStep) bool { |
| 1691 | 1684 | if (!self.target.isWindows() and !self.target.isUefi()) return false; |
| 1692 | 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 | 1689 | pub fn linkLibC(self: *LibExeObjStep) void { |
| 1697 | 1690 | if (!self.is_linking_libc) { |
| 1698 | 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 | 1696 | pub fn linkLibCpp(self: *LibExeObjStep) void { |
| 1704 | 1697 | if (!self.is_linking_libcpp) { |
| 1705 | 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 | 1708 | /// This one has no integration with anything, it just puts -lname on the command line. |
| 1716 | 1709 | /// Prefer to use `linkSystemLibrary` instead. |
| 1717 | 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 | 1714 | /// This links against a system library, exclusively using pkg-config to find the library. |
| ... | ... | @@ -1835,12 +1828,12 @@ pub const LibExeObjStep = struct { |
| 1835 | 1828 | } |
| 1836 | 1829 | |
| 1837 | 1830 | pub fn setNamePrefix(self: *LibExeObjStep, text: []const u8) void { |
| 1838 | | assert(self.kind == Kind.Test); |
| 1831 | assert(self.kind == .@"test"); |
| 1839 | 1832 | self.name_prefix = self.builder.dupe(text); |
| 1840 | 1833 | } |
| 1841 | 1834 | |
| 1842 | 1835 | pub fn setFilter(self: *LibExeObjStep, text: ?[]const u8) void { |
| 1843 | | assert(self.kind == Kind.Test); |
| 1836 | assert(self.kind == .@"test"); |
| 1844 | 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 | 1848 | .files = files_copy, |
| 1856 | 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 | 1854 | pub fn addCSourceFile(self: *LibExeObjStep, file: []const u8, flags: []const []const u8) void { |
| ... | ... | @@ -1868,7 +1861,7 @@ pub const LibExeObjStep = struct { |
| 1868 | 1861 | pub fn addCSourceFileSource(self: *LibExeObjStep, source: CSourceFile) void { |
| 1869 | 1862 | const c_source_file = self.builder.allocator.create(CSourceFile) catch unreachable; |
| 1870 | 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 | 1865 | source.source.addStepDependencies(&self.step); |
| 1873 | 1866 | } |
| 1874 | 1867 | |
| ... | ... | @@ -1904,14 +1897,14 @@ pub const LibExeObjStep = struct { |
| 1904 | 1897 | |
| 1905 | 1898 | /// Returns the generated import library. This function can only be called for libraries. |
| 1906 | 1899 | pub fn getOutputLibSource(self: *LibExeObjStep) FileSource { |
| 1907 | | assert(self.kind == Kind.Lib); |
| 1900 | assert(self.kind == .lib); |
| 1908 | 1901 | return FileSource{ .generated = &self.output_lib_path_source }; |
| 1909 | 1902 | } |
| 1910 | 1903 | |
| 1911 | 1904 | /// Returns the generated header file. |
| 1912 | 1905 | /// This function can only be called for libraries or object files which have `emit_h` set. |
| 1913 | 1906 | pub fn getOutputHSource(self: *LibExeObjStep) FileSource { |
| 1914 | | assert(self.kind != Kind.Exe); |
| 1907 | assert(self.kind != .exe); |
| 1915 | 1908 | assert(self.emit_h); |
| 1916 | 1909 | return FileSource{ .generated = &self.output_h_path_source }; |
| 1917 | 1910 | } |
| ... | ... | @@ -1924,14 +1917,14 @@ pub const LibExeObjStep = struct { |
| 1924 | 1917 | } |
| 1925 | 1918 | |
| 1926 | 1919 | pub fn addAssemblyFile(self: *LibExeObjStep, path: []const u8) void { |
| 1927 | | self.link_objects.append(LinkObject{ |
| 1920 | self.link_objects.append(.{ |
| 1928 | 1921 | .assembly_file = .{ .path = self.builder.dupe(path) }, |
| 1929 | 1922 | }) catch unreachable; |
| 1930 | 1923 | } |
| 1931 | 1924 | |
| 1932 | 1925 | pub fn addAssemblyFileSource(self: *LibExeObjStep, source: FileSource) void { |
| 1933 | 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 | 1928 | source_duped.addStepDependencies(&self.step); |
| 1936 | 1929 | } |
| 1937 | 1930 | |
| ... | ... | @@ -1940,12 +1933,12 @@ pub const LibExeObjStep = struct { |
| 1940 | 1933 | } |
| 1941 | 1934 | |
| 1942 | 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 | 1937 | source.addStepDependencies(&self.step); |
| 1945 | 1938 | } |
| 1946 | 1939 | |
| 1947 | 1940 | pub fn addObject(self: *LibExeObjStep, obj: *LibExeObjStep) void { |
| 1948 | | assert(obj.kind == Kind.Obj); |
| 1941 | assert(obj.kind == .obj); |
| 1949 | 1942 | self.linkLibraryOrObject(obj); |
| 1950 | 1943 | } |
| 1951 | 1944 | |
| ... | ... | @@ -2105,7 +2098,7 @@ pub const LibExeObjStep = struct { |
| 2105 | 2098 | |
| 2106 | 2099 | /// If Vcpkg was found on the system, it will be added to include and lib |
| 2107 | 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 | 2102 | // Ideally in the Unattempted case we would call the function recursively |
| 2110 | 2103 | // after findVcpkgRoot and have only one switch statement, but the compiler |
| 2111 | 2104 | // cannot resolve the error set. |
| ... | ... | @@ -2125,7 +2118,7 @@ pub const LibExeObjStep = struct { |
| 2125 | 2118 | .not_found => return error.VcpkgNotFound, |
| 2126 | 2119 | .found => |root| { |
| 2127 | 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 | 2122 | defer self.builder.allocator.free(triplet); |
| 2130 | 2123 | |
| 2131 | 2124 | const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" }); |
| ... | ... | @@ -2141,7 +2134,7 @@ pub const LibExeObjStep = struct { |
| 2141 | 2134 | } |
| 2142 | 2135 | |
| 2143 | 2136 | pub fn setExecCmd(self: *LibExeObjStep, args: []const ?[]const u8) void { |
| 2144 | | assert(self.kind == Kind.Test); |
| 2137 | assert(self.kind == .@"test"); |
| 2145 | 2138 | const duped_args = self.builder.allocator.alloc(?[]u8, args.len) catch unreachable; |
| 2146 | 2139 | for (args) |arg, i| { |
| 2147 | 2140 | duped_args[i] = if (arg) |a| self.builder.dupe(a) else null; |
| ... | ... | @@ -2151,8 +2144,8 @@ pub const LibExeObjStep = struct { |
| 2151 | 2144 | |
| 2152 | 2145 | fn linkLibraryOrObject(self: *LibExeObjStep, other: *LibExeObjStep) void { |
| 2153 | 2146 | self.step.dependOn(&other.step); |
| 2154 | | self.link_objects.append(LinkObject{ .other_step = other }) catch unreachable; |
| 2155 | | self.include_dirs.append(IncludeDir{ .other_step = other }) catch unreachable; |
| 2147 | self.link_objects.append(.{ .other_step = other }) catch unreachable; |
| 2148 | self.include_dirs.append(.{ .other_step = other }) catch unreachable; |
| 2156 | 2149 | |
| 2157 | 2150 | // BUG: The following code introduces a order-of-call dependency: |
| 2158 | 2151 | // var lib = addSharedLibrary(...); |
| ... | ... | @@ -2208,10 +2201,10 @@ pub const LibExeObjStep = struct { |
| 2208 | 2201 | zig_args.append(builder.zig_exe) catch unreachable; |
| 2209 | 2202 | |
| 2210 | 2203 | const cmd = switch (self.kind) { |
| 2211 | | .Lib => "build-lib", |
| 2212 | | .Exe => "build-exe", |
| 2213 | | .Obj => "build-obj", |
| 2214 | | .Test => "test", |
| 2204 | .lib => "build-lib", |
| 2205 | .exe => "build-exe", |
| 2206 | .obj => "build-obj", |
| 2207 | .@"test" => "test", |
| 2215 | 2208 | }; |
| 2216 | 2209 | zig_args.append(cmd) catch unreachable; |
| 2217 | 2210 | |
| ... | ... | @@ -2233,12 +2226,12 @@ pub const LibExeObjStep = struct { |
| 2233 | 2226 | .static_path => |static_path| try zig_args.append(static_path.getPath(builder)), |
| 2234 | 2227 | |
| 2235 | 2228 | .other_step => |other| switch (other.kind) { |
| 2236 | | .Exe => unreachable, |
| 2237 | | .Test => unreachable, |
| 2238 | | .Obj => { |
| 2229 | .exe => unreachable, |
| 2230 | .@"test" => unreachable, |
| 2231 | .obj => { |
| 2239 | 2232 | try zig_args.append(other.getOutputSource().getPath(builder)); |
| 2240 | 2233 | }, |
| 2241 | | .Lib => { |
| 2234 | .lib => { |
| 2242 | 2235 | const full_path_lib = other.getOutputLibSource().getPath(builder); |
| 2243 | 2236 | try zig_args.append(full_path_lib); |
| 2244 | 2237 | |
| ... | ... | @@ -2408,7 +2401,7 @@ pub const LibExeObjStep = struct { |
| 2408 | 2401 | zig_args.append("--name") catch unreachable; |
| 2409 | 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 | 2405 | if (self.version) |version| { |
| 2413 | 2406 | zig_args.append("--version") catch unreachable; |
| 2414 | 2407 | zig_args.append(builder.fmt("{}", .{version})) catch unreachable; |
| ... | ... | @@ -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 | 2679 | try builder.spawnChild(zig_args.items); |
| 2687 | 2680 | } else { |
| 2688 | 2681 | try zig_args.append("--enable-cache"); |
| ... | ... | @@ -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 | 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 | 2747 | pub const InstallArtifactStep = struct { |
| 2748 | pub const base_id = .install_artifact; |
| 2749 | |
| 2755 | 2750 | step: Step, |
| 2756 | 2751 | builder: *Builder, |
| 2757 | 2752 | artifact: *LibExeObjStep, |
| ... | ... | @@ -2767,22 +2762,22 @@ pub const InstallArtifactStep = struct { |
| 2767 | 2762 | const self = builder.allocator.create(Self) catch unreachable; |
| 2768 | 2763 | self.* = Self{ |
| 2769 | 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 | 2766 | .artifact = artifact, |
| 2772 | 2767 | .dest_dir = artifact.override_dest_dir orelse switch (artifact.kind) { |
| 2773 | | .Obj => unreachable, |
| 2774 | | .Test => unreachable, |
| 2775 | | .Exe => InstallDir{ .Bin = {} }, |
| 2776 | | .Lib => InstallDir{ .Lib = {} }, |
| 2768 | .obj => unreachable, |
| 2769 | .@"test" => unreachable, |
| 2770 | .exe => InstallDir{ .bin = {} }, |
| 2771 | .lib => InstallDir{ .lib = {} }, |
| 2777 | 2772 | }, |
| 2778 | 2773 | .pdb_dir = if (artifact.producesPdbFile()) blk: { |
| 2779 | | if (artifact.kind == .Exe) { |
| 2780 | | break :blk InstallDir{ .Bin = {} }; |
| 2774 | if (artifact.kind == .exe) { |
| 2775 | break :blk InstallDir{ .bin = {} }; |
| 2781 | 2776 | } else { |
| 2782 | | break :blk InstallDir{ .Lib = {} }; |
| 2777 | break :blk InstallDir{ .lib = {} }; |
| 2783 | 2778 | } |
| 2784 | 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 | 2782 | self.step.dependOn(&artifact.step); |
| 2788 | 2783 | artifact.install_step = self; |
| ... | ... | @@ -2790,13 +2785,13 @@ pub const InstallArtifactStep = struct { |
| 2790 | 2785 | builder.pushInstalledFile(self.dest_dir, artifact.out_filename); |
| 2791 | 2786 | if (self.artifact.isDynamicLibrary()) { |
| 2792 | 2787 | if (artifact.major_only_filename) |name| { |
| 2793 | | builder.pushInstalledFile(.Lib, name); |
| 2788 | builder.pushInstalledFile(.lib, name); |
| 2794 | 2789 | } |
| 2795 | 2790 | if (artifact.name_only_filename) |name| { |
| 2796 | | builder.pushInstalledFile(.Lib, name); |
| 2791 | builder.pushInstalledFile(.lib, name); |
| 2797 | 2792 | } |
| 2798 | 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 | 2797 | if (self.pdb_dir) |pdb_dir| { |
| ... | ... | @@ -2830,6 +2825,8 @@ pub const InstallArtifactStep = struct { |
| 2830 | 2825 | }; |
| 2831 | 2826 | |
| 2832 | 2827 | pub const InstallFileStep = struct { |
| 2828 | pub const base_id = .install_file; |
| 2829 | |
| 2833 | 2830 | step: Step, |
| 2834 | 2831 | builder: *Builder, |
| 2835 | 2832 | source: FileSource, |
| ... | ... | @@ -2845,7 +2842,7 @@ pub const InstallFileStep = struct { |
| 2845 | 2842 | builder.pushInstalledFile(dir, dest_rel_path); |
| 2846 | 2843 | return InstallFileStep{ |
| 2847 | 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 | 2846 | .source = source.dupe(builder), |
| 2850 | 2847 | .dir = dir.dupe(builder), |
| 2851 | 2848 | .dest_rel_path = builder.dupePath(dest_rel_path), |
| ... | ... | @@ -2886,6 +2883,8 @@ pub const InstallDirectoryOptions = struct { |
| 2886 | 2883 | }; |
| 2887 | 2884 | |
| 2888 | 2885 | pub const InstallDirStep = struct { |
| 2886 | pub const base_id = .install_dir; |
| 2887 | |
| 2889 | 2888 | step: Step, |
| 2890 | 2889 | builder: *Builder, |
| 2891 | 2890 | options: InstallDirectoryOptions, |
| ... | ... | @@ -2897,7 +2896,7 @@ pub const InstallDirStep = struct { |
| 2897 | 2896 | builder.pushInstalledFile(options.install_dir, options.install_subdir); |
| 2898 | 2897 | return InstallDirStep{ |
| 2899 | 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 | 2900 | .options = options.dupe(builder), |
| 2902 | 2901 | }; |
| 2903 | 2902 | } |
| ... | ... | @@ -2938,6 +2937,8 @@ pub const InstallDirStep = struct { |
| 2938 | 2937 | }; |
| 2939 | 2938 | |
| 2940 | 2939 | pub const LogStep = struct { |
| 2940 | pub const base_id = .log; |
| 2941 | |
| 2941 | 2942 | step: Step, |
| 2942 | 2943 | builder: *Builder, |
| 2943 | 2944 | data: []const u8, |
| ... | ... | @@ -2945,7 +2946,7 @@ pub const LogStep = struct { |
| 2945 | 2946 | pub fn init(builder: *Builder, data: []const u8) LogStep { |
| 2946 | 2947 | return LogStep{ |
| 2947 | 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 | 2950 | .data = builder.dupe(data), |
| 2950 | 2951 | }; |
| 2951 | 2952 | } |
| ... | ... | @@ -2957,6 +2958,8 @@ pub const LogStep = struct { |
| 2957 | 2958 | }; |
| 2958 | 2959 | |
| 2959 | 2960 | pub const RemoveDirStep = struct { |
| 2961 | pub const base_id = .remove_dir; |
| 2962 | |
| 2960 | 2963 | step: Step, |
| 2961 | 2964 | builder: *Builder, |
| 2962 | 2965 | dir_path: []const u8, |
| ... | ... | @@ -2964,7 +2967,7 @@ pub const RemoveDirStep = struct { |
| 2964 | 2967 | pub fn init(builder: *Builder, dir_path: []const u8) RemoveDirStep { |
| 2965 | 2968 | return RemoveDirStep{ |
| 2966 | 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 | 2971 | .dir_path = builder.dupePath(dir_path), |
| 2969 | 2972 | }; |
| 2970 | 2973 | } |
| ... | ... | @@ -2990,20 +2993,20 @@ pub const Step = struct { |
| 2990 | 2993 | done_flag: bool, |
| 2991 | 2994 | |
| 2992 | 2995 | pub const Id = enum { |
| 2993 | | TopLevel, |
| 2994 | | LibExeObj, |
| 2995 | | InstallArtifact, |
| 2996 | | InstallFile, |
| 2997 | | InstallDir, |
| 2998 | | Log, |
| 2999 | | RemoveDir, |
| 3000 | | Fmt, |
| 3001 | | TranslateC, |
| 3002 | | WriteFile, |
| 3003 | | Run, |
| 3004 | | CheckFile, |
| 3005 | | InstallRaw, |
| 3006 | | Custom, |
| 2996 | top_level, |
| 2997 | lib_exe_obj, |
| 2998 | install_artifact, |
| 2999 | install_file, |
| 3000 | install_dir, |
| 3001 | log, |
| 3002 | remove_dir, |
| 3003 | fmt, |
| 3004 | translate_c, |
| 3005 | write_file, |
| 3006 | run, |
| 3007 | check_file, |
| 3008 | install_raw, |
| 3009 | custom, |
| 3007 | 3010 | }; |
| 3008 | 3011 | |
| 3009 | 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 | 3037 | fn makeNoOp(self: *Step) anyerror!void {} |
| 3035 | 3038 | |
| 3036 | 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 | 3041 | return @fieldParentPtr(T, "step", step); |
| 3039 | 3042 | } |
| 3040 | 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 | 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 | 3098 | found, |
| 3108 | 3099 | }; |
| 3109 | 3100 | |
| 3110 | | pub const VcpkgLinkage = std.builtin.LinkMode; |
| 3111 | | |
| 3112 | 3101 | pub const InstallDir = union(enum) { |
| 3113 | | Prefix: void, |
| 3114 | | Lib: void, |
| 3115 | | Bin: void, |
| 3116 | | Header: void, |
| 3102 | prefix: void, |
| 3103 | lib: void, |
| 3104 | bin: void, |
| 3105 | header: void, |
| 3117 | 3106 | /// A path relative to the prefix |
| 3118 | | Custom: []const u8, |
| 3107 | custom: []const u8, |
| 3119 | 3108 | |
| 3120 | 3109 | fn dupe(self: InstallDir, builder: *Builder) InstallDir { |
| 3121 | | if (self == .Custom) { |
| 3110 | if (self == .custom) { |
| 3122 | 3111 | // Written with this temporary to avoid RLS problems |
| 3123 | | const duped_path = builder.dupe(self.Custom); |
| 3124 | | return .{ .Custom = duped_path }; |
| 3112 | const duped_path = builder.dupe(self.custom); |
| 3113 | return .{ .custom = duped_path }; |
| 3125 | 3114 | } else { |
| 3126 | 3115 | return self; |
| 3127 | 3116 | } |