Skip to content

Commit 58f298e

Browse files
author
Daniel Schulte
committed
Add support for building with MinGW
1 parent f71fc50 commit 58f298e

File tree

7 files changed

+29
-12
lines changed

7 files changed

+29
-12
lines changed

cmake/AwsCFlags.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ function(aws_set_common_properties target)
6868
if (LEGACY_COMPILER_SUPPORT)
6969
list(APPEND AWS_C_FLAGS -Wno-strict-aliasing)
7070
endif()
71+
72+
if(CMAKE_C_IMPLICIT_LINK_LIBRARIES MATCHES "mingw32")
73+
list(APPEND AWS_C_FLAGS -D__USE_MINGW_ANSI_STDIO=1 -Wno-unused-local-typedefs)
74+
endif()
7175
endif()
7276

7377
check_include_file(stdint.h HAS_STDINT)

include/aws/common/byte_order.inl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#include <aws/common/byte_order.h>
2020
#include <aws/common/common.h>
2121

22-
#ifdef _MSC_VER
22+
#ifdef _WIN32
2323
# include <stdlib.h>
2424
#else
2525
# include <netinet/in.h>
26-
#endif /* _MSC_VER */
26+
#endif /* _WIN32 */
2727

2828
AWS_EXTERN_C_BEGIN
2929

@@ -49,7 +49,7 @@ AWS_STATIC_IMPL uint64_t aws_hton64(uint64_t x) {
4949
uint64_t v;
5050
__asm__("bswap %q0" : "=r"(v) : "0"(x));
5151
return v;
52-
#elif defined(_MSC_VER)
52+
#elif defined(_WIN32)
5353
return _byteswap_uint64(x);
5454
#else
5555
uint32_t low = (uint32_t)x;
@@ -69,7 +69,7 @@ AWS_STATIC_IMPL uint64_t aws_ntoh64(uint64_t x) {
6969
* Convert 32 bit integer from host to network byte order.
7070
*/
7171
AWS_STATIC_IMPL uint32_t aws_hton32(uint32_t x) {
72-
#ifdef _MSC_VER
72+
#ifdef _WIN32
7373
return aws_is_big_endian() ? x : _byteswap_ulong(x);
7474
#else
7575
return htonl(x);
@@ -126,7 +126,7 @@ AWS_STATIC_IMPL double aws_htonf64(double x) {
126126
* Convert 32 bit integer from network to host byte order.
127127
*/
128128
AWS_STATIC_IMPL uint32_t aws_ntoh32(uint32_t x) {
129-
#ifdef _MSC_VER
129+
#ifdef _WIN32
130130
return aws_is_big_endian() ? x : _byteswap_ulong(x);
131131
#else
132132
return ntohl(x);
@@ -151,7 +151,7 @@ AWS_STATIC_IMPL double aws_ntohf64(double x) {
151151
* Convert 16 bit integer from host to network byte order.
152152
*/
153153
AWS_STATIC_IMPL uint16_t aws_hton16(uint16_t x) {
154-
#ifdef _MSC_VER
154+
#ifdef _WIN32
155155
return aws_is_big_endian() ? x : _byteswap_ushort(x);
156156
#else
157157
return htons(x);
@@ -162,7 +162,7 @@ AWS_STATIC_IMPL uint16_t aws_hton16(uint16_t x) {
162162
* Convert 16 bit integer from network to host byte order.
163163
*/
164164
AWS_STATIC_IMPL uint16_t aws_ntoh16(uint16_t x) {
165-
#ifdef _MSC_VER
165+
#ifdef _WIN32
166166
return aws_is_big_endian() ? x : _byteswap_ushort(x);
167167
#else
168168
return ntohs(x);

include/aws/common/logging.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,9 @@ struct aws_logger_vtable {
111111
aws_log_subject_t subject,
112112
const char *format,
113113
...)
114-
#if defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
114+
#if defined(__MINGW32__)
115+
__attribute__((format(gnu_printf, 4, 5)))
116+
#elif defined(__clang__) || defined(__GNUC__) || defined(__GNUG__)
115117
__attribute__((format(printf, 4, 5)))
116118
#endif /* non-ms compilers: TODO - find out what versions format support was added in */
117119
;

include/aws/testing/aws_test_harness.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,9 @@ struct aws_test_harness {
365365
};
366366

367367
#if defined(_WIN32)
368+
# ifdef __MINGW32__
369+
# include <winsock2.h>
370+
# endif
368371
# include <windows.h>
369372
static LONG WINAPI s_test_print_stack_trace(struct _EXCEPTION_POINTERS *exception_pointers) {
370373
# if !defined(AWS_HEADER_CHECKER)

source/windows/environment.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ int aws_get_environment_value(
2323
const struct aws_string *variable_name,
2424
struct aws_string **value_out) {
2525

26+
#ifndef __MINGW32__
2627
#pragma warning(push)
2728
#pragma warning(disable : 4996)
29+
#endif
2830

2931
const char *value = getenv(aws_string_c_str(variable_name));
3032

33+
#ifndef __MINGW32__
3134
#pragma warning(pop)
35+
#endif
3236

3337
if (value == NULL) {
3438
*value_out = NULL;

source/windows/system_info.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ void aws_debug_break(void) {
4040
}
4141

4242
/* If I meet the engineer that wrote the dbghelp.h file for the windows 8.1 SDK we're gonna have words! */
43+
#ifndef __MINGW32__
4344
#pragma warning(disable : 4091)
45+
#endif
4446
#include <dbghelp.h>
4547

4648
struct win_symbol_data {
@@ -124,7 +126,7 @@ static void s_init_dbghelp_impl(void *user_data) {
124126
return;
125127
}
126128

127-
static bool s_init_dbghelp() {
129+
static bool s_init_dbghelp(void) {
128130
if (AWS_LIKELY(s_SymInitialize)) {
129131
return true;
130132
}
@@ -188,7 +190,7 @@ char **aws_backtrace_symbols(void *const *stack, size_t num_frames) {
188190
/* no luck, record the address and last error */
189191
DWORD last_error = GetLastError();
190192
int len = snprintf(
191-
sym_buf, AWS_ARRAY_SIZE(sym_buf), "at 0x%p: Failed to lookup symbol: error %u", stack[i], last_error);
193+
sym_buf, AWS_ARRAY_SIZE(sym_buf), "at 0x%p: Failed to lookup symbol: error %lu", stack[i], last_error);
192194
if (len > 0) {
193195
struct aws_byte_cursor sym_cur = aws_byte_cursor_from_array(sym_buf, len);
194196
aws_byte_buf_append_dynamic(&symbols, &sym_cur);
@@ -209,7 +211,7 @@ char **aws_backtrace_addr2line(void *const *frames, size_t stack_depth) {
209211
void aws_backtrace_print(FILE *fp, void *call_site_data) {
210212
struct _EXCEPTION_POINTERS *exception_pointers = call_site_data;
211213
if (exception_pointers) {
212-
fprintf(fp, "** Exception 0x%x occured **\n", exception_pointers->ExceptionRecord->ExceptionCode);
214+
fprintf(fp, "** Exception 0x%lx occured **\n", exception_pointers->ExceptionRecord->ExceptionCode);
213215
}
214216

215217
if (!s_init_dbghelp()) {

tests/atomics_test.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323

2424
#ifdef _WIN32
2525
# include <malloc.h>
26-
# define alloca _alloca
26+
# ifndef __MINGW32__
27+
# define alloca _alloca
28+
# endif
2729
#elif defined(__FreeBSD__) || defined(__NetBSD__)
2830
# include <stdlib.h>
2931
#else

0 commit comments

Comments
 (0)