-
Notifications
You must be signed in to change notification settings - Fork 0
222 lines (203 loc) · 8.45 KB
/
runnable_cxx.yml
File metadata and controls
222 lines (203 loc) · 8.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
# Github action to test for C++ interoperability
#
# Most tests in the test-suite run on the CI when it comes to cross-platform testing.
# However, the dlang auto-tester uses somewhat old host C/C++ compiler.
# This is good for testing compatibility with e.g. LTS distributions,
# but becomes problematic when we want to test more cutting-edge features,
# such as newer C++ standards (C++17, C++20, etc...).
#
# This is the reason why we have this action: we have full control over the toolchain,
# and it is cross platform. The supported platforms are whatever Github Actions support,
# which is usually whatever the vendor (Canonical, Apple, Microsoft) supports.
#
# Notes:
# - When debugging/troubleshooting, make sure to check the printed compiler versions.
# - Try to use the native Github action syntax (${{ expression }}) when possible,
# as they are substituted with their value in the logs, unlike env variable.
# For example use `${{ github.workspace }}` over `${GITHUB_WORKSPACE}`
#
# TODO:
# - Test clang on Windows? (note: probably not all tests respect a CC/CXX env variable on Windows)
name: C++ interop tests
# Only triggers on pushes to master & stable, as well as PR to master and stable
# Sometimes reverts appear in the upstream repository (e.g. when the revert button
# is clicked by a contributor with commit access), this should be tested as PR).
#
# Also note that Github actions does not retrigger on target branch changes,
# hence the check on push.
on:
pull_request:
branches:
- master
- stable
push:
branches:
- master
- stable
# Use this branch name in your fork to test changes
- github-actions
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
main:
name: Run
if: github.repository == 'dlang/dmd'
strategy:
# Since those tests takes very little time, don't use `fail-fast`.
# If runtime expand, we might want to comment this out,
# as most failing PRs do so because they don't compile / something is broken,
# very few PRs actually benefit from this.
fail-fast: false
matrix:
include:
# Linux, clang:
# NOTE: cannot test MODEL=32 with clang on Linux, due to a single failure as of April 2025:
# runnable_cxx/cppa.d:261: cppa.check13956: Assertion `arg6 == 6' failed.
- { os: ubuntu-24.04, compiler: clang-18, model: 64 }
- { os: ubuntu-22.04, compiler: clang-15, model: 64 }
- { os: ubuntu-24.04, compiler: clang-14, model: 64 }
- { os: ubuntu-22.04, compiler: clang-11, model: 64 }
# Linux, g++:
- { os: ubuntu-24.04, compiler: g++-13, model: 64 }
- { os: ubuntu-24.04, compiler: g++-13, model: 32 }
- { os: ubuntu-22.04, compiler: g++-12, model: 64 }
- { os: ubuntu-22.04, compiler: g++-12, model: 32 }
- { os: ubuntu-22.04, compiler: g++-9, model: 64 }
- { os: ubuntu-22.04, compiler: g++-9, model: 32 }
# macOS, Apple clang from Xcode:
# Disabled due to issues with x87: https://github.com/dlang/dmd/issues/21987
#- { os: macos-15, xcode: '16.4', model: 64 }
- { os: macos-14, xcode: '16.2', model: 64 }
# Windows, cl.exe from Visual Studio:
# NOTE: as of April 2025, image windows-2025 only has VS 2022, so no point in testing that image too
- { os: windows-2022, model: 64 }
- { os: windows-2022, model: 32 }
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash
steps:
- name: Set environment variable N (parallelism)
run: echo "N=$(${{ runner.os == 'macOS' && 'sysctl -n hw.logicalcpu' || 'nproc' }})" >> $GITHUB_ENV
- name: Set environment variable MODEL
run: echo "MODEL=${{ matrix.model }}" >> $GITHUB_ENV
- name: 'macOS: Upgrade GNU make'
if: runner.os == 'macOS'
run: |
set -eux
brew install make
sudo ln -s $(which gmake) /usr/local/bin/make
make --version
########################################
# Setting up the host D compiler #
########################################
- name: Install D host compiler
uses: dlang-community/setup-dlang@v2
- name: 'Posix: Clear LD_LIBRARY_PATH environment variable' # don't use host druntime/Phobos .so/.dylib etc.
if: runner.os != 'Windows'
run: echo "LD_LIBRARY_PATH=" >> $GITHUB_ENV
##############################################
# Find out which branch we need to check out #
##############################################
- name: Determine base branch
id: base_branch
run: |
# For pull requests, base_ref will not be empty
if [ ! -z ${{ github.base_ref }} ]; then
echo "branch=${{ github.base_ref }}" >> $GITHUB_OUTPUT
# Otherwise, use whatever ref we have:
# For branches this in the format 'refs/heads/<branch_name>',
# and for tags it is refs/tags/<tag_name>.
else
echo "branch=${{ github.ref }}" >> $GITHUB_OUTPUT
fi
#####################################
# Checking out DMD and Phobos #
#####################################
- name: Checkout DMD
uses: actions/checkout@v4
with:
path: dmd
persist-credentials: false
- name: Checkout Phobos
uses: actions/checkout@v4
with:
path: phobos
repository: dlang/phobos
ref: ${{ steps.base_branch.outputs.branch }}
persist-credentials: false
########################################
# Setting up the host C++ compiler #
########################################
- name: 'Linux: Install C++ compiler'
if: runner.os == 'Linux'
run: |
set -eux
sudo apt-get update
apt_packages='${{ matrix.compiler }}'
if [[ "$MODEL" == 32 ]]; then
if [[ '${{ matrix.compiler }}' =~ ^g\+\+ ]]; then
apt_packages+=" ${{ matrix.compiler }}-multilib"
else
apt_packages+=" g++-multilib"
fi
fi
sudo apt-get install -y $apt_packages
- name: 'Windows: Set up MSVC environment' # puts cl.exe in PATH etc.
if: runner.os == 'Windows'
uses: seanmiddleditch/gha-setup-vsdevenv@v4
with:
arch: ${{ matrix.model == '64' && 'x64' || 'x86' }}
- name: 'Posix: Set up CC and CXX environment variables'
if: runner.os != 'Windows'
run: |
set -eux
if [[ '${{ runner.os }}' == Linux ]]; then
compiler='${{ matrix.compiler }}'
echo "CC=${compiler/g++/gcc}" >> $GITHUB_ENV
echo "CXX=${compiler/clang/clang++}" >> $GITHUB_ENV
elif [[ '${{ runner.os }}' == macOS ]]; then
sudo xcode-select -switch /Applications/Xcode_${{ matrix.xcode }}.app
echo "CC=cc" >> $GITHUB_ENV
echo "CXX=c++" >> $GITHUB_ENV
fi
- name: Print used C/C++ compiler versions
run: |
set -eux
if [[ '${{ runner.os }}' == Windows ]]; then
which cl.exe
else
$CC --version
$CXX --version
fi
########################################
# Building DMD, druntime, Phobos #
########################################
- name: Build compiler & standard library
run: |
set -eux
extraFlags=()
if [[ '${{ matrix.os }}' == macos-14 ]]; then
# DMD doesn't work on arm64 yet. Make LDC host compiler cross-compile
# DMD to x86_64, and then use implicit Rosetta emulation.
extraFlags=(HOST_DFLAGS="-mtriple=x86_64-apple-macos14")
fi
make -C dmd -j$N "${extraFlags[@]}"
make -C phobos -j$N
########################################
# Running the test suite #
########################################
- name: Run compiler C++ test suite
run: ./dmd/compiler/test/run.d --environment runnable_cxx dshell/dll_cxx.d ${{ matrix.os == 'macos-14' && 'HOST_DMD="$PWD/dmd/generated/osx/release/64/dmd"' || '' }}
- name: Run druntime C++ tests
run: make -C dmd/druntime -j$N test/stdcpp/.run
- name: 'Posix: Run C++ frontend unittests'
if: runner.os != 'Windows' # not supported by build.d yet
run: |
set -eux
extraFlags=()
if [[ '${{ matrix.os }}' == macos-14 ]]; then
extraFlags=(HOST_DMD=ldmd2 DFLAGS="-mtriple=x86_64-apple-macos14" CXXFLAGS="-arch x86_64")
fi
./dmd/generated/build cxx-unittest "${extraFlags[@]}"