From: "plaisthos (Code Review)" Date: Wed, 18 Sep 2024 11:36:53 +0000 In-Reply-To: References: Reply-To: arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <7a02a2847d5c237142173b44ddf744c3cfe76b17-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="bxq8/1O0U+c="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: Add building/testing with msbuild and the clang compiler List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld Cc: openvpn-devel --bxq8/1O0U+c= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld. Hello flichtenheld,=20 I'd like you to reexamine a change. Please visit http://gerrit.openvpn.net/c/openvpn/+/751?usp=3Demail to look at the new patch set (#5). The following approvals got outdated and were removed: Code-Review-1 by flichtenheld Change subject: Add building/testing with msbuild and the clang compiler ...................................................................... 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 --- M .github/workflows/build.yaml M CMakeLists.txt M CMakePresets.json M config.h.cmake.in M src/openvpnmsica/openvpnmsica.c M src/openvpnmsica/openvpnmsica.h 6 files changed, 77 insertions(+), 14 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/51/751/5 diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 361d457..d326937 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -272,7 +272,7 @@ strategy: fail-fast: false matrix: - arch: [amd64, x86, arm64] + arch: [amd64, x86, arm64, amd64-clang, x86-clang] name: "msbuild - ${{ matrix.arch }} - openssl" env: diff --git a/CMakeLists.txt b/CMakeLists.txt index ad620fa..f4a305f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -622,7 +622,8 @@ check_linker_flag(C -Wl,--wrap=3Dparse_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" diff --git a/CMakePresets.json b/CMakePresets.json index 135b19d..b6ec201 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -122,6 +122,10 @@ } }, { + "name": "clangtoolset", + "toolset": "ClangCL" + }, + { "name": "mingw-x64", "inherits": [ "base", "base-mingw", "x64-mingw" ] }, @@ -134,6 +138,10 @@ "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" ] }, @@ -142,10 +150,18 @@ "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" ] }, @@ -154,6 +170,10 @@ "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", "binaryDir": "out/build/unix" @@ -174,6 +194,11 @@ "configuration": "Release" }, { + "name": "win-amd64-clang-release", + "configurePreset": "win-amd64-clang-release", + "configuration": "Release" + }, + { "name": "win-arm64-release", "configurePreset": "win-arm64-release", "configuration": "Release" @@ -184,11 +209,21 @@ "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", "configuration": "Debug" @@ -199,6 +234,11 @@ "configuration": "Debug" }, { + "name": "win-x86-clang-debug", + "configurePreset": "win-x86-clang-debug", + "configuration": "Debug" + }, + { "name": "unix-native", "configurePreset": "unix-native" } @@ -209,18 +249,34 @@ "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" } diff --git a/config.h.cmake.in b/config.h.cmake.in index 18af5e9..724da2e 100644 --- a/config.h.cmake.in +++ b/config.h.cmake.in @@ -442,8 +442,10 @@ # 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 typedef uint32_t in_addr_t; typedef uint16_t in_port_t; @@ -455,7 +457,7 @@ #define SIGTERM 15 #endif -#if defined(_MSC_VER) +#if defined(_MSC_VER) && !defined(RC_INVOKED) #include typedef SSIZE_T ssize_t; #define strncasecmp strnicmp diff --git a/src/openvpnmsica/openvpnmsica.c b/src/openvpnmsica/openvpnmsic= a.c index 5ffb5b3..1033c61 100644 --- a/src/openvpnmsica/openvpnmsica.c +++ b/src/openvpnmsica/openvpnmsica.c @@ -300,7 +300,7 @@ UINT __stdcall FindSystemInfo(_In_ MSIHANDLE hInstall) { -#ifdef _MSC_VER +#ifdef DLLEXP_EXPORT #pragma comment(linker, DLLEXP_EXPORT) #endif @@ -337,7 +337,7 @@ 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.). */ @@ -360,7 +360,7 @@ UINT __stdcall StartOpenVPNGUI(_In_ MSIHANDLE hInstall) { -#ifdef _MSC_VER +#ifdef DLLEXP_EXPORT #pragma comment(linker, DLLEXP_EXPORT) #endif @@ -633,7 +633,7 @@ UINT __stdcall EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall) { -#ifdef _MSC_VER +#ifdef DLLEXP_EXPORT #pragma comment(linker, DLLEXP_EXPORT) #endif @@ -786,7 +786,7 @@ { goto cleanup_szDisplayName; } -#ifdef __GNUC__ +#if defined(__GNUC__) || defined(__clang__) /* * warning: enumeration value =E2=80=98MSICONDITION_TRUE=E2=80=99 not hand= led in switch * warning: enumeration value =E2=80=98MSICONDITION_NONE=E2=80=99 not hand= led in switch @@ -806,7 +806,7 @@ free(szValue); goto cleanup_szDisplayName; } -#ifdef __GNUC__ +#if defined(__GNUC__) || defined(__clang__) #pragma GCC diagnostic pop #endif free(szValue); @@ -962,7 +962,7 @@ UINT __stdcall ProcessDeferredAction(_In_ MSIHANDLE hInstall) { -#ifdef _MSC_VER +#ifdef DLLEXP_EXPORT #pragma comment(linker, DLLEXP_EXPORT) #endif @@ -1162,7 +1162,7 @@ UINT __stdcall CheckAndScheduleReboot(_In_ MSIHANDLE hInstall) { -#ifdef _MSC_VER +#ifdef DLLEXP_EXPORT #pragma comment(linker, DLLEXP_EXPORT) #endif diff --git a/src/openvpnmsica/openvpnmsica.h b/src/openvpnmsica/openvpnmsic= a.h index 6640d7e..d4c8596 100644 --- a/src/openvpnmsica/openvpnmsica.h +++ b/src/openvpnmsica/openvpnmsica.h @@ -66,7 +66,11 @@ 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 -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/751?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I43d84034f3e920a45731c4aab4f851a60921290d Gerrit-Change-Number: 751 Gerrit-PatchSet: 5 Gerrit-Owner: plaisthos Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: flichtenheld Gerrit-MessageType: newpatchset --bxq8/1O0U+c= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld.

