Browse code

Add building/testing with msbuild and the clang compiler

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>

Arne Schwabe authored on 2024/12/27 20:22:07
Showing 7 changed files
... ...
@@ -259,7 +259,7 @@ jobs:
259 259
       strategy:
260 260
         fail-fast: false
261 261
         matrix:
262
-          arch: [amd64, x86, arm64]
262
+          arch: [amd64, x86, arm64, amd64-clang, x86-clang]
263 263
 
264 264
       name: "msbuild - ${{ matrix.arch }} - openssl"
265 265
       env:
... ...
@@ -627,7 +627,8 @@ if (BUILD_TESTING)
627 627
         check_linker_flag(C -Wl,--wrap=parse_line LD_SUPPORTS_WRAP)
628 628
     endif()
629 629
 
630
-    if (${LD_SUPPORTS_WRAP})
630
+    # Clang-cl (which is also MSVC) is wrongly detected to support wrap
631
+    if (NOT MSVC AND "${LD_SUPPORTS_WRAP}")
631 632
         list(APPEND unit_tests
632 633
             "test_argv"
633 634
             "test_tls_crypt"
... ...
@@ -122,6 +122,10 @@
122 122
             }
123 123
         },
124 124
         {
125
+            "name": "clangtoolset",
126
+            "toolset": "ClangCL"
127
+        },
128
+        {
125 129
             "name": "mingw-x64",
126 130
             "inherits": [ "base", "base-mingw", "x64-mingw" ]
127 131
         },
... ...
@@ -134,6 +138,10 @@
134 134
             "inherits": [ "base", "base-windows", "x64", "release" ]
135 135
         },
136 136
         {
137
+            "name": "win-amd64-clang-release",
138
+            "inherits": [ "base", "base-windows", "clangtoolset", "x64", "release" ]
139
+        },
140
+        {
137 141
             "name": "win-arm64-release",
138 142
             "inherits": [ "base", "base-windows", "arm64", "release" ]
139 143
         },
... ...
@@ -142,10 +150,18 @@
142 142
             "inherits": [ "base", "base-windows", "x86", "release" ]
143 143
         },
144 144
         {
145
+            "name": "win-x86-clang-release",
146
+            "inherits": [ "base", "base-windows", "clangtoolset", "x86", "release" ]
147
+        },
148
+        {
145 149
             "name": "win-amd64-debug",
146 150
             "inherits": [ "base", "base-windows", "x64", "debug" ]
147 151
         },
148 152
         {
153
+            "name": "win-amd64-clang-debug",
154
+            "inherits": [ "base", "base-windows", "clangtoolset", "x64", "debug" ]
155
+        },
156
+        {
149 157
             "name": "win-arm64-debug",
150 158
             "inherits": [ "base", "base-windows", "arm64", "debug" ]
151 159
         },
... ...
@@ -154,6 +170,10 @@
154 154
             "inherits": [ "base", "base-windows", "x86", "debug" ]
155 155
         },
156 156
         {
157
+            "name": "win-x86-clang-debug",
158
+            "inherits": [ "base", "base-windows", "clangtoolset", "x86", "debug" ]
159
+        },
160
+        {
157 161
             "name": "unix-native",
158 162
             "generator": "Ninja Multi-Config",
159 163
             "binaryDir": "out/build/unix"
... ...
@@ -174,6 +194,11 @@
174 174
             "configuration": "Release"
175 175
         },
176 176
         {
177
+            "name": "win-amd64-clang-release",
178
+            "configurePreset": "win-amd64-clang-release",
179
+            "configuration": "Release"
180
+        },
181
+        {
177 182
             "name": "win-arm64-release",
178 183
             "configurePreset": "win-arm64-release",
179 184
             "configuration": "Release"
... ...
@@ -184,11 +209,21 @@
184 184
             "configuration": "Release"
185 185
         },
186 186
         {
187
+            "name": "win-x86-clang-release",
188
+            "configurePreset": "win-x86-clang-release",
189
+            "configuration": "Release"
190
+        },
191
+        {
187 192
             "name": "win-amd64-debug",
188 193
             "configurePreset": "win-amd64-debug",
189 194
             "configuration": "Debug"
190 195
         },
