From f15ec9a59b777a2b7998518858f11f5da0dfcb2d Mon Sep 17 00:00:00 2001 From: emekoi Date: Thu, 1 Aug 2019 17:51:53 -0500 Subject: implemented runtime abi detetction for windows --- src/target.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/target.cpp') diff --git a/src/target.cpp b/src/target.cpp index 7bb248a35f..d34254f1d1 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -506,7 +506,7 @@ void get_native_target(ZigTarget *target) { &oformat); target->os = get_zig_os_type(os_type); target->is_native = true; - if (target->abi == ZigLLVM_UnknownEnvironment) { + if (target->os == OsWindows || target->abi == ZigLLVM_UnknownEnvironment) { target->abi = target_default_abi(target->arch, target->os); } if (target_is_glibc(target)) { @@ -1504,6 +1504,16 @@ bool target_is_single_threaded(const ZigTarget *target) { return target_is_wasm(target); } +static ZigLLVM_EnvironmentType target_get_win32_abi() { + FILE* files[] = { stdin, stdout, stderr, nullptr }; + for (int i = 0; files[i] != nullptr; i++) { + if (os_is_cygwin_pty(_fileno(files[i]))) { + return ZigLLVM_GNU; + } + } + return ZigLLVM_MSVC; +} + ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) { if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) { return ZigLLVM_Musl; @@ -1544,8 +1554,9 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) { case OsHurd: return ZigLLVM_GNU; case OsUefi: - case OsWindows: return ZigLLVM_MSVC; + case OsWindows: + return target_get_win32_abi(); case OsLinux: case OsWASI: return ZigLLVM_Musl; -- cgit v1.2.3 From 102d3f30c406e2818c6320a48f2405fa7e1e4237 Mon Sep 17 00:00:00 2001 From: emekoi Date: Thu, 1 Aug 2019 18:27:39 -0500 Subject: accept unix style paths on windows-gnu --- src/os.cpp | 8 ++++---- src/os.hpp | 5 +++++ src/target.cpp | 2 +- std/os/windows.zig | 7 +++---- 4 files changed, 13 insertions(+), 9 deletions(-) (limited to 'src/target.cpp') diff --git a/src/os.cpp b/src/os.cpp index 5844070609..6c1a2581df 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -1130,7 +1130,7 @@ Error os_get_cwd(Buf *out_cwd) { bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) { #if defined(ZIG_OS_WINDOWS) HANDLE handle = (HANDLE)_get_osfhandle(fd); - + // Cygwin/msys's pty is a pipe. if (handle == INVALID_HANDLE_VALUE || GetFileType(handle) != FILE_TYPE_PIPE) { return false; @@ -1138,7 +1138,7 @@ bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) { int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH; WCHAR *p = NULL; - + FILE_NAME_INFO *nameinfo = (FILE_NAME_INFO *)allocate(size); if (nameinfo == NULL) { return false; @@ -1179,13 +1179,13 @@ bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) { free(nameinfo); return (p != NULL); #else - return false + return false; #endif } bool os_stderr_tty(void) { #if defined(ZIG_OS_WINDOWS) - return _isatty(_fileno(stderr)) != 0 || os_is_cygwin_pty(_fileno(stderr)); + return _isatty(fileno(stderr)) != 0 || os_is_cygwin_pty(fileno(stderr)); #elif defined(ZIG_OS_POSIX) return isatty(STDERR_FILENO) != 0; #else diff --git a/src/os.hpp b/src/os.hpp index fc0e1929f2..7354528c34 100644 --- a/src/os.hpp +++ b/src/os.hpp @@ -89,6 +89,11 @@ struct Termination { #define OsFile int #endif +#if defined(ZIG_OS_WINDOWS) +#undef fileno +#define fileno _fileno +#endif + struct OsTimeStamp { uint64_t sec; uint64_t nsec; diff --git a/src/target.cpp b/src/target.cpp index d34254f1d1..695a810e39 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -1507,7 +1507,7 @@ bool target_is_single_threaded(const ZigTarget *target) { static ZigLLVM_EnvironmentType target_get_win32_abi() { FILE* files[] = { stdin, stdout, stderr, nullptr }; for (int i = 0; files[i] != nullptr; i++) { - if (os_is_cygwin_pty(_fileno(files[i]))) { + if (os_is_cygwin_pty(fileno(files[i]))) { return ZigLLVM_GNU; } } diff --git a/std/os/windows.zig b/std/os/windows.zig index ac76e8f58f..954e56443f 100644 --- a/std/os/windows.zig +++ b/std/os/windows.zig @@ -65,7 +65,7 @@ pub const CreateFileError = error{ InvalidUtf8, /// On Windows, file paths cannot contain these characters: - /// '/', '*', '?', '"', '<', '>', '|' + /// '*', '?', '"', '<', '>', '|', and '/' (when the ABI is not GNU) BadPathName, Unexpected, @@ -831,8 +831,8 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) // disallow forward slashes in zig std lib file functions on Windows. for (s) |byte| { switch (byte) { - '/', '*', '?', '"', '<', '>', '|' => return error.BadPathName, - else => {}, + '*', '?', '"', '<', '>', '|' => return error.BadPathName, + else => if (builtin.abi == .msvc and byte == '/') return error.BadPathName, } } const start_index = if (mem.startsWith(u8, s, "\\\\") or !std.fs.path.isAbsolute(s)) 0 else blk: { @@ -866,7 +866,6 @@ pub fn unexpectedError(err: DWORD) std.os.UnexpectedError { return error.Unexpected; } - /// Call this when you made a windows NtDll call /// and you get an unexpected status. pub fn unexpectedStatus(status: NTSTATUS) std.os.UnexpectedError { -- cgit v1.2.3 From 59e2c87b4b89bf16321b499124d568ac5a19c300 Mon Sep 17 00:00:00 2001 From: emekoi Date: Sat, 3 Aug 2019 18:40:27 -0500 Subject: move windows abi detection to `get_native_target` --- src/target.cpp | 28 +++++++++++++++------------- std/os/windows.zig | 5 ++--- 2 files changed, 17 insertions(+), 16 deletions(-) (limited to 'src/target.cpp') diff --git a/src/target.cpp b/src/target.cpp index 695a810e39..4a45707f78 100644 --- a/src/target.cpp +++ b/src/target.cpp @@ -491,6 +491,16 @@ Error target_parse_glibc_version(ZigGLibCVersion *glibc_ver, const char *text) { return ErrorNone; } +static ZigLLVM_EnvironmentType target_get_win32_abi() { + FILE* files[] = { stdin, stdout, stderr, nullptr }; + for (int i = 0; files[i] != nullptr; i++) { + if (os_is_cygwin_pty(fileno(files[i]))) { + return ZigLLVM_GNU; + } + } + return ZigLLVM_MSVC; +} + void get_native_target(ZigTarget *target) { // first zero initialize *target = {}; @@ -505,8 +515,11 @@ void get_native_target(ZigTarget *target) { &target->abi, &oformat); target->os = get_zig_os_type(os_type); + if (target->os == OsWindows) { + target->abi = target_get_win32_abi(); + } target->is_native = true; - if (target->os == OsWindows || target->abi == ZigLLVM_UnknownEnvironment) { + if (target->abi == ZigLLVM_UnknownEnvironment) { target->abi = target_default_abi(target->arch, target->os); } if (target_is_glibc(target)) { @@ -1504,16 +1517,6 @@ bool target_is_single_threaded(const ZigTarget *target) { return target_is_wasm(target); } -static ZigLLVM_EnvironmentType target_get_win32_abi() { - FILE* files[] = { stdin, stdout, stderr, nullptr }; - for (int i = 0; files[i] != nullptr; i++) { - if (os_is_cygwin_pty(fileno(files[i]))) { - return ZigLLVM_GNU; - } - } - return ZigLLVM_MSVC; -} - ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) { if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) { return ZigLLVM_Musl; @@ -1554,9 +1557,8 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) { case OsHurd: return ZigLLVM_GNU; case OsUefi: - return ZigLLVM_MSVC; case OsWindows: - return target_get_win32_abi(); + return ZigLLVM_MSVC; case OsLinux: case OsWASI: return ZigLLVM_Musl; diff --git a/std/os/windows.zig b/std/os/windows.zig index 954e56443f..eccc968561 100644 --- a/std/os/windows.zig +++ b/std/os/windows.zig @@ -827,12 +827,11 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16) // > converting the name to an NT-style name, except when using the "\\?\" // > prefix as detailed in the following sections. // from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation - // Because we want the larger maximum path length for absolute paths, we - // disallow forward slashes in zig std lib file functions on Windows. for (s) |byte| { switch (byte) { '*', '?', '"', '<', '>', '|' => return error.BadPathName, - else => if (builtin.abi == .msvc and byte == '/') return error.BadPathName, + '/' => if (builtin.abi == .msvc) return error.BadPathName, + else => {}, } } const start_index = if (mem.startsWith(u8, s, "\\\\") or !std.fs.path.isAbsolute(s)) 0 else blk: { -- cgit v1.2.3