plaisthos uploaded patch set #5 to this change.

<= a href=3D"http://gerrit.openvpn.net/c/openvpn/+/751?usp=3Demail">View Chang= e

The following approvals got outdated and were removed: Code-Review-1 by flichtenheld

Add building/testing with msbuild and the cla=
ng compiler

The LLVM/clang compiler warning and error message are ea= sier too read
than their MSVC cl counterparts. Also compiling/running te= sts on Windows
with a different compiler has the benefit of a better cov= erage.

This includes a few minor changes to allow clang-cl to compil= e the
project.

Change-Id: I43d84034f3e920a45731c4aab4f851a6092129= 0d
Signed-off-by: Arne Schwabe <arne@...1227...>
---
M .gith= ub/workflows/build.yaml
M CMakeLists.txt
M CMakePresets.json
M con= fig.h.cmake.in
M src/openvpnmsica/openvpnmsica.c
M src/openvpnmsica/o= penvpnmsica.h
6 files changed, 77 insertions(+), 14 deletions(-)

=
git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/51/751/5
=
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.y=
aml
index 361d457..d326937 100644
--- a/.gi= thub/workflows/build.yaml
+++ b/.github/workflows/build.yam= l
@@ -272,7 +272,7 @@
strategy:
fail-fast: false
matrix:
- arch: [amd64, x8= 6, arm64]
+ = arch: [amd64, x86, arm64, amd64-clang, x86-clang]
<= br> name: "msbuild - ${{ matrix.arch }} - openssl"
env:
diff --git a/CMakeLists.txt b/CMa= keLists.txt
index ad620fa..f4a305f 100644
-= -- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@= -622,7 +622,8 @@
check_linker_flag(C -Wl,--wrap= =3Dparse_line LD_SUPPORTS_WRAP)
endif()

- if (${LD_SUPPO= RTS_WRAP})
+ # Cla= ng-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"
diff --git a/CMakePresets.json b= /CMakePresets.json
index 135b19d..b6ec201 100644
= --- a/CMakePresets.json
+++ b/CMakePresets.json
@@ -122,6 +122,10 @@
}
},

