]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Add building/testing with msbuild and the clang compiler
authorArne Schwabe <arne@rfc2549.org>
Fri, 27 Dec 2024 11:22:07 +0000 (12:22 +0100)
committerGert Doering <gert@greenie.muc.de>
Fri, 27 Dec 2024 11:30:55 +0000 (12:30 +0100)
The LLVM/clang compiler warning and error message are easier too read
than their MSVC cl counterparts. Also compiling/running tests on Windows
with a different compiler has the benefit of a better coverage.

This includes a few minor changes to allow clang-cl to compile the
project.

Change-Id: I43d84034f3e920a45731c4aab4f851a60921290d
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Lev Stipakov <lstipakov@gmail.com>
Message-Id: <20241227112209.11572-1-gert@greenie.muc.de>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg30231.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
.github/workflows/build.yaml
CMakeLists.txt
CMakePresets.json
config.h.cmake.in
src/openvpnmsica/openvpnmsica.c
src/openvpnmsica/openvpnmsica.h
tests/unit_tests/openvpn/test_buffer.c

index 3958ef0caeedf84b8ea440aeb28962ef900b8129..767de0b92d052d6933fd629d93efc70f0e79c34e 100644 (file)
@@ -259,7 +259,7 @@ jobs:
       strategy:
         fail-fast: false
         matrix:
-          arch: [amd64, x86, arm64]
+          arch: [amd64, x86, arm64, amd64-clang, x86-clang]
 
       name: "msbuild - ${{ matrix.arch }} - openssl"
       env:
index 61f0cc5ead2c087f9d4c35fae2b32531ca579d1f..5b5b7ff43af58feae6f54cc95bb1f46a3565cfc4 100644 (file)
@@ -627,7 +627,8 @@ if (BUILD_TESTING)
         check_linker_flag(C -Wl,--wrap=parse_line LD_SUPPORTS_WRAP)
     endif()
 
-    if (${LD_SUPPORTS_WRAP})
+    # Clang-cl (which is also MSVC) is wrongly detected to support wrap
+    if (NOT MSVC AND "${LD_SUPPORTS_WRAP}")
         list(APPEND unit_tests
             "test_argv"
             "test_tls_crypt"
index 135b19d029d258537d355ffa6b7469af04f69732..b6ec20121471cea688eea70cb685022aed802a6d 100644 (file)
                 "CMAKE_BUILD_TYPE": "Release"
             }
         },
+        {
+            "name": "clangtoolset",
+            "toolset": "ClangCL"
+        },
         {
             "name": "mingw-x64",
             "inherits": [ "base", "base-mingw", "x64-mingw" ]
             "name": "win-amd64-release",
             "inherits": [ "base", "base-windows", "x64", "release" ]
         },
+        {
+            "name": "win-amd64-clang-release",
+            "inherits": [ "base", "base-windows", "clangtoolset", "x64", "release" ]
+        },
         {
             "name": "win-arm64-release",
             "inherits": [ "base", "base-windows", "arm64", "release" ]
             "name": "win-x86-release",
             "inherits": [ "base", "base-windows", "x86", "release" ]
         },
+        {
+            "name": "win-x86-clang-release",
+            "inherits": [ "base", "base-windows", "clangtoolset", "x86", "release" ]
+        },
         {
             "name": "win-amd64-debug",
             "inherits": [ "base", "base-windows", "x64", "debug" ]
         },
+        {
+            "name": "win-amd64-clang-debug",
+            "inherits": [ "base", "base-windows", "clangtoolset", "x64", "debug" ]
+        },
         {
             "name": "win-arm64-debug",
             "inherits": [ "base", "base-windows", "arm64", "debug" ]
             "name": "win-x86-debug",
             "inherits": [ "base", "base-windows", "x86", "debug" ]
         },
+        {
+            "name": "win-x86-clang-debug",
+            "inherits": [ "base", "base-windows", "clangtoolset", "x86", "debug" ]
+        },
         {
             "name": "unix-native",
             "generator": "Ninja Multi-Config",
             "configurePreset": "win-amd64-release",
             "configuration": "Release"
         },
