authorgravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2019-08-03 18:40:27-05:00
committergravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2019-08-03 18:40:27-05:00
log59e2c87b4b89bf16321b499124d568ac5a19c300
tree885c3eedd13f1922ffed3f7bf6e1116840f3dccc
parent102d3f30c406e2818c6320a48f2405fa7e1e4237

move windows abi detection to `get_native_target`


2 files changed, 17 insertions(+), 16 deletions(-)

src/target.cpp+15-13
...@@ -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,8 +515,11 @@ void get_native_target(ZigTarget *target) {...@@ -505,8 +515,11 @@ 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->os == OsWindows || 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);
511 }524 }
512 if (target_is_glibc(target)) {525 if (target_is_glibc(target)) {
...@@ -1504,16 +1517,6 @@ bool target_is_single_threaded(const ZigTarget *target) {...@@ -1504,16 +1517,6 @@ bool target_is_single_threaded(const ZigTarget *target) {
1504 return target_is_wasm(target);1517 return target_is_wasm(target);
1505}1518}
15061519
1507static 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
1517ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {1520ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
1518 if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) {1521 if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) {
1519 return ZigLLVM_Musl;1522 return ZigLLVM_Musl;
...@@ -1554,9 +1557,8 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {...@@ -1554,9 +1557,8 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
1554 case OsHurd:1557 case OsHurd:
1555 return ZigLLVM_GNU;1558 return ZigLLVM_GNU;
1556 case OsUefi:1559 case OsUefi:
1557 return ZigLLVM_MSVC;
1558 case OsWindows:1560 case OsWindows:
1559 return target_get_win32_abi();1561 return ZigLLVM_MSVC;
1560 case OsLinux:1562 case OsLinux:
1561 case OsWASI:1563 case OsWASI:
1562 return ZigLLVM_Musl;1564 return ZigLLVM_Musl;
std/os/windows.zig+2-3
...@@ -827,12 +827,11 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)...@@ -827,12 +827,11 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
827 // > converting the name to an NT-style name, except when using the "\\?\"827 // > converting the name to an NT-style name, except when using the "\\?\"
828 // > prefix as detailed in the following sections.828 // > prefix as detailed in the following sections.
829 // from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation829 // from https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file#maximum-path-length-limitation
830 // Because we want the larger maximum path length for absolute paths, we
831 // disallow forward slashes in zig std lib file functions on Windows.
832 for (s) |byte| {830 for (s) |byte| {
833 switch (byte) {831 switch (byte) {
834 '*', '?', '"', '<', '>', '|' => return error.BadPathName,832 '*', '?', '"', '<', '>', '|' => return error.BadPathName,
835 else => if (builtin.abi == .msvc and byte == '/') return error.BadPathName,833 '/' => if (builtin.abi == .msvc) return error.BadPathName,
834 else => {},
836 }835 }
837 }836 }
838 const start_index = if (mem.startsWith(u8, s, "\\\\") or !std.fs.path.isAbsolute(s)) 0 else blk: {837 const start_index = if (mem.startsWith(u8, s, "\\\\") or !std.fs.path.isAbsolute(s)) 0 else blk: {