From f8ea72a150638c3e2dd4779e5f09a8aaf6d39146 Mon Sep 17 00:00:00 2001 From: "Kelly (KT) Thompson" Date: Mon, 21 Sep 2020 19:56:16 -0600 Subject: [PATCH] Fix MSVC CLI builds as run by the regression system. (#912) * Fix MSVC CLI builds as run by the regression system. + After upgrading to Microsoft Visual Studio 2019 16.8.0 Preview 3, the regression system could no longer build Draco due to build errors reported in system headers pulled in by `rng/test`. This version of MSVC also pulls in a newer version of CMake. + It was determined that these build errors could be eliminated by registering the rng unit tests as C++ files instead of C files, even though their file extensions are `.c`. + Also add a couple of new warning suppressions for MSVC. The new version is more agressive in reporting warnings. Only suppress issues found in the Random123 header files (we don't need to fix the TPL code). * more cleanup for msvc build. * Go back to registering as C for all compilers except MSVC. Exclude ut_gsl.c for MSVC. --- CMakeSettings.json | 32 ++++++++++++++------------------ src/rng/test/CMakeLists.txt | 32 ++++++++++++++++++++++++++------ src/rng/test/time_serial.c | 11 +++++++++++ src/rng/test/time_serial.h | 5 +++-- src/rng/test/ut_gsl.c | 4 +++- src/rng/test/ut_gsl.h | 7 ++----- 6 files changed, 59 insertions(+), 32 deletions(-) diff --git a/CMakeSettings.json b/CMakeSettings.json index d6b9eb088c..6472693602 100644 --- a/CMakeSettings.json +++ b/CMakeSettings.json @@ -1,9 +1,10 @@ { "environments": [ { - "BuildDir": "${env.USERPROFILE}\\vs2019", - "projectname": "draco", - "install_subdir": "install/d" + "BuildDir": "${env.work_dir}", + "projectname": "draco", + "install_subdir": "install", + "cmakeToolchain": "C:/work/vendors64/vs2019-toolchain.cmake" } ], "configurations": [ @@ -12,26 +13,23 @@ "generator": "Visual Studio 16 2019 Win64", "configurationType": "Debug", "inheritEnvironments": [ "msvc_x64_x64" ], - "buildRoot": "${env.BuildDir}/${name}/${env.projectname}", - "installRoot": "${env.BuildDir}/${name}/${env.install_subdir}", + "buildRoot": "${env.BuildDir}/${env.projectname}/${name}", + "installRoot": "${env.BuildDir}/${env.projectname}/${env.install_subdir}", "cmakeCommandArgs": "", "buildCommandArgs": "-verbosity:minimal -m:${env.NUMBER_OF_PROCESSORS}", "ctestCommandArgs": "-j ${env.NUMBER_OF_PROCESSORS} --output-on-failure", - "cmakeToolchain": "C:/work/vendors64/vs2019-toolchain.cmake", - "variables": [], - "cmakeExecutable": "C:/Program Files/CMake/bin/cmake.exe" + "variables": [] }, { "name": "x64-Release", "generator": "Visual Studio 16 2019 Win64", "configurationType": "Release", - "buildRoot": "${env.BuildDir}/${name}/${env.projectname}", - "installRoot": "${env.BuildDir}/${name}/${env.install_subdir}", + "buildRoot": "${env.BuildDir}/${env.projectname}/${name}", + "installRoot": "${env.BuildDir}/${env.projectname}/${env.install_subdir}", "cmakeExecutable": "C:/Program Files/CMake/bin/cmake.exe", "cmakeCommandArgs": "", "buildCommandArgs": "-verbosity:minimal -m:${env.NUMBER_OF_PROCESSORS}", "ctestCommandArgs": "-j ${env.NUMBER_OF_PROCESSORS} --output-on-failure", - "cmakeToolchain": "C:/work/vendors64/vs2019-toolchain.cmake", "inheritEnvironments": [ "msvc_x64_x64" ], "variables": [] }, @@ -39,13 +37,12 @@ "name": "x64-Debug-scalar", "generator": "Visual Studio 16 2019 Win64", "configurationType": "Debug", - "buildRoot": "${env.BuildDir}/${name}/${env.projectname}", - "installRoot": "${env.BuildDir}/${name}/${env.install_subdir}", + "buildRoot": "${env.BuildDir}/${env.projectname}/${name}", + "installRoot": "${env.BuildDir}/${env.projectname}/${env.install_subdir}", "cmakeExecutable": "C:/Program Files/CMake/bin/cmake.exe", "cmakeCommandArgs": "-DDRACO_C4=SCALAR", "buildCommandArgs": "-verbosity:minimal -m:${env.NUMBER_OF_PROCESSORS}", "ctestCommandArgs": "-j ${env.NUMBER_OF_PROCESSORS} --output-on-failure", - "cmakeToolchain": "C:/work/vendors64/vs2019-toolchain.cmake", "inheritEnvironments": [ "msvc_x64_x64" ], "variables": [] }, @@ -53,13 +50,12 @@ "name": "x64-Clang-Debug", "generator": "Visual Studio 16 2019 Win64", "configurationType": "Debug", - "buildRoot": "${env.BuildDir}/${name}/${env.projectname}", - "installRoot": "${env.BuildDir}/${name}/${env.install_subdir}", + "buildRoot": "${env.BuildDir}/${env.projectname}/${name}", + "installRoot": "${env.BuildDir}/${env.projectname}/${env.install_subdir}", "cmakeExecutable": "C:/Program Files/CMake/bin/cmake.exe", - "cmakeCommandArgs": "-DCMAKE_C_COMPILER:FILEPATH=\"C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/PREVIEW/VC/Tools/Llvm/x64/bin/clang-cl.exe\"", + "cmakeCommandArgs": "-DCMAKE_C_COMPILER:FILEPATH=\"C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2019/PREVIEW/VC/Tools/llvm/x64/bin/clang-cl.exe\"", "buildCommandArgs": "-v:m -m:${env.NUMBER_OF_PROCESSORS} ", "ctestCommandArgs": "-j ${env.NUMBER_OF_PROCESSORS} --output-on-failure", - "cmakeToolchain": "C:/work/vendors64/vs2019-toolchain.cmake", "inheritEnvironments": [ "clang_cl_x64_x64" ], "intelliSenseMode": "windows-clang-x64", "variables": [] diff --git a/src/rng/test/CMakeLists.txt b/src/rng/test/CMakeLists.txt index 6dbedff366..2c2b6de809 100755 --- a/src/rng/test/CMakeLists.txt +++ b/src/rng/test/CMakeLists.txt @@ -3,8 +3,7 @@ # author Kelly Thompson # date 2012 Aug 1 # brief Generate build project files for rng/test. -# note Copyright (C) 2016-2019, Triad National Security, LLC. -# All rights reserved. +# note Copyright (C) 2016-2019, Triad National Security, LLC., All rights reserved. #--------------------------------------------------------------------------------------------------# project( rng_test C CXX ) @@ -23,14 +22,24 @@ set( random123_unit_tests ${PROJECT_SOURCE_DIR}/ut_aes.cpp ${PROJECT_SOURCE_DIR}/ut_ars.c ${PROJECT_SOURCE_DIR}/ut_carray.cpp - ${PROJECT_SOURCE_DIR}/ut_gsl.c ${PROJECT_SOURCE_DIR}/ut_M128.cpp ${PROJECT_SOURCE_DIR}/ut_uniform.cpp ) - +# [2020-08-21 KT] The code in ut_gsl.c is not valid C++. Because this test is a mix of C and C++, +# it causes issues. Most compilers are happy to compile this code with C, visual studio is not. +# When marked as C++, this test fails with: +# +# "C:\projects\draco\src\rng\test\ut_gsl.c(62,1): error C2086: 'const gsl_rng_type \ +# *gsl_rng_cbrng': redefinition" +# +# Indeed, reviewing the Random123 file gsl_cbrng.h reveals that that gsl_rng_type is declared twice, +# first on line 68 and then again on line 125 (with an assignment this time). We can continue +# building and running this tests on platforms that can processs it (all but MSVC right now). +if( NOT MSVC ) + list(APPEND random123_unit_tests ${PROJECT_SOURCE_DIR}/ut_gsl.c ) +endif() if( R123_USE_CXX11 ) - list( APPEND random123_unit_tests - ${PROJECT_SOURCE_DIR}/ut_Engine.cpp ) + list( APPEND random123_unit_tests ${PROJECT_SOURCE_DIR}/ut_Engine.cpp ) endif() # Random123 known-answer tests @@ -39,6 +48,17 @@ set( random123_known_answer_tests ${PROJECT_SOURCE_DIR}/kat_cpp.cpp ) +# Some compilers (esp. MSVC) have trouble with compiling these files as C11 code, so tell cmake +# to treat them as C++14. ut_gsl.c has a bug that prevents it from compiling as C++, so we omit it +# from this list. +if( MSVC ) + set_source_files_properties( + ${PROJECT_SOURCE_DIR}/time_serial.c + ${PROJECT_SOURCE_DIR}/ut_ars.c + ${PROJECT_SOURCE_DIR}/kat_c.c + PROPERTIES LANGUAGE CXX ) +endif() + #--------------------------------------------------------------------------------------------------# # Build Unit tests #--------------------------------------------------------------------------------------------------# diff --git a/src/rng/test/time_serial.c b/src/rng/test/time_serial.c index 70163cb4e7..0aa93669a7 100644 --- a/src/rng/test/time_serial.c +++ b/src/rng/test/time_serial.c @@ -40,7 +40,14 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include "time_misc.h" #include "util_print.h" +#ifdef _MSC_FULL_VER +// - 4505 :: 'warmupCPU': unreferenced local function has been removed. +#pragma warning(push) +#pragma warning(disable : 4505) +#endif + #include "util_cpu.h" + #define KERNEL R123_STATIC_INLINE #define get_global_id(i) (i) #include "time_random123.h" @@ -165,6 +172,10 @@ int main(int argc, char **argv) { #pragma GCC diagnostic pop #endif +#ifdef _MSC_FULL_VER +#pragma warning(pop) +#endif + //------------------------------------------------------------------------------------------------// // end time_serial.c //------------------------------------------------------------------------------------------------// diff --git a/src/rng/test/time_serial.h b/src/rng/test/time_serial.h index 9150cc86c2..1737438278 100644 --- a/src/rng/test/time_serial.h +++ b/src/rng/test/time_serial.h @@ -19,8 +19,9 @@ #ifdef _MSC_FULL_VER // - 4204 :: nonstandard extension used: non-constant aggregate initializer. +// - 4127 :: conditional expression is constant #pragma warning(push) -#pragma warning(disable : 4204 4100) +#pragma warning(disable : 4204 4100 4127) #endif #include @@ -28,7 +29,7 @@ #include #include -#ifdef _MSC_FULL_VERf +#ifdef _MSC_FULL_VER #pragma warning(pop) #endif diff --git a/src/rng/test/ut_gsl.c b/src/rng/test/ut_gsl.c index 469063b375..6475d484be 100644 --- a/src/rng/test/ut_gsl.c +++ b/src/rng/test/ut_gsl.c @@ -45,8 +45,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifdef _MSC_FULL_VER // 4311 - 'type cast': pointer truncation from 'char[54]' to 'long' // 4202 - nonstandard extension used: non-constant aggregate initializer +// 4127 - conditional expression is constant +// 4302 - 'type cast': truncation from 'const char *' to 'long' #pragma warning(push) -#pragma warning(disable : 4311 4204) +#pragma warning(disable : 4311 4204 4127 4302) #endif #include "rng/config.h" diff --git a/src/rng/test/ut_gsl.h b/src/rng/test/ut_gsl.h index 708c974ca2..1ae01cc226 100644 --- a/src/rng/test/ut_gsl.h +++ b/src/rng/test/ut_gsl.h @@ -4,10 +4,7 @@ * \author Gabriel M. Rockefeller * \date Tue Oct 9 19:02:09 2012 * \brief ut_gsl header file. - * \note Copyright (C) 2016-2020 Triad National Security, LLC - */ -/*------------------------------------------------------------------------------------------------*/ -/* $Id$ */ + * \note Copyright (C) 2016-2020 Triad National Security, LLC., All rights reserved. */ /*------------------------------------------------------------------------------------------------*/ #ifndef rng_test_ut_gsl_h @@ -23,5 +20,5 @@ #endif /* rng_test_ut_gsl_h */ /*------------------------------------------------------------------------------------------------*/ -/* end of rng/test/ut_gsl.h */ +/* end of rng/test/ut_gsl.h */ /*------------------------------------------------------------------------------------------------*/