Skip to content

Commit

Permalink
Add building/testing with msbuild and the clang compiler
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
schwabe committed Sep 17, 2024
1 parent b236261 commit 2fa0eb1
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,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:
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,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"
Expand Down
56 changes: 56 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@
"CMAKE_BUILD_TYPE": "Release"
}
},
{
"name": "clangtoolset",
"toolset": "ClangCL"
},
{
"name": "mingw-x64",
"inherits": [ "base", "base-mingw", "x64-mingw" ]
Expand All @@ -133,6 +137,10 @@
"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" ]
Expand All @@ -141,10 +149,18 @@
"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" ]
Expand All @@ -153,6 +169,10 @@
"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",
Expand All @@ -173,6 +193,11 @@
"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",
Expand All @@ -183,11 +208,21 @@
"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",
Expand All @@ -198,6 +233,11 @@
"configurePreset": "win-x86-debug",
"configuration": "Debug"
},
{
"name": "win-x86-clang-debug",
"configurePreset": "win-x86-clang-debug",
"configuration": "Debug"
},
{
"name": "unix-native",
"configurePreset": "unix-native"
Expand All @@ -208,18 +248,34 @@
"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"
Expand Down
8 changes: 5 additions & 3 deletions config.h.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,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;
Expand All @@ -455,7 +457,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
Expand Down
16 changes: 8 additions & 8 deletions src/openvpnmsica/openvpnmsica.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ find_adapters(
UINT __stdcall
FindSystemInfo(_In_ MSIHANDLE hInstall)
{
#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
#pragma comment(linker, DLLEXP_EXPORT)
#endif

Expand Down Expand Up @@ -337,7 +337,7 @@ FindSystemInfo(_In_ MSIHANDLE hInstall)
UINT __stdcall
CloseOpenVPNGUI(_In_ MSIHANDLE hInstall)
{
#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
#pragma comment(linker, DLLEXP_EXPORT)
#endif
UNREFERENCED_PARAMETER(hInstall); /* This CA is does not interact with MSI session (report errors, access properties, tables, etc.). */
Expand All @@ -360,7 +360,7 @@ CloseOpenVPNGUI(_In_ MSIHANDLE hInstall)
UINT __stdcall
StartOpenVPNGUI(_In_ MSIHANDLE hInstall)
{
#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
#pragma comment(linker, DLLEXP_EXPORT)
#endif

Expand Down Expand Up @@ -633,7 +633,7 @@ schedule_adapter_delete(
UINT __stdcall
EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
{
#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
#pragma comment(linker, DLLEXP_EXPORT)
#endif

Expand Down Expand Up @@ -786,7 +786,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
Expand All @@ -806,7 +806,7 @@ EvaluateTUNTAPAdapters(_In_ MSIHANDLE hInstall)
free(szValue);
goto cleanup_szDisplayName;
}
#ifdef __GNUC__
#if defined(__GNUC__) || defined(__clang__)
#pragma GCC diagnostic pop
#endif
free(szValue);
Expand Down Expand Up @@ -962,7 +962,7 @@ CreateRebootFile(_In_z_ LPCWSTR szTmpDir)
UINT __stdcall
ProcessDeferredAction(_In_ MSIHANDLE hInstall)
{
#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
#pragma comment(linker, DLLEXP_EXPORT)
#endif

Expand Down Expand Up @@ -1162,7 +1162,7 @@ ProcessDeferredAction(_In_ MSIHANDLE hInstall)
UINT __stdcall
CheckAndScheduleReboot(_In_ MSIHANDLE hInstall)
{
#ifdef _MSC_VER
#if defined(_MSC_VER) && !defined(__clang__)
#pragma comment(linker, DLLEXP_EXPORT)
#endif

Expand Down
4 changes: 3 additions & 1 deletion src/openvpnmsica/openvpnmsica.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ extern DWORD openvpnmsica_thread_data_idx;
extern "C" {
#endif

#ifdef __GNUC__
/* Ensure that clang-cl, which does not understand the #pragma comment(linker, ...)
* is handled the same way as mingw */
#if defined(__GNUC__) || defined(__clang__)
#define DLLEXP_DECL __declspec(dllexport)
#else
#define DLLEXP_DECL
Expand Down

0 comments on commit 2fa0eb1

Please sign in to comment.