+        {
+            "name": "win-amd64-clang-release",
+            "configurePreset": "win-amd64-clang-release",
+            "configuration": "Release"
+        },
         {
             "name": "win-arm64-release",
             "configurePreset": "win-arm64-release",
             "configurePreset": "win-x86-release",
             "configuration": "Release"
         },
+        {
+            "name": "win-x86-clang-release",
+            "configurePreset": "win-x86-clang-release",
+            "configuration": "Release"
+        },
         {
             "name": "win-amd64-debug",
             "configurePreset": "win-amd64-debug",
             "configuration": "Debug"
         },
+        {
+            "name": "win-amd64-clang-debug",
+            "configurePreset": "win-amd64-clang-debug",
+            "configuration": "Debug"
+        },
         {
             "name": "win-arm64-debug",
             "configurePreset": "win-arm64-debug",
             "configurePreset": "win-x86-debug",
             "configuration": "Debug"
         },
+        {
+            "name": "win-x86-clang-debug",
+            "configurePreset": "win-x86-clang-debug",
+            "configuration": "Debug"
+        },
         {
             "name": "unix-native",
             "configurePreset": "unix-native"
             "name": "win-amd64-release",
             "configurePreset": "win-amd64-release"
         },
+        {
+            "name": "win-amd64-clang-release",
+            "configurePreset": "win-amd64-clang-release"
+        },
         {
             "name": "win-x86-release",
             "configurePreset": "win-x86-release"
         },
+        {
+            "name": "win-x86-clang-release",
+            "configurePreset": "win-x86-clang-release"
+        },
         {
             "name": "win-amd64-debug",
             "configurePreset": "win-amd64-debug"
         },
+        {
+            "name": "win-amd64-clang-debug",
+            "configurePreset": "win-amd64-clang-debug"
+        },
         {
             "name": "win-x86-debug",
             "configurePreset": "win-x86-debug"
         },
