| ... | @@ -204,10 +204,10 @@ pub const Builder = struct { | ... | @@ -204,10 +204,10 @@ pub const Builder = struct { |
| 204 | pub fn resolveInstallPrefix(self: *Builder, install_prefix: ?[]const u8, dir_list: DirList) void { | 204 | pub fn resolveInstallPrefix(self: *Builder, install_prefix: ?[]const u8, dir_list: DirList) void { |
| 205 | if (self.dest_dir) |dest_dir| { | 205 | if (self.dest_dir) |dest_dir| { |
| 206 | self.install_prefix = install_prefix orelse "/usr"; | 206 | self.install_prefix = install_prefix orelse "/usr"; |
| 207 | self.install_path = fs.path.join(self.allocator, &[_][]const u8{ dest_dir, self.install_prefix }) catch unreachable; | 207 | self.install_path = self.pathJoin(&.{ dest_dir, self.install_prefix }); |
| 208 | } else { | 208 | } else { |
| 209 | self.install_prefix = install_prefix orelse | 209 | self.install_prefix = install_prefix orelse |
| 210 | (fs.path.join(self.allocator, &[_][]const u8{ self.build_root, "zig-out" }) catch unreachable); | 210 | (self.pathJoin(&.{ self.build_root, "zig-out" })); |
| 211 | self.install_path = self.install_prefix; | 211 | self.install_path = self.install_prefix; |
| 212 | } | 212 | } |
| 213 | | 213 | |
| ... | @@ -230,9 +230,9 @@ pub const Builder = struct { | ... | @@ -230,9 +230,9 @@ pub const Builder = struct { |
| 230 | h_list[1] = dir; | 230 | h_list[1] = dir; |
| 231 | } | 231 | } |
| 232 | | 232 | |
| 233 | self.lib_dir = fs.path.join(self.allocator, &lib_list) catch unreachable; | 233 | self.lib_dir = self.pathJoin(&lib_list); |
| 234 | self.exe_dir = fs.path.join(self.allocator, &exe_list) catch unreachable; | 234 | self.exe_dir = self.pathJoin(&exe_list); |
| 235 | self.h_dir = fs.path.join(self.allocator, &h_list) catch unreachable; | 235 | self.h_dir = self.pathJoin(&h_list); |
| 236 | } | 236 | } |
| 237 | | 237 | |
| 238 | fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource { | 238 | fn convertOptionalPathToFileSource(path: ?[]const u8) ?FileSource { |
| ... | @@ -1086,6 +1086,11 @@ pub const Builder = struct { | ... | @@ -1086,6 +1086,11 @@ pub const Builder = struct { |
| 1086 | return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable; | 1086 | return fs.path.resolve(self.allocator, &[_][]const u8{ self.build_root, rel_path }) catch unreachable; |
| 1087 | } | 1087 | } |
| 1088 | | 1088 | |
| | 1089 | /// Shorthand for `std.fs.path.join(builder.allocator, paths) catch unreachable` |
| | 1090 | pub fn pathJoin(self: *Builder, paths: []const []const u8) []u8 { |
| | 1091 | return fs.path.join(self.allocator, paths) catch unreachable; |
| | 1092 | } |
| | 1093 | |
| 1089 | pub fn fmt(self: *Builder, comptime format: []const u8, args: anytype) []u8 { | 1094 | pub fn fmt(self: *Builder, comptime format: []const u8, args: anytype) []u8 { |
| 1090 | return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable; | 1095 | return fmt_lib.allocPrint(self.allocator, format, args) catch unreachable; |
| 1091 | } | 1096 | } |
| ... | @@ -1098,7 +1103,7 @@ pub const Builder = struct { | ... | @@ -1098,7 +1103,7 @@ pub const Builder = struct { |
| 1098 | if (fs.path.isAbsolute(name)) { | 1103 | if (fs.path.isAbsolute(name)) { |
| 1099 | return name; | 1104 | return name; |
| 1100 | } | 1105 | } |
| 1101 | const full_path = try fs.path.join(self.allocator, &[_][]const u8{ | 1106 | const full_path = self.pathJoin(&.{ |
| 1102 | search_prefix, | 1107 | search_prefix, |
| 1103 | "bin", | 1108 | "bin", |
| 1104 | self.fmt("{s}{s}", .{ name, exe_extension }), | 1109 | self.fmt("{s}{s}", .{ name, exe_extension }), |
| ... | @@ -1113,7 +1118,7 @@ pub const Builder = struct { | ... | @@ -1113,7 +1118,7 @@ pub const Builder = struct { |
| 1113 | } | 1118 | } |
| 1114 | var it = mem.tokenize(u8, PATH, &[_]u8{fs.path.delimiter}); | 1119 | var it = mem.tokenize(u8, PATH, &[_]u8{fs.path.delimiter}); |
| 1115 | while (it.next()) |path| { | 1120 | while (it.next()) |path| { |
| 1116 | const full_path = try fs.path.join(self.allocator, &[_][]const u8{ | 1121 | const full_path = self.pathJoin(&.{ |
| 1117 | path, | 1122 | path, |
| 1118 | self.fmt("{s}{s}", .{ name, exe_extension }), | 1123 | self.fmt("{s}{s}", .{ name, exe_extension }), |
| 1119 | }); | 1124 | }); |
| ... | @@ -1126,7 +1131,7 @@ pub const Builder = struct { | ... | @@ -1126,7 +1131,7 @@ pub const Builder = struct { |
| 1126 | return name; | 1131 | return name; |
| 1127 | } | 1132 | } |
| 1128 | for (paths) |path| { | 1133 | for (paths) |path| { |
| 1129 | const full_path = try fs.path.join(self.allocator, &[_][]const u8{ | 1134 | const full_path = self.pathJoin(&.{ |
| 1130 | path, | 1135 | path, |
| 1131 | self.fmt("{s}{s}", .{ name, exe_extension }), | 1136 | self.fmt("{s}{s}", .{ name, exe_extension }), |
| 1132 | }); | 1137 | }); |
| ... | @@ -1225,7 +1230,7 @@ pub const Builder = struct { | ... | @@ -1225,7 +1230,7 @@ pub const Builder = struct { |
| 1225 | .bin => self.exe_dir, | 1230 | .bin => self.exe_dir, |
| 1226 | .lib => self.lib_dir, | 1231 | .lib => self.lib_dir, |
| 1227 | .header => self.h_dir, | 1232 | .header => self.h_dir, |
| 1228 | .custom => |path| fs.path.join(self.allocator, &[_][]const u8{ self.install_path, path }) catch unreachable, | 1233 | .custom => |path| self.pathJoin(&.{ self.install_path, path }), |
| 1229 | }; | 1234 | }; |
| 1230 | return fs.path.resolve( | 1235 | return fs.path.resolve( |
| 1231 | self.allocator, | 1236 | self.allocator, |
| ... | @@ -1705,11 +1710,9 @@ pub const LibExeObjStep = struct { | ... | @@ -1705,11 +1710,9 @@ pub const LibExeObjStep = struct { |
| 1705 | } | 1710 | } |
| 1706 | } | 1711 | } |
| 1707 | if (self.output_dir != null) { | 1712 | if (self.output_dir != null) { |
| 1708 | self.output_lib_path_source.path = | 1713 | self.output_lib_path_source.path = self.builder.pathJoin( |
| 1709 | fs.path.join( | 1714 | &.{ self.output_dir.?, self.out_lib_filename }, |
| 1710 | self.builder.allocator, | 1715 | ); |
| 1711 | &[_][]const u8{ self.output_dir.?, self.out_lib_filename }, | | |
| 1712 | ) catch unreachable; | | |
| 1713 | } | 1716 | } |
| 1714 | } | 1717 | } |
| 1715 | } | 1718 | } |
| ... | @@ -2136,14 +2139,14 @@ pub const LibExeObjStep = struct { | ... | @@ -2136,14 +2139,14 @@ pub const LibExeObjStep = struct { |
| 2136 | const triplet = try self.target.vcpkgTriplet(allocator, if (linkage == .static) .Static else .Dynamic); | 2139 | const triplet = try self.target.vcpkgTriplet(allocator, if (linkage == .static) .Static else .Dynamic); |
| 2137 | defer self.builder.allocator.free(triplet); | 2140 | defer self.builder.allocator.free(triplet); |
| 2138 | | 2141 | |
| 2139 | const include_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "include" }); | 2142 | const include_path = self.builder.pathJoin(&.{ root, "installed", triplet, "include" }); |
| 2140 | errdefer allocator.free(include_path); | 2143 | errdefer allocator.free(include_path); |
| 2141 | try self.include_dirs.append(IncludeDir{ .raw_path = include_path }); | 2144 | try self.include_dirs.append(IncludeDir{ .raw_path = include_path }); |
| 2142 | | 2145 | |
| 2143 | const lib_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "lib" }); | 2146 | const lib_path = self.builder.pathJoin(&.{ root, "installed", triplet, "lib" }); |
| 2144 | try self.lib_paths.append(lib_path); | 2147 | try self.lib_paths.append(lib_path); |
| 2145 | | 2148 | |
| 2146 | self.vcpkg_bin_path = try fs.path.join(allocator, &[_][]const u8{ root, "installed", triplet, "bin" }); | 2149 | self.vcpkg_bin_path = self.builder.pathJoin(&.{ root, "installed", triplet, "bin" }); |
| 2147 | }, | 2150 | }, |
| 2148 | } | 2151 | } |
| 2149 | } | 2152 | } |
| ... | @@ -2655,11 +2658,11 @@ pub const LibExeObjStep = struct { | ... | @@ -2655,11 +2658,11 @@ pub const LibExeObjStep = struct { |
| 2655 | | 2658 | |
| 2656 | for (builder.search_prefixes.items) |search_prefix| { | 2659 | for (builder.search_prefixes.items) |search_prefix| { |
| 2657 | try zig_args.append("-L"); | 2660 | try zig_args.append("-L"); |
| 2658 | try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{ | 2661 | try zig_args.append(builder.pathJoin(&.{ |
| 2659 | search_prefix, "lib", | 2662 | search_prefix, "lib", |
| 2660 | })); | 2663 | })); |
| 2661 | try zig_args.append("-isystem"); | 2664 | try zig_args.append("-isystem"); |
| 2662 | try zig_args.append(try fs.path.join(builder.allocator, &[_][]const u8{ | 2665 | try zig_args.append(builder.pathJoin(&.{ |
| 2663 | search_prefix, "include", | 2666 | search_prefix, "include", |
| 2664 | })); | 2667 | })); |
| 2665 | } | 2668 | } |
| ... | @@ -2764,26 +2767,20 @@ pub const LibExeObjStep = struct { | ... | @@ -2764,26 +2767,20 @@ pub const LibExeObjStep = struct { |
| 2764 | | 2767 | |
| 2765 | // Update generated files | 2768 | // Update generated files |
| 2766 | if (self.output_dir != null) { | 2769 | if (self.output_dir != null) { |
| 2767 | self.output_path_source.path = | 2770 | self.output_path_source.path = builder.pathJoin( |
| 2768 | fs.path.join( | 2771 | &.{ self.output_dir.?, self.out_filename }, |
| 2769 | self.builder.allocator, | 2772 | ); |
| 2770 | &[_][]const u8{ self.output_dir.?, self.out_filename }, | | |
| 2771 | ) catch unreachable; | | |
| 2772 | | 2773 | |
| 2773 | if (self.emit_h) { | 2774 | if (self.emit_h) { |
| 2774 | self.output_h_path_source.path = | 2775 | self.output_h_path_source.path = builder.pathJoin( |
| 2775 | fs.path.join( | 2776 | &.{ self.output_dir.?, self.out_h_filename }, |
| 2776 | self.builder.allocator, | 2777 | ); |
| 2777 | &[_][]const u8{ self.output_dir.?, self.out_h_filename }, | | |
| 2778 | ) catch unreachable; | | |
| 2779 | } | 2778 | } |
| 2780 | | 2779 | |
| 2781 | if (self.target.isWindows() or self.target.isUefi()) { | 2780 | if (self.target.isWindows() or self.target.isUefi()) { |
| 2782 | self.output_pdb_path_source.path = | 2781 | self.output_pdb_path_source.path = builder.pathJoin( |
| 2783 | fs.path.join( | 2782 | &.{ self.output_dir.?, self.out_pdb_filename }, |
| 2784 | self.builder.allocator, | 2783 | ); |
| 2785 | &[_][]const u8{ self.output_dir.?, self.out_pdb_filename }, | | |
| 2786 | ) catch unreachable; | | |
| 2787 | } | 2784 | } |
| 2788 | } | 2785 | } |
| 2789 | | 2786 | |
| ... | @@ -2964,11 +2961,11 @@ pub const InstallDirStep = struct { | ... | @@ -2964,11 +2961,11 @@ pub const InstallDirStep = struct { |
| 2964 | } | 2961 | } |
| 2965 | } | 2962 | } |
| 2966 | | 2963 | |
| 2967 | const full_path = try fs.path.join(self.builder.allocator, &[_][]const u8{ | 2964 | const full_path = self.builder.pathJoin(&.{ |
| 2968 | full_src_dir, entry.path, | 2965 | full_src_dir, entry.path, |
| 2969 | }); | 2966 | }); |
| 2970 | | 2967 | |
| 2971 | const dest_path = try fs.path.join(self.builder.allocator, &[_][]const u8{ | 2968 | const dest_path = self.builder.pathJoin(&.{ |
| 2972 | dest_prefix, entry.path, | 2969 | dest_prefix, entry.path, |
| 2973 | }); | 2970 | }); |
| 2974 | | 2971 | |