Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compiling on mingw is now supported #1542

Merged
merged 6 commits into from
Sep 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions example/hello_world/hello_windows.zig
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
22 changes: 16 additions & 6 deletions src/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/windows_com.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
#include <io.h>
#include <shellapi.h>

// Standard headers
#include <stdio.h>

// COM support header files
#include <comdef.h>

Expand Down