From cd24c784a3e81673bbe9e184a0f4437ad20dd23b Mon Sep 17 00:00:00 2001 From: Nikita Karpey Date: Tue, 10 Mar 2020 20:06:52 +0500 Subject: [PATCH] Improved support for Mingw-w64 (#648) * Build fixed through Mingw-w64 * Initial try to build using appveyor and MSYS2 --- CMakeLists.txt | 3 +++ appveyor-build.bat | 14 ++++++++++++++ appveyor.yml | 41 +++++++++++++++++++---------------------- src/common/common.h | 8 ++++---- src/kem/sike/config.h | 5 +++++ tests/CMakeLists.txt | 2 +- tests/test_sha3.c | 6 +++--- 7 files changed, 49 insertions(+), 30 deletions(-) create mode 100644 appveyor-build.bat diff --git a/CMakeLists.txt b/CMakeLists.txt index 49a9d1838..193ec6573 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -57,6 +57,9 @@ if(CMAKE_C_COMPILER_ID STREQUAL "Clang" OR CMAKE_C_COMPILER_ID STREQUAL "AppleClang") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fcolor-diagnostics -Wno-missing-braces -Wno-missing-field-initializers") endif() +if(MINGW OR MSYS OR CYGWIN) + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-maybe-uninitialized") +endif() if(BUILD_SHARED_LIBS) set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) endif() diff --git a/appveyor-build.bat b/appveyor-build.bat new file mode 100644 index 000000000..9226bd7d2 --- /dev/null +++ b/appveyor-build.bat @@ -0,0 +1,14 @@ +@echo off +IF %COMPILER%==msys2 ( + @echo on + SET "PATH=C:\msys64\mingw64\bin;%PATH%" + bash -lc "cd ${APPVEYOR_BUILD_FOLDER} && mkdir build && cd build && cmake .. -GNinja -DBUILD_SHARED_LIBS=%BUILD_SHARED% && ninja" +) +IF %COMPILER%==msvc2019 ( + @echo on + CALL "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" + mkdir build + cd build + cmake .. -GNinja -DBUILD_SHARED_LIBS=%BUILD_SHARED% + ninja +) diff --git a/appveyor.yml b/appveyor.yml index 48c3512a1..818f5a358 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -8,35 +8,32 @@ platform: x64 branches: except: - /master-new-.*/ - -init: - - call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat" - - set PATH="C:\\Python37";"C:\\Python37\Scripts";%PATH% - + environment: matrix: - BUILD_SHARED: OFF + COMPILER: msvc2019 - BUILD_SHARED: ON + COMPILER: msvc2019 + - BUILD_SHARED: OFF + COMPILER: msys2 + - BUILD_SHARED: ON + COMPILER: msys2 -before_build: - - cmd: |- - mkdir build - cd build - cmake .. -G"Ninja" -DBUILD_SHARED_LIBS=%BUILD_SHARED% build_script: - - ninja - + - cmd: '%APPVEYOR_BUILD_FOLDER%\appveyor-build.bat' + before_test: - - python -m pip install pytest pytest-xdist - + - cmd: |- + SET "PATH=C:\Python37;C:\Python37\Scripts;%PATH%" + pip.exe install pytest pytest-xdist + test_script: - - cmd: >- - cd %APPVEYOR_BUILD_FOLDER%\build - - set PATH=%cd%\bin;%PATH% && ninja run_tests + - cmd: |- + cd %APPVEYOR_BUILD_FOLDER%\build + set PATH=%cd%\bin;%PATH% && ninja run_tests after_test: - - ps: >- - $wc = New-Object 'System.Net.WebClient' - - $wc.UploadFile("https://ci.appveyor.com/api/testresults/xunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\test-results\pytest\test-results.xml)) + - ps: |- + $wc = New-Object 'System.Net.WebClient' + $wc.UploadFile("https://ci.appveyor.com/api/testresults/xunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path .\test-results\pytest\test-results.xml)) diff --git a/src/common/common.h b/src/common/common.h index b549cc579..83d61cb49 100644 --- a/src/common/common.h +++ b/src/common/common.h @@ -92,11 +92,11 @@ OQS_API void OQS_MEM_insecure_free(void *ptr); * an API specification but when an implementation doesn't actually use the argument * and we'd get a compiler warning otherwise. */ -#if defined(_WIN32) -#define UNUSED -// __attribute__ not supported in VS -#else +#ifdef __GNUC__ #define UNUSED __attribute__((unused)) +#else +// __attribute__ not supported in VS +#define UNUSED #endif #if defined(__cplusplus) diff --git a/src/kem/sike/config.h b/src/kem/sike/config.h index ee5947e49..a2124e950 100644 --- a/src/kem/sike/config.h +++ b/src/kem/sike/config.h @@ -144,6 +144,11 @@ static __inline unsigned int is_digit_lessthan_ct(digit_t x, digit_t y) { // Is #elif (TARGET == TARGET_AMD64 && OS_TARGET == OS_WIN) +#if defined(__MINGW64__) +#include +#include +#endif + // Digit multiplication #define MUL(multiplier, multiplicand, hi, lo) \ (lo) = _umul128((multiplier), (multiplicand), (hi)); diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5e51352e2..7708e4e1f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,7 +2,7 @@ if (MINGW OR MSYS OR CYGWIN) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D__USE_MINGW_ANSI_STDIO=1 -Wno-unknown-pragmas -Wno-unused-parameter") endif() -if(NOT WIN32 OR MINGW OR MSYS OR CYGWIN) +if(NOT WIN32) set(LIBM m) if(OQS_USE_OPENSSL) diff --git a/tests/test_sha3.c b/tests/test_sha3.c index 30474db62..9d5f0382f 100644 --- a/tests/test_sha3.c +++ b/tests/test_sha3.c @@ -8,10 +8,10 @@ #include "system_info.c" -#if defined(_WIN32) -#define UNUSED -#else +#ifdef __GNUC__ #define UNUSED __attribute__((unused)) +#else +#define UNUSED #endif /**