authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-21 12:29:42-04:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2019-08-21 12:29:42-04:00
logec7d7a5b14540ea3b2bab9f11318630338467965
tree857f6dea4affaa4858ef00ba543ab24e008c2efc
parent81c441f8855d4c58f0b2ff86d3d007cf0bf395d3
parent59e2c87b4b89bf16321b499124d568ac5a19c300
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #2991 from emekoi/mingw-ci

mingw improvements

4 files changed, 40 insertions(+), 20 deletions(-)

src/os.cpp+15-15
...@@ -1125,29 +1125,27 @@ Error os_get_cwd(Buf *out_cwd) {...@@ -1125,29 +1125,27 @@ Error os_get_cwd(Buf *out_cwd) {
1125#endif1125#endif
1126}1126}
11271127
1128#if defined(ZIG_OS_WINDOWS)
1129#define is_wprefix(s, prefix) \1128#define is_wprefix(s, prefix) \
1130 (wcsncmp((s), (prefix), sizeof(prefix) / sizeof(WCHAR) - 1) == 0)1129 (wcsncmp((s), (prefix), sizeof(prefix) / sizeof(WCHAR) - 1) == 0)
1131static bool is_stderr_cyg_pty(void) {1130bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd) {
1132 HANDLE stderr_handle = GetStdHandle(STD_ERROR_HANDLE);1131#if defined(ZIG_OS_WINDOWS)
1133 if (stderr_handle == INVALID_HANDLE_VALUE)1132 HANDLE handle = (HANDLE)_get_osfhandle(fd);
1133
1134 // Cygwin/msys's pty is a pipe.
1135 if (handle == INVALID_HANDLE_VALUE || GetFileType(handle) != FILE_TYPE_PIPE) {
1134 return false;1136 return false;
1137 }
11351138
1136 int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH;1139 int size = sizeof(FILE_NAME_INFO) + sizeof(WCHAR) * MAX_PATH;
1137 FILE_NAME_INFO *nameinfo;
1138 WCHAR *p = NULL;1140 WCHAR *p = NULL;
11391141
1140 // Cygwin/msys's pty is a pipe.1142 FILE_NAME_INFO *nameinfo = (FILE_NAME_INFO *)allocate<char>(size);
1141 if (GetFileType(stderr_handle) != FILE_TYPE_PIPE) {
1142 return 0;
1143 }
1144 nameinfo = (FILE_NAME_INFO *)allocate<char>(size);
1145 if (nameinfo == NULL) {1143 if (nameinfo == NULL) {
1146 return 0;1144 return false;
1147 }1145 }
1148 // Check the name of the pipe:1146 // Check the name of the pipe:
1149 // '\{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master'1147 // '\{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master'
1150 if (GetFileInformationByHandleEx(stderr_handle, FileNameInfo, nameinfo, size)) {1148 if (GetFileInformationByHandleEx(handle, FileNameInfo, nameinfo, size)) {
1151 nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = L'\0';1149 nameinfo->FileName[nameinfo->FileNameLength / sizeof(WCHAR)] = L'\0';
1152 p = nameinfo->FileName;1150 p = nameinfo->FileName;
1153 if (is_wprefix(p, L"\\cygwin-")) { /* Cygwin */1151 if (is_wprefix(p, L"\\cygwin-")) { /* Cygwin */
...@@ -1180,12 +1178,14 @@ static bool is_stderr_cyg_pty(void) {...@@ -1180,12 +1178,14 @@ static bool is_stderr_cyg_pty(void) {
1180 }1178 }
1181 free(nameinfo);1179 free(nameinfo);
1182 return (p != NULL);1180 return (p != NULL);
1183}1181#else
1182 return false;
1184#endif1183#endif
1184}
11851185
1186bool os_stderr_tty(void) {1186bool os_stderr_tty(void) {
1187#if defined(ZIG_OS_WINDOWS)1187#if defined(ZIG_OS_WINDOWS)
1188 return _isatty(_fileno(stderr)) != 0 || is_stderr_cyg_pty();1188 return _isatty(fileno(stderr)) != 0 || os_is_cygwin_pty(fileno(stderr));
1189#elif defined(ZIG_OS_POSIX)1189#elif defined(ZIG_OS_POSIX)
1190 return isatty(STDERR_FILENO) != 0;1190 return isatty(STDERR_FILENO) != 0;
1191#else1191#else
...@@ -1486,7 +1486,7 @@ WORD original_console_attributes = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BL...@@ -1486,7 +1486,7 @@ WORD original_console_attributes = FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BL
14861486
1487void os_stderr_set_color(TermColor color) {1487void os_stderr_set_color(TermColor color) {
1488#if defined(ZIG_OS_WINDOWS)1488#if defined(ZIG_OS_WINDOWS)
1489 if (is_stderr_cyg_pty()) {1489 if (os_stderr_tty()) {
1490 set_color_posix(color);1490 set_color_posix(color);
1491 return;1491 return;
1492 }1492 }
src/os.hpp+8
...@@ -11,6 +11,7 @@...@@ -11,6 +11,7 @@
11#include "list.hpp"11#include "list.hpp"
12#include "buffer.hpp"12#include "buffer.hpp"
13#include "error.hpp"13#include "error.hpp"
14#include "target.hpp"
14#include "zig_llvm.h"15#include "zig_llvm.h"
15#include "windows_sdk.h"16#include "windows_sdk.h"
1617
...@@ -88,6 +89,11 @@ struct Termination {...@@ -88,6 +89,11 @@ struct Termination {
88#define OsFile int89#define OsFile int
89#endif90#endif
9091
92#if defined(ZIG_OS_WINDOWS)
93#undef fileno
94#define fileno _fileno
95#endif
96
91struct OsTimeStamp {97struct OsTimeStamp {
92 uint64_t sec;98 uint64_t sec;
93 uint64_t nsec;99 uint64_t nsec;
...@@ -152,6 +158,8 @@ Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_include_path(ZigWindowsSDK *sdk, Buf...@@ -152,6 +158,8 @@ Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_include_path(ZigWindowsSDK *sdk, Buf
152Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_lib_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type);158Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_lib_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type);
153Error ATTRIBUTE_MUST_USE os_get_win32_kern32_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type);159Error ATTRIBUTE_MUST_USE os_get_win32_kern32_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type);
154160
161bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd);
162
155Error ATTRIBUTE_MUST_USE os_self_exe_shared_libs(ZigList<Buf *> &paths);163Error ATTRIBUTE_MUST_USE os_self_exe_shared_libs(ZigList<Buf *> &paths);
156164
157#endif165#endif
src/target.cpp+14-1
...@@ -491,6 +491,16 @@ Error target_parse_glibc_version(ZigGLibCVersion *glibc_ver, const char *text) {...@@ -491,6 +491,16 @@ Error target_parse_glibc_version(ZigGLibCVersion *glibc_ver, const char *text) {
491 return ErrorNone;491 return ErrorNone;
492}492}
493493
494static ZigLLVM_EnvironmentType target_get_win32_abi() {
495 FILE* files[] = { stdin, stdout, stderr, nullptr };
496 for (int i = 0; files[i] != nullptr; i++) {
497 if (os_is_cygwin_pty(fileno(files[i]))) {
498 return ZigLLVM_GNU;
499 }
500 }
501 return ZigLLVM_MSVC;
502}
503
494void get_native_target(ZigTarget *target) {504void get_native_target(ZigTarget *target) {
495 // first zero initialize505 // first zero initialize
496 *target = {};506 *target = {};
...@@ -505,6 +515,9 @@ void get_native_target(ZigTarget *target) {...@@ -505,6 +515,9 @@ void get_native_target(ZigTarget *target) {
505 &target->abi,515 &target->abi,
506 &oformat);516 &oformat);
507 target->os = get_zig_os_type(os_type);517 target->os = get_zig_os_type(os_type);
518 if (target->os == OsWindows) {
519 target->abi = target_get_win32_abi();
520 }
508 target->is_native = true;521 target->is_native = true;
509 if (target->abi == ZigLLVM_UnknownEnvironment) {522 if (target->abi == ZigLLVM_UnknownEnvironment) {
510 target->abi = target_default_abi(target->arch, target->os);523 target->abi = target_default_abi(target->arch, target->os);
...@@ -1601,7 +1614,7 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {...@@ -1601,7 +1614,7 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
1601 return ZigLLVM_GNU;1614 return ZigLLVM_GNU;
1602 case OsUefi:1615 case OsUefi:
1603 case OsWindows:1616 case OsWindows:
1604 return ZigLLVM_MSVC;1617 return ZigLLVM_MSVC;
1605 case OsLinux:1618 case OsLinux:
1606 case OsWASI:1619 case OsWASI:
1607 return ZigLLVM_Musl;1620 return ZigLLVM_Musl;
std/os/windows.zig+3-4
...@@ -65,7 +65,7 @@ pub const CreateFileError = error{...@@ -65,7 +65,7 @@ pub const CreateFileError = error{
65 InvalidUtf8,65 InvalidUtf8,
6666
67 /// On Windows, file paths cannot contain these characters:67 /// On Windows, file paths cannot contain these characters:
68 /// '/', '*', '?', '"', '<', '>', '|'68 /// '*', '?', '"', '<', '>', '|', and '/' (when the ABI is not GNU)
69 BadPathName,69 BadPathName,
7070
71 Unexpected,71 Unexpected,
...@@ -836,11 +836,10 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)...@@ -836,11 +836,10 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
836 // > converting the name to an NT-style name, except when using the "\\?\"836 // > converting the name to an NT-style name, except when using the "\\?\"
837 // > prefix as detailed in the following sections.837 // > prefix as detailed in the following sections.
838 // from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation838 // from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
839 // Because we want the larger maximum path length for absolute paths, we
840 // disallow forward slashes in zig std lib file functions on Windows.
841 for (s) |byte| {839 for (s) |byte| {
842 switch (byte) {840 switch (byte) {
843 '/', '*', '?', '"', '<', '>', '|' => return error.BadPathName,841 '*', '?', '"', '<', '>', '|' => return error.BadPathName,
842 '/' => if (builtin.abi == .msvc) return error.BadPathName,
844 else => {},843 else => {},
845 }844 }
846 }845 }