191 196
         {
197
+            "name": "win-amd64-clang-debug",
198
+            "configurePreset": "win-amd64-clang-debug",
199
+            "configuration": "Debug"
200
+        },
201
+        {
192 202
             "name": "win-arm64-debug",
193 203
             "configurePreset": "win-arm64-debug",
194 204
             "configuration": "Debug"
... ...
@@ -199,6 +234,11 @@
199 199
             "configuration": "Debug"
200 200
         },
201 201
         {
202
+            "name": "win-x86-clang-debug",
203
+            "configurePreset": "win-x86-clang-debug",
204
+            "configuration": "Debug"
205
+        },
206
+        {
202 207
             "name": "unix-native",
203 208
             "configurePreset": "unix-native"
204 209
         }
... ...
@@ -209,18 +249,34 @@
209 209
             "configurePreset": "win-amd64-release"
210 210
         },
211 211
         {
212
+            "name": "win-amd64-clang-release",
213
+            "configurePreset": "win-amd64-clang-release"
214
+        },
215
+        {
212 216
             "name": "win-x86-release",
213 217
             "configurePreset": "win-x86-release"
214 218
         },
215 219
         {
220
+            "name": "win-x86-clang-release",
221
+            "configurePreset": "win-x86-clang-release"
222
+        },
223
+        {
216 224
             "name": "win-amd64-debug",
217 225
             "configurePreset": "win-amd64-debug"
218 226
         },
219 227
         {
228
+            "name": "win-amd64-clang-debug",
229
+            "configurePreset": "win-amd64-clang-debug"
230
+        },
231
+        {
220 232
             "name": "win-x86-debug",
221 233
             "configurePreset": "win-x86-debug"
222 234
         },
223 235
         {
236
+            "name": "win-x86-clang-debug",
237
+            "configurePreset": "win-x86-clang-debug"
238
+        },
239
+        {
224 240
             "name": "unix-native",
225 241
             "configurePreset": "unix-native"
226 242
         }
... ...
@@ -439,8 +439,10 @@ don't. */
439 439
 # define _GNU_SOURCE 1
440 440
 #endif
441 441
 
442
-
443
-#if defined(_WIN32)
442
+/* if inttypes.h is included this breaks rc.exe when using the ClangCL
443
+ * Toolchain as it pulls in a inttypes.h variant for clang that rc.exe does
444
+ * not understand (#include_next preprocessor directive) */
445
+#if defined(_WIN32) && !defined(RC_INVOKED)
444 446
 #include <inttypes.h>
445 447
 typedef uint32_t in_addr_t;
446 448
 typedef uint16_t in_port_t;
... ...
@@ -452,7 +454,7 @@ typedef uint16_t in_port_t;
452 452
 #define SIGTERM   15
453 453
 #endif
454 454
 
455
-#if defined(_MSC_VER)
455
+#if defined(_MSC_VER) && !defined(RC_INVOKED)
456 456
 #include <BaseTsd.h>
457 457
 typedef SSIZE_T ssize_t;
458 458
 #define strncasecmp strnicmp
... ...
@@ -303,7 +303,7 @@ cleanup_pAdapterList:
303 303
 UINT __stdcall
304 304
 FindSystemInfo(_In_ MSIHANDLE hInstall)
