| ... | ... | @@ -53,7 +53,7 @@ pub const Builder = struct { |
| 53 | 53 | release_mode: ?builtin.Mode, |
| 54 | 54 | is_release: bool, |
| 55 | 55 | override_lib_dir: ?[]const u8, |
| 56 | | |
| 56 | vcpkg_root: VcpkgRoot, |
| 57 | 57 | pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null, |
| 58 | 58 | |
| 59 | 59 | const PkgConfigError = error{ |
| ... | ... | @@ -159,6 +159,7 @@ pub const Builder = struct { |
| 159 | 159 | .is_release = false, |
| 160 | 160 | .override_lib_dir = null, |
| 161 | 161 | .install_path = undefined, |
| 162 | .vcpkg_root = VcpkgRoot{ .Unattempted = {} }, |
| 162 | 163 | }; |
| 163 | 164 | try self.top_level_steps.append(&self.install_tls); |
| 164 | 165 | try self.top_level_steps.append(&self.uninstall_tls); |
| ... | ... | @@ -1046,6 +1047,7 @@ pub const LibExeObjStep = struct { |
| 1046 | 1047 | output_dir: ?[]const u8, |
| 1047 | 1048 | need_system_paths: bool, |
| 1048 | 1049 | is_linking_libc: bool = false, |
| 1050 | vcpkg_bin_path: ?[]const u8 = null, |
| 1049 | 1051 | |
| 1050 | 1052 | installed_path: ?[]const u8, |
| 1051 | 1053 | install_step: ?*InstallArtifactStep, |
| ... | ... | @@ -1264,6 +1266,11 @@ pub const LibExeObjStep = struct { |
| 1264 | 1266 | // option is supplied. |
| 1265 | 1267 | const run_step = RunStep.create(exe.builder, exe.builder.fmt("run {}", exe.step.name)); |
| 1266 | 1268 | run_step.addArtifactArg(exe); |
| 1269 | |
| 1270 | if (exe.vcpkg_bin_path) |path| { |
| 1271 | run_step.addPathDir(path); |
| 1272 | } |
| 1273 | |
| 1267 | 1274 | return run_step; |
| 1268 | 1275 | } |
| 1269 | 1276 | |
| ... | ... | @@ -1569,6 +1576,43 @@ pub const LibExeObjStep = struct { |
| 1569 | 1576 | }) catch unreachable; |
| 1570 | 1577 | } |
| 1571 | 1578 | |
| 1579 | /// If Vcpkg was found on the system, it will be added to include and lib |
| 1580 | /// paths for the specified target. |
| 1581 | pub fn addVcpkgPaths(self: *LibExeObjStep, linkage: VcpkgLinkage) !void { |
| 1582 | // Ideally in the Unattempted case we would call the function recursively |
| 1583 | // after findVcpkgRoot and have only one switch statement, but the compiler |
| 1584 | // cannot resolve the error set. |
| 1585 | switch (self.builder.vcpkg_root) { |
| 1586 | .Unattempted => { |
| 1587 | self.builder.vcpkg_root = if (try findVcpkgRoot(self.builder.allocator)) |root| |
| 1588 | VcpkgRoot{ .Found = root } |
| 1589 | else |
| 1590 | .NotFound; |
| 1591 | }, |
| 1592 | .NotFound => return error.VcpkgNotFound, |
| 1593 | .Found => {}, |
| 1594 | } |
| 1595 | |
| 1596 | switch (self.builder.vcpkg_root) { |
| 1597 | .Unattempted => unreachable, |
| 1598 | .NotFound => return error.VcpkgNotFound, |
| 1599 | .Found => |root| { |
| 1600 | const allocator = self.builder.allocator; |
| 1601 | const triplet = try Target.vcpkgTriplet(allocator, self.target, linkage); |
| 1602 | defer self.builder.allocator.free(triplet); |
| 1603 | |
| 1604 | const include_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "include" }); |
| 1605 | errdefer allocator.free(include_path); |
| 1606 | try self.include_dirs.append(IncludeDir{ .RawPath = include_path }); |
| 1607 | |
| 1608 | const lib_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "lib" }); |
| 1609 | try self.lib_paths.append(lib_path); |
| 1610 | |
| 1611 | self.vcpkg_bin_path = try fs.path.join(allocator, [_][]const u8{ root, "installed", triplet, "bin" }); |
| 1612 | }, |
| 1613 | } |
| 1614 | } |
| 1615 | |
| 1572 | 1616 | pub fn setExecCmd(self: *LibExeObjStep, args: []const ?[]const u8) void { |
| 1573 | 1617 | assert(self.kind == Kind.Test); |
| 1574 | 1618 | self.exec_cmd_args = args; |
| ... | ... | @@ -2341,6 +2385,42 @@ fn doAtomicSymLinks(allocator: *Allocator, output_path: []const u8, filename_maj |
| 2341 | 2385 | }; |
| 2342 | 2386 | } |
| 2343 | 2387 | |
| 2388 | /// Returned slice must be freed by the caller. |
| 2389 | fn findVcpkgRoot(allocator: *Allocator) !?[]const u8 { |
| 2390 | const appdata_path = try fs.getAppDataDir(allocator, "vcpkg"); |
| 2391 | defer allocator.free(appdata_path); |
| 2392 | |
| 2393 | const path_file = try fs.path.join(allocator, [_][]const u8{ appdata_path, "vcpkg.path.txt" }); |
| 2394 | defer allocator.free(path_file); |
| 2395 | |
| 2396 | const file = fs.File.openRead(path_file) catch return null; |
| 2397 | defer file.close(); |
| 2398 | |
| 2399 | const size = @intCast(usize, try file.getEndPos()); |
| 2400 | const vcpkg_path = try allocator.alloc(u8, size); |
| 2401 | const size_read = try file.read(vcpkg_path); |
| 2402 | std.debug.assert(size == size_read); |
| 2403 | |
| 2404 | return vcpkg_path; |
| 2405 | } |
| 2406 | |
| 2407 | const VcpkgRoot = union(VcpkgRootStatus) { |
| 2408 | Unattempted: void, |
| 2409 | NotFound: void, |
| 2410 | Found: []const u8, |
| 2411 | }; |
| 2412 | |
| 2413 | const VcpkgRootStatus = enum { |
| 2414 | Unattempted, |
| 2415 | NotFound, |
| 2416 | Found, |
| 2417 | }; |
| 2418 | |
| 2419 | pub const VcpkgLinkage = enum { |
| 2420 | Static, |
| 2421 | Dynamic, |
| 2422 | }; |
| 2423 | |
| 2344 | 2424 | pub const InstallDir = enum { |
| 2345 | 2425 | Prefix, |
| 2346 | 2426 | Lib, |