Skip to content

Commit 6370285

Browse files
authored
Merge pull request #2 from bl-sdk/mingw-support
pull in toolchain updates, support native mingw
2 parents a6a9933 + 27d4696 commit 6370285

File tree

10 files changed

+120
-28
lines changed

10 files changed

+120
-28
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Checks: >
3636
-cppcoreguidelines-non-private-member-variables-in-classes,
3737
CheckOptions:
3838
cppcoreguidelines-special-member-functions.AllowSoleDefaultDtor: true
39+
cppcoreguidelines-rvalue-reference-param-not-moved.IgnoreUnnamedParams: true
3940
misc-non-private-member-variables-in-classes.IgnoreClassesWithAllMemberVariablesBeingPublic: true
4041

4142
readability-identifier-naming.GlobalConstantCase: UPPER_CASE

.cruft.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"template": "[email protected]:bl-sdk/common_dotfiles.git",
3-
"commit": "a66f9767ed477bfa89d6ca505392d226ebdd4275",
3+
"commit": "fb06ff8c773806b3f8cc69dbda60c0a7b481c6de",
44
"checkout": null,
55
"context": {
66
"cookiecutter": {

.github/workflows/build.yml

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ env:
1010
# Important to pin the clang version, cause we also use it for linting
1111
CLANG_VERSION: 17
1212
CLANG_TIDY_JOBS: 4
13-
# Since we use rather new c++ features, we need a rather new version of MinGW
14-
# LLVM MinGW seems to be the newest prebuilt binaries around
15-
LLVM_MINGW_VERSION: llvm-mingw-20230919-msvcrt-ubuntu-20.04-x86_64
16-
LLVM_MINGW_DOWNLOAD: https://github.com/mstorsjo/llvm-mingw/releases/download/20230919/llvm-mingw-20230919-msvcrt-ubuntu-20.04-x86_64.tar.xz
13+
# LLVM MinGW download
14+
LLVM_MINGW_VERSION: llvm-mingw-20231128-msvcrt-ubuntu-20.04-x86_64
15+
LLVM_MINGW_DOWNLOAD: https://github.com/mstorsjo/llvm-mingw/releases/download/20231128/llvm-mingw-20231128-msvcrt-ubuntu-20.04-x86_64.tar.xz
1716
# xwin settings
18-
XWIN_VERSION: xwin-0.3.1-x86_64-unknown-linux-musl
19-
XWIN_DOWNLOAD: https://github.com/Jake-Shadle/xwin/releases/download/0.3.1/xwin-0.3.1-x86_64-unknown-linux-musl.tar.gz
17+
XWIN_VERSION: xwin-0.5.0-x86_64-unknown-linux-musl
18+
XWIN_DOWNLOAD: https://github.com/Jake-Shadle/xwin/releases/download/0.5.0/xwin-0.5.0-x86_64-unknown-linux-musl.tar.gz
2019

2120
jobs:
2221
cache-clang:
@@ -55,15 +54,15 @@ jobs:
5554

5655
steps:
5756
- name: Restore Clang Cache
58-
if: contains(matrix.preset, 'clang')
57+
if: startswith(matrix.preset, 'clang')
5958
uses: actions/cache/restore@v3
6059
with:
6160
path: C:\Program Files\LLVM
6261
key: ${{ runner.os }}-clang-${{ env.CLANG_VERSION }}
6362
fail-on-cache-miss: true
6463

6564
- name: Add MSVC to PATH
66-
if: contains(matrix.preset, 'msvc')
65+
if: startswith(matrix.preset, 'msvc')
6766
uses: TheMrMilchmann/setup-msvc-dev@v2
6867
with:
6968
arch: ${{ fromJSON('["x86", "x64"]')[contains(matrix.preset, 'x64')] }}
@@ -97,10 +96,12 @@ jobs:
9796
fail-fast: false
9897
matrix:
9998
preset: [
100-
"mingw-x86-release",
101-
"mingw-x64-release",
10299
"clang-cross-x86-release",
103100
"clang-cross-x64-release",
101+
"llvm-mingw-x86-release",
102+
"llvm-mingw-x64-release",
103+
"mingw-x86-release",
104+
"mingw-x64-release",
104105
]
105106

106107
steps:
@@ -111,7 +112,7 @@ jobs:
111112
# Caching would also lose the +x - so we'd have to tar before caching/untar after, making it
112113
# even slower
113114
- name: Setup Clang
114-
if: contains(matrix.preset, 'clang')
115+
if: startswith(matrix.preset, 'clang')
115116
run: |
116117
wget https://apt.llvm.org/llvm.sh
117118
chmod +x llvm.sh
@@ -133,13 +134,19 @@ jobs:
133134
/usr/bin/llvm-rc-${{ env.CLANG_VERSION }} \
134135
200
135136
136-
- name: Setup MinGW
137-
if: contains(matrix.preset, 'mingw')
137+
- name: Setup LLVM MinGW
138+
if: startswith(matrix.preset, 'llvm-mingw')
138139
run: |
139140
wget -nv ${{ env.LLVM_MINGW_DOWNLOAD }}
140141
tar -xf ${{ env.LLVM_MINGW_VERSION }}.tar.xz -C ~/
141142
echo $(readlink -f ~/${{ env.LLVM_MINGW_VERSION }}/bin) >> $GITHUB_PATH
142143
144+
- name: Set up MinGW
145+
if: startswith(matrix.preset, 'mingw')
146+
uses: egor-tensin/setup-mingw@v2
147+
with:
148+
platform: ${{ fromJSON('["x86", "x64"]')[contains(matrix.preset, 'x64')] }}
149+
143150
# xwin does take long enough that caching's worth it
144151
- name: Restore xwin cache
145152
if: contains(matrix.preset, 'cross')
@@ -223,6 +230,13 @@ jobs:
223230
working-directory: ${{ env.GITHUB_WORKSPACE }}
224231
run: cmake . --preset ${{ matrix.preset }} -DCMAKE_DISABLE_PRECOMPILE_HEADERS=On
225232

233+
- name: Remove `.modmap`s from compile commands
234+
run: |
235+
(Get-Content "out\build\${{ matrix.preset }}\compile_commands.json") `
236+
-replace "@CMakeFiles.+?\.modmap", "" `
237+
| Set-Content `
238+
-Path "out\build\${{ matrix.preset }}\compile_commands.json"
239+
226240
- name: Run clang-tidy
227241
working-directory: ${{ env.GITHUB_WORKSPACE }}
228242
run: |

CMakeLists.txt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.24)
22

3-
project(pluginloader VERSION 1.0.1)
3+
project(pluginloader VERSION 1.0.2)
44

55
add_library(_pluginloader_base INTERFACE)
66
set(CMAKE_EXPORT_COMPILE_COMMANDS True)
@@ -10,11 +10,16 @@ set_target_properties(_pluginloader_base PROPERTIES
1010
COMPILE_WARNING_AS_ERROR True
1111
INTERPROCEDURAL_OPTIMIZATION True
1212
)
13+
1314
if(MSVC)
1415
target_compile_options(_pluginloader_base INTERFACE /W4)
1516
else()
1617
target_compile_options(_pluginloader_base INTERFACE -Wall -Wextra -Wpedantic)
1718
endif()
19+
# CMake doesn't understand warnings as errors for MinGW yet
20+
if(MINGW)
21+
target_compile_options(_pluginloader_base INTERFACE -Werror)
22+
endif()
1823

1924
set(CONFIGURE_FILES_DIR "${CMAKE_CURRENT_BINARY_DIR}/configure")
2025

CMakePresets.json

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,26 @@
4949
},
5050
"toolchainFile": "common_cmake/clang-cross-x64.cmake"
5151
},
52+
{
53+
"name": "_llvm_mingw_x86",
54+
"hidden": true,
55+
"condition": {
56+
"type": "notEquals",
57+
"lhs": "${hostSystemName}",
58+
"rhs": "Windows"
59+
},
60+
"toolchainFile": "common_cmake/llvm-i686-w64-mingw32.cmake"
61+
},
62+
{
63+
"name": "_llvm_mingw_x64",
64+
"hidden": true,
65+
"condition": {
66+
"type": "notEquals",
67+
"lhs": "${hostSystemName}",
68+
"rhs": "Windows"
69+
},
70+
"toolchainFile": "common_cmake/llvm-x86_64-w64-mingw32.cmake"
71+
},
5272
{
5373
"name": "_mingw_x86",
5474
"hidden": true,
@@ -193,6 +213,42 @@
193213
"_release"
194214
]
195215
},
216+
{
217+
"name": "llvm-mingw-x86-debug",
218+
"displayName": "x86 Debug (LLVM MinGW)",
219+
"inherits": [
220+
"_base",
221+
"_llvm_mingw_x86",
222+
"_debug"
223+
]
224+
},
225+
{
226+
"name": "llvm-mingw-x86-release",
227+
"displayName": "x86 Release (LLVM MinGW)",
228+
"inherits": [
229+
"_base",
230+
"_llvm_mingw_x86",
231+
"_release"
232+
]
233+
},
234+
{
235+
"name": "llvm-mingw-x64-debug",
236+
"displayName": "x64 Debug (LLVM MinGW)",
237+
"inherits": [
238+
"_base",
239+
"_llvm_mingw_x64",
240+
"_debug"
241+
]
242+
},
243+
{
244+
"name": "llvm-mingw-x64-release",
245+
"displayName": "x64 Release (LLVM MinGW)",
246+
"inherits": [
247+
"_base",
248+
"_llvm_mingw_x64",
249+
"_release"
250+
]
251+
},
196252
{
197253
"name": "mingw-x86-debug",
198254
"displayName": "x86 Debug (MinGW)",

src/pch.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ using std::uint8_t;
2626

2727
#endif
2828

29-
#if defined(_MSC_VER)
30-
#define DLL_EXPORT extern "C" __declspec(dllexport)
31-
#elif defined(__clang__)
29+
#if defined(__clang__) || defined(__MINGW32__)
3230
#define DLL_EXPORT extern "C" [[gnu::dllexport]]
31+
#elif defined(_MSC_VER)
32+
#define DLL_EXPORT extern "C" __declspec(dllexport)
3333
#else
34-
#error Unknown DLL export attribute
34+
#error Unknown dllexport attribute
3535
#endif
3636

3737
#endif /* PCH_H */

src/proxy/d3d11.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,15 @@ FARPROC d3d11_core_create_device_ptr = nullptr;
1414
FARPROC d3d11_create_device_ptr = nullptr;
1515
FARPROC d3d11_create_device_and_swap_chain_ptr = nullptr;
1616

17+
} // namespace
18+
1719
// NOLINTBEGIN(readability-identifier-naming, readability-identifier-length)
1820

21+
#if defined(__MINGW32__)
22+
#pragma GCC diagnostic push
23+
#pragma GCC diagnostic ignored "-Wcast-function-type"
24+
#endif
25+
1926
DLL_EXPORT HRESULT D3D11CoreCreateDevice(void* fact,
2027
void* adapt,
2128
unsigned int flag,
@@ -56,9 +63,12 @@ DLL_EXPORT HRESULT D3D11CreateDeviceAndSwapChain(void* adapt,
5663
d3d11_create_device_and_swap_chain_ptr)(adapt, dt, soft, flags, ft, fl, ver, swapChainDesc,
5764
swapChain, ppDevice, featureLevel, context);
5865
}
59-
// NOLINTEND(readability-identifier-naming, readability-identifier-length)
6066

61-
} // namespace
67+
#if defined(__MINGW32__)
68+
#pragma GCC diagnostic pop
69+
#endif
70+
71+
// NOLINTEND(readability-identifier-naming, readability-identifier-length)
6272

6373
void init(HMODULE /*this_dll*/) {
6474
// Suspend all other threads to prevent a giant race condition

src/proxy/xinput1_3.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ FARPROC xinput_set_state_ptr = nullptr;
2020
const constexpr auto XINPUT_GET_STATE_EX_ORDINAL = 100;
2121
FARPROC xinput_get_state_ex_ptr = nullptr;
2222

23-
// NOLINTBEGIN(readability-identifier-naming, readability-identifier-length)
23+
} // namespace
24+
25+
// NOLINTBEGIN(readability-identifier-naming)
26+
27+
#if defined(__MINGW32__)
28+
#pragma GCC diagnostic push
29+
#pragma GCC diagnostic ignored "-Wcast-function-type"
30+
#endif
2431

2532
DLL_EXPORT void XInputEnable(BOOL enable) {
2633
return reinterpret_cast<decltype(&XInputEnable)>(xinput_enable_ptr)(enable);
@@ -65,9 +72,11 @@ DLL_EXPORT DWORD XInputGetStateEx(DWORD dwUserIndex, void* pState) {
6572
pState);
6673
}
6774

68-
// NOLINTEND(readability-identifier-naming, readability-identifier-length)
75+
#if defined(__MINGW32__)
76+
#pragma GCC diagnostic pop
77+
#endif
6978

70-
} // namespace
79+
// NOLINTEND(readability-identifier-naming)
7180

7281
void init(HMODULE /*this_dll*/) {
7382
// Suspend all other threads to prevent a giant race condition

src/util.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,6 @@ void adjust_running_status(bool resume) {
5151
HANDLE thread = OpenThread(THREAD_GET_CONTEXT | THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME,
5252
0, te32.th32ThreadID);
5353
if (thread != nullptr) {
54-
CONTEXT context;
55-
context.ContextFlags = CONTEXT_DEBUG_REGISTERS;
56-
5754
if (resume) {
5855
ResumeThread(thread);
5956
} else {

0 commit comments

Comments
 (0)