xref: /llvm-project/.github/workflows/libcxx-build-and-test.yaml (revision 7f845cba2ccc2ab637b8e40fbafb9f83a2d67c70)
1# This file defines pre-commit CI for libc++, libc++abi, and libunwind (on Github).
2#
3# We split the configurations in multiple stages with the intent of saving compute time
4# when a job fails early in the pipeline. This is why the jobs are marked as `continue-on-error: false`.
5# We try to run the CI configurations with the most signal in the first stage.
6#
7# Stages 1 & 2 are meant to be "smoke tests", and are meant to catch most build/test failures quickly and without using
8# too many resources.
9# Stage 3 is "everything else", and is meant to catch breakages on more niche or unique configurations.
10#
11# Therefore, we "fail-fast" for any failures during stages 1 & 2, meaning any job failing cancels all other running jobs,
12# under the assumption that if the "smoke tests" fail, then the other configurations will likely fail in the same way.
13# However, stage 3 does not fail fast, as it's more likely that any one job failing is a flake or a configuration-specific
14#
15name: Build and Test libc++
16on:
17  pull_request:
18    paths:
19      - 'libcxx/**'
20      - 'libcxxabi/**'
21      - 'libunwind/**'
22      - 'runtimes/**'
23      - 'cmake/**'
24      - '.github/workflows/libcxx-build-and-test.yaml'
25  schedule:
26    # Run nightly at 08:00 UTC (aka 00:00 Pacific, aka 03:00 Eastern)
27    - cron: '0 8 * * *'
28
29permissions:
30  contents: read # Default everything to read-only
31
32concurrency:
33  group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
34  cancel-in-progress: true
35
36jobs:
37  stage1:
38    if: github.repository_owner == 'llvm'
39    runs-on: libcxx-self-hosted-linux
40    container: ghcr.io/llvm/libcxx-linux-builder:d8a0709b1090350a7fe3604d8ab78c7d62f10698
41    continue-on-error: false
42    strategy:
43      fail-fast: false
44      matrix:
45        config: [
46          'frozen-cxx03-headers',
47          'generic-cxx03',
48          'generic-cxx26',
49          'generic-modules'
50        ]
51        cc: [  'clang-20' ]
52        cxx: [ 'clang++-20' ]
53        include:
54          - config: 'generic-gcc'
55            cc: 'gcc-14'
56            cxx: 'g++-14'
57    steps:
58      - uses: actions/checkout@v4
59      - name: ${{ matrix.config }}.${{ matrix.cxx }}
60        run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
61        env:
62          CC: ${{ matrix.cc }}
63          CXX: ${{ matrix.cxx }}
64      - uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
65        if: always()
66        with:
67          name: ${{ matrix.config }}-${{ matrix.cxx }}-results
68          path: |
69            **/test-results.xml
70            **/*.abilist
71            **/CMakeConfigureLog.yaml
72            **/CMakeError.log
73            **/CMakeOutput.log
74            **/crash_diagnostics/*
75  stage2:
76    if: github.repository_owner == 'llvm'
77    runs-on: libcxx-self-hosted-linux
78    container: ghcr.io/llvm/libcxx-linux-builder:d8a0709b1090350a7fe3604d8ab78c7d62f10698
79    needs: [ stage1 ]
80    continue-on-error: false
81    strategy:
82      fail-fast: false
83      matrix:
84        config: [
85          'generic-cxx11',
86          'generic-cxx14',
87          'generic-cxx17',
88          'generic-cxx20',
89          'generic-cxx23'
90        ]
91        cc: [ 'clang-20' ]
92        cxx: [ 'clang++-20' ]
93        include:
94          - config: 'generic-gcc-cxx11'
95            cc: 'gcc-14'
96            cxx: 'g++-14'
97          - config: 'generic-cxx23'
98            cc: 'clang-18'
99            cxx: 'clang++-18'
100          - config: 'generic-cxx26'
101            cc: 'clang-19'
102            cxx: 'clang++-19'
103    steps:
104      - uses: actions/checkout@v4
105      - name: ${{ matrix.config }}
106        run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
107        env:
108          CC: ${{ matrix.cc }}
109          CXX: ${{ matrix.cxx }}
110      - uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
111        if: always()  # Upload artifacts even if the build or test suite fails
112        with:
113          name: ${{ matrix.config }}-${{ matrix.cxx }}-results
114          path: |
115            **/test-results.xml
116            **/*.abilist
117            **/CMakeConfigureLog.yaml
118            **/CMakeError.log
119            **/CMakeOutput.log
120            **/crash_diagnostics/*
121  stage3:
122    if: github.repository_owner == 'llvm'
123    needs: [ stage1, stage2 ]
124    continue-on-error: false
125    strategy:
126      fail-fast: false
127      max-parallel: 8
128      matrix:
129        config: [
130          'generic-abi-unstable',
131          'generic-hardening-mode-debug',
132          'generic-hardening-mode-extensive',
133          'generic-hardening-mode-fast',
134          'generic-hardening-mode-fast-with-abi-breaks',
135          'generic-merged',
136          'generic-modules-lsv',
137          'generic-no-exceptions',
138          'generic-no-experimental',
139          'generic-no-filesystem',
140          'generic-no-localization',
141          'generic-no-terminal',
142          'generic-no-random_device',
143          'generic-no-threads',
144          'generic-no-tzdb',
145          'generic-no-unicode',
146          'generic-no-wide-characters',
147          'generic-no-rtti',
148          'generic-optimized-speed',
149          'generic-static',
150          'bootstrapping-build'
151        ]
152        machine: [ 'libcxx-self-hosted-linux' ]
153        include:
154        - config: 'generic-cxx26'
155          machine: libcxx-self-hosted-linux
156        - config: 'generic-asan'
157          machine: libcxx-self-hosted-linux
158        - config: 'generic-tsan'
159          machine: libcxx-self-hosted-linux
160        - config: 'generic-ubsan'
161          machine: libcxx-self-hosted-linux
162        # Use a larger machine for MSAN to avoid timeout and memory allocation issues.
163        - config: 'generic-msan'
164          machine: libcxx-self-hosted-linux
165    runs-on: ${{ matrix.machine }}
166    container: ghcr.io/llvm/libcxx-linux-builder:d8a0709b1090350a7fe3604d8ab78c7d62f10698
167    steps:
168      - uses: actions/checkout@v4
169      - name: ${{ matrix.config }}
170        run: libcxx/utils/ci/run-buildbot ${{ matrix.config }}
171        env:
172          CC: clang-20
173          CXX: clang++-20
174      - uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
175        if: always()
176        with:
177          name: ${{ matrix.config }}-results
178          path: |
179            **/test-results.xml
180            **/*.abilist
181            **/CMakeConfigureLog.yaml
182            **/CMakeError.log
183            **/CMakeOutput.log
184            **/crash_diagnostics/*
185
186  macos:
187    needs: [ stage1 ]
188    strategy:
189      fail-fast: false
190      matrix:
191        include:
192        - config: generic-cxx03
193          os: macos-15
194        - config: generic-cxx23
195          os: macos-15
196        - config: generic-modules
197          os: macos-15
198        - config: apple-configuration
199          os: macos-15
200        - config: apple-system
201          os: macos-13
202        - config: apple-system-hardened
203          os: macos-13
204    runs-on: ${{ matrix.os }}
205    steps:
206      - uses: actions/checkout@v4
207      - uses: maxim-lobanov/setup-xcode@v1
208        with:
209          xcode-version: 'latest'
210      - uses: seanmiddleditch/gha-setup-ninja@master
211      - name: Build and test
212        run: |
213          python3 -m venv .venv
214          source .venv/bin/activate
215          python -m pip install psutil
216          bash libcxx/utils/ci/run-buildbot ${{ matrix.config }}
217      - uses: actions/upload-artifact@26f96dfa697d77e81fd5907df203aa23a56210a8 # v4.3.0
218        if: always()  # Upload artifacts even if the build or test suite fails
219        with:
220          name: macos-${{ matrix.config }}-results
221          path: |
222            **/test-results.xml
223            **/*.abilist
224            **/CMakeConfigureLog.yaml
225            **/CMakeError.log
226            **/CMakeOutput.log
227            **/crash_diagnostics/*
228
229  windows:
230    runs-on: windows-2022
231    needs: [ stage1 ]
232    strategy:
233      fail-fast: false
234      matrix:
235        include:
236        - { config: clang-cl-dll, mingw: false }
237        - { config: clang-cl-static, mingw: false }
238        - { config: clang-cl-no-vcruntime, mingw: false }
239        - { config: clang-cl-debug, mingw: false }
240        - { config: clang-cl-static-crt, mingw: false }
241        - { config: mingw-dll, mingw: true }
242        - { config: mingw-static, mingw: true }
243        - { config: mingw-dll-i686, mingw: true }
244        - { config: mingw-incomplete-sysroot, mingw: true }
245    steps:
246      - uses: actions/checkout@v4
247      - name: Install dependencies
248        run: |
249          choco install -y ninja
250          pip install psutil
251      - name: Install a current LLVM
252        if: ${{ matrix.mingw != true }}
253        run: |
254          choco install -y llvm --version=18.1.6 --allow-downgrade
255      - name: Install llvm-mingw
256        if: ${{ matrix.mingw == true }}
257        run: |
258          curl -LO https://github.com/mstorsjo/llvm-mingw/releases/download/20240606/llvm-mingw-20240606-ucrt-x86_64.zip
259          powershell Expand-Archive llvm-mingw*.zip -DestinationPath .
260          del llvm-mingw*.zip
261          mv llvm-mingw* c:\llvm-mingw
262          echo "c:\llvm-mingw\bin" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf8 -Append
263      - name: Simulate a from-scratch build of llvm-mingw
264        if: ${{ matrix.config == 'mingw-incomplete-sysroot' }}
265        run: |
266          rm -r c:\llvm-mingw\include\c++
267          rm -r c:\llvm-mingw\*-w64-mingw32\lib\libc++*
268          rm -r c:\llvm-mingw\*-w64-mingw32\lib\libunwind*
269      - name: Add Git Bash to the path
270        run: |
271          echo "c:\Program Files\Git\usr\bin" | Out-File -FilePath $Env:GITHUB_PATH -Encoding utf8 -Append
272      - name: Set up the MSVC dev environment
273        if: ${{ matrix.mingw != true }}
274        uses: ilammy/msvc-dev-cmd@v1
275      - name: Build and test
276        run: |
277          bash libcxx/utils/ci/run-buildbot ${{ matrix.config }}
278