Debian Codegraph @

subprojects/meson-docs/docs/markdown/Continuous-Integration.md

raw
1 # Continuous Integration
2
3 Here you will find snippets to use Meson with various CI such as
4 Travis and AppVeyor.
5
6 Please [file an issue](https://github.com/mesonbuild/meson/issues/new)
7 if these instructions don't work for you.
8
9 ## Travis-CI with Docker
10
11 Travis with Docker gives access to newer non-LTS Ubuntu versions with
12 pre-installed libraries of your choice.
13
14 This `yml` file is derived from the
15 [configuration used by Meson](https://github.com/mesonbuild/meson/blob/master/.travis.yml)
16 for running its own tests.
17
18 ```yaml
19 os:
20 - linux
21 - osx
22
23 language:
24 - cpp
25
26 services:
27 - docker
28
29 before_install:
30 - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
31 - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install python3 ninja; fi
32 - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then pip3 install meson; fi
33 - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker pull YOUR/REPO:eoan; fi
34
35 script:
36 - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo FROM YOUR/REPO:eoan > Dockerfile; fi
37 - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo ADD . /root >> Dockerfile; fi
38 - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker build -t withgit .; fi
39 - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run withgit /bin/sh -c "cd /root && TRAVIS=true CC=$CC CXX=$CXX meson setup builddir && meson test -C builddir"; fi
40 - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then SDKROOT=$(xcodebuild -version -sdk macosx Path) meson setup builddir && meson test -C builddir; fi
41 ```
42
43 ## CircleCI for Linux host (with custom Docker images)
44
45 [CircleCi](https://circleci.com/) can work for spinning all of the
46 Linux images you wish. Here's a sample `yml` file for use with that.
47
48 ```yaml
49 version: 2.1
50
51 executors:
52 # Your dependencies would go in the docker images that represent
53 # the Linux distributions you are supporting
54 meson_ubuntu_builder:
55 docker:
56 - image: your_dockerhub_username/ubuntu-sys
57
58 meson_debian_builder:
59 docker:
60 - image: your_dockerhub_username/debian-sys
61
62 meson_fedora_builder:
63 docker:
64 - image: your_dockerhub_username/fedora-sys
65
66 jobs:
67 meson_ubuntu_build:
68 executor: meson_ubuntu_builder
69 steps:
70 - checkout
71 - run:
72 name: Configure Project
73 command: meson setup builddir --backend ninja
74 - run:
75 name: Compile Project
76 command: meson compile -C builddir
77 - run:
78 name: Run Tests
79 command: meson test -C builddir
80
81 meson_debian_build:
82 executor: meson_debian_builder
83 steps:
84 - checkout
85 - run:
86 name: Configure Project
87 command: meson setup builddir --backend ninja
88 - run:
89 name: Compile Project
90 command: meson compile -C builddir
91 - run:
92 name: Run Tests
93 command: meson test -C builddir
94
95 meson_fedora_build:
96 executor: meson_fedora_builder
97 steps:
98 - checkout
99 - run:
100 name: Configure Project
101 command: meson setup builddir --backend ninja
102 - run:
103 name: Compile Project
104 command: meson compile -C builddir
105 - run:
106 name: Run Tests
107 command: meson test -C builddir
108
109 workflows:
110 version: 2
111 linux_workflow:
112 jobs:
113 - meson_ubuntu_build
114 - meson_debian_build
115 - meson_fedora_build
116
117 ```
118
119 ## CircleCI for Linux host (without custom Docker images)
120
121 This CircleCI configuration defines two jobs, `build-linux` and `build-macos`,
122 within a workflow named `build`. The `build-linux` job utilizes a Docker image
123 with Python 3.12.3, while `build-macos` runs on macOS with Xcode 15.3.0. Each
124 job involves checking out the code, installing Meson and Ninja, configuring the
125 project, compiling it, and running tests using Meson.
126
127 ```yaml
128 version: 2.1
129
130 jobs:
131 build-linux:
132 docker:
133 - image: cimg/python:3.12.3
134 steps:
135 - checkout
136 - run:
137 name: Install Meson and Ninja
138 command: |
139 python -m pip install --user meson ninja
140 - run:
141 name: Configure Project
142 command: |
143 meson setup builddir
144 - run:
145 name: Compile Project
146 command: |
147 meson compile -C builddir
148 - run:
149 name: Run Tests
150 command: |
151 meson test -C builddir
152
153 build-macos:
154 macos:
155 xcode: 15.3.0
156 steps:
157 - checkout
158 - run:
159 name: Install Meson and Ninja
160 command: |
161 python -m pip install meson ninja
162 - run:
163 name: Configure Project
164 command: |
165 meson setup builddir
166 - run:
167 name: Compile Project
168 command: |
169 meson compile -C builddir
170 - run:
171 name: Run Tests
172 command: |
173 meson test -C builddir
174
175 workflows:
176 version: 2.1
177 build:
178 jobs:
179 - build-linux
180 - build-macos
181 ```
182
183 ## AppVeyor for Windows
184
185 For CI on Windows, [AppVeyor](https://www.appveyor.com/) has a wide
186 selection of [default
187 configurations](https://www.appveyor.com/docs/windows-images-software/).
188 AppVeyor also has
189 [MacOS](https://www.appveyor.com/docs/macos-images-software/) and
190 [Linux](https://www.appveyor.com/docs/linux-images-software/) CI
191 images. This is a sample `appveyor.yml` file for Windows with Visual
192 Studio 2017, 2019, and 2022.
193
194 ```yaml
195 version: 1.0.{build}
196 image:
197 - Visual Studio 2022
198 - Visual Studio 2019
199 - Visual Studio 2017
200
201 install:
202 - cmd: python -m pip install meson ninja
203
204 build_script:
205 - cmd: >-
206 meson setup builddir
207 meson compile -C builddir
208
209 test_script:
210 - cmd: meson test -C builddir
211 ```
212
213 ### Qt
214
215 For Qt 5, add the following line near the `PYTHON_ROOT` assignment:
216
217 ```yaml
218 - cmd: if %arch%==x86 (set QT_ROOT=C:\Qt\5.11\%compiler%) else (set QT_ROOT=C:\Qt\5.11\%compiler%_64)
219 ```
220
221 And afterwards add `%QT_ROOT%\bin` to the `PATH` variable.
222
223 You might have to adjust your build matrix as there are, for example,
224 no msvc2017 32-bit builds. Visit the [Build
225 Environment](https://www.appveyor.com/docs/build-environment/) page in
226 the AppVeyor docs for more details.
227
228 ### Boost
229
230 The following statement is sufficient for Meson to find Boost:
231
232 ```yaml
233 - cmd: set BOOST_ROOT=C:\Libraries\boost_1_67_0
234 ```
235
236 ## Travis without Docker
237
238 Non-Docker Travis-CI builds can use Linux, MacOS or Windows.
239 Set the desired compiler(s) in the build **matrix**.
240 This example is for **Linux** (Ubuntu 18.04) and **C**.
241
242 ```yaml
243 dist: bionic
244 group: travis_latest
245
246 os: linux
247 language: python
248
249 matrix:
250 include:
251 - env: CC=gcc
252 - env: CC=clang
253
254 install:
255 - pip install meson ninja
256
257 script:
258 - meson setup builddir
259 - meson compile -C builddir
260 - meson test -C builddir
261 ```
262
263 ## GitHub Actions
264
265 GitHub Actions provides a versatile platform for continuous integration
266 (CI). This example workflow file, `ci_meson.yml`, is tailored for C-based
267 projects utilizing GCC on Linux, macOS, and Windows. Triggered by changes
268 to C code files, it automates building and testing processes using different
269 versions of Meson (1.0.0, 1.1.0, 1.2.0, 1.3.0, 1.4.0) across various operating
270 systems. Each job in the workflow handles checkout, dependency installation,
271 project configuration, test execution, and optional test log uploads upon
272 failure.
273
274 ```yaml
275 name: CI Meson
276
277 on:
278 push:
279 paths:
280 - "**.c"
281 - "**.h"
282 pull_request:
283 paths:
284 - "**.c"
285 - "**.h"
286
287 jobs:
288 build:
289 name: Build and Test on ${{ matrix.os }} with Meson v${{ matrix.meson_version }}
290 runs-on: ${{ matrix.os }}
291 strategy:
292 matrix:
293 os: [ubuntu-latest, macos-latest, windows-latest]
294 meson_version: ["1.2.0", "1.3.0", "1.4.0"]
295 steps:
296 - name: Checkout code
297 uses: actions/checkout@v4
298 - name: Set up Python
299 uses: actions/setup-python@v5
300 with:
301 python-version: '3.x'
302 - name: Install dependencies
303 run: python -m pip install meson==${{ matrix.meson_version }} ninja
304 - name: Configure Project
305 run: meson setup builddir/
306 env:
307 CC: gcc
308 - name: Run Tests
309 run: meson test -C builddir/ -v
310 - name: Upload Test Log
311 uses: actions/upload-artifact@v4
312 if: failure()
313 with:
314 name: ${{ matrix.os }}_Meson_Testlog
315 path: builddir/meson-logs/testlog.txt
316
317 ```