| author | |
| committer | |
| log | f15ec9a59b777a2b7998518858f11f5da0dfcb2d |
| tree | a43c1ce2cb326a6e27c294951a1f22c513768fe9 |
| parent | e68fee39847712f9316628e6efe8daa8fc13a5a5 |
3 files changed, 32 insertions(+), 18 deletions(-)
src/os.cpp+16-16| ... | @@ -1125,29 +1125,27 @@ Error os_get_cwd(Buf *out_cwd) { | ... | @@ -1125,29 +1125,27 @@ Error os_get_cwd(Buf *out_cwd) { |
| 1125 | #endif | 1125 | #endif |
| 1126 | } | 1126 | } |
| 1127 | 1127 | ||
| 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) |
| 1131 | static bool is_stderr_cyg_pty(void) { | 1130 | bool 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 | } | ||
| 1135 | 1138 | ||
| 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; |
| 1139 | 1141 | ||
| 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 | #endif | 1183 | #endif |
| 1184 | } | ||
| 1185 | 1185 | ||
| 1186 | bool os_stderr_tty(void) { | 1186 | bool 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 | #else | 1191 | #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 |
| 1486 | 1486 | ||
| 1487 | void os_stderr_set_color(TermColor color) { | 1487 | void 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+3| ... | @@ -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" |
| 16 | 17 | ||
| ... | @@ -152,6 +153,8 @@ Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_include_path(ZigWindowsSDK *sdk, Buf | ... | @@ -152,6 +153,8 @@ Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_include_path(ZigWindowsSDK *sdk, Buf |
| 152 | Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_lib_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type); | 153 | Error ATTRIBUTE_MUST_USE os_get_win32_ucrt_lib_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type); |
| 153 | Error ATTRIBUTE_MUST_USE os_get_win32_kern32_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type); | 154 | Error ATTRIBUTE_MUST_USE os_get_win32_kern32_path(ZigWindowsSDK *sdk, Buf *output_buf, ZigLLVM_ArchType platform_type); |
| 154 | 155 | ||
| 156 | bool ATTRIBUTE_MUST_USE os_is_cygwin_pty(int fd); | ||
| 157 | |||
| 155 | Error ATTRIBUTE_MUST_USE os_self_exe_shared_libs(ZigList<Buf *> &paths); | 158 | Error ATTRIBUTE_MUST_USE os_self_exe_shared_libs(ZigList<Buf *> &paths); |
| 156 | 159 | ||
| 157 | #endif | 160 | #endif |
src/target.cpp+13-2| ... | @@ -506,7 +506,7 @@ void get_native_target(ZigTarget *target) { | ... | @@ -506,7 +506,7 @@ void get_native_target(ZigTarget *target) { |
| 506 | &oformat); | 506 | &oformat); |
| 507 | target->os = get_zig_os_type(os_type); | 507 | target->os = get_zig_os_type(os_type); |
| 508 | target->is_native = true; | 508 | target->is_native = true; |
| 509 | if (target->abi == ZigLLVM_UnknownEnvironment) { | 509 | if (target->os == OsWindows || target->abi == ZigLLVM_UnknownEnvironment) { |
| 510 | target->abi = target_default_abi(target->arch, target->os); | 510 | target->abi = target_default_abi(target->arch, target->os); |
| 511 | } | 511 | } |
| 512 | if (target_is_glibc(target)) { | 512 | if (target_is_glibc(target)) { |
| ... | @@ -1504,6 +1504,16 @@ bool target_is_single_threaded(const ZigTarget *target) { | ... | @@ -1504,6 +1504,16 @@ bool target_is_single_threaded(const ZigTarget *target) { |
| 1504 | return target_is_wasm(target); | 1504 | return target_is_wasm(target); |
| 1505 | } | 1505 | } |
| 1506 | 1506 | ||
| 1507 | static ZigLLVM_EnvironmentType target_get_win32_abi() { | ||
| 1508 | FILE* files[] = { stdin, stdout, stderr, nullptr }; | ||
| 1509 | for (int i = 0; files[i] != nullptr; i++) { | ||
| 1510 | if (os_is_cygwin_pty(_fileno(files[i]))) { | ||
| 1511 | return ZigLLVM_GNU; | ||
| 1512 | } | ||
| 1513 | } | ||
| 1514 | return ZigLLVM_MSVC; | ||
| 1515 | } | ||
| 1516 | |||
| 1507 | ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) { | 1517 | ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) { |
| 1508 | if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) { | 1518 | if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) { |
| 1509 | return ZigLLVM_Musl; | 1519 | return ZigLLVM_Musl; |
| ... | @@ -1544,8 +1554,9 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) { | ... | @@ -1544,8 +1554,9 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) { |
| 1544 | case OsHurd: | 1554 | case OsHurd: |
| 1545 | return ZigLLVM_GNU; | 1555 | return ZigLLVM_GNU; |
| 1546 | case OsUefi: | 1556 | case OsUefi: |
| 1547 | case OsWindows: | ||
| 1548 | return ZigLLVM_MSVC; | 1557 | return ZigLLVM_MSVC; |
| 1558 | case OsWindows: | ||
| 1559 | return target_get_win32_abi(); | ||
| 1549 | case OsLinux: | 1560 | case OsLinux: |
| 1550 | case OsWASI: | 1561 | case OsWASI: |
| 1551 | return ZigLLVM_Musl; | 1562 | return ZigLLVM_Musl; |