From 425e38b6e0601e12329f93b2e94c76c1da300b8e Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Sat, 13 Apr 2024 22:16:27 -0400 Subject: [PATCH 1/2] WindowsSdk: fix for new x86_64-windows CI --- lib/std/math.zig | 25 ++ lib/std/os/windows.zig | 8 + lib/std/zig/LibCInstallation.zig | 74 +++--- lib/std/zig/WindowsSdk.zig | 426 ++++++++++++++++--------------- 4 files changed, 282 insertions(+), 251 deletions(-) diff --git a/lib/std/math.zig b/lib/std/math.zig index 19dd82ec67..858e9243bf 100644 --- a/lib/std/math.zig +++ b/lib/std/math.zig @@ -1588,6 +1588,31 @@ pub const Order = enum { try testing.expect(Order.invert(order(-1, 0)) == .gt); } + pub fn differ(self: Order) ?Order { + return if (self != .eq) self else null; + } + + test differ { + const neg: i32 = -1; + const zero: i32 = 0; + const pos: i32 = 1; + try testing.expect(order(zero, neg).differ() orelse + order(pos, zero) == .gt); + try testing.expect(order(zero, zero).differ() orelse + order(zero, zero) == .eq); + try testing.expect(order(pos, pos).differ() orelse + order(neg, zero) == .lt); + try testing.expect(order(zero, zero).differ() orelse + order(pos, neg).differ() orelse + order(neg, zero) == .gt); + try testing.expect(order(pos, pos).differ() orelse + order(pos, pos).differ() orelse + order(neg, neg) == .eq); + try testing.expect(order(zero, pos).differ() orelse + order(neg, pos).differ() orelse + order(pos, neg) == .lt); + } + pub fn compare(self: Order, op: CompareOperator) bool { return switch (self) { .lt => switch (op) { diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index 1c0b7d9d80..27a7b8a351 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -3672,7 +3672,15 @@ pub const SEC_LARGE_PAGES = 0x80000000; pub const HKEY = *opaque {}; pub const HKEY_CLASSES_ROOT: HKEY = @ptrFromInt(0x80000000); +pub const HKEY_CURRENT_USER: HKEY = @ptrFromInt(0x80000001); pub const HKEY_LOCAL_MACHINE: HKEY = @ptrFromInt(0x80000002); +pub const HKEY_USERS: HKEY = @ptrFromInt(0x80000003); +pub const HKEY_PERFORMANCE_DATA: HKEY = @ptrFromInt(0x80000004); +pub const HKEY_PERFORMANCE_TEXT: HKEY = @ptrFromInt(0x80000050); +pub const HKEY_PERFORMANCE_NLSTEXT: HKEY = @ptrFromInt(0x80000060); +pub const HKEY_CURRENT_CONFIG: HKEY = @ptrFromInt(0x80000005); +pub const HKEY_DYN_DATA: HKEY = @ptrFromInt(0x80000006); +pub const HKEY_CURRENT_USER_LOCAL_SETTINGS: HKEY = @ptrFromInt(0x80000007); /// Combines the STANDARD_RIGHTS_REQUIRED, KEY_QUERY_VALUE, KEY_SET_VALUE, KEY_CREATE_SUB_KEY, /// KEY_ENUMERATE_SUB_KEYS, KEY_NOTIFY, and KEY_CREATE_LINK access rights. diff --git a/lib/std/zig/LibCInstallation.zig b/lib/std/zig/LibCInstallation.zig index f8ee9be602..656ea32981 100644 --- a/lib/std/zig/LibCInstallation.zig +++ b/lib/std/zig/LibCInstallation.zig @@ -182,18 +182,18 @@ pub fn findNative(args: FindNativeOptions) FindError!LibCInstallation { }); return self; } else if (is_windows) { - var sdk = std.zig.WindowsSdk.find(args.allocator) catch |err| switch (err) { + const sdk = std.zig.WindowsSdk.find(args.allocator) catch |err| switch (err) { error.NotFound => return error.WindowsSdkNotFound, error.PathTooLong => return error.WindowsSdkNotFound, error.OutOfMemory => return error.OutOfMemory, }; defer sdk.free(args.allocator); - try self.findNativeMsvcIncludeDir(args, &sdk); - try self.findNativeMsvcLibDir(args, &sdk); - try self.findNativeKernel32LibDir(args, &sdk); - try self.findNativeIncludeDirWindows(args, &sdk); - try self.findNativeCrtDirWindows(args, &sdk); + try self.findNativeMsvcIncludeDir(args, sdk); + try self.findNativeMsvcLibDir(args, sdk); + try self.findNativeKernel32LibDir(args, sdk); + try self.findNativeIncludeDirWindows(args, sdk); + try self.findNativeCrtDirWindows(args, sdk); } else if (is_haiku) { try self.findNativeIncludeDirPosix(args); try self.findNativeGccDirHaiku(args); @@ -358,19 +358,19 @@ fn findNativeIncludeDirPosix(self: *LibCInstallation, args: FindNativeOptions) F fn findNativeIncludeDirWindows( self: *LibCInstallation, args: FindNativeOptions, - sdk: *std.zig.WindowsSdk, + sdk: std.zig.WindowsSdk, ) FindError!void { const allocator = args.allocator; - var search_buf: [2]Search = undefined; - const searches = fillSearch(&search_buf, sdk); + var install_buf: [2]std.zig.WindowsSdk.Installation = undefined; + const installs = fillInstallations(&install_buf, sdk); var result_buf = std.ArrayList(u8).init(allocator); defer result_buf.deinit(); - for (searches) |search| { + for (installs) |install| { result_buf.shrinkAndFree(0); - try result_buf.writer().print("{s}\\Include\\{s}\\ucrt", .{ search.path, search.version }); + try result_buf.writer().print("{s}\\Include\\{s}\\ucrt", .{ install.path, install.version }); var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { error.FileNotFound, @@ -397,12 +397,12 @@ fn findNativeIncludeDirWindows( fn findNativeCrtDirWindows( self: *LibCInstallation, args: FindNativeOptions, - sdk: *std.zig.WindowsSdk, + sdk: std.zig.WindowsSdk, ) FindError!void { const allocator = args.allocator; - var search_buf: [2]Search = undefined; - const searches = fillSearch(&search_buf, sdk); + var install_buf: [2]std.zig.WindowsSdk.Installation = undefined; + const installs = fillInstallations(&install_buf, sdk); var result_buf = std.ArrayList(u8).init(allocator); defer result_buf.deinit(); @@ -415,9 +415,9 @@ fn findNativeCrtDirWindows( else => return error.UnsupportedArchitecture, }; - for (searches) |search| { + for (installs) |install| { result_buf.shrinkAndFree(0); - try result_buf.writer().print("{s}\\Lib\\{s}\\ucrt\\{s}", .{ search.path, search.version, arch_sub_dir }); + try result_buf.writer().print("{s}\\Lib\\{s}\\ucrt\\{s}", .{ install.path, install.version, arch_sub_dir }); var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { error.FileNotFound, @@ -464,12 +464,12 @@ fn findNativeGccDirHaiku(self: *LibCInstallation, args: FindNativeOptions) FindE fn findNativeKernel32LibDir( self: *LibCInstallation, args: FindNativeOptions, - sdk: *std.zig.WindowsSdk, + sdk: std.zig.WindowsSdk, ) FindError!void { const allocator = args.allocator; - var search_buf: [2]Search = undefined; - const searches = fillSearch(&search_buf, sdk); + var install_buf: [2]std.zig.WindowsSdk.Installation = undefined; + const installs = fillInstallations(&install_buf, sdk); var result_buf = std.ArrayList(u8).init(allocator); defer result_buf.deinit(); @@ -482,10 +482,10 @@ fn findNativeKernel32LibDir( else => return error.UnsupportedArchitecture, }; - for (searches) |search| { + for (installs) |install| { result_buf.shrinkAndFree(0); const stream = result_buf.writer(); - try stream.print("{s}\\Lib\\{s}\\um\\{s}", .{ search.path, search.version, arch_sub_dir }); + try stream.print("{s}\\Lib\\{s}\\um\\{s}", .{ install.path, install.version, arch_sub_dir }); var dir = fs.cwd().openDir(result_buf.items, .{}) catch |err| switch (err) { error.FileNotFound, @@ -511,7 +511,7 @@ fn findNativeKernel32LibDir( fn findNativeMsvcIncludeDir( self: *LibCInstallation, args: FindNativeOptions, - sdk: *std.zig.WindowsSdk, + sdk: std.zig.WindowsSdk, ) FindError!void { const allocator = args.allocator; @@ -543,7 +543,7 @@ fn findNativeMsvcIncludeDir( fn findNativeMsvcLibDir( self: *LibCInstallation, args: FindNativeOptions, - sdk: *std.zig.WindowsSdk, + sdk: std.zig.WindowsSdk, ) FindError!void { const allocator = args.allocator; const msvc_lib_dir = sdk.msvc_lib_dir orelse return error.LibCRuntimeNotFound; @@ -654,28 +654,20 @@ fn printVerboseInvocation( } } -const Search = struct { - path: []const u8, - version: []const u8, -}; - -fn fillSearch(search_buf: *[2]Search, sdk: *std.zig.WindowsSdk) []Search { - var search_end: usize = 0; +fn fillInstallations( + installs: *[2]std.zig.WindowsSdk.Installation, + sdk: std.zig.WindowsSdk, +) []std.zig.WindowsSdk.Installation { + var installs_len: usize = 0; if (sdk.windows10sdk) |windows10sdk| { - search_buf[search_end] = .{ - .path = windows10sdk.path, - .version = windows10sdk.version, - }; - search_end += 1; + installs[installs_len] = windows10sdk; + installs_len += 1; } if (sdk.windows81sdk) |windows81sdk| { - search_buf[search_end] = .{ - .path = windows81sdk.path, - .version = windows81sdk.version, - }; - search_end += 1; + installs[installs_len] = windows81sdk; + installs_len += 1; } - return search_buf[0..search_end]; + return installs[0..installs_len]; } const inf_loop_env_key = "ZIG_IS_DETECTING_LIBC_PATHS"; diff --git a/lib/std/zig/WindowsSdk.zig b/lib/std/zig/WindowsSdk.zig index 3b9b788a7b..bebb0fc5a1 100644 --- a/lib/std/zig/WindowsSdk.zig +++ b/lib/std/zig/WindowsSdk.zig @@ -1,5 +1,5 @@ -windows10sdk: ?Windows10Sdk, -windows81sdk: ?Windows81Sdk, +windows10sdk: ?Installation, +windows81sdk: ?Installation, msvc_lib_dir: ?[]const u8, const WindowsSdk = @This(); @@ -9,7 +9,7 @@ const builtin = @import("builtin"); const windows = std.os.windows; const RRF = windows.advapi32.RRF; -const WINDOWS_KIT_REG_KEY = "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots"; +const windows_kits_reg_key = "SOFTWARE\\Microsoft\\Windows Kits\\Installed Roots"; // https://learn.microsoft.com/en-us/windows/win32/msi/productversion const version_major_minor_max_length = "255.255".len; @@ -23,34 +23,24 @@ pub fn find(allocator: std.mem.Allocator) error{ OutOfMemory, NotFound, PathTooL if (builtin.os.tag != .windows) return error.NotFound; //note(dimenus): If this key doesn't exist, neither the Win 8 SDK nor the Win 10 SDK is installed - const roots_key = RegistryWtf8.openKey(windows.HKEY_LOCAL_MACHINE, WINDOWS_KIT_REG_KEY) catch |err| switch (err) { + const roots_key = RegistryWtf8.openKey(windows.HKEY_LOCAL_MACHINE, windows_kits_reg_key) catch |err| switch (err) { error.KeyNotFound => return error.NotFound, }; defer roots_key.closeKey(); - const windows10sdk: ?Windows10Sdk = blk: { - const windows10sdk = Windows10Sdk.find(allocator) catch |err| switch (err) { - error.Windows10SdkNotFound, - error.PathTooLong, - error.VersionTooLong, - => break :blk null, - error.OutOfMemory => return error.OutOfMemory, - }; - const is_valid_version = windows10sdk.isValidVersion(); - if (!is_valid_version) break :blk null; - break :blk windows10sdk; + const windows10sdk = Installation.find(allocator, roots_key, "KitsRoot10", "", "v10.0") catch |err| switch (err) { + error.InstallationNotFound => null, + error.PathTooLong => null, + error.VersionTooLong => null, + error.OutOfMemory => return error.OutOfMemory, }; errdefer if (windows10sdk) |*w| w.free(allocator); - const windows81sdk: ?Windows81Sdk = blk: { - const windows81sdk = Windows81Sdk.find(allocator, &roots_key) catch |err| switch (err) { - error.Windows81SdkNotFound => break :blk null, - error.PathTooLong => break :blk null, - error.VersionTooLong => break :blk null, - error.OutOfMemory => return error.OutOfMemory, - }; - // no check - break :blk windows81sdk; + const windows81sdk = Installation.find(allocator, roots_key, "KitsRoot81", "winver", "v8.1") catch |err| switch (err) { + error.InstallationNotFound => null, + error.PathTooLong => null, + error.VersionTooLong => null, + error.OutOfMemory => return error.OutOfMemory, }; errdefer if (windows81sdk) |*w| w.free(allocator); @@ -60,96 +50,91 @@ pub fn find(allocator: std.mem.Allocator) error{ OutOfMemory, NotFound, PathTooL }; errdefer allocator.free(msvc_lib_dir); - return WindowsSdk{ + return .{ .windows10sdk = windows10sdk, .windows81sdk = windows81sdk, .msvc_lib_dir = msvc_lib_dir, }; } -pub fn free(self: *const WindowsSdk, allocator: std.mem.Allocator) void { - if (self.windows10sdk) |*w10sdk| { +pub fn free(sdk: WindowsSdk, allocator: std.mem.Allocator) void { + if (sdk.windows10sdk) |*w10sdk| { w10sdk.free(allocator); } - if (self.windows81sdk) |*w81sdk| { + if (sdk.windows81sdk) |*w81sdk| { w81sdk.free(allocator); } - if (self.msvc_lib_dir) |msvc_lib_dir| { + if (sdk.msvc_lib_dir) |msvc_lib_dir| { allocator.free(msvc_lib_dir); } } -/// Iterates via `iterator` and collects all folders with names starting with `optional_prefix` -/// and similar to SemVer. Returns slice of folder names sorted in descending order. +/// Iterates via `iterator` and collects all folders with names starting with `strip_prefix` +/// and a version. Returns slice of version strings sorted in descending order. /// Caller owns result. -fn iterateAndFilterBySemVer( +fn iterateAndFilterByVersion( iterator: *std.fs.Dir.Iterator, allocator: std.mem.Allocator, - comptime optional_prefix: ?[]const u8, -) error{ OutOfMemory, VersionNotFound }![][]const u8 { - var dirs_filtered_list = std.ArrayList([]const u8).init(allocator); - errdefer { - for (dirs_filtered_list.items) |filtered_dir| allocator.free(filtered_dir); - dirs_filtered_list.deinit(); + prefix: []const u8, +) error{OutOfMemory}![][]const u8 { + const Version = struct { + nums: [4]u32, + build: []const u8, + + fn parseNum(num: []const u8) ?u32 { + if (num[0] == '0' and num.len > 1) return null; + return std.fmt.parseInt(u32, num, 10) catch null; + } + + fn order(lhs: @This(), rhs: @This()) std.math.Order { + return std.mem.order(u32, &lhs.nums, &rhs.nums).differ() orelse + std.mem.order(u8, lhs.build, rhs.build); + } + }; + var versions = std.ArrayList(Version).init(allocator); + var dirs = std.ArrayList([]const u8).init(allocator); + defer { + versions.deinit(); + for (dirs.items) |filtered_dir| allocator.free(filtered_dir); + dirs.deinit(); } - var normalized_name_buf: [std.fs.MAX_NAME_BYTES + ".0+build.0".len]u8 = undefined; - var normalized_name_fbs = std.io.fixedBufferStream(&normalized_name_buf); - const normalized_name_w = normalized_name_fbs.writer(); - iterate_folder: while (true) : (normalized_name_fbs.reset()) { - const maybe_entry = iterator.next() catch continue :iterate_folder; - const entry = maybe_entry orelse break :iterate_folder; + iterate: while (iterator.next() catch null) |entry| { + if (entry.kind != .directory) continue; + if (!std.mem.startsWith(u8, entry.name, prefix)) continue; - if (entry.kind != .directory) - continue :iterate_folder; - - // invalidated on next iteration - const subfolder_name = blk: { - if (comptime optional_prefix) |prefix| { - if (!std.mem.startsWith(u8, entry.name, prefix)) continue :iterate_folder; - break :blk entry.name[prefix.len..]; - } else break :blk entry.name; + var version: Version = .{ + .nums = .{0} ** 4, + .build = "", }; + const suffix = entry.name[prefix.len..]; + const underscore = std.mem.indexOfScalar(u8, entry.name, '_'); + var num_it = std.mem.splitScalar(u8, suffix[0 .. underscore orelse suffix.len], '.'); + version.nums[0] = Version.parseNum(num_it.first()) orelse continue; + for (version.nums[1..]) |*num| + num.* = Version.parseNum(num_it.next() orelse break) orelse continue :iterate + else if (num_it.next()) |_| continue; - { // check if subfolder name looks similar to SemVer - switch (std.mem.count(u8, subfolder_name, ".")) { - 0 => normalized_name_w.print("{s}.0.0+build.0", .{subfolder_name}) catch unreachable, // 17 => 17.0.0+build.0 - 1 => if (std.mem.indexOfScalar(u8, subfolder_name, '_')) |underscore_pos| blk: { // 17.0_9e9cbb98 => 17.0.1+build.9e9cbb98 - var subfolder_name_tmp_copy_buf: [std.fs.MAX_NAME_BYTES]u8 = undefined; - const subfolder_name_tmp_copy = subfolder_name_tmp_copy_buf[0..subfolder_name.len]; - @memcpy(subfolder_name_tmp_copy, subfolder_name); + const name = try allocator.dupe(u8, suffix); + errdefer allocator.free(name); + if (underscore) |pos| version.build = name[pos + 1 ..]; - subfolder_name_tmp_copy[underscore_pos] = '.'; // 17.0_9e9cbb98 => 17.0.9e9cbb98 - var subfolder_name_parts = std.mem.splitScalar(u8, subfolder_name_tmp_copy, '.'); // [ 17, 0, 9e9cbb98 ] - - const first = subfolder_name_parts.first(); // 17 - const second = subfolder_name_parts.next().?; // 0 - const third = subfolder_name_parts.rest(); // 9e9cbb98 - - break :blk normalized_name_w.print("{s}.{s}.1+build.{s}", .{ first, second, third }) catch unreachable; // [ 17, 0, 9e9cbb98 ] => 17.0.1+build.9e9cbb98 - } else normalized_name_w.print("{s}.0+build.0", .{subfolder_name}) catch unreachable, // 17.0 => 17.0.0+build.0 - else => normalized_name_w.print("{s}+build.0", .{subfolder_name}) catch unreachable, // 17.0.0 => 17.0.0+build.0 - } - const subfolder_name_normalized: []const u8 = normalized_name_fbs.getWritten(); - const sem_ver = std.SemanticVersion.parse(subfolder_name_normalized); - _ = sem_ver catch continue :iterate_folder; - } - // entry.name passed check - - const subfolder_name_allocated = try allocator.dupe(u8, subfolder_name); - errdefer allocator.free(subfolder_name_allocated); - try dirs_filtered_list.append(subfolder_name_allocated); + try versions.append(version); + try dirs.append(name); } - const dirs_filtered_slice = try dirs_filtered_list.toOwnedSlice(); - // Keep in mind that order of these names is not guaranteed by Windows, - // so we cannot just reverse or "while (popOrNull())" this ArrayList. - std.mem.sortUnstable([]const u8, dirs_filtered_slice, {}, struct { - fn desc(_: void, lhs: []const u8, rhs: []const u8) bool { - return std.mem.order(u8, lhs, rhs) == .gt; + std.mem.sortUnstableContext(0, dirs.items.len, struct { + versions: []Version, + dirs: [][]const u8, + pub fn lessThan(context: @This(), lhs: usize, rhs: usize) bool { + return context.versions[lhs].order(context.versions[rhs]).compare(.gt); } - }.desc); - return dirs_filtered_slice; + pub fn swap(context: @This(), lhs: usize, rhs: usize) void { + std.mem.swap(Version, &context.versions[lhs], &context.versions[rhs]); + std.mem.swap([]const u8, &context.dirs[lhs], &context.dirs[rhs]); + } + }{ .versions = versions.items, .dirs = dirs.items }); + return dirs.toOwnedSlice(); } const RegistryWtf8 = struct { @@ -167,12 +152,12 @@ const RegistryWtf8 = struct { }; const registry_wtf16le = try RegistryWtf16Le.openKey(hkey, key_wtf16le); - return RegistryWtf8{ .key = registry_wtf16le.key }; + return .{ .key = registry_wtf16le.key }; } /// Closes key, after that usage is invalid - pub fn closeKey(self: *const RegistryWtf8) void { - const return_code_int: windows.HRESULT = windows.advapi32.RegCloseKey(self.key); + pub fn closeKey(reg: RegistryWtf8) void { + const return_code_int: windows.HRESULT = windows.advapi32.RegCloseKey(reg.key); const return_code: windows.Win32Error = @enumFromInt(return_code_int); switch (return_code) { .SUCCESS => {}, @@ -182,7 +167,7 @@ const RegistryWtf8 = struct { /// Get string from registry. /// Caller owns result. - pub fn getString(self: *const RegistryWtf8, allocator: std.mem.Allocator, subkey: []const u8, value_name: []const u8) error{ OutOfMemory, ValueNameNotFound, NotAString, StringNotFound }![]u8 { + pub fn getString(reg: RegistryWtf8, allocator: std.mem.Allocator, subkey: []const u8, value_name: []const u8) error{ OutOfMemory, ValueNameNotFound, NotAString, StringNotFound }![]u8 { const subkey_wtf16le: [:0]const u16 = subkey_wtf16le: { var subkey_wtf16le_buf: [RegistryWtf16Le.key_name_max_len]u16 = undefined; const subkey_wtf16le_len: usize = std.unicode.wtf8ToWtf16Le(subkey_wtf16le_buf[0..], subkey) catch unreachable; @@ -197,7 +182,7 @@ const RegistryWtf8 = struct { break :value_name_wtf16le value_name_wtf16le_buf[0..value_name_wtf16le_len :0]; }; - const registry_wtf16le = RegistryWtf16Le{ .key = self.key }; + const registry_wtf16le: RegistryWtf16Le = .{ .key = reg.key }; const value_wtf16le = try registry_wtf16le.getString(allocator, subkey_wtf16le, value_name_wtf16le); defer allocator.free(value_wtf16le); @@ -208,7 +193,7 @@ const RegistryWtf8 = struct { } /// Get DWORD (u32) from registry. - pub fn getDword(self: *const RegistryWtf8, subkey: []const u8, value_name: []const u8) error{ ValueNameNotFound, NotADword, DwordTooLong, DwordNotFound }!u32 { + pub fn getDword(reg: RegistryWtf8, subkey: []const u8, value_name: []const u8) error{ ValueNameNotFound, NotADword, DwordTooLong, DwordNotFound }!u32 { const subkey_wtf16le: [:0]const u16 = subkey_wtf16le: { var subkey_wtf16le_buf: [RegistryWtf16Le.key_name_max_len]u16 = undefined; const subkey_wtf16le_len: usize = std.unicode.wtf8ToWtf16Le(subkey_wtf16le_buf[0..], subkey) catch unreachable; @@ -223,8 +208,8 @@ const RegistryWtf8 = struct { break :value_name_wtf16le value_name_wtf16le_buf[0..value_name_wtf16le_len :0]; }; - const registry_wtf16le = RegistryWtf16Le{ .key = self.key }; - return try registry_wtf16le.getDword(subkey_wtf16le, value_name_wtf16le); + const registry_wtf16le: RegistryWtf16Le = .{ .key = reg.key }; + return registry_wtf16le.getDword(subkey_wtf16le, value_name_wtf16le); } /// Under private space with flags: @@ -239,7 +224,7 @@ const RegistryWtf8 = struct { }; const registry_wtf16le = try RegistryWtf16Le.loadFromPath(absolute_path_wtf16le); - return RegistryWtf8{ .key = registry_wtf16le.key }; + return .{ .key = registry_wtf16le.key }; } }; @@ -272,12 +257,12 @@ const RegistryWtf16Le = struct { else => return error.KeyNotFound, } - return RegistryWtf16Le{ .key = key }; + return .{ .key = key }; } /// Closes key, after that usage is invalid - fn closeKey(self: *const RegistryWtf16Le) void { - const return_code_int: windows.HRESULT = windows.advapi32.RegCloseKey(self.key); + fn closeKey(reg: RegistryWtf16Le) void { + const return_code_int: windows.HRESULT = windows.advapi32.RegCloseKey(reg.key); const return_code: windows.Win32Error = @enumFromInt(return_code_int); switch (return_code) { .SUCCESS => {}, @@ -286,13 +271,13 @@ const RegistryWtf16Le = struct { } /// Get string ([:0]const u16) from registry. - fn getString(self: *const RegistryWtf16Le, allocator: std.mem.Allocator, subkey_wtf16le: [:0]const u16, value_name_wtf16le: [:0]const u16) error{ OutOfMemory, ValueNameNotFound, NotAString, StringNotFound }![]const u16 { + fn getString(reg: RegistryWtf16Le, allocator: std.mem.Allocator, subkey_wtf16le: [:0]const u16, value_name_wtf16le: [:0]const u16) error{ OutOfMemory, ValueNameNotFound, NotAString, StringNotFound }![]const u16 { var actual_type: windows.ULONG = undefined; // Calculating length to allocate var value_wtf16le_buf_size: u32 = 0; // in bytes, including any terminating NUL character or characters. var return_code_int: windows.HRESULT = windows.advapi32.RegGetValueW( - self.key, + reg.key, subkey_wtf16le, value_name_wtf16le, RRF.RT_REG_SZ, @@ -319,7 +304,7 @@ const RegistryWtf16Le = struct { errdefer allocator.free(value_wtf16le_buf); return_code_int = windows.advapi32.RegGetValueW( - self.key, + reg.key, subkey_wtf16le, value_name_wtf16le, RRF.RT_REG_SZ, @@ -355,13 +340,13 @@ const RegistryWtf16Le = struct { } /// Get DWORD (u32) from registry. - fn getDword(self: *const RegistryWtf16Le, subkey_wtf16le: [:0]const u16, value_name_wtf16le: [:0]const u16) error{ ValueNameNotFound, NotADword, DwordTooLong, DwordNotFound }!u32 { + fn getDword(reg: RegistryWtf16Le, subkey_wtf16le: [:0]const u16, value_name_wtf16le: [:0]const u16) error{ ValueNameNotFound, NotADword, DwordTooLong, DwordNotFound }!u32 { var actual_type: windows.ULONG = undefined; var reg_size: u32 = @sizeOf(u32); var reg_value: u32 = 0; const return_code_int: windows.HRESULT = windows.advapi32.RegGetValueW( - self.key, + reg.key, subkey_wtf16le, value_name_wtf16le, RRF.RT_REG_DWORD, @@ -405,28 +390,118 @@ const RegistryWtf16Le = struct { else => return error.KeyNotFound, } - return RegistryWtf16Le{ .key = key }; + return .{ .key = key }; } }; -pub const Windows10Sdk = struct { +pub const Installation = struct { path: []const u8, version: []const u8, - /// Find path and version of Windows 10 SDK. + /// Find path and version of Windows SDK. /// Caller owns the result's fields. /// After finishing work, call `free(allocator)`. - fn find(allocator: std.mem.Allocator) error{ OutOfMemory, Windows10SdkNotFound, PathTooLong, VersionTooLong }!Windows10Sdk { - const v10_key = RegistryWtf8.openKey(windows.HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Microsoft SDKs\\Windows\\v10.0") catch |err| switch (err) { - error.KeyNotFound => return error.Windows10SdkNotFound, - }; - defer v10_key.closeKey(); + fn find( + allocator: std.mem.Allocator, + roots_key: RegistryWtf8, + roots_subkey: []const u8, + prefix: []const u8, + version_key_name: []const u8, + ) error{ OutOfMemory, InstallationNotFound, PathTooLong, VersionTooLong }!Installation { + roots: { + const installation = findFromRoot(allocator, roots_key, roots_subkey, prefix) catch + break :roots; + if (installation.isValidVersion()) return installation; + installation.free(allocator); + } + { + const installation = try findFromInstallationFolder(allocator, version_key_name); + if (installation.isValidVersion()) return installation; + installation.free(allocator); + } + return error.InstallationNotFound; + } - const path: []const u8 = path10: { - const path_maybe_with_trailing_slash = v10_key.getString(allocator, "", "InstallationFolder") catch |err| switch (err) { - error.NotAString => return error.Windows10SdkNotFound, - error.ValueNameNotFound => return error.Windows10SdkNotFound, - error.StringNotFound => return error.Windows10SdkNotFound, + fn findFromRoot( + allocator: std.mem.Allocator, + roots_key: RegistryWtf8, + roots_subkey: []const u8, + prefix: []const u8, + ) error{ OutOfMemory, InstallationNotFound, PathTooLong, VersionTooLong }!Installation { + const path = path: { + const path_maybe_with_trailing_slash = roots_key.getString(allocator, "", roots_subkey) catch |err| switch (err) { + error.NotAString => return error.InstallationNotFound, + error.ValueNameNotFound => return error.InstallationNotFound, + error.StringNotFound => return error.InstallationNotFound, + + error.OutOfMemory => return error.OutOfMemory, + }; + if (path_maybe_with_trailing_slash.len > std.fs.MAX_PATH_BYTES or !std.fs.path.isAbsolute(path_maybe_with_trailing_slash)) { + allocator.free(path_maybe_with_trailing_slash); + return error.PathTooLong; + } + + var path = std.ArrayList(u8).fromOwnedSlice(allocator, path_maybe_with_trailing_slash); + errdefer path.deinit(); + + // String might contain trailing slash, so trim it here + if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop(); + break :path try path.toOwnedSlice(); + }; + errdefer allocator.free(path); + + const version = version: { + var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; + const sdk_lib_dir_path = std.fmt.bufPrint(buf[0..], "{s}\\Lib\\", .{path}) catch |err| switch (err) { + error.NoSpaceLeft => return error.PathTooLong, + }; + if (!std.fs.path.isAbsolute(sdk_lib_dir_path)) return error.InstallationNotFound; + + // enumerate files in sdk path looking for latest version + var sdk_lib_dir = std.fs.openDirAbsolute(sdk_lib_dir_path, .{ + .iterate = true, + }) catch |err| switch (err) { + error.NameTooLong => return error.PathTooLong, + else => return error.InstallationNotFound, + }; + defer sdk_lib_dir.close(); + + var iterator = sdk_lib_dir.iterate(); + const versions = try iterateAndFilterByVersion(&iterator, allocator, prefix); + defer { + for (versions[1..]) |version| allocator.free(version); + allocator.free(versions); + } + break :version versions[0]; + }; + errdefer allocator.free(version); + + return .{ .path = path, .version = version }; + } + + fn findFromInstallationFolder( + allocator: std.mem.Allocator, + version_key_name: []const u8, + ) error{ OutOfMemory, InstallationNotFound, PathTooLong, VersionTooLong }!Installation { + var key_name_buf: [RegistryWtf16Le.key_name_max_len]u8 = undefined; + const key = key: for ([_][]const u8{ "\\Wow6432Node", "" }) |wow6432node| { + for ([_]windows.HKEY{ windows.HKEY_LOCAL_MACHINE, windows.HKEY_CURRENT_USER }) |hkey| { + break :key RegistryWtf8.openKey(hkey, std.fmt.bufPrint( + &key_name_buf, + "SOFTWARE{s}\\Microsoft\\Microsoft SDKs\\Windows\\{s}", + .{ wow6432node, version_key_name }, + ) catch unreachable) catch |err| switch (err) { + error.KeyNotFound => return error.InstallationNotFound, + }; + } + } else return error.InstallationNotFound; + defer key.closeKey(); + + const path: []const u8 = path: { + const path_maybe_with_trailing_slash = key.getString(allocator, "", "InstallationFolder") catch |err| switch (err) { + error.NotAString => return error.InstallationNotFound, + error.ValueNameNotFound => return error.InstallationNotFound, + error.StringNotFound => return error.InstallationNotFound, error.OutOfMemory => return error.OutOfMemory, }; @@ -443,17 +518,17 @@ pub const Windows10Sdk = struct { if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop(); const path_without_trailing_slash = try path.toOwnedSlice(); - break :path10 path_without_trailing_slash; + break :path path_without_trailing_slash; }; errdefer allocator.free(path); - const version: []const u8 = version10: { + const version: []const u8 = version: { // note(dimenus): Microsoft doesn't include the .0 in the ProductVersion key.... - const version_without_0 = v10_key.getString(allocator, "", "ProductVersion") catch |err| switch (err) { - error.NotAString => return error.Windows10SdkNotFound, - error.ValueNameNotFound => return error.Windows10SdkNotFound, - error.StringNotFound => return error.Windows10SdkNotFound, + const version_without_0 = key.getString(allocator, "", "ProductVersion") catch |err| switch (err) { + error.NotAString => return error.InstallationNotFound, + error.ValueNameNotFound => return error.InstallationNotFound, + error.StringNotFound => return error.InstallationNotFound, error.OutOfMemory => return error.OutOfMemory, }; @@ -468,21 +543,27 @@ pub const Windows10Sdk = struct { try version.appendSlice(".0"); const version_with_0 = try version.toOwnedSlice(); - break :version10 version_with_0; + break :version version_with_0; }; errdefer allocator.free(version); - return Windows10Sdk{ .path = path, .version = version }; + return .{ .path = path, .version = version }; } /// Check whether this version is enumerated in registry. - fn isValidVersion(windows10sdk: *const Windows10Sdk) bool { + fn isValidVersion(installation: Installation) bool { var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - const reg_query_as_wtf8 = std.fmt.bufPrint(buf[0..], "{s}\\{s}\\Installed Options", .{ WINDOWS_KIT_REG_KEY, windows10sdk.version }) catch |err| switch (err) { + const reg_query_as_wtf8 = std.fmt.bufPrint(buf[0..], "{s}\\{s}\\Installed Options", .{ + windows_kits_reg_key, + installation.version, + }) catch |err| switch (err) { error.NoSpaceLeft => return false, }; - const options_key = RegistryWtf8.openKey(windows.HKEY_LOCAL_MACHINE, reg_query_as_wtf8) catch |err| switch (err) { + const options_key = RegistryWtf8.openKey( + windows.HKEY_LOCAL_MACHINE, + reg_query_as_wtf8, + ) catch |err| switch (err) { error.KeyNotFound => return false, }; defer options_key.closeKey(); @@ -492,87 +573,16 @@ pub const Windows10Sdk = struct { .aarch64 => "OptionId.DesktopCPParm64", .x86_64 => "OptionId.DesktopCPPx64", .x86 => "OptionId.DesktopCPPx86", - else => |tag| @compileError("Windows 10 SDK cannot be detected on architecture " ++ tag), + else => |tag| @compileError("Windows SDK cannot be detected on architecture " ++ tag), }; const reg_value = options_key.getDword("", option_name) catch return false; return (reg_value == 1); } - fn free(self: *const Windows10Sdk, allocator: std.mem.Allocator) void { - allocator.free(self.path); - allocator.free(self.version); - } -}; - -pub const Windows81Sdk = struct { - path: []const u8, - version: []const u8, - - /// Find path and version of Windows 8.1 SDK. - /// Caller owns the result's fields. - /// After finishing work, call `free(allocator)`. - fn find(allocator: std.mem.Allocator, roots_key: *const RegistryWtf8) error{ OutOfMemory, Windows81SdkNotFound, PathTooLong, VersionTooLong }!Windows81Sdk { - const path: []const u8 = path81: { - const path_maybe_with_trailing_slash = roots_key.getString(allocator, "", "KitsRoot81") catch |err| switch (err) { - error.NotAString => return error.Windows81SdkNotFound, - error.ValueNameNotFound => return error.Windows81SdkNotFound, - error.StringNotFound => return error.Windows81SdkNotFound, - - error.OutOfMemory => return error.OutOfMemory, - }; - if (path_maybe_with_trailing_slash.len > std.fs.MAX_PATH_BYTES or !std.fs.path.isAbsolute(path_maybe_with_trailing_slash)) { - allocator.free(path_maybe_with_trailing_slash); - return error.PathTooLong; - } - - var path = std.ArrayList(u8).fromOwnedSlice(allocator, path_maybe_with_trailing_slash); - errdefer path.deinit(); - - // String might contain trailing slash, so trim it here - if (path.items.len > "C:\\".len and path.getLast() == '\\') _ = path.pop(); - - const path_without_trailing_slash = try path.toOwnedSlice(); - break :path81 path_without_trailing_slash; - }; - errdefer allocator.free(path); - - const version: []const u8 = version81: { - var buf: [std.fs.MAX_PATH_BYTES]u8 = undefined; - const sdk_lib_dir_path = std.fmt.bufPrint(buf[0..], "{s}\\Lib\\", .{path}) catch |err| switch (err) { - error.NoSpaceLeft => return error.PathTooLong, - }; - if (!std.fs.path.isAbsolute(sdk_lib_dir_path)) return error.Windows81SdkNotFound; - - // enumerate files in sdk path looking for latest version - var sdk_lib_dir = std.fs.openDirAbsolute(sdk_lib_dir_path, .{ - .iterate = true, - }) catch |err| switch (err) { - error.NameTooLong => return error.PathTooLong, - else => return error.Windows81SdkNotFound, - }; - defer sdk_lib_dir.close(); - - var iterator = sdk_lib_dir.iterate(); - const versions = iterateAndFilterBySemVer(&iterator, allocator, "winv") catch |err| switch (err) { - error.OutOfMemory => return error.OutOfMemory, - error.VersionNotFound => return error.Windows81SdkNotFound, - }; - defer { - for (versions) |version| allocator.free(version); - allocator.free(versions); - } - const latest_version = try allocator.dupe(u8, versions[0]); - break :version81 latest_version; - }; - errdefer allocator.free(version); - - return Windows81Sdk{ .path = path, .version = version }; - } - - fn free(self: *const Windows81Sdk, allocator: std.mem.Allocator) void { - allocator.free(self.path); - allocator.free(self.version); + fn free(install: Installation, allocator: std.mem.Allocator) void { + allocator.free(install.path); + allocator.free(install.version); } }; @@ -634,7 +644,7 @@ const MsvcLibDir = struct { /// Example: 17.4.33205.214 -> 0x0011000481b500d6 fn parseVersionQuad(version: []const u8) error{InvalidVersion}!u64 { var it = std.mem.splitScalar(u8, version, '.'); - const a = it.next() orelse return error.InvalidVersion; + const a = it.first(); const b = it.next() orelse return error.InvalidVersion; const c = it.next() orelse return error.InvalidVersion; const d = it.next() orelse return error.InvalidVersion; @@ -791,11 +801,7 @@ const MsvcLibDir = struct { defer visualstudio_folder.close(); var iterator = visualstudio_folder.iterate(); - const versions = iterateAndFilterBySemVer(&iterator, allocator, null) catch |err| switch (err) { - error.OutOfMemory => return error.OutOfMemory, - error.VersionNotFound => return error.PathNotFound, - }; - break :vs_versions versions; + break :vs_versions try iterateAndFilterByVersion(&iterator, allocator, ""); }; defer { for (vs_versions) |vs_version| allocator.free(vs_version); From 71ccdb5a66da500f8447018553ff0ac32e55face Mon Sep 17 00:00:00 2001 From: Jacob Young Date: Sat, 13 Apr 2024 23:12:52 -0400 Subject: [PATCH 2/2] ci: add self-hosted x86_64 windows --- .github/workflows/ci.yaml | 4 ++-- ci/aarch64-linux-debug.sh | 12 ++++++------ ci/aarch64-linux-release.sh | 12 ++++++------ ci/aarch64-macos-debug.sh | 8 ++++---- ci/aarch64-macos-release.sh | 8 ++++---- ci/x86_64-linux-debug.sh | 12 ++++++------ ci/x86_64-linux-release.sh | 12 ++++++------ ci/x86_64-macos-release.sh | 8 ++++---- ci/x86_64-windows-debug.ps1 | 17 +++++------------ ci/x86_64-windows-release.ps1 | 17 +++++------------ 10 files changed, 48 insertions(+), 62 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index d09466f82d..ad67596360 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -69,7 +69,7 @@ jobs: - name: Build and Test run: ci/aarch64-macos-release.sh x86_64-windows-debug: - runs-on: windows-latest + runs-on: [self-hosted, Windows, x86_64] env: ARCH: "x86_64" steps: @@ -78,7 +78,7 @@ jobs: - name: Build and Test run: ci/x86_64-windows-debug.ps1 x86_64-windows-release: - runs-on: windows-latest + runs-on: [self-hosted, Windows, x86_64] env: ARCH: "x86_64" steps: diff --git a/ci/aarch64-linux-debug.sh b/ci/aarch64-linux-debug.sh index 750f76e103..5f71607be8 100644 --- a/ci/aarch64-linux-debug.sh +++ b/ci/aarch64-linux-debug.sh @@ -29,8 +29,8 @@ cd build-debug # Override the cache directories because they won't actually help other CI runs # which will be testing alternate versions of zig, and ultimately would just # fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" cmake .. \ -DCMAKE_INSTALL_PREFIX="stage3-debug" \ @@ -67,7 +67,7 @@ stage3-debug/bin/zig build test docs \ -Dstatic-llvm \ -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ - --zig-lib-dir "$(pwd)/../lib" + --zig-lib-dir "$PWD/../lib" # Look for HTML errors. # TODO: move this to a build.zig flag (-Denable-tidy) @@ -80,8 +80,8 @@ rm -rf ../build-new mkdir ../build-new cd ../build-new -export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" @@ -105,5 +105,5 @@ stage3/bin/zig build -p stage4 \ -Dtarget=native-native-musl \ -Dno-lib \ --search-prefix "$PREFIX" \ - --zig-lib-dir "$(pwd)/../lib" + --zig-lib-dir "$PWD/../lib" stage4/bin/zig test ../test/behavior.zig diff --git a/ci/aarch64-linux-release.sh b/ci/aarch64-linux-release.sh index 2a70b4dd1a..87c908807b 100644 --- a/ci/aarch64-linux-release.sh +++ b/ci/aarch64-linux-release.sh @@ -29,8 +29,8 @@ cd build-release # Override the cache directories because they won't actually help other CI runs # which will be testing alternate versions of zig, and ultimately would just # fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" cmake .. \ -DCMAKE_INSTALL_PREFIX="stage3-release" \ @@ -67,7 +67,7 @@ stage3-release/bin/zig build test docs \ -Dstatic-llvm \ -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ - --zig-lib-dir "$(pwd)/../lib" + --zig-lib-dir "$PWD/../lib" # Look for HTML errors. # TODO: move this to a build.zig flag (-Denable-tidy) @@ -80,8 +80,8 @@ rm -rf ../build-new mkdir ../build-new cd ../build-new -export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" @@ -105,5 +105,5 @@ stage3/bin/zig build -p stage4 \ -Dtarget=native-native-musl \ -Dno-lib \ --search-prefix "$PREFIX" \ - --zig-lib-dir "$(pwd)/../lib" + --zig-lib-dir "$PWD/../lib" stage4/bin/zig test ../test/behavior.zig diff --git a/ci/aarch64-macos-debug.sh b/ci/aarch64-macos-debug.sh index 33712cefdf..fb85914c49 100755 --- a/ci/aarch64-macos-debug.sh +++ b/ci/aarch64-macos-debug.sh @@ -6,7 +6,7 @@ set -e # Script assumes the presence of the following: # s3cmd -ZIGDIR="$(pwd)" +ZIGDIR="$PWD" TARGET="$ARCH-macos-none" MCPU="baseline" CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866" @@ -26,8 +26,8 @@ cd build # Override the cache directories because they won't actually help other CI runs # which will be testing alternate versions of zig, and ultimately would just # fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" PATH="$HOME/local/bin:$PATH" cmake .. \ -DCMAKE_INSTALL_PREFIX="stage3-debug" \ @@ -44,7 +44,7 @@ PATH="$HOME/local/bin:$PATH" cmake .. \ $HOME/local/bin/ninja install stage3-debug/bin/zig build test docs \ - --zig-lib-dir "$(pwd)/../lib" \ + --zig-lib-dir "$PWD/../lib" \ -Denable-macos-sdk \ -Dstatic-llvm \ -Dskip-non-native \ diff --git a/ci/aarch64-macos-release.sh b/ci/aarch64-macos-release.sh index b3b82180e5..e34c3e31da 100755 --- a/ci/aarch64-macos-release.sh +++ b/ci/aarch64-macos-release.sh @@ -6,7 +6,7 @@ set -e # Script assumes the presence of the following: # s3cmd -ZIGDIR="$(pwd)" +ZIGDIR="$PWD" TARGET="$ARCH-macos-none" MCPU="baseline" CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866" @@ -26,8 +26,8 @@ cd build # Override the cache directories because they won't actually help other CI runs # which will be testing alternate versions of zig, and ultimately would just # fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" PATH="$HOME/local/bin:$PATH" cmake .. \ -DCMAKE_INSTALL_PREFIX="stage3-release" \ @@ -44,7 +44,7 @@ PATH="$HOME/local/bin:$PATH" cmake .. \ $HOME/local/bin/ninja install stage3-release/bin/zig build test docs \ - --zig-lib-dir "$(pwd)/../lib" \ + --zig-lib-dir "$PWD/../lib" \ -Denable-macos-sdk \ -Dstatic-llvm \ -Dskip-non-native \ diff --git a/ci/x86_64-linux-debug.sh b/ci/x86_64-linux-debug.sh index 828f46c0f4..f818073b36 100755 --- a/ci/x86_64-linux-debug.sh +++ b/ci/x86_64-linux-debug.sh @@ -37,8 +37,8 @@ cd build-debug # Override the cache directories because they won't actually help other CI runs # which will be testing alternate versions of zig, and ultimately would just # fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" cmake .. \ -DCMAKE_INSTALL_PREFIX="stage3-debug" \ @@ -75,7 +75,7 @@ stage3-debug/bin/zig build test docs \ -Dstatic-llvm \ -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ - --zig-lib-dir "$(pwd)/../lib" + --zig-lib-dir "$PWD/../lib" # Look for HTML errors. # TODO: move this to a build.zig flag (-Denable-tidy) @@ -88,8 +88,8 @@ rm -rf ../build-new mkdir ../build-new cd ../build-new -export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" @@ -113,5 +113,5 @@ stage3/bin/zig build -p stage4 \ -Dtarget=native-native-musl \ -Dno-lib \ --search-prefix "$PREFIX" \ - --zig-lib-dir "$(pwd)/../lib" + --zig-lib-dir "$PWD/../lib" stage4/bin/zig test ../test/behavior.zig diff --git a/ci/x86_64-linux-release.sh b/ci/x86_64-linux-release.sh index 08f2b6c477..e73c074b28 100755 --- a/ci/x86_64-linux-release.sh +++ b/ci/x86_64-linux-release.sh @@ -37,8 +37,8 @@ cd build-release # Override the cache directories because they won't actually help other CI runs # which will be testing alternate versions of zig, and ultimately would just # fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" cmake .. \ -DCMAKE_INSTALL_PREFIX="stage3-release" \ @@ -76,7 +76,7 @@ stage3-release/bin/zig build test docs \ -Dstatic-llvm \ -Dtarget=native-native-musl \ --search-prefix "$PREFIX" \ - --zig-lib-dir "$(pwd)/../lib" + --zig-lib-dir "$PWD/../lib" # Look for HTML errors. # TODO: move this to a build.zig flag (-Denable-tidy) @@ -105,8 +105,8 @@ rm -rf ../build-new mkdir ../build-new cd ../build-new -export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" export CC="$ZIG cc -target $TARGET -mcpu=$MCPU" export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU" @@ -130,5 +130,5 @@ stage3/bin/zig build -p stage4 \ -Dtarget=native-native-musl \ -Dno-lib \ --search-prefix "$PREFIX" \ - --zig-lib-dir "$(pwd)/../lib" + --zig-lib-dir "$PWD/../lib" stage4/bin/zig test ../test/behavior.zig diff --git a/ci/x86_64-macos-release.sh b/ci/x86_64-macos-release.sh index 041941b2cf..c67613d3fc 100755 --- a/ci/x86_64-macos-release.sh +++ b/ci/x86_64-macos-release.sh @@ -3,7 +3,7 @@ set -x set -e -ZIGDIR="$(pwd)" +ZIGDIR="$PWD" TARGET="$ARCH-macos-none" MCPU="baseline" CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.12.0-dev.467+0345d7866" @@ -40,8 +40,8 @@ cd build # Override the cache directories because they won't actually help other CI runs # which will be testing alternate versions of zig, and ultimately would just # fill up space on the hard drive for no reason. -export ZIG_GLOBAL_CACHE_DIR="$(pwd)/zig-global-cache" -export ZIG_LOCAL_CACHE_DIR="$(pwd)/zig-local-cache" +export ZIG_GLOBAL_CACHE_DIR="$PWD/zig-global-cache" +export ZIG_LOCAL_CACHE_DIR="$PWD/zig-local-cache" cmake .. \ -DCMAKE_PREFIX_PATH="$PREFIX" \ @@ -56,7 +56,7 @@ cmake .. \ make $JOBS install stage3/bin/zig build test docs \ - --zig-lib-dir "$(pwd)/../lib" \ + --zig-lib-dir "$PWD/../lib" \ -Denable-macos-sdk \ -Dstatic-llvm \ -Dskip-non-native \ diff --git a/ci/x86_64-windows-debug.ps1 b/ci/x86_64-windows-debug.ps1 index 84cf253957..6f8039883d 100644 --- a/ci/x86_64-windows-debug.ps1 +++ b/ci/x86_64-windows-debug.ps1 @@ -1,19 +1,10 @@ $TARGET = "$($Env:ARCH)-windows-gnu" $ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.12.0-dev.2073+402fe565a" $MCPU = "baseline" -$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip" -$PREFIX_PATH = "$(Get-Location)\$ZIG_LLVM_CLANG_LLD_NAME" +$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME" $ZIG = "$PREFIX_PATH\bin\zig.exe" $ZIG_LIB_DIR = "$(Get-Location)\lib" -choco install ninja -Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL" -Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$ZIG_LLVM_CLANG_LLD_NAME.zip" - -Write-Output "Extracting..." -Add-Type -AssemblyName System.IO.Compression.FileSystem ; -[System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/$ZIG_LLVM_CLANG_LLD_NAME.zip", "$PWD") - function CheckLastExitCode { if (!$?) { exit 1 @@ -43,6 +34,8 @@ Set-Location -Path 'build-debug' -DCMAKE_BUILD_TYPE=Debug ` -DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" ` -DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" ` + -DCMAKE_AR="$($ZIG -Replace "\\", "/")" ` + -DZIG_AR_WORKAROUND=ON ` -DZIG_TARGET_TRIPLE="$TARGET" ` -DZIG_TARGET_MCPU="$MCPU" ` -DZIG_STATIC=ON ` @@ -85,10 +78,10 @@ CheckLastExitCode --mod build_options config.zig CheckLastExitCode -Import-Module "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" +Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" CheckLastExitCode -Enter-VsDevShell -VsInstallPath "C:\Program Files\Microsoft Visual Studio\2022\Enterprise" ` +Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" ` -DevCmdArguments '-arch=x64 -no_logo' ` -StartInPath $(Get-Location) CheckLastExitCode diff --git a/ci/x86_64-windows-release.ps1 b/ci/x86_64-windows-release.ps1 index 4cda0ad98b..68d22c9eab 100644 --- a/ci/x86_64-windows-release.ps1 +++ b/ci/x86_64-windows-release.ps1 @@ -1,19 +1,10 @@ $TARGET = "$($Env:ARCH)-windows-gnu" $ZIG_LLVM_CLANG_LLD_NAME = "zig+llvm+lld+clang-$TARGET-0.12.0-dev.2073+402fe565a" $MCPU = "baseline" -$ZIG_LLVM_CLANG_LLD_URL = "https://ziglang.org/deps/$ZIG_LLVM_CLANG_LLD_NAME.zip" -$PREFIX_PATH = "$(Get-Location)\$ZIG_LLVM_CLANG_LLD_NAME" +$PREFIX_PATH = "$($Env:USERPROFILE)\$ZIG_LLVM_CLANG_LLD_NAME" $ZIG = "$PREFIX_PATH\bin\zig.exe" $ZIG_LIB_DIR = "$(Get-Location)\lib" -choco install ninja -Write-Output "Downloading $ZIG_LLVM_CLANG_LLD_URL" -Invoke-WebRequest -Uri "$ZIG_LLVM_CLANG_LLD_URL" -OutFile "$ZIG_LLVM_CLANG_LLD_NAME.zip" - -Write-Output "Extracting..." -Add-Type -AssemblyName System.IO.Compression.FileSystem ; -[System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD/$ZIG_LLVM_CLANG_LLD_NAME.zip", "$PWD") - function CheckLastExitCode { if (!$?) { exit 1 @@ -43,6 +34,8 @@ Set-Location -Path 'build-release' -DCMAKE_BUILD_TYPE=Release ` -DCMAKE_C_COMPILER="$($ZIG -Replace "\\", "/");cc;-target;$TARGET;-mcpu=$MCPU" ` -DCMAKE_CXX_COMPILER="$($ZIG -Replace "\\", "/");c++;-target;$TARGET;-mcpu=$MCPU" ` + -DCMAKE_AR="$($ZIG -Replace "\\", "/")" ` + -DZIG_AR_WORKAROUND=ON ` -DZIG_TARGET_TRIPLE="$TARGET" ` -DZIG_TARGET_MCPU="$MCPU" ` -DZIG_STATIC=ON ` @@ -84,10 +77,10 @@ CheckLastExitCode --mod build_options config.zig CheckLastExitCode -Import-Module "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" +Import-Module "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\Microsoft.VisualStudio.DevShell.dll" CheckLastExitCode -Enter-VsDevShell -VsInstallPath "C:\Program Files\Microsoft Visual Studio\2022\Enterprise" ` +Enter-VsDevShell -VsInstallPath "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools" ` -DevCmdArguments '-arch=x64 -no_logo' ` -StartInPath $(Get-Location) CheckLastExitCode