authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-16 19:58:27-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-02-16 19:58:27-05:00
log5c54d7bee7ca4d7d7948e2549fd67b61e2dcaf17
treee2afba1cbd2b853dc9a8843158f001eb1880b8bf
parent20f3b0efff76cb3c611b72c1c1862490aef79b80
signaturelock-open Commit is signed but in an unrecognized format.

add missing implementations of libc installation to detect msvc paths


5 files changed, 55 insertions(+), 5 deletions(-)

lib/std/fs.zig-1
......@@ -96,7 +96,6 @@ pub fn updateFile(source_path: []const u8, dest_path: []const u8) !PrevStatus {
9696/// atime, and mode of the source file so that the next call to `updateFile` will not need a copy.
9797/// Returns the previous status of the file before updating.
9898/// If any of the directories do not exist for dest_path, they are created.
99/// TODO https://github.com/ziglang/zig/issues/2885
10099pub fn updateFileMode(source_path: []const u8, dest_path: []const u8, mode: ?File.Mode) !PrevStatus {
101100 const my_cwd = cwd();
102101
src-self-hosted/libc_installation.zig+51-4
......@@ -36,6 +36,7 @@ pub const LibCInstallation = struct {
3636 LibCStdLibHeaderNotFound,
3737 LibCKernel32LibNotFound,
3838 UnsupportedArchitecture,
39 WindowsSdkNotFound,
3940 };
4041
4142 pub fn parse(
......@@ -174,7 +175,7 @@ pub const LibCInstallation = struct {
174175 }
175176
176177 /// Finds the default, native libc.
177 pub fn findNative(allocator: *Allocator) !LibCInstallation {
178 pub fn findNative(allocator: *Allocator) FindError!LibCInstallation {
178179 var self: LibCInstallation = .{};
179180
180181 if (is_windows) {
......@@ -199,8 +200,8 @@ pub const LibCInstallation = struct {
199200 try batch.wait();
200201 },
201202 .OutOfMemory => return error.OutOfMemory,
202 .NotFound => return error.NotFound,
203 .PathTooLong => return error.NotFound,
203 .NotFound => return error.WindowsSdkNotFound,
204 .PathTooLong => return error.WindowsSdkNotFound,
204205 }
205206 }
206207 } else {
......@@ -311,7 +312,11 @@ pub const LibCInstallation = struct {
311312 return error.LibCStdLibHeaderNotFound;
312313 }
313314
314 fn findNativeIncludeDirWindows(self: *LibCInstallation, allocator: *Allocator, sdk: *ZigWindowsSDK) !void {
315 fn findNativeIncludeDirWindows(
316 self: *LibCInstallation,
317 allocator: *Allocator,
318 sdk: *ZigWindowsSDK,
319 ) FindError!void {
315320 var search_buf: [2]Search = undefined;
316321 const searches = fillSearch(&search_buf, sdk);
317322
......@@ -432,6 +437,48 @@ pub const LibCInstallation = struct {
432437 }
433438 return error.LibCKernel32LibNotFound;
434439 }
440
441 fn findNativeMsvcIncludeDir(
442 self: *LibCInstallation,
443 allocator: *Allocator,
444 sdk: *ZigWindowsSDK,
445 ) FindError!void {
446 const msvc_lib_dir_ptr = sdk.msvc_lib_dir_ptr orelse return error.LibCStdLibHeaderNotFound;
447 const msvc_lib_dir = msvc_lib_dir_ptr[0..sdk.msvc_lib_dir_len];
448 const up1 = fs.path.dirname(msvc_lib_dir) orelse return error.LibCStdLibHeaderNotFound;
449 const up2 = fs.path.dirname(up1) orelse return error.LibCStdLibHeaderNotFound;
450
451 var result_buf = try std.Buffer.init(allocator, up2);
452 defer result_buf.deinit();
453
454 try result_buf.append("\\include");
455
456 var dir = fs.cwd().openDirList(result_buf.toSliceConst()) catch |err| switch (err) {
457 error.FileNotFound,
458 error.NotDir,
459 error.NoDevice,
460 => return error.LibCStdLibHeaderNotFound,
461
462 else => return error.FileSystem,
463 };
464 defer dir.close();
465
466 dir.accessZ("vcruntime.h", .{}) catch |err| switch (err) {
467 error.FileNotFound => return error.LibCStdLibHeaderNotFound,
468 else => return error.FileSystem,
469 };
470
471 self.sys_include_dir = result_buf.toOwnedSlice();
472 }
473
474 fn findNativeMsvcLibDir(
475 self: *LibCInstallation,
476 allocator: *Allocator,
477 sdk: *ZigWindowsSDK,
478 ) FindError!void {
479 const msvc_lib_dir_ptr = sdk.msvc_lib_dir_ptr orelse return error.LibCRuntimeNotFound;
480 self.msvc_lib_dir = try std.mem.dupeZ(allocator, u8, msvc_lib_dir_ptr[0..sdk.msvc_lib_dir_len]);
481 }
435482};
436483
437484const default_cc_exe = if (is_windows) "cc.exe" else "cc";
src-self-hosted/stage2.zig+2
......@@ -108,6 +108,7 @@ const Error = extern enum {
108108 LibCStdLibHeaderNotFound,
109109 LibCKernel32LibNotFound,
110110 UnsupportedArchitecture,
111 WindowsSdkNotFound,
111112};
112113
113114const FILE = std.c.FILE;
......@@ -985,6 +986,7 @@ export fn stage2_libc_find_native(stage1_libc: *Stage2LibCInstallation) Error {
985986 error.LibCStdLibHeaderNotFound => return .LibCStdLibHeaderNotFound,
986987 error.LibCKernel32LibNotFound => return .LibCKernel32LibNotFound,
987988 error.UnsupportedArchitecture => return .UnsupportedArchitecture,
989 error.WindowsSdkNotFound => return .WindowsSdkNotFound,
988990 };
989991 stage1_libc.initFromStage2(libc);
990992 return .None;
src/error.cpp+1
......@@ -79,6 +79,7 @@ const char *err_str(Error err) {
7979 case ErrorLibCStdLibHeaderNotFound: return "libc std lib headers not found";
8080 case ErrorLibCKernel32LibNotFound: return "kernel32 library not found";
8181 case ErrorUnsupportedArchitecture: return "unsupported architecture";
82 case ErrorWindowsSdkNotFound: return "Windows SDK not found";
8283 }
8384 return "(invalid error)";
8485}
src/stage2.h+1
......@@ -99,6 +99,7 @@ enum Error {
9999 ErrorLibCStdLibHeaderNotFound,
100100 ErrorLibCKernel32LibNotFound,
101101 ErrorUnsupportedArchitecture,
102 ErrorWindowsSdkNotFound,
102103};
103104
104105// ABI warning