mirror of
https://github.com/ziglang/zig.git
synced 2026-01-21 06:45:24 +00:00
add missing implementations of libc installation to detect msvc paths
This commit is contained in:
parent
20f3b0efff
commit
5c54d7bee7
@ -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();
|
||||
|
||||
|
||||
@ -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";
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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)";
|
||||
}
|
||||
|
||||
@ -99,6 +99,7 @@ enum Error {
|
||||
ErrorLibCStdLibHeaderNotFound,
|
||||
ErrorLibCKernel32LibNotFound,
|
||||
ErrorUnsupportedArchitecture,
|
||||
ErrorWindowsSdkNotFound,
|
||||
};
|
||||
|
||||
// ABI warning
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user