305 305
 {
306
-#ifdef _MSC_VER
306
+#ifdef DLLEXP_EXPORT
307 307
 #pragma comment(linker, DLLEXP_EXPORT)
308 308
 #endif
309 309
 
... ...
@@ -340,7 +340,7 @@ FindSystemInfo(_In_ MSIHANDLE hInstall)
340 340
 UINT __stdcall
341 341
 CloseOpenVPNGUI(_In_ MSIHANDLE hInstall)
342 342
 {
343
-#ifdef _MSC_VER
343
+#ifdef DLLEXP_EXPORT
344 344
 #pragma comment(linker, DLLEXP_EXPORT)
345 345
 #endif
346 346
     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)
363 363
 UINT __stdcall
364 364
 StartOpenVPNGUI(_In_ MSIHANDLE hInstall)
365 365
 {
366
-#ifdef _MSC_VER
366
+#ifdef DLLEXP_EXPORT
367 367
 #pragma comment(linker, DLLEXP_EXPORT)
368 368
 #endif
369 369
 
... ...
@@ -636,7 +636,7 @@ schedule_adapter_delete(
636 636
 UINT __stdcall
637 637
 EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
638 638
 {
639
-#ifdef _MSC_VER
639
+#ifdef DLLEXP_EXPORT
640 640
 #pragma comment(linker, DLLEXP_EXPORT)
641 641
 #endif
642 642
 
... ...
@@ -789,7 +789,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
789 789
                 {
790 790
                     goto cleanup_szDisplayName;
791 791
                 }
792
-#ifdef __GNUC__
792
+#if defined(__GNUC__) || defined(__clang__)
793 793
 /*
794 794
  * warning: enumeration value ‘MSICONDITION_TRUE’ not handled in switch
795 795
  * warning: enumeration value ‘MSICONDITION_NONE’ not handled in switch
... ...
@@ -809,7 +809,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
809 809
                         free(szValue);
810 810
                         goto cleanup_szDisplayName;
811 811
                 }
812
-#ifdef __GNUC__
812
+#if defined(__GNUC__) || defined(__clang__)
813 813
 #pragma GCC diagnostic pop
814 814
 #endif
815 815
                 free(szValue);
... ...
@@ -965,7 +965,7 @@ CreateRebootFile(_In_z_ LPCWSTR szTmpDir)
965 965
 UINT __stdcall
966 966
 ProcessDeferredAction(_In_ MSIHANDLE hInstall)
967 967
 {
968
-#ifdef _MSC_VER
968
+#ifdef DLLEXP_EXPORT
969 969
 #pragma comment(linker, DLLEXP_EXPORT)
970 970
 #endif
971 971
 
... ...
@@ -1165,7 +1165,7 @@ cleanup_CoInitialize:
1165 1165
 UINT __stdcall
1166 1166
 CheckAndScheduleReboot(_In_ MSIHANDLE hInstall)
1167 1167
 {
1168
-#ifdef _MSC_VER
1168
+#ifdef DLLEXP_EXPORT
1169 1169
 #pragma comment(linker, DLLEXP_EXPORT)
1170 1170
 #endif
1171 1171
 
... ...
@@ -66,7 +66,11 @@ extern DWORD openvpnmsica_thread_data_idx;
66 66
 extern "C" {
67 67
 #endif
68 68
 
69
-#ifdef __GNUC__
69
+/* Ensure that clang-cl, which does not understand the cl specific
70
+ * preprocessor defines like #pragma comment(linker, DLLEXP_EXPORT)
71
+ * is handled the same way as mingw and uses the alternative instead
72
+ * and does not define DLLEXP_EXPORT */
73
+#if defined(__GNUC__) || defined(__clang__)
70 74
 #define DLLEXP_DECL __declspec(dllexport)
71 75
 #else
72 76
 #define DLLEXP_DECL
... ...
@@ -389,8 +389,9 @@ test_snprintf(void **state)
389 389
 
390 390
     /* Instead of trying to trick the compiler here, disable the warnings
391 391
      * for this unit test. We know that the results will be truncated
392
-     * and we want to test that */
393
-#if defined(__GNUC__)
392
+     * and we want to test that. Not we need the clang as clang-cl (msvc) does
393
+     * not define __GNUC__ like it does under UNIX(-like) platforms */
394
+#if defined(__GNUC__) || defined(__clang__)
394 395
 /* some clang version do not understand -Wformat-truncation, so ignore the
395 396
  * warning to avoid warnings/errors (-Werror) about unknown pragma/option */
396 397
 #if defined(__clang__)
... ...
@@ -418,7 +419,7 @@ test_snprintf(void **state)
418 418
     assert_int_equal(ret, 10);
419 419
     assert_int_equal(buf[9], '\0');
420 420
 
421
-#if defined(__GNUC__)
421
+#if defined(__GNUC__) || defined(__clang__)
422 422
 #pragma GCC diagnostic pop
423 423
 #if defined(__clang__)
424 424
 #pragma clang diagnostic pop