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) {
491491 return ErrorNone;
492492}
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
494504void get_native_target(ZigTarget *target) {
495505 // first zero initialize
496506 *target = {};
......@@ -505,8 +515,11 @@ void get_native_target(ZigTarget *target) {
505515 &target->abi,
506516 &oformat);
507517 target->os = get_zig_os_type(os_type);
518 if (target->os == OsWindows) {
519 target->abi = target_get_win32_abi();
520 }
508521 target->is_native = true;
509 if (target->os == OsWindows || target->abi == ZigLLVM_UnknownEnvironment) {
522 if (target->abi == ZigLLVM_UnknownEnvironment) {
510523 target->abi = target_default_abi(target->arch, target->os);
511524 }
512525 if (target_is_glibc(target)) {
......@@ -1504,16 +1517,6 @@ bool target_is_single_threaded(const ZigTarget *target) {
15041517 return target_is_wasm(target);
15051518}
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
15171520ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
15181521 if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) {
15191522 return ZigLLVM_Musl;
......@@ -1554,9 +1557,8 @@ ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
15541557 case OsHurd:
15551558 return ZigLLVM_GNU;
15561559 case OsUefi:
1557 return ZigLLVM_MSVC;
15581560 case OsWindows:
1559 return target_get_win32_abi();
1561 return ZigLLVM_MSVC;
15601562 case OsLinux:
15611563 case OsWASI:
15621564 return ZigLLVM_Musl;
std/os/windows.zig+2-3
......@@ -827,12 +827,11 @@ pub fn sliceToPrefixedSuffixedFileW(s: []const u8, comptime suffix: []const u16)
827827 // > converting the name to an NT-style name, except when using the "\\?\"
828828 // > prefix as detailed in the following sections.
829829 // 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.
832830 for (s) |byte| {
833831 switch (byte) {
834832 '*', '?', '"', '<', '>', '|' => return error.BadPathName,
835 else => if (builtin.abi == .msvc and byte == '/') return error.BadPathName,
833 '/' => if (builtin.abi == .msvc) return error.BadPathName,
834 else => {},
836835 }
837836 }
838837 const start_index = if (mem.startsWith(u8, s, "\\\\") or !std.fs.path.isAbsolute(s)) 0 else blk: {