{
+ "name": "clangtoolset&quo= t;,
+ &quo= t;toolset": "ClangCL"
+ },
+ {
"name": "ming= w-x64",
"inherits": [ "bas= e", "base-mingw", "x64-mingw" ]
= },
@@ -134,6 +138,10 @@
= "inherits": [ "base", "base-windows", "= x64", "release" ]
},
{

+ = "name": "win-amd64-clang-release",
+ "inherits": [= "base", "base-windows", "clangtoolset", &quo= t;x64", "release" ]

+ },
+ {
"name": "win-ar= m64-release",
"inherits": [ &qu= ot;base", "base-windows", "arm64", "release&q= uot; ]
},
@@ -142,10 +150,18 @@
"inherits": [ "base", "= base-windows", "x86", "release" ]
= },
{
+ "name": "win-x86-clang-releas= e",
+ = "inherits": [ "base", "base-windows", "= clangtoolset", "x86", "release" ]
+ },
+ {
"= name": "win-amd64-debug",
"= ;inherits": [ "base", "base-windows", "x64&qu= ot;, "debug" ]
},
= {
+ &qu= ot;name": "win-amd64-clang-debug",
+ "inherits": [ "bas= e", "base-windows", "clangtoolset", "x64"= ;, "debug" ]
+ = {
"name": "win-arm64-debug&qu= ot;,
"inherits": [ "base",= "base-windows", "arm64", "debug" ] },
@@ -154,6 +170,10 @@
= "inherits": [ "base", "base-windows"= ;, "x86", "debug" ]
},<= br> {
+= "name": "win-x86-clang-debug",
+ "inherits"= : [ "base", "base-windows", "clangtoolset", &= quot;x86", "debug" ]

+ },
+ {
"name": "unix-= native",
"generator": "Nin= ja Multi-Config",
"binaryDir": = "out/build/unix"
@@ -174,6 +194,11 @@
<= span> "configuration": "Release"
= },
{
+ "name": "win-amd64-clan= g-release",
+ = "configurePreset": "win-amd64-clang-release",<= /span>
+ "co= nfiguration": "Release"
+ },
+ {
"name": "wi= n-arm64-release",
"configurePreset&q= uot;: "win-arm64-release",
"con= figuration": "Release"
@@ -184,11 +209,21 @@=
"configuration": "Release"= ;
},
{
+ "name": "wi= n-x86-clang-release",
+ "configurePreset": "win-x86-clang-release= ",
+ = "configuration": "Release"
+ },
+ {
"name": = "win-amd64-debug",
"configurePr= eset": "win-amd64-debug",
"= ;configuration": "Debug"
},<= br> {
+= "name": "win-amd64-clang-debug",
= + "configurePre= set": "win-amd64-clang-debug",
+ "configuration": "Debu= g"
+ },
+ {
<= span> "name": "win-arm64-debug",

= "configurePreset": "win-arm64-debug"= ,
"configuration": "Debug"=
@@ -199,6 +234,11 @@
"co= nfiguration": "Debug"
},
= {
+ = "name": "win-x86-clang-debug",
+ "configurePreset&q= uot;: "win-x86-clang-debug",

+ "configuration": "Debug"=
+ },+ {
= "name": "unix-native",
= "configurePreset": "unix-native"
}
@@ -209,18 +249,34 @@
= "configurePreset": "win-amd64-release"
<= span> },
{
+ "name": "win-amd64-clang= -release",
+ = "configurePreset": "win-amd64-clang-release"
+ },
<= span style=3D"color: hsl(120, 100%, 40%);">+ {

= "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"
<= span> },
{
+ "name": "win-amd64-clang= -debug",
+ = "configurePreset": "win-amd64-clang-debug"=
+ },
+ {
= "name": "win-x86-debug",
= "configurePreset": "win-x86-debug"
= },
{
+ "name": "win-x86-clang-debug&q= uot;,
+ &q= uot;configurePreset": "win-x86-clang-debug"
+ },
+ {
"= name": "unix-native",
"con= figurePreset": "unix-native"
}
diff --git a/config.h.cmake.in b/config.h.cmake.in
index 18af5e9..724da2e 100644

--- a/config.h.cmake.in
+++ b/config.h.cmake.in
@@ -442,8 +442,10 @@=
# define _GNU_SOURCE 1
#endif
=
-
-#if defined(_WIN32)

+/* if inttypes.h is included this b= reaks 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) && !define= d(RC_INVOKED)
#include <inttypes.h>
= typedef uint32_t in_addr_t;
typedef uint16_t in_port_t;
@@ -455,7 +457,7 @@
#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
dif= f --git a/src/openvpnmsica/openvpnmsica.c b/src/openvpnmsica/openvpnmsica.c=
index 5ffb5b3..1033c61 100644
--- a/src/op= envpnmsica/openvpnmsica.c
+++ b/src/openvpnmsica/openvpnmsi= ca.c
@@ -300,7 +300,7 @@
UINT __stdcall
FindSystemInfo(_In_ MSIHANDLE hInstall)
{
-#ifdef _MSC_VER<= br>+#ifdef DLLEXP_EXPORT=
#pragma comment(linker, DLLEXP_EXPORT)
#endif

@@ -337,7 +337,7 @@
UINT = __stdcall
CloseOpenVPNGUI(_In_ MSIHANDLE hInstall)<= br> {
-#ifdef _MS= C_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.). */
@@ -360,7 +360,7 @@
UIN= T __stdcall
StartOpenVPNGUI(_In_ MSIHANDLE hInstall)

{
-#ifdef _= MSC_VER
+#ifdef DLLEX= P_EXPORT
#pragma comment(linker, DLLEXP_EXPORT)
= #endif

@@ -633,7 +633,7 @@<= br> UINT __stdcall
EvaluateTUNTAPAdapters(_In_ MSIHA= NDLE hInstall)
{
-#ifdef _MSC_VER
+#ifdef DLLEXP_EXPORT
#pragma comment(linker, DLLEX= P_EXPORT)
#endif

@@ -786= ,7 +786,7 @@
{
= goto cleanup_szDisplayName;
}
-#ifdef __GNUC__+#if defined(__GNUC__) || def= ined(__clang__)
/*
* warning: enumeratio= n value =E2=80=98MSICONDITION_TRUE=E2=80=99 not handled in switch * warning: enumeration value =E2=80=98MSICONDITION_NONE=E2=80=99 n= ot handled in switch
@@ -806,7 +806,7 @@
= free(szValue);
= goto cleanup_szDisplayName;
}-#ifdef __GNUC__
+#if defined(__GNUC__) || defined(_= _clang__)

#pragma GCC diagnostic pop
#end= if
free(szValue);
@@ -962,= 7 +962,7 @@
UINT __stdcall
ProcessDeferre= dAction(_In_ MSIHANDLE hInstall)
{
-#ifdef _MSC_VER
+#ifdef DLLEXP_EXPORT
#pragma c= omment(linker, DLLEXP_EXPORT)
#endif

@@ -1162,7 +1162,7 @@
UINT __stdcall CheckAndScheduleReboot(_In_ MSIHANDLE hInstall)
{=
-#ifdef _MSC_VER
+#ifdef DLLEXP_EXPORT
#pragma comment(linker, DLLEXP_EXPORT)
#endif=

diff --git a/src/openvpnmsica/openvpnmsi= ca.h b/src/openvpnmsica/openvpnmsica.h
index 6640d7e..d4c85= 96 100644
--- a/src/openvpnmsica/openvpnmsica.h
<= span>+++ b/src/openvpnmsica/openvpnmsica.h

@@ -66,7 +66,11 = @@
extern "C" {
#endif
-#ifdef __GNU= C__
+/* Ensure that c= lang-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 */
+#i= f defined(__GNUC__) || defined(__clang__)
#define DLLEXP_D= ECL __declspec(dllexport)
#else
#define D= LLEXP_DECL

To view, visit change 751. To uns= ubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I43d84034f3e920a45731c4aab4f= 851a60921290d
Gerrit-Change-Number: 751
Gerrit-PatchSet: 5
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-MessageType: newpatchset
--bxq8/1O0U+c=--