authorgravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2018-09-17 23:13:17-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-09-18 00:13:17-04:00
log68c1d059178a36add751e97e11cee004cfdf612e
tree4edc229327766abca7b530258977be4b4a51d948
parent13645585fe2904f38d13df12e571ecac5bf9e8e6

compiling on mingw is now supported (#1542)

* compiles on mingw-w64 * fixed error in os_file_overwrite on windows * fixed windows hello_world example

4 files changed, 24 insertions(+), 6 deletions(-)

CMakeLists.txt+3
......@@ -796,6 +796,9 @@ if(MSVC)
796796 set(EXE_CFLAGS "${EXE_CFLAGS}")
797797else()
798798 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")
799 if(MINGW)
800 set(EXE_CFLAGS "${EXE_CFLAGS} -D__USE_MINGW_ANSI_STDIO -Wno-pedantic-ms-format")
801 endif()
799802endif()
800803
801804set(BLAKE_CFLAGS "-std=c99")
example/hello_world/hello_windows.zig+2
......@@ -1,5 +1,7 @@
11use @import("std").os.windows;
22
3extern "user32" stdcallcc fn MessageBoxA(hWnd: ?HANDLE, lpText: ?LPCTSTR, lpCaption: ?LPCTSTR, uType: UINT) c_int;
4
35export fn WinMain(hInstance: HINSTANCE, hPrevInstance: HINSTANCE, lpCmdLine: PWSTR, nCmdShow: INT) INT {
46 _ = MessageBoxA(null, c"hello", c"title", 0);
57 return 0;
src/os.cpp+16-6
......@@ -23,6 +23,14 @@
2323#define WIN32_LEAN_AND_MEAN
2424#endif
2525
26#if !defined(_WIN32_WINNT)
27#define _WIN32_WINNT 0x600
28#endif
29
30#if !defined(NTDDI_VERSION)
31#define NTDDI_VERSION 0x06000000
32#endif
33
2634#include <windows.h>
2735#include <shlobj.h>
2836#include <io.h>
......@@ -1634,16 +1642,16 @@ static Optional<uint32_t> Utf16LeIterator_nextCodepoint(Utf16LeIterator *it) {
16341642 if (it->bytes[it->i] == 0 && it->bytes[it->i + 1] == 0)
16351643 return {};
16361644 uint32_t c0 = ((uint32_t)it->bytes[it->i]) | (((uint32_t)it->bytes[it->i + 1]) << 8);
1637 if (c0 & ~((uint32_t)0x03ff) == 0xd800) {
1645 if ((c0 & ~((uint32_t)0x03ff)) == 0xd800) {
16381646 // surrogate pair
16391647 it->i += 2;
16401648 assert(it->bytes[it->i] != 0 || it->bytes[it->i + 1] != 0);
16411649 uint32_t c1 = ((uint32_t)it->bytes[it->i]) | (((uint32_t)it->bytes[it->i + 1]) << 8);
1642 assert(c1 & ~((uint32_t)0x03ff) == 0xdc00);
1650 assert((c1 & ~((uint32_t)0x03ff)) == 0xdc00);
16431651 it->i += 2;
16441652 return Optional<uint32_t>::some(0x10000 + (((c0 & 0x03ff) << 10) | (c1 & 0x03ff)));
16451653 } else {
1646 assert(c0 & ~((uint32_t)0x03ff) != 0xdc00);
1654 assert((c0 & ~((uint32_t)0x03ff)) != 0xdc00);
16471655 it->i += 2;
16481656 return Optional<uint32_t>::some(c0);
16491657 }
......@@ -1714,7 +1722,7 @@ static void utf16le_ptr_to_utf8(Buf *out, WCHAR *utf16le) {
17141722// Ported from std.os.getAppDataDir
17151723Error os_get_app_data_dir(Buf *out_path, const char *appname) {
17161724#if defined(ZIG_OS_WINDOWS)
1717 Error err;
1725 // Error err;
17181726 WCHAR *dir_path_ptr;
17191727 switch (SHGetKnownFolderPath(FOLDERID_LocalAppData, KF_FLAG_CREATE, nullptr, &dir_path_ptr)) {
17201728 case S_OK:
......@@ -1928,7 +1936,8 @@ Error os_file_mtime(OsFile file, OsTimeStamp *mtime) {
19281936 FILETIME last_write_time;
19291937 if (!GetFileTime(file, nullptr, nullptr, &last_write_time))
19301938 return ErrorUnexpected;
1931 mtime->sec = last_write_time.dwLowDateTime | (last_write_time.dwHighDateTime << 32);
1939 // mtime->sec = last_write_time.dwLowDateTime | (last_write_time.dwHighDateTime << 32);
1940 mtime->sec = (((ULONGLONG) last_write_time.dwHighDateTime) << 32) + last_write_time.dwLowDateTime;
19321941 mtime->nsec = 0;
19331942 return ErrorNone;
19341943#elif defined(ZIG_OS_LINUX)
......@@ -2007,11 +2016,12 @@ Error os_file_read_all(OsFile file, Buf *contents) {
20072016
20082017Error os_file_overwrite(OsFile file, Buf *contents) {
20092018#if defined(ZIG_OS_WINDOWS)
2019 DWORD bytes_written;
20102020 if (SetFilePointer(file, 0, nullptr, FILE_BEGIN) == INVALID_SET_FILE_POINTER)
20112021 return ErrorFileSystem;
20122022 if (!SetEndOfFile(file))
20132023 return ErrorFileSystem;
2014 if (!WriteFile(file, buf_ptr(contents), buf_len(contents), nullptr, nullptr))
2024 if (!WriteFile(file, buf_ptr(contents), buf_len(contents), &bytes_written, nullptr))
20152025 return ErrorFileSystem;
20162026 return ErrorNone;
20172027#else
src/windows_com.hpp+3
......@@ -28,6 +28,9 @@
2828#include <io.h>
2929#include <shellapi.h>
3030
31// Standard headers
32#include <stdio.h>
33
3134// COM support header files
3235#include <comdef.h>
3336