From 415b761190d85b94ab4d39dde510122fbb4977ff Mon Sep 17 00:00:00 2001 From: apple1417 Date: Fri, 5 Jan 2024 15:41:54 +1300 Subject: [PATCH 1/2] pull in toolchain updates, support native mingw while this shouldn't really have an effect, going to bump the minor version anyway --- .clang-tidy | 1 + .cruft.json | 2 +- .github/workflows/build.yml | 33 +++++++++++++--------- CMakeLists.txt | 7 ++++- CMakePresets.json | 56 +++++++++++++++++++++++++++++++++++++ common_cmake | 2 +- src/pch.h | 8 +++--- src/proxy/d3d11.cpp | 14 ++++++++-- src/proxy/xinput1_3.cpp | 15 ++++++++-- src/util.cpp | 3 -- 10 files changed, 113 insertions(+), 28 deletions(-) diff --git a/.clang-tidy b/.clang-tidy index 4885f75..9534cad 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -36,6 +36,7 @@ Checks: > -cppcoreguidelines-non-private-member-variables-in-classes, CheckOptions: cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true + cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams: true misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true readability-identifier-naming.GlobalConstantCase: UPPER_CASE diff --git a/.cruft.json b/.cruft.json index b8b09e2..6904a90 100644 --- a/.cruft.json +++ b/.cruft.json @@ -1,6 +1,6 @@ { "template": "git@github.com:bl-sdk/common_dotfiles.git", - "commit": "a66f9767ed477bfa89d6ca505392d226ebdd4275", + "commit": "fb06ff8c773806b3f8cc69dbda60c0a7b481c6de", "checkout": null, "context": { "cookiecutter": { diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ef03a8a..dfa0ed8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,13 +10,12 @@ env: # Important to pin the clang version, cause we also use it for linting CLANG_VERSION: 17 CLANG_TIDY_JOBS: 4 - # Since we use rather new c++ features, we need a rather new version of MinGW - # LLVM MinGW seems to be the newest prebuilt binaries around - LLVM_MINGW_VERSION: llvm-mingw-20230919-msvcrt-ubuntu-20.04-x86_64 - LLVM_MINGW_DOWNLOAD: https://github.com/mstorsjo/llvm-mingw/releases/download/20230919/llvm-mingw-20230919-msvcrt-ubuntu-20.04-x86_64.tar.xz + # LLVM MinGW download + LLVM_MINGW_VERSION: llvm-mingw-20231128-msvcrt-ubuntu-20.04-x86_64 + LLVM_MINGW_DOWNLOAD: https://github.com/mstorsjo/llvm-mingw/releases/download/20231128/llvm-mingw-20231128-msvcrt-ubuntu-20.04-x86_64.tar.xz # xwin settings - XWIN_VERSION: xwin-0.3.1-x86_64-unknown-linux-musl - XWIN_DOWNLOAD: https://github.com/Jake-Shadle/xwin/releases/download/0.3.1/xwin-0.3.1-x86_64-unknown-linux-musl.tar.gz + XWIN_VERSION: xwin-0.5.0-x86_64-unknown-linux-musl + XWIN_DOWNLOAD: https://github.com/Jake-Shadle/xwin/releases/download/0.5.0/xwin-0.5.0-x86_64-unknown-linux-musl.tar.gz jobs: cache-clang: @@ -55,7 +54,7 @@ jobs: steps: - name: Restore Clang Cache - if: contains(matrix.preset, 'clang') + if: startswith(matrix.preset, 'clang') uses: actions/cache/restore@v3 with: path: C:\Program Files\LLVM @@ -63,7 +62,7 @@ jobs: fail-on-cache-miss: true - name: Add MSVC to PATH - if: contains(matrix.preset, 'msvc') + if: startswith(matrix.preset, 'msvc') uses: TheMrMilchmann/setup-msvc-dev@v2 with: arch: ${{ fromJSON('["x86", "x64"]')[contains(matrix.preset, 'x64')] }} @@ -97,10 +96,12 @@ jobs: fail-fast: false matrix: preset: [ - "mingw-x86-release", - "mingw-x64-release", "clang-cross-x86-release", "clang-cross-x64-release", + "llvm-mingw-x86-release", + "llvm-mingw-x64-release", + "mingw-x86-release", + "mingw-x64-release", ] steps: @@ -111,7 +112,7 @@ jobs: # Caching would also lose the +x - so we'd have to tar before caching/untar after, making it # even slower - name: Setup Clang - if: contains(matrix.preset, 'clang') + if: startswith(matrix.preset, 'clang') run: | wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh @@ -133,13 +134,19 @@ jobs: /usr/bin/llvm-rc-${{ env.CLANG_VERSION }} \ 200 - - name: Setup MinGW - if: contains(matrix.preset, 'mingw') + - name: Setup LLVM MinGW + if: startswith(matrix.preset, 'llvm-mingw') run: | wget -nv ${{ env.LLVM_MINGW_DOWNLOAD }} tar -xf ${{ env.LLVM_MINGW_VERSION }}.tar.xz -C ~/ echo $(readlink -f ~/${{ env.LLVM_MINGW_VERSION }}/bin) >> $GITHUB_PATH + - name: Set up MinGW + if: startswith(matrix.preset, 'mingw') + uses: egor-tensin/setup-mingw@v2 + with: + platform: ${{ fromJSON('["x86", "x64"]')[contains(matrix.preset, 'x64')] }} + # xwin does take long enough that caching's worth it - name: Restore xwin cache if: contains(matrix.preset, 'cross') diff --git a/CMakeLists.txt b/CMakeLists.txt index 8050d68..e6d4fbb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.24) -project(pluginloader VERSION 1.0.1) +project(pluginloader VERSION 1.0.2) add_library(_pluginloader_base INTERFACE) set(CMAKE_EXPORT_COMPILE_COMMANDS True) @@ -10,11 +10,16 @@ set_target_properties(_pluginloader_base PROPERTIES COMPILE_WARNING_AS_ERROR True INTERPROCEDURAL_OPTIMIZATION True ) + if(MSVC) target_compile_options(_pluginloader_base INTERFACE /W4) else() target_compile_options(_pluginloader_base INTERFACE -Wall -Wextra -Wpedantic) endif() +# CMake doesn't understand warnings as errors for MinGW yet +if(MINGW) + target_compile_options(_pluginloader_base INTERFACE -Werror) +endif() set(CONFIGURE_FILES_DIR "${CMAKE_CURRENT_BINARY_DIR}/configure") diff --git a/CMakePresets.json b/CMakePresets.json index 7b1855d..ecd5b7b 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -49,6 +49,26 @@ }, "toolchainFile": "common_cmake/clang-cross-x64.cmake" }, + { + "name": "_llvm_mingw_x86", + "hidden": true, + "condition": { + "type": "notEquals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + }, + "toolchainFile": "common_cmake/llvm-i686-w64-mingw32.cmake" + }, + { + "name": "_llvm_mingw_x64", + "hidden": true, + "condition": { + "type": "notEquals", + "lhs": "${hostSystemName}", + "rhs": "Windows" + }, + "toolchainFile": "common_cmake/llvm-x86_64-w64-mingw32.cmake" + }, { "name": "_mingw_x86", "hidden": true, @@ -193,6 +213,42 @@ "_release" ] }, + { + "name": "llvm-mingw-x86-debug", + "displayName": "x86 Debug (LLVM MinGW)", + "inherits": [ + "_base", + "_llvm_mingw_x86", + "_debug" + ] + }, + { + "name": "llvm-mingw-x86-release", + "displayName": "x86 Release (LLVM MinGW)", + "inherits": [ + "_base", + "_llvm_mingw_x86", + "_release" + ] + }, + { + "name": "llvm-mingw-x64-debug", + "displayName": "x64 Debug (LLVM MinGW)", + "inherits": [ + "_base", + "_llvm_mingw_x64", + "_debug" + ] + }, + { + "name": "llvm-mingw-x64-release", + "displayName": "x64 Release (LLVM MinGW)", + "inherits": [ + "_base", + "_llvm_mingw_x64", + "_release" + ] + }, { "name": "mingw-x86-debug", "displayName": "x86 Debug (MinGW)", diff --git a/common_cmake b/common_cmake index 43d270c..c953298 160000 --- a/common_cmake +++ b/common_cmake @@ -1 +1 @@ -Subproject commit 43d270c81896de6674166fa839caadf2da2c468a +Subproject commit c95329887138e361a46b1129b640c77f00df7086 diff --git a/src/pch.h b/src/pch.h index 6459fc2..ab3a8a0 100644 --- a/src/pch.h +++ b/src/pch.h @@ -26,12 +26,12 @@ using std::uint8_t; #endif -#if defined(_MSC_VER) -#define DLL_EXPORT extern "C" __declspec(dllexport) -#elif defined(__clang__) +#if defined(__clang__) || defined(__MINGW32__) #define DLL_EXPORT extern "C" [[gnu::dllexport]] +#elif defined(_MSC_VER) +#define DLL_EXPORT extern "C" __declspec(dllexport) #else -#error Unknown DLL export attribute +#error Unknown dllexport attribute #endif #endif /* PCH_H */ diff --git a/src/proxy/d3d11.cpp b/src/proxy/d3d11.cpp index 4494de6..7689911 100644 --- a/src/proxy/d3d11.cpp +++ b/src/proxy/d3d11.cpp @@ -14,8 +14,15 @@ FARPROC d3d11_core_create_device_ptr = nullptr; FARPROC d3d11_create_device_ptr = nullptr; FARPROC d3d11_create_device_and_swap_chain_ptr = nullptr; +} // namespace + // NOLINTBEGIN(readability-identifier-naming, readability-identifier-length) +#if defined(__MINGW32__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-function-type" +#endif + DLL_EXPORT HRESULT D3D11CoreCreateDevice(void* fact, void* adapt, unsigned int flag, @@ -56,9 +63,12 @@ DLL_EXPORT HRESULT D3D11CreateDeviceAndSwapChain(void* adapt, d3d11_create_device_and_swap_chain_ptr)(adapt, dt, soft, flags, ft, fl, ver, swapChainDesc, swapChain, ppDevice, featureLevel, context); } -// NOLINTEND(readability-identifier-naming, readability-identifier-length) -} // namespace +#if defined(__MINGW32__) +#pragma GCC diagnostic pop +#endif + +// NOLINTEND(readability-identifier-naming, readability-identifier-length) void init(HMODULE /*this_dll*/) { // Suspend all other threads to prevent a giant race condition diff --git a/src/proxy/xinput1_3.cpp b/src/proxy/xinput1_3.cpp index ba6c99d..de2a65d 100644 --- a/src/proxy/xinput1_3.cpp +++ b/src/proxy/xinput1_3.cpp @@ -20,7 +20,14 @@ FARPROC xinput_set_state_ptr = nullptr; const constexpr auto XINPUT_GET_STATE_EX_ORDINAL = 100; FARPROC xinput_get_state_ex_ptr = nullptr; -// NOLINTBEGIN(readability-identifier-naming, readability-identifier-length) +} // namespace + +// NOLINTBEGIN(readability-identifier-naming) + +#if defined(__MINGW32__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-function-type" +#endif DLL_EXPORT void XInputEnable(BOOL enable) { return reinterpret_cast(xinput_enable_ptr)(enable); @@ -65,9 +72,11 @@ DLL_EXPORT DWORD XInputGetStateEx(DWORD dwUserIndex, void* pState) { pState); } -// NOLINTEND(readability-identifier-naming, readability-identifier-length) +#if defined(__MINGW32__) +#pragma GCC diagnostic pop +#endif -} // namespace +// NOLINTEND(readability-identifier-naming) void init(HMODULE /*this_dll*/) { // Suspend all other threads to prevent a giant race condition diff --git a/src/util.cpp b/src/util.cpp index b89219b..42551e2 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -51,9 +51,6 @@ void adjust_running_status(bool resume) { HANDLE thread = OpenThread(THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME, 0, te32.th32ThreadID); if (thread != nullptr) { - CONTEXT context; - context.ContextFlags = CONTEXT_DEBUG_REGISTERS; - if (resume) { ResumeThread(thread); } else { From 27d4696a423b516613dc733524586219a751a82e Mon Sep 17 00:00:00 2001 From: apple1417 Date: Fri, 5 Jan 2024 15:52:22 +1300 Subject: [PATCH 2/2] remove .modmap files from clang tidy compile commands --- .github/workflows/build.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dfa0ed8..5b44b72 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -230,6 +230,13 @@ jobs: working-directory: ${{ env.GITHUB_WORKSPACE }} run: cmake . --preset ${{ matrix.preset }} -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On + - name: Remove `.modmap`s from compile commands + run: | + (Get-Content "out\build\${{ matrix.preset }}\compile_commands.json") ` + -replace "@CMakeFiles.+?\.modmap", "" ` + | Set-Content ` + -Path "out\build\${{ matrix.preset }}\compile_commands.json" + - name: Run clang-tidy working-directory: ${{ env.GITHUB_WORKSPACE }} run: |