+        {
+            "name": "win-x86-clang-debug",
+            "configurePreset": "win-x86-clang-debug"
+        },
         {
             "name": "unix-native",
             "configurePreset": "unix-native"
index 3c517d7390c2338b2bc76e7096cf1425beb0ce0b..74a53a6a11d4915ffd06be010f8a245d65b66998 100644 (file)
@@ -439,8 +439,10 @@ don't. */
 # define _GNU_SOURCE 1
 #endif
 
-
-#if defined(_WIN32)
+/* if inttypes.h is included this breaks rc.exe when using the ClangCL
+ * Toolchain as it pulls in a inttypes.h variant for clang that rc.exe does
+ * not understand (#include_next preprocessor directive) */
+#if defined(_WIN32) && !defined(RC_INVOKED)
 #include <inttypes.h>
 typedef uint32_t in_addr_t;
 typedef uint16_t in_port_t;
@@ -452,7 +454,7 @@ typedef uint16_t in_port_t;
 #define SIGTERM   15
 #endif
 
-#if defined(_MSC_VER)
+#if defined(_MSC_VER) && !defined(RC_INVOKED)
 #include <BaseTsd.h>
 typedef SSIZE_T ssize_t;
 #define strncasecmp strnicmp
index 154fff4af81a905e3dcb580b1de9ffe4fd0c7719..17152e0e80c054fb80c91d35f62c7164fb0931b9 100644 (file)
@@ -303,7 +303,7 @@ cleanup_pAdapterList:
 UINT __stdcall
 FindSystemInfo(_In_ MSIHANDLE hInstall)
 {
-#ifdef _MSC_VER
+#ifdef DLLEXP_EXPORT
 #pragma comment(linker, DLLEXP_EXPORT)
 #endif
 
@@ -340,7 +340,7 @@ FindSystemInfo(_In_ MSIHANDLE hInstall)
 UINT __stdcall
 CloseOpenVPNGUI(_In_ MSIHANDLE hInstall)
 {
-#ifdef _MSC_VER
+#ifdef DLLEXP_EXPORT
 #pragma comment(linker, DLLEXP_EXPORT)
 #endif
     UNREFERENCED_PARAMETER(hInstall); /* This CA is does not interact with MSI session (report errors, access properties, tables, etc.). */
@@ -363,7 +363,7 @@ CloseOpenVPNGUI(_In_ MSIHANDLE hInstall)
 UINT __stdcall
 StartOpenVPNGUI(_In_ MSIHANDLE hInstall)
 {
-#ifdef _MSC_VER
+#ifdef DLLEXP_EXPORT
 #pragma comment(linker, DLLEXP_EXPORT)
 #endif
 
@@ -636,7 +636,7 @@ schedule_adapter_delete(
 UINT __stdcall
 EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
 {
-#ifdef _MSC_VER
+#ifdef DLLEXP_EXPORT
 #pragma comment(linker, DLLEXP_EXPORT)
 #endif
 
@@ -789,7 +789,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
                 {
                     goto cleanup_szDisplayName;
                 }
-#ifdef __GNUC__
+#if defined(__GNUC__) || defined(__clang__)
 /*
  * warning: enumeration value ‘MSICONDITION_TRUE’ not handled in switch
  * warning: enumeration value ‘MSICONDITION_NONE’ not handled in switch
@@ -809,7 +809,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
                         free(szValue);
                         goto cleanup_szDisplayName;
                 }
-#ifdef __GNUC__
+#if defined(__GNUC__) || defined(__clang__)
 #pragma GCC diagnostic pop
 #endif
                 free(szValue);
@@ -965,7 +965,7 @@ CreateRebootFile(_In_z_ LPCWSTR szTmpDir)
 UINT __stdcall
 ProcessDeferredAction(_In_ MSIHANDLE hInstall)
 {
-#ifdef _MSC_VER
+#ifdef DLLEXP_EXPORT
 #pragma comment(linker, DLLEXP_EXPORT)
 #endif
 
@@ -1165,7 +1165,7 @@ cleanup_CoInitialize:
 UINT __stdcall
 CheckAndScheduleReboot(_In_ MSIHANDLE hInstall)
 {
-#ifdef _MSC_VER
+#ifdef DLLEXP_EXPORT
 #pragma comment(linker, DLLEXP_EXPORT)
 #endif
 
index 7aacdf310e6448510f6342c58265ea347c54a126..761aa4763458804a3705ec158ba1a8e24fd326fa 100644 (file)
@@ -66,7 +66,11 @@ extern DWORD openvpnmsica_thread_data_idx;
 extern "C" {
 #endif
 
-#ifdef __GNUC__
+/* Ensure that clang-cl, which does not understand the cl specific
+ * preprocessor defines like #pragma comment(linker, DLLEXP_EXPORT)
+ * is handled the same way as mingw and uses the alternative instead
+ * and does not define DLLEXP_EXPORT */
+#if defined(__GNUC__) || defined(__clang__)
 #define DLLEXP_DECL __declspec(dllexport)
 #else
 #define DLLEXP_DECL
index d43d5c1ecf3c1e756e494f575beae25689ccbdb7..3a1007a47a8d60caadea50d3c81d4022506ef1d2 100644 (file)
@@ -389,8 +389,9 @@ test_snprintf(void **state)
 
     /* Instead of trying to trick the compiler here, disable the warnings
      * for this unit test. We know that the results will be truncated
-     * and we want to test that */
-#if defined(__GNUC__)
+     * and we want to test that. Not we need the clang as clang-cl (msvc) does
+     * not define __GNUC__ like it does under UNIX(-like) platforms */
+#if defined(__GNUC__) || defined(__clang__)
 /* some clang version do not understand -Wformat-truncation, so ignore the
  * warning to avoid warnings/errors (-Werror) about unknown pragma/option */
 #if defined(__clang__)
@@ -418,7 +419,7 @@ test_snprintf(void **state)
     assert_int_equal(ret, 10);
     assert_int_equal(buf[9], '\0');
 
-#if defined(__GNUC__)
+#if defined(__GNUC__) || defined(__clang__)
 #pragma GCC diagnostic pop
 #if defined(__clang__)
 #pragma clang diagnostic pop