diff --git a/lib/std/fs.zig b/lib/std/fs.zig index bc9ae6aa2d..a00ba6a63f 100644 --- a/lib/std/fs.zig +++ b/lib/std/fs.zig @@ -96,7 +96,6 @@ pub fn updateFile(source_path: []const u8, dest_path: []const u8) !PrevStatus { /// atime, and mode of the source file so that the next call to `updateFile` will not need a copy. /// Returns the previous status of the file before updating. /// If any of the directories do not exist for dest_path, they are created. -/// TODO https://github.com/ziglang/zig/issues/2885 pub fn updateFileMode(source_path: []const u8, dest_path: []const u8, mode: ?File.Mode) !PrevStatus { const my_cwd = cwd(); diff --git a/src-self-hosted/libc_installation.zig b/src-self-hosted/libc_installation.zig index d66f00c14e..85d6fc61ed 100644 --- a/src-self-hosted/libc_installation.zig +++ b/src-self-hosted/libc_installation.zig @@ -36,6 +36,7 @@ pub const LibCInstallation = struct { LibCStdLibHeaderNotFound, LibCKernel32LibNotFound, UnsupportedArchitecture, + WindowsSdkNotFound, }; pub fn parse( @@ -174,7 +175,7 @@ pub const LibCInstallation = struct { } /// Finds the default, native libc. - pub fn findNative(allocator: *Allocator) !LibCInstallation { + pub fn findNative(allocator: *Allocator) FindError!LibCInstallation { var self: LibCInstallation = .{}; if (is_windows) { @@ -199,8 +200,8 @@ pub const LibCInstallation = struct { try batch.wait(); }, .OutOfMemory => return error.OutOfMemory, - .NotFound => return error.NotFound, - .PathTooLong => return error.NotFound, + .NotFound => return error.WindowsSdkNotFound, + .PathTooLong => return error.WindowsSdkNotFound, } } } else { @@ -311,7 +312,11 @@ pub const LibCInstallation = struct { return error.LibCStdLibHeaderNotFound; } - fn findNativeIncludeDirWindows(self: *LibCInstallation, allocator: *Allocator, sdk: *ZigWindowsSDK) !void { + fn findNativeIncludeDirWindows( + self: *LibCInstallation, + allocator: *Allocator, + sdk: *ZigWindowsSDK, + ) FindError!void { var search_buf: [2]Search = undefined; const searches = fillSearch(&search_buf, sdk); @@ -432,6 +437,48 @@ pub const LibCInstallation = struct { } return error.LibCKernel32LibNotFound; } + + fn findNativeMsvcIncludeDir( + self: *LibCInstallation, + allocator: *Allocator, + sdk: *ZigWindowsSDK, + ) FindError!void { + const msvc_lib_dir_ptr = sdk.msvc_lib_dir_ptr orelse return error.LibCStdLibHeaderNotFound; + const msvc_lib_dir = msvc_lib_dir_ptr[0..sdk.msvc_lib_dir_len]; + const up1 = fs.path.dirname(msvc_lib_dir) orelse return error.LibCStdLibHeaderNotFound; + const up2 = fs.path.dirname(up1) orelse return error.LibCStdLibHeaderNotFound; + + var result_buf = try std.Buffer.init(allocator, up2); + defer result_buf.deinit(); + + try result_buf.append("\\include"); + + var dir = fs.cwd().openDirList(result_buf.toSliceConst()) catch |err| switch (err) { + error.FileNotFound, + error.NotDir, + error.NoDevice, + => return error.LibCStdLibHeaderNotFound, + + else => return error.FileSystem, + }; + defer dir.close(); + + dir.accessZ("vcruntime.h", .{}) catch |err| switch (err) { + error.FileNotFound => return error.LibCStdLibHeaderNotFound, + else => return error.FileSystem, + }; + + self.sys_include_dir = result_buf.toOwnedSlice(); + } + + fn findNativeMsvcLibDir( + self: *LibCInstallation, + allocator: *Allocator, + sdk: *ZigWindowsSDK, + ) FindError!void { + const msvc_lib_dir_ptr = sdk.msvc_lib_dir_ptr orelse return error.LibCRuntimeNotFound; + self.msvc_lib_dir = try std.mem.dupeZ(allocator, u8, msvc_lib_dir_ptr[0..sdk.msvc_lib_dir_len]); + } }; const default_cc_exe = if (is_windows) "cc.exe" else "cc"; diff --git a/src-self-hosted/stage2.zig b/src-self-hosted/stage2.zig index 95719d47a9..897f2a3ed8 100644 --- a/src-self-hosted/stage2.zig +++ b/src-self-hosted/stage2.zig @@ -108,6 +108,7 @@ const Error = extern enum { LibCStdLibHeaderNotFound, LibCKernel32LibNotFound, UnsupportedArchitecture, + WindowsSdkNotFound, }; const FILE = std.c.FILE; @@ -985,6 +986,7 @@ export fn stage2_libc_find_native(stage1_libc: *Stage2LibCInstallation) Error { error.LibCStdLibHeaderNotFound => return .LibCStdLibHeaderNotFound, error.LibCKernel32LibNotFound => return .LibCKernel32LibNotFound, error.UnsupportedArchitecture => return .UnsupportedArchitecture, + error.WindowsSdkNotFound => return .WindowsSdkNotFound, }; stage1_libc.initFromStage2(libc); return .None; diff --git a/src/error.cpp b/src/error.cpp index 1e0267eb67..b7cc8e630a 100644 --- a/src/error.cpp +++ b/src/error.cpp @@ -79,6 +79,7 @@ const char *err_str(Error err) { case ErrorLibCStdLibHeaderNotFound: return "libc std lib headers not found"; case ErrorLibCKernel32LibNotFound: return "kernel32 library not found"; case ErrorUnsupportedArchitecture: return "unsupported architecture"; + case ErrorWindowsSdkNotFound: return "Windows SDK not found"; } return "(invalid error)"; } diff --git a/src/stage2.h b/src/stage2.h index f6bb17c884..856a5c3df8 100644 --- a/src/stage2.h +++ b/src/stage2.h @@ -99,6 +99,7 @@ enum Error { ErrorLibCStdLibHeaderNotFound, ErrorLibCKernel32LibNotFound, ErrorUnsupportedArchitecture, + ErrorWindowsSdkNotFound, }; // ABI warning