compiling on mingw is now supported (#1542)

* compiles on mingw-w64
* fixed error in os_file_overwrite on windows
* fixed windows hello_world example
This commit is contained in:
emekoi 2018-09-17 23:13:17 -05:00 committed by Andrew Kelley
parent 13645585fe
commit 68c1d05917
4 changed files with 24 additions and 6 deletions

View File

@ -796,6 +796,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")

View File

@ -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;

View File

@ -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 <windows.h>
#include <shlobj.h>
#include <io.h>
@ -1634,16 +1642,16 @@ static Optional<uint32_t> 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<uint32_t>::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<uint32_t>::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)
@ -2007,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

View File

@ -28,6 +28,9 @@
#include <io.h>
#include <shellapi.h>
// Standard headers
#include <stdio.h>
// COM support header files
#include <comdef.h>