Skip to content

Commit e54eb27

Browse files
author
Daniel Schulte
committed
Add support for building with MinGW
1 parent bf55bd2 commit e54eb27

File tree

13 files changed

+50
-13
lines changed

13 files changed

+50
-13
lines changed

aws-cpp-sdk-core/include/aws/core/utils/Array.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace Aws
6464
{
6565
m_data.reset(Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG));
6666

67-
#ifdef _WIN32
67+
#if defined(_WIN32) && !defined(__MINGW32__)
6868
std::copy(arrayToCopy, arrayToCopy + arraySize, stdext::checked_array_iterator< T * >(m_data.get(), m_size));
6969
#else
7070
std::copy(arrayToCopy, arrayToCopy + arraySize, m_data.get());
@@ -92,7 +92,7 @@ namespace Aws
9292
if(arr->m_size > 0 && arr->m_data)
9393
{
9494
size_t arraySize = arr->m_size;
95-
#ifdef _WIN32
95+
#if defined(_WIN32) && !defined(__MINGW32__)
9696
std::copy(arr->m_data.get(), arr->m_data.get() + arraySize, stdext::checked_array_iterator< T * >(m_data.get() + location, m_size));
9797
#else
9898
std::copy(arr->m_data.get(), arr->m_data.get() + arraySize, m_data.get() + location);
@@ -111,7 +111,7 @@ namespace Aws
111111
{
112112
m_data.reset(Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG));
113113

114-
#ifdef _WIN32
114+
#if defined(_WIN32) && !defined(__MINGW32__)
115115
std::copy(other.m_data.get(), other.m_data.get() + other.m_size, stdext::checked_array_iterator< T * >(m_data.get(), m_size));
116116
#else
117117
std::copy(other.m_data.get(), other.m_data.get() + other.m_size, m_data.get());
@@ -144,7 +144,7 @@ namespace Aws
144144
{
145145
m_data.reset(Aws::NewArray<T>(m_size, ARRAY_ALLOCATION_TAG));
146146

147-
#ifdef _WIN32
147+
#if defined(_WIN32) && !defined(__MINGW32__)
148148
std::copy(other.m_data.get(), other.m_data.get() + other.m_size, stdext::checked_array_iterator< T * >(m_data.get(), m_size));
149149
#else
150150
std::copy(other.m_data.get(), other.m_data.get() + other.m_size, m_data.get());

aws-cpp-sdk-core/include/aws/core/utils/crypto/bcrypt/CryptoImpl.h

+7
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,14 @@ namespace Aws
3939
{
4040
namespace Crypto
4141
{
42+
#ifdef __MINGW32__
43+
#pragma GCC diagnostic push
44+
#pragma GCC diagnostic ignored "-Wunused-variable"
45+
#endif
4246
static const char* SecureRandom_BCrypt_Tag = "SecureRandom_BCrypt";
47+
#ifdef __MINGW32__
48+
#pragma GCC diagnostic pop
49+
#endif
4350

4451
class SecureRandomBytes_BCrypt : public SecureRandomBytes
4552
{

aws-cpp-sdk-core/include/aws/core/utils/event/EventHeader.h

+10
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
#include <aws/event-stream/event_stream.h>
2525
#include <cassert>
2626

27+
#ifdef __MINGW32__
28+
#pragma GCC diagnostic push
29+
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
30+
#pragma GCC diagnostic ignored "-Wuninitialized"
31+
#endif
32+
2733
namespace Aws
2834
{
2935
namespace Utils
@@ -319,3 +325,7 @@ namespace Aws
319325
}
320326
}
321327
}
328+
329+
#ifdef __MINGW32__
330+
#pragma GCC diagnostic pop
331+
#endif

aws-cpp-sdk-core/source/http/windows/WinHttpSyncHttpClient.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ bool WinHttpSyncHttpClient::DoQueryHeaders(void* hHttpRequest, std::shared_ptr<H
267267
wmemset(contentTypeStr, 0, static_cast<size_t>(dwSize / sizeof(wchar_t)));
268268

269269
WinHttpQueryHeaders(hHttpRequest, WINHTTP_QUERY_CONTENT_TYPE, nullptr, &contentTypeStr, &dwSize, 0);
270-
if (contentTypeStr[0] != NULL)
270+
if (contentTypeStr[0] != 0)
271271
{
272272
Aws::String contentStr = StringUtils::FromWString(contentTypeStr);
273273
response->SetContentType(contentStr);
@@ -298,7 +298,7 @@ bool WinHttpSyncHttpClient::DoQueryHeaders(void* hHttpRequest, std::shared_ptr<H
298298

299299
bool WinHttpSyncHttpClient::DoSendRequest(void* hHttpRequest) const
300300
{
301-
return (WinHttpSendRequest(hHttpRequest, NULL, NULL, 0, 0, 0, NULL) != 0);
301+
return (WinHttpSendRequest(hHttpRequest, NULL, 0, 0, 0, 0, 0) != 0);
302302
}
303303

304304
bool WinHttpSyncHttpClient::DoReadData(void* hHttpRequest, char* body, uint64_t size, uint64_t& read) const

aws-cpp-sdk-core/source/http/windows/WinINetSyncHttpClient.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ bool WinINetSyncHttpClient::DoQueryHeaders(void* hHttpRequest, std::shared_ptr<H
228228
char contentTypeStr[1024];
229229
dwSize = sizeof(contentTypeStr);
230230
HttpQueryInfoA(hHttpRequest, HTTP_QUERY_CONTENT_TYPE, &contentTypeStr, &dwSize, 0);
231-
if (contentTypeStr[0] != NULL)
231+
if (contentTypeStr[0] != 0)
232232
{
233233
response->SetContentType(contentTypeStr);
234234
AWS_LOGSTREAM_DEBUG(GetLogTag(), "Received content type " << contentTypeStr);

aws-cpp-sdk-core/source/http/windows/WinSyncHttpClient.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ void WinSyncHttpClient::MakeRequestInternal(HttpRequest& request,
322322
}
323323
}
324324

325-
if (!success && !IsRequestProcessingEnabled() || !ContinueRequest(request))
325+
if (!success && (!IsRequestProcessingEnabled() || !ContinueRequest(request)))
326326
{
327327
response->SetClientErrorType(CoreErrors::USER_CANCELLED);
328328
response->SetClientErrorMessage("Request processing disabled or continuation cancelled by user's continuation handler.");

aws-cpp-sdk-core/source/platform/windows/Environment.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ that would need to be manually freed in all the client functions, just copy it i
2929
*/
3030
Aws::String GetEnv(const char *variableName)
3131
{
32+
#ifdef _MSC_VER
3233
char* variableValue = nullptr;
3334
std::size_t valueSize = 0;
3435
auto queryResult = _dupenv_s(&variableValue, &valueSize, variableName);
@@ -41,6 +42,10 @@ Aws::String GetEnv(const char *variableName)
4142
}
4243

4344
return result;
45+
#else // __MINGW32__
46+
auto variableValue = std::getenv(variableName);
47+
return Aws::String( variableValue ? variableValue : "" );
48+
#endif
4449
}
4550

4651
} // namespace Environment

aws-cpp-sdk-core/source/platform/windows/FileSystem.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
#include <iostream>
2222
#include <Userenv.h>
2323

24-
#pragma warning( disable : 4996)
24+
#ifdef _MSC_VER
25+
# pragma warning( disable : 4996)
26+
#endif
2527

2628
using namespace Aws::Utils;
2729
namespace Aws
@@ -314,6 +316,9 @@ Aws::String CreateTempFilePath()
314316
{
315317
#ifdef _MSC_VER
316318
#pragma warning(disable: 4996) // _CRT_SECURE_NO_WARNINGS
319+
#else
320+
// Definition from the MSVC stdio.h
321+
#define L_tmpnam_s (sizeof("\\") + 16)
317322
#endif
318323
char s_tempName[L_tmpnam_s+1];
319324

aws-cpp-sdk-core/source/platform/windows/OSVersionInfo.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
#include <iomanip>
2121

22+
#ifdef _MSC_VER
2223
#pragma warning(disable: 4996)
24+
#endif
2325
#include <windows.h>
2426
#include <stdio.h>
2527
namespace Aws

aws-cpp-sdk-core/source/utils/crypto/factory/Factories.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ std::shared_ptr<Aws::Utils::Crypto::HMAC> Aws::Utils::Crypto::CreateSha256HMACIm
755755
return s_Sha256HMACFactory->CreateImplementation();
756756
}
757757

758-
#ifdef _WIN32
758+
#ifdef _MSC_VER
759759
#pragma warning( push )
760760
#pragma warning( disable : 4702 )
761761
#endif
@@ -840,7 +840,7 @@ std::shared_ptr<SymmetricCipher> Aws::Utils::Crypto::CreateAES_KeyWrapImplementa
840840
return s_AES_KeyWrapFactory->CreateImplementation(key);
841841
}
842842

843-
#ifdef _WIN32
843+
#ifdef _MSC_VER
844844
#pragma warning(pop)
845845
#endif
846846

aws-cpp-sdk-s3-integration-tests/BucketAndObjectOperationTest.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@
5454
#include <aws/testing/TestingEnvironment.h>
5555
#include <fstream>
5656

57-
#ifdef _WIN32
57+
#ifdef _MSC_VER
5858
#pragma warning(disable: 4127)
59-
#endif //_WIN32
59+
#endif //_MSC_VER
6060

6161
#include <aws/core/http/standard/StandardHttpRequest.h>
6262

cmake/compiler_settings.cmake

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ else()
1111
set(COMPILER_CLANG 1)
1212
else()
1313
set(COMPILER_GCC 1)
14+
if(CMAKE_CXX_IMPLICIT_LINK_LIBRARIES MATCHES "mingw32")
15+
set(COMPILER_MINGW 1)
16+
endif()
1417
endif()
1518
set(USE_GCC_FLAGS 1)
1619
endif()
@@ -34,6 +37,9 @@ endfunction()
3437

3538
macro(set_gcc_flags)
3639
list(APPEND AWS_COMPILER_FLAGS "-fno-exceptions" "-std=c++${CPP_STANDARD}")
40+
if(COMPILER_IS_MINGW)
41+
list(APPEND AWS_COMPILER_FLAGS -D__USE_MINGW_ANSI_STDIO=1)
42+
endif()
3743

3844
if(NOT BUILD_SHARED_LIBS)
3945
list(APPEND AWS_COMPILER_FLAGS "-fPIC")

testing-resources/source/platform/windows/PlatformTesting.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
#include <aws/testing/platform/PlatformTesting.h>
1717

18+
#ifdef _MSC_VER
1819
#pragma warning(disable: 4996)
20+
#endif
1921
#include <windows.h>
2022
#include <aws/core/utils/memory/stl/AWSStringStream.h>
2123

0 commit comments

Comments
 (0)