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 {...@@ -96,7 +96,6 @@ pub fn updateFile(source_path: []const u8, dest_path: []const u8) !PrevStatus {
96/// atime, and mode of the source file so that the next call to `updateFile` will not need a copy.96/// atime, and mode of the source file so that the next call to `updateFile` will not need a copy.
97/// Returns the previous status of the file before updating.97/// Returns the previous status of the file before updating.
98/// If any of the directories do not exist for dest_path, they are created.98/// If any of the directories do not exist for dest_path, they are created.
99/// TODO https://github.com/ziglang/zig/issues/2885
100pub fn updateFileMode(source_path: []const u8, dest_path: []const u8, mode: ?File.Mode) !PrevStatus {99pub fn updateFileMode(source_path: []const u8, dest_path: []const u8, mode: ?File.Mode) !PrevStatus {
101 const my_cwd = cwd();100 const my_cwd = cwd();
102101
src-self-hosted/libc_installation.zig+51-4
...@@ -36,6 +36,7 @@ pub const LibCInstallation = struct {...@@ -36,6 +36,7 @@ pub const LibCInstallation = struct {
36 LibCStdLibHeaderNotFound,36 LibCStdLibHeaderNotFound,
37 LibCKernel32LibNotFound,37 LibCKernel32LibNotFound,
38 UnsupportedArchitecture,38 UnsupportedArchitecture,
39 WindowsSdkNotFound,
39 };40 };
4041
41 pub fn parse(42 pub fn parse(
...@@ -174,7 +175,7 @@ pub const LibCInstallation = struct {...@@ -174,7 +175,7 @@ pub const LibCInstallation = struct {
174 }175 }
175176
176 /// Finds the default, native libc.177 /// Finds the default, native libc.
177 pub fn findNative(allocator: *Allocator) !LibCInstallation {178 pub fn findNative(allocator: *Allocator) FindError!LibCInstallation {
178 var self: LibCInstallation = .{};179 var self: LibCInstallation = .{};
179180
180 if (is_windows) {181 if (is_windows) {
...@@ -199,8 +200,8 @@ pub const LibCInstallation = struct {...@@ -199,8 +200,8 @@ pub const LibCInstallation = struct {
199 try batch.wait();200 try batch.wait();
200 },201 },
201 .OutOfMemory => return error.OutOfMemory,202 .OutOfMemory => return error.OutOfMemory,
202 .NotFound => return error.NotFound,203 .NotFound => return error.WindowsSdkNotFound,
203 .PathTooLong => return error.NotFound,204 .PathTooLong => return error.WindowsSdkNotFound,
204 }205 }
205 }206 }
206 } else {207 } else {
...@@ -311,7 +312,11 @@ pub const LibCInstallation = struct {...@@ -311,7 +312,11 @@ pub const LibCInstallation = struct {
311 return error.LibCStdLibHeaderNotFound;312 return error.LibCStdLibHeaderNotFound;
312 }313 }
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 {
315 var search_buf: [2]Search = undefined;320 var search_buf: [2]Search = undefined;
316 const searches = fillSearch(&search_buf, sdk);321 const searches = fillSearch(&search_buf, sdk);
317322
...@@ -432,6 +437,48 @@ pub const LibCInstallation = struct {...@@ -432,6 +437,48 @@ pub const LibCInstallation = struct {
432 }437 }
433 return error.LibCKernel32LibNotFound;438 return error.LibCKernel32LibNotFound;
434 }439 }
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 }
435};482};
436483
437const default_cc_exe = if (is_windows) "cc.exe" else "cc";484const default_cc_exe = if (is_windows) "cc.exe" else "cc";
src-self-hosted/stage2.zig+2
...@@ -108,6 +108,7 @@ const Error = extern enum {...@@ -108,6 +108,7 @@ const Error = extern enum {
108 LibCStdLibHeaderNotFound,108 LibCStdLibHeaderNotFound,
109 LibCKernel32LibNotFound,109 LibCKernel32LibNotFound,
110 UnsupportedArchitecture,110 UnsupportedArchitecture,
111 WindowsSdkNotFound,
111};112};
112113
113const FILE = std.c.FILE;114const FILE = std.c.FILE;
...@@ -985,6 +986,7 @@ export fn stage2_libc_find_native(stage1_libc: *Stage2LibCInstallation) Error {...@@ -985,6 +986,7 @@ export fn stage2_libc_find_native(stage1_libc: *Stage2LibCInstallation) Error {
985 error.LibCStdLibHeaderNotFound => return .LibCStdLibHeaderNotFound,986 error.LibCStdLibHeaderNotFound => return .LibCStdLibHeaderNotFound,
986 error.LibCKernel32LibNotFound => return .LibCKernel32LibNotFound,987 error.LibCKernel32LibNotFound => return .LibCKernel32LibNotFound,
987 error.UnsupportedArchitecture => return .UnsupportedArchitecture,988 error.UnsupportedArchitecture => return .UnsupportedArchitecture,
989 error.WindowsSdkNotFound => return .WindowsSdkNotFound,
988 };990 };
989 stage1_libc.initFromStage2(libc);991 stage1_libc.initFromStage2(libc);
990 return .None;992 return .None;
src/error.cpp+1
...@@ -79,6 +79,7 @@ const char *err_str(Error err) {...@@ -79,6 +79,7 @@ const char *err_str(Error err) {
79 case ErrorLibCStdLibHeaderNotFound: return "libc std lib headers not found";79 case ErrorLibCStdLibHeaderNotFound: return "libc std lib headers not found";
80 case ErrorLibCKernel32LibNotFound: return "kernel32 library not found";80 case ErrorLibCKernel32LibNotFound: return "kernel32 library not found";
81 case ErrorUnsupportedArchitecture: return "unsupported architecture";81 case ErrorUnsupportedArchitecture: return "unsupported architecture";
82 case ErrorWindowsSdkNotFound: return "Windows SDK not found";
82 }83 }
83 return "(invalid error)";84 return "(invalid error)";
84}85}
src/stage2.h+1
...@@ -99,6 +99,7 @@ enum Error {...@@ -99,6 +99,7 @@ enum Error {
99 ErrorLibCStdLibHeaderNotFound,99 ErrorLibCStdLibHeaderNotFound,
100 ErrorLibCKernel32LibNotFound,100 ErrorLibCKernel32LibNotFound,
101 ErrorUnsupportedArchitecture,101 ErrorUnsupportedArchitecture,
102 ErrorWindowsSdkNotFound,
102};103};
103104
104// ABI warning105// ABI warning