From 7aa1c9b723fb8ef4ef56e44f60c975de04bb0e0b Mon Sep 17 00:00:00 2001 From: emekoi Date: Mon, 17 Sep 2018 16:43:27 -0500 Subject: [PATCH 1/3] compiles on mingw-w64 (but doesn't work) --- CMakeLists.txt | 3 +++ src/os.cpp | 19 ++++++++++++++----- src/windows_com.hpp | 3 +++ 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ee9f9c2817ad..0b372a9ec3d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -793,6 +793,9 @@ if(MSVC) set(EXE_CFLAGS "${EXE_CFLAGS}") else() set(EXE_CFLAGS "${EXE_CFLAGS} -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -D_GNU_SOURCE -fno-exceptions -fno-rtti -Werror=strict-prototypes -Werror=old-style-definition -Werror=type-limits -Wno-missing-braces") + if(MINGW) + set(EXE_CFLAGS "${EXE_CFLAGS} -D__USE_MINGW_ANSI_STDIO -Wno-pedantic-ms-format") + endif() endif() set(BLAKE_CFLAGS "-std=c99") diff --git a/src/os.cpp b/src/os.cpp index 6e46b96e41fd..2208c74c8bf7 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -23,6 +23,14 @@ #define WIN32_LEAN_AND_MEAN #endif +#if !defined(_WIN32_WINNT) +#define _WIN32_WINNT 0x600 +#endif + +#if !defined(NTDDI_VERSION) +#define NTDDI_VERSION 0x06000000 +#endif + #include #include #include @@ -1634,16 +1642,16 @@ static Optional Utf16LeIterator_nextCodepoint(Utf16LeIterator *it) { if (it->bytes[it->i] == 0 && it->bytes[it->i + 1] == 0) return {}; uint32_t c0 = ((uint32_t)it->bytes[it->i]) | (((uint32_t)it->bytes[it->i + 1]) << 8); - if (c0 & ~((uint32_t)0x03ff) == 0xd800) { + if ((c0 & ~((uint32_t)0x03ff)) == 0xd800) { // surrogate pair it->i += 2; assert(it->bytes[it->i] != 0 || it->bytes[it->i + 1] != 0); uint32_t c1 = ((uint32_t)it->bytes[it->i]) | (((uint32_t)it->bytes[it->i + 1]) << 8); - assert(c1 & ~((uint32_t)0x03ff) == 0xdc00); + assert((c1 & ~((uint32_t)0x03ff)) == 0xdc00); it->i += 2; return Optional::some(0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff))); } else { - assert(c0 & ~((uint32_t)0x03ff) != 0xdc00); + assert((c0 & ~((uint32_t)0x03ff)) != 0xdc00); it->i += 2; return Optional::some(c0); } @@ -1714,7 +1722,7 @@ static void utf16le_ptr_to_utf8(Buf *out, WCHAR *utf16le) { // Ported from std.os.getAppDataDir Error os_get_app_data_dir(Buf *out_path, const char *appname) { #if defined(ZIG_OS_WINDOWS) - Error err; + // Error err; WCHAR *dir_path_ptr; switch (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &dir_path_ptr)) { case S_OK: @@ -1928,7 +1936,8 @@ Error os_file_mtime(OsFile file, OsTimeStamp *mtime) { FILETIME last_write_time; if (!GetFileTime(file, nullptr, nullptr, &last_write_time)) return ErrorUnexpected; - mtime->sec = last_write_time.dwLowDateTime | (last_write_time.dwHighDateTime << 32); + // mtime->sec = last_write_time.dwLowDateTime | (last_write_time.dwHighDateTime << 32); + mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime; mtime->nsec = 0; return ErrorNone; #elif defined(ZIG_OS_LINUX) diff --git a/src/windows_com.hpp b/src/windows_com.hpp index 4c807218c0c0..f9833e091228 100644 --- a/src/windows_com.hpp +++ b/src/windows_com.hpp @@ -28,6 +28,9 @@ #include #include +// Standard headers +#include + // COM support header files #include From b5f2cc0fb5b512dbcf7d386cddaf00ce62e48393 Mon Sep 17 00:00:00 2001 From: emekoi Date: Mon, 17 Sep 2018 18:33:04 -0500 Subject: [PATCH 2/3] fixed error in os_file_overwrite on windows --- src/os.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/os.cpp b/src/os.cpp index 12cc12216d5d..6c620fae2e62 100644 --- a/src/os.cpp +++ b/src/os.cpp @@ -2016,11 +2016,12 @@ Error os_file_read_all(OsFile file, Buf *contents) { Error os_file_overwrite(OsFile file, Buf *contents) { #if defined(ZIG_OS_WINDOWS) + DWORD bytes_written; if (SetFilePointer(file, 0, nullptr, FILE_BEGIN) == INVALID_SET_FILE_POINTER) return ErrorFileSystem; if (!SetEndOfFile(file)) return ErrorFileSystem; - if (!WriteFile(file, buf_ptr(contents), buf_len(contents), nullptr, nullptr)) + if (!WriteFile(file, buf_ptr(contents), buf_len(contents), &bytes_written, nullptr)) return ErrorFileSystem; return ErrorNone; #else From 1fce04b4680b1fe24f9323e41648c876c7b5be81 Mon Sep 17 00:00:00 2001 From: emekoi Date: Mon, 17 Sep 2018 18:41:49 -0500 Subject: [PATCH 3/3] fixed windows hello_world example --- example/hello_world/hello_windows.zig | 2 ++ 1 file changed, 2 insertions(+) diff --git a/example/hello_world/hello_windows.zig b/example/hello_world/hello_windows.zig index f55db2edebdd..8016c3c49075 100644 --- a/example/hello_world/hello_windows.zig +++ b/example/hello_world/hello_windows.zig @@ -1,5 +1,7 @@ use @import("std").os.windows; +extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) c_int; + export fn WinMain(hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: PWSTR, nCmdShow: INT) INT { _ = MessageBoxA(null, c"hello", c"title", 0); return 0;