Skip to content

Commit 10cfb94

Browse files
firewaveglankk
andauthored
added MinGW workflow (#475)
Co-authored-by: glankk <glankk@users.noreply.github.com>
1 parent 9eea499 commit 10cfb94

File tree

4 files changed

+163
-4
lines changed

4 files changed

+163
-4
lines changed

.github/workflows/CI-mingw.yml

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
name: CI-mingw
2+
3+
on: [push, pull_request]
4+
5+
permissions:
6+
contents: read
7+
8+
defaults:
9+
run:
10+
shell: msys2 {0}
11+
12+
jobs:
13+
build:
14+
15+
strategy:
16+
matrix:
17+
compiler: [g++, clang++]
18+
# TODO: add MSYS after #556 is fixed
19+
msystem: [MINGW32, MINGW64, CLANG64]
20+
include:
21+
#- msystem: MSYS
22+
# pkg-prefix: ''
23+
- msystem: MINGW32
24+
pkg-prefix: 'mingw-w64-i686-'
25+
- msystem: MINGW64
26+
pkg-prefix: 'mingw-w64-x86_64-'
27+
- msystem: CLANG64
28+
pkg-prefix: 'mingw-w64-clang-x86_64-'
29+
- compiler: g++
30+
compiler-pkg: gcc
31+
- compiler: clang++
32+
compiler-pkg: clang
33+
exclude:
34+
- msystem: CLANG64
35+
compiler: g++
36+
fail-fast: false
37+
38+
runs-on: windows-2025
39+
40+
env:
41+
CXX: ${{ matrix.compiler }}
42+
43+
steps:
44+
- uses: actions/checkout@v4
45+
with:
46+
persist-credentials: false
47+
48+
- name: Set up MSYS2
49+
uses: msys2/setup-msys2@v2
50+
with:
51+
release: false # use pre-installed
52+
msystem: ${{ matrix.msystem }}
53+
# TODO: install mingw-w64-x86_64-make and use mingw32.make instead - currently fails with "Windows Subsystem for Linux has no installed distributions."
54+
# TODO: also run tests with non-prefixed Python?
55+
install: >-
56+
make
57+
${{ matrix.pkg-prefix }}cmake
58+
${{ matrix.pkg-prefix }}python
59+
${{ matrix.pkg-prefix }}python-pytest
60+
61+
- name: install compiler
62+
run: |
63+
pacman -S --noconfirm ${{ matrix.pkg-prefix }}${{ matrix.compiler-pkg }}
64+
${CXX} -v
65+
66+
- name: make simplecpp
67+
run: |
68+
make -j$(nproc) CXXOPTS="-Werror"
69+
70+
# gcc *and* clang are required to run-tests.py
71+
# install it at this point since it has gcc as dependency which might interfere with the build
72+
- name: install compiler (clang)
73+
if: matrix.compiler == 'g++'
74+
run: |
75+
pacman -S --noconfirm clang
76+
77+
- name: install compiler (gcc)
78+
if: matrix.compiler == 'clang++'
79+
run: |
80+
pacman -S --noconfirm gcc
81+
82+
- name: make test
83+
run: |
84+
# TODO: run tests with Windows paths
85+
make -j$(nproc) test
86+
87+
- name: selfcheck
88+
run: |
89+
# TODO: run tests with Windows paths
90+
make -j$(nproc) selfcheck
91+
92+
- name: make (c++14)
93+
run: |
94+
make clean
95+
make -j$(nproc) CXXOPTS="-Werror -std=c++14"
96+
97+
- name: make (c++17)
98+
run: |
99+
make clean
100+
make -j$(nproc) CXXOPTS="-Werror -std=c++17"
101+
102+
- name: make (c++20)
103+
run: |
104+
make clean
105+
make -j$(nproc) CXXOPTS="-Werror -std=c++20"
106+
107+
- name: make (c++23)
108+
run: |
109+
make clean
110+
make -j$(nproc) CXXOPTS="-Werror -std=c++23"
111+
112+
- name: Run CMake
113+
run: |
114+
cmake -S . -B cmake.output -DCMAKE_COMPILE_WARNING_AS_ERROR=On
115+
116+
- name: CMake simplecpp
117+
run: |
118+
cmake --build cmake.output --target simplecpp -- -j $(nproc)
119+
120+
- name: CMake testrunner
121+
run: |
122+
cmake --build cmake.output --target testrunner -- -j $(nproc)
123+
124+
- name: Run testrunner
125+
run: |
126+
./cmake.output/testrunner
127+
128+
- name: Run with libstdc++ debug mode
129+
if: matrix.compiler == 'g++'
130+
run: |
131+
make clean
132+
make -j$(nproc) test selfcheck CXXOPTS="-Werror -g3 -D_GLIBCXX_DEBUG"
133+
134+
- name: Run with libc++ hardening mode
135+
if: matrix.compiler == 'clang++' && matrix.msystem == 'CLANG64'
136+
run: |
137+
make clean
138+
make -j$(nproc) test selfcheck CXXOPTS="-Werror -stdlib=libc++ -g3 -D_LIBCPP_HARDENING_MODE=_LIBCPP_HARDENING_MODE_DEBUG" LDOPTS="-lc++"

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
3434
add_compile_options(-Woverloaded-virtual) # when a function declaration hides virtual functions from a base class
3535

3636
add_compile_options(-Wsuggest-attribute=noreturn)
37-
add_compile_options_safe(-Wuseless-cast)
37+
if (NOT MINGW)
38+
add_compile_options_safe(-Wuseless-cast)
39+
endif()
3840

3941
# we are not interested in these
4042
set_source_files_properties(test.cpp PROPERTIES COMPILE_FLAGS -Wno-multichar)
@@ -62,6 +64,14 @@ elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
6264

6365
# contradicts -Wcovered-switch-default
6466
add_compile_options(-Wno-switch-default)
67+
if (MINGW)
68+
add_compile_options(-Wno-reserved-macro-identifier)
69+
add_compile_options(-Wno-unused-macros)
70+
endif()
71+
72+
# these are experimental warnings which might produce false positives
73+
add_compile_options_safe(-Wno-thread-safety-negative)
74+
add_compile_options_safe(-Wno-thread-safety-beta)
6575

6676
# TODO: fix these?
6777
add_compile_options(-Wno-padded)

selfcheck.sh

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,20 @@ if [ "$cxx_type" = "Ubuntu" ] || [ "$cxx_type" = "Debian" ]; then
4141
fi
4242

4343
# TODO: generate defines from compiler
44-
if [ "$cxx_type" = "g++" ]; then
44+
if [ "$cxx_type" = "g++" ] || [ "$cxx_type" = "g++.exe" ]; then
4545
defs=
4646
defs="$defs -D__GNUC__"
4747
defs="$defs -D__STDC__"
4848
defs="$defs -D__x86_64__"
4949
defs="$defs -D__STDC_HOSTED__"
5050
defs="$defs -D__CHAR_BIT__=8"
51+
if [ "${MSYSTEM}" = "MINGW32" ] || [ "${MSYSTEM}" = "MINGW64" ]; then
52+
defs="$defs -D_WIN32"
53+
fi
5154
defs="$defs -D__has_builtin(x)=(1)"
5255
defs="$defs -D__has_cpp_attribute(x)=(1)"
5356
defs="$defs -D__has_attribute(x)=(1)"
57+
defs="$defs -Ddefined(x)=(0)"
5458

5559
inc=
5660
while read line
@@ -63,12 +67,19 @@ elif [ "$cxx_type" = "clang" ]; then
6367
defs="$defs -D__x86_64__"
6468
defs="$defs -D__STDC_HOSTED__"
6569
defs="$defs -D__CHAR_BIT__=8"
70+
defs="$defs -D__BYTE_ORDER__=1234"
71+
defs="$defs -D__SIZEOF_SIZE_T__=8"
72+
if [ "${MSYSTEM}" = "MINGW32" ] || [ "${MSYSTEM}" = "MINGW64" ] || [ "${MSYSTEM}" = "CLANG64" ]; then
73+
defs="$defs -D_WIN32"
74+
fi
6675
defs="$defs -D__has_builtin(x)=(1)"
6776
defs="$defs -D__has_cpp_attribute(x)=(1)"
6877
defs="$defs -D__has_feature(x)=(1)"
69-
defs="$defs -D__has_include_next(x)=(0)"
78+
defs="$defs -D__has_include_next(x)=(1)"
7079
defs="$defs -D__has_attribute(x)=(0)"
7180
defs="$defs -D__building_module(x)=(0)"
81+
defs="$defs -D__has_extension(x)=(1)"
82+
defs="$defs -Ddefined(x)=(0)"
7283

7384
inc=
7485
while read line

simplecpp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3120,7 +3120,7 @@ std::pair<simplecpp::FileData *, bool> simplecpp::FileDataCache::get(const std::
31203120
bool simplecpp::FileDataCache::getFileId(const std::string &path, FileID &id)
31213121
{
31223122
#ifdef _WIN32
3123-
HANDLE hFile = CreateFileA(path.c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
3123+
HANDLE hFile = CreateFileA(path.c_str(), 0, FILE_SHARE_READ | FILE_SHARE_WRITE, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
31243124

31253125
if (hFile == INVALID_HANDLE_VALUE)
31263126
return false;

0 commit comments

Comments
 (0)