Skip to content

Commit 17e1d5c

Browse files
committed
ci: Use MinGW toolchain with Win32 threads.
It seems impossible to statically link libwinpthread DLL on release builds at least with CMake. Fixes #82
1 parent 9ff11fd commit 17e1d5c

File tree

8 files changed

+36
-20
lines changed

8 files changed

+36
-20
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
uses: actions/cache@v3
1919
with:
2020
path: downloads/*.7z
21-
key: ${{ runner.os }}-${{ matrix.target }}-mingw-12.2.0-dbghelp-10.0.18362.1
21+
key: ${{ runner.os }}-${{ matrix.target }}-mingw-12.2.0-win32-dbghelp-10.0.18362.1
2222
- run: Get-Host | Select-Object Version
2323
- run: python -m pip install gcovr codecov
2424
- name: Build

BUILD.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
Required:
77

8-
* [MinGW](https://github.com/brechtsanders/winlibs_mingw/releases) toolchain
8+
* [MinGW](https://github.com/niXman/mingw-builds-binaries) toolchain
9+
10+
* _win32_ threads (as opposed to _posix_ threads) is recommended to avoid dependency on `libwinpthread-1.dll`
911

1012
* [CMake](http://www.cmake.org/)
1113

CMakeLists.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set (CPACK_PACKAGE_VERSION_PATCH "8")
1313

1414

1515
option (ENABLE_COVERAGE "Enable code coverage." OFF)
16+
option (POSIX_THREADS "Allow posix threads." OFF)
1617

1718

1819
##############################################################################
@@ -65,6 +66,24 @@ add_compiler_flags (-fno-strict-aliasing)
6566

6667
include (StaticCRT)
6768

69+
# Avoid Posix threads. Posix threads is required for support of certain C++11
70+
# multi-threading features, but it introduces a new DLL dependency and we don't
71+
# use those features.
72+
execute_process (
73+
COMMAND "${CMAKE_COMMAND}" -E echo "#include <thread>\n#ifdef _GLIBCXX_HAS_GTHREADS\n#error _GLIBCXX_HAS_GTHREADS\n#endif"
74+
COMMAND "${CMAKE_CXX_COMPILER}" -x c++ -E -
75+
RESULT_VARIABLE STATUS_CXX11_THREADS
76+
OUTPUT_QUIET
77+
ERROR_QUIET
78+
)
79+
if (NOT STATUS_CXX11_THREADS EQUAL 0)
80+
if (POSIX_THREADS)
81+
message (WARNING "Win32 threads recommended.")
82+
else ()
83+
message (SEND_ERROR "Win32 threads required.")
84+
endif ()
85+
endif ()
86+
6887
# Enable stack protection
6988
# XXX: Broken on https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86832
7089
if (CMAKE_CXX_COMPILER_VERSION VERSION_LESS "8.0" OR

ci/build.ps1

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ function Exec {
1818
}
1919
}
2020

21-
$MINGW_64_URL = 'https://github.com/brechtsanders/winlibs_mingw/releases/download/12.2.0-14.0.6-10.0.0-msvcrt-r2/winlibs-x86_64-posix-seh-gcc-12.2.0-llvm-14.0.6-mingw-w64msvcrt-10.0.0-r2.7z'
22-
$MINGW_32_URL = 'https://github.com/brechtsanders/winlibs_mingw/releases/download/12.2.0-14.0.6-10.0.0-msvcrt-r2/winlibs-i686-posix-dwarf-gcc-12.2.0-llvm-14.0.6-mingw-w64msvcrt-10.0.0-r2.7z'
23-
$MINGW_64_SUM = 'c0dd9f2113a151dd2fe3dce8ceb30df90120fab4537349d7c0ee22e9ff4fe3bc'
24-
$MINGW_32_SUM = '80ab3fb4b65870509f968e07e44f90d216eaf130fe9eb320b7a98285a84a0d2e'
21+
$MINGW_64_URL = 'https://github.com/niXman/mingw-builds-binaries/releases/download/12.2.0-rt_v10-rev2/x86_64-12.2.0-release-win32-seh-msvcrt-rt_v10-rev2.7z'
22+
$MINGW_32_URL = 'https://github.com/niXman/mingw-builds-binaries/releases/download/12.2.0-rt_v10-rev2/i686-12.2.0-release-win32-dwarf-msvcrt-rt_v10-rev2.7z'
23+
$MINGW_64_SUM = 'dbe4de36401906f296c2752afd512891a227a787f3b9cf10115b409feaef39aa'
24+
$MINGW_32_SUM = 'd76daf7a176f6e65ff75adc26efbadba89787bb14265696b94dce302cf1f8115'
2525

2626
$DBGHELP_64_URL = 'https://gist.githubusercontent.com/jrfonseca/55a9a0e0e228ad841032df1624da5e27/raw/8b5f0a1578be701128f09f886f9636389ae60268/dbghelp-win64.7z'
2727
$DBGHELP_32_URL = 'https://gist.githubusercontent.com/jrfonseca/55a9a0e0e228ad841032df1624da5e27/raw/8b5f0a1578be701128f09f886f9636389ae60268/dbghelp-win32.7z'
@@ -131,9 +131,6 @@ Exec { cmake --build $buildDir --use-stderr --target test }
131131
# MinGW GCC
132132
Exec { cmake "-S" tests\apps "-B" "$buildRoot\apps\$target" -G $generator "-DCMAKE_BUILD_TYPE=Debug" }
133133
Exec { cmake --build "$buildRoot\apps\$target" }
134-
# MinGW Clang
135-
Exec { cmake "-S" tests\apps "-B" "$buildRoot\apps\$target-clang" -G $generator "-DCMAKE_BUILD_TYPE=Debug" "-DCMAKE_C_COMPILER=clang" "-DCMAKE_CXX_COMPILER=clang++" "-DCMAKE_C_FLAGS_DEBUG=-g" "-DCMAKE_CXX_FLAGS_DEBUG=-g" }
136-
Exec { cmake --build "$buildRoot\apps\$target-clang" }
137134
# MSVC 32-bits
138135
Exec { cmake "-S" tests\apps "-B" "$buildRoot\apps\msvc32" -G "Visual Studio 17 2022" -A Win32 }
139136
Exec { cmake --build "$buildRoot\apps\msvc32" --config Debug "--" /verbosity:minimal /maxcpucount }
@@ -142,9 +139,9 @@ if ($target -eq "mingw64") {
142139
Exec { cmake -Stests\apps "-B$buildRoot\apps\msvc64" -G "Visual Studio 17 2022" -A x64 }
143140
Exec { cmake --build "$buildRoot\apps\msvc64" --config Debug "--" /verbosity:minimal /maxcpucount }
144141

145-
Exec { python ci\spawndesk.py python tests\apps\test.py $buildDir\bin\catchsegv.exe "$buildRoot\apps\$target" "$buildRoot\apps\$target-clang" "$buildRoot\apps\msvc32\Debug" "$buildRoot\apps\msvc64\Debug" }
142+
Exec { python ci\spawndesk.py python tests\apps\test.py $buildDir\bin\catchsegv.exe "$buildRoot\apps\$target" "$buildRoot\apps\msvc32\Debug" "$buildRoot\apps\msvc64\Debug" }
146143
} else {
147-
Exec { python ci\spawndesk.py python tests\apps\test.py $buildDir\bin\catchsegv.exe "$buildRoot\apps\$target" "$buildRoot\apps\$target-clang" "$buildRoot\apps\msvc32\Debug" }
144+
Exec { python ci\spawndesk.py python tests\apps\test.py $buildDir\bin\catchsegv.exe "$buildRoot\apps\$target" "$buildRoot\apps\msvc32\Debug" }
148145
}
149146

150147
#

ci/build.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ test ! -d /usr/lib/ccache || export PATH="/usr/lib/ccache:$PATH"
2222

2323
WINE=${WINE:-$(which wine)}
2424

25-
x86_64-w64-mingw32-g++-posix --version
26-
i686-w64-mingw32-g++-posix --version
25+
x86_64-w64-mingw32-g++-win32 --version
26+
i686-w64-mingw32-g++-win32 --version
2727
ninja --version
2828
cmake --version
2929
python3 --version

ci/toolchain/i686-w64-mingw32-gcc.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set (CMAKE_SYSTEM_NAME Windows)
22
set (CMAKE_SYSTEM_PROCESSOR X86)
3-
set (CMAKE_C_COMPILER i686-w64-mingw32-gcc-posix)
4-
set (CMAKE_CXX_COMPILER i686-w64-mingw32-g++-posix)
3+
set (CMAKE_C_COMPILER i686-w64-mingw32-gcc-win32)
4+
set (CMAKE_CXX_COMPILER i686-w64-mingw32-g++-win32)
55
set (CMAKE_RC_COMPILER i686-w64-mingw32-windres)
66
set (CMAKE_FIND_ROOT_PATH /usr/i686-w64-mingw32)
77
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

ci/toolchain/x86_64-w64-mingw32-gcc.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set (CMAKE_SYSTEM_NAME Windows)
22
set (CMAKE_SYSTEM_PROCESSOR AMD64)
3-
set (CMAKE_C_COMPILER x86_64-w64-mingw32-gcc-posix)
4-
set (CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++-posix)
3+
set (CMAKE_C_COMPILER x86_64-w64-mingw32-gcc-win32)
4+
set (CMAKE_CXX_COMPILER x86_64-w64-mingw32-g++-win32)
55
set (CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
66
set (CMAKE_FIND_ROOT_PATH /usr/x86_64-w64-mingw32)
77
set (CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)

cmake/StaticCRT.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,9 @@ if (MINGW)
2727
ERROR_QUIET
2828
)
2929
if (NOT STATUS_CXX11_THREADS EQUAL 0)
30-
message (STATUS "MinGW with POSIX threads detected.")
3130
# https://stackoverflow.com/a/28001271
31+
# XXX Unfortunately this doesn't work for Release builds, https://github.com/jrfonseca/drmingw/issues/82
3232
set (CMAKE_CXX_STANDARD_LIBRARIES "-Wl,-Bstatic -lstdc++ -lpthread -Wl,-Bdynamic ${CMAKE_CXX_STANDARD_LIBRARIES}")
33-
else ()
34-
message (STATUS "MinGW with Win32 threads detected.")
3533
endif ()
3634
endif ()
3735
endif ()

0 commit comments

Comments
 (0)