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: {