From 579f572cf203eda11da7e4e919fdfc12e15f03e2 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 1 Dec 2023 13:01:39 -0700 Subject: [PATCH] zig build system: remove vcpkg integration Instead of vcpkg, users are encouraged to use the Zig package manager to fulfill dependencies on Windows. --- lib/std/Build.zig | 17 ---------- lib/std/Build/Step/Compile.zig | 59 ---------------------------------- lib/std/zig/CrossTarget.zig | 37 --------------------- 3 files changed, 113 deletions(-) diff --git a/lib/std/Build.zig b/lib/std/Build.zig index 590ac5aadf..8726feb7c1 100644 --- a/lib/std/Build.zig +++ b/lib/std/Build.zig @@ -67,7 +67,6 @@ cache_root: Cache.Directory, global_cache_root: Cache.Directory, cache: *Cache, zig_lib_dir: ?LazyPath, -vcpkg_root: VcpkgRoot = .unattempted, pkg_config_pkg_list: ?(PkgConfigError![]const PkgConfigPkg) = null, args: ?[][]const u8 = null, debug_log_scopes: []const []const u8 = &.{}, @@ -841,10 +840,6 @@ pub fn addRunArtifact(b: *Build, exe: *Step.Compile) *Step.Run { run_step.enableTestRunnerMode(); } - if (exe.vcpkg_bin_path) |path| { - run_step.addPathDir(path); - } - return run_step; } @@ -1978,18 +1973,6 @@ pub fn constructCMacro(allocator: Allocator, name: []const u8, value: ?[]const u return macro; } -pub const VcpkgRoot = union(VcpkgRootStatus) { - unattempted: void, - not_found: void, - found: []const u8, -}; - -pub const VcpkgRootStatus = enum { - unattempted, - not_found, - found, -}; - pub const InstallDir = union(enum) { prefix: void, lib: void, diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index 31d07a4359..4cd8868752 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -16,7 +16,6 @@ const PkgConfigPkg = std.Build.PkgConfigPkg; const PkgConfigError = std.Build.PkgConfigError; const RunError = std.Build.RunError; const Module = std.Build.Module; -const VcpkgRoot = std.Build.VcpkgRoot; const InstallDir = std.Build.InstallDir; const GeneratedFile = std.Build.GeneratedFile; const Compile = @This(); @@ -63,7 +62,6 @@ test_server_mode: bool, wasi_exec_model: ?std.builtin.WasiExecModel = null, installed_headers: ArrayList(*Step), -vcpkg_bin_path: ?[]const u8 = null, // keep in sync with src/Compilation.zig:RcIncludes /// Behavior of automatic detection of include directories when compiling .rc files. @@ -936,44 +934,6 @@ pub fn addFrameworkPath(self: *Compile, directory_source: LazyPath) void { directory_source.addStepDependencies(&self.step); } -/// If Vcpkg was found on the system, it will be added to include and lib -/// paths for the specified target. -pub fn addVcpkgPaths(self: *Compile, linkage: Compile.Linkage) !void { - const b = self.step.owner; - // Ideally in the Unattempted case we would call the function recursively - // after findVcpkgRoot and have only one switch statement, but the compiler - // cannot resolve the error set. - switch (b.vcpkg_root) { - .unattempted => { - b.vcpkg_root = if (try findVcpkgRoot(b.allocator)) |root| - VcpkgRoot{ .found = root } - else - .not_found; - }, - .not_found => return error.VcpkgNotFound, - .found => {}, - } - - switch (b.vcpkg_root) { - .unattempted => unreachable, - .not_found => return error.VcpkgNotFound, - .found => |root| { - const allocator = b.allocator; - const triplet = try self.target.vcpkgTriplet(allocator, if (linkage == .static) .Static else .Dynamic); - defer b.allocator.free(triplet); - - const include_path = b.pathJoin(&.{ root, "installed", triplet, "include" }); - errdefer allocator.free(include_path); - try self.include_dirs.append(.{ .path = .{ .path = include_path } }); - - const lib_path = b.pathJoin(&.{ root, "installed", triplet, "lib" }); - try self.lib_paths.append(.{ .path = lib_path }); - - self.vcpkg_bin_path = b.pathJoin(&.{ root, "installed", triplet, "bin" }); - }, - } -} - pub fn setExecCmd(self: *Compile, args: []const ?[]const u8) void { const b = self.step.owner; assert(self.kind == .@"test"); @@ -1814,25 +1774,6 @@ fn make(step: *Step, prog_node: *std.Progress.Node) !void { } } -/// Returned slice must be freed by the caller. -fn findVcpkgRoot(allocator: Allocator) !?[]const u8 { - const appdata_path = try fs.getAppDataDir(allocator, "vcpkg"); - defer allocator.free(appdata_path); - - const path_file = try fs.path.join(allocator, &[_][]const u8{ appdata_path, "vcpkg.path.txt" }); - defer allocator.free(path_file); - - const file = fs.cwd().openFile(path_file, .{}) catch return null; - defer file.close(); - - const size = @as(usize, @intCast(try file.getEndPos())); - const vcpkg_path = try allocator.alloc(u8, size); - const size_read = try file.read(vcpkg_path); - std.debug.assert(size == size_read); - - return vcpkg_path; -} - pub fn doAtomicSymLinks( step: *Step, output_path: []const u8, diff --git a/lib/std/zig/CrossTarget.zig b/lib/std/zig/CrossTarget.zig index ea496051b4..c65269e4d3 100644 --- a/lib/std/zig/CrossTarget.zig +++ b/lib/std/zig/CrossTarget.zig @@ -636,43 +636,6 @@ pub fn wantSharedLibSymLinks(self: CrossTarget) bool { return self.getOsTag() != .windows; } -pub const VcpkgLinkage = std.builtin.LinkMode; - -/// Returned slice must be freed by the caller. -pub fn vcpkgTriplet(self: CrossTarget, allocator: mem.Allocator, linkage: VcpkgLinkage) ![]u8 { - const arch = switch (self.getCpuArch()) { - .x86 => "x86", - .x86_64 => "x64", - - .arm, - .armeb, - .thumb, - .thumbeb, - .aarch64_32, - => "arm", - - .aarch64, - .aarch64_be, - => "arm64", - - else => return error.UnsupportedVcpkgArchitecture, - }; - - const os = switch (self.getOsTag()) { - .windows => "windows", - .linux => "linux", - .macos => "macos", - else => return error.UnsupportedVcpkgOperatingSystem, - }; - - const static_suffix = switch (linkage) { - .Static => "-static", - .Dynamic => "", - }; - - return std.fmt.allocPrint(allocator, "{s}-{s}{s}", .{ arch, os, static_suffix }); -} - pub fn isGnuLibC(self: CrossTarget) bool { return Target.isGnuLibC_os_tag_abi(self.getOsTag(), self.getAbi()); }