2017-05-03 09:03:27 +08:00
# Continuous Integration
2017-03-30 02:03:43 +08:00
2017-08-24 22:51:44 +08:00
Here you will find snippets to use Meson with various CI such as
Travis and AppVeyor.
2017-03-30 02:03:43 +08:00
2017-08-24 22:51:44 +08:00
Please [file an issue ](https://github.com/mesonbuild/meson/issues/new )
if these instructions don't work for you.
2017-03-30 02:03:43 +08:00
2019-12-01 07:41:02 +08:00
## Travis-CI with Docker
2017-03-30 02:03:43 +08:00
2019-12-01 07:41:02 +08:00
Travis with Docker gives access to newer non-LTS Ubuntu versions with
pre-installed libraries of your choice.
2017-03-30 02:03:43 +08:00
2019-12-01 07:41:02 +08:00
This `yml` file is derived from the
[configuration used by Meson ](https://github.com/mesonbuild/meson/blob/master/.travis.yml )
for running its own tests.
2017-03-30 02:03:43 +08:00
```yaml
os:
- linux
- osx
language:
- cpp
services:
- docker
before_install:
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
2019-12-01 05:33:06 +08:00
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install python3 ninja; fi
2017-03-30 02:03:43 +08:00
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then pip3 install meson; fi
2019-12-01 07:41:02 +08:00
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker pull YOUR/REPO:eoan; fi
2017-03-30 02:03:43 +08:00
script:
2019-12-01 07:41:02 +08:00
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo FROM YOUR/REPO:eoan > Dockerfile; fi
2017-03-30 02:03:43 +08:00
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo ADD . /root >> Dockerfile; fi
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker build -t withgit .; fi
2020-06-15 23:36:08 +08:00
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker run withgit /bin/sh -c "cd /root && TRAVIS=true CC=$CC CXX=$CXX meson builddir && meson test -C builddir"; fi
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then SDKROOT=$(xcodebuild -version -sdk macosx Path) meson builddir && meson test -C builddir; fi
2017-03-30 02:03:43 +08:00
```
2019-12-01 05:33:06 +08:00
## CircleCi for Linux (with Docker)
2019-12-01 07:41:02 +08:00
[CircleCi ](https://circleci.com/ ) can work for spinning all of the Linux images you wish.
2019-12-01 05:33:06 +08:00
Here's a sample `yml` file for use with that.
```yaml
version: 2.1
executors:
# Your dependencies would go in the docker images that represent
# the Linux distributions you are supporting
meson_ubuntu_builder:
docker:
- image: your_dockerhub_username/ubuntu-sys
2019-12-01 07:41:02 +08:00
meson_debian_builder:
2019-12-01 05:33:06 +08:00
docker:
- image: your_dockerhub_username/debian-sys
meson_fedora_builder:
docker:
- image: your_dockerhub_username/fedora-sys
jobs:
meson_ubuntu_build:
executor: meson_ubuntu_builder
steps:
- checkout
- run: meson setup builddir --backend ninja
2020-06-15 23:36:08 +08:00
- run: meson compile -C builddir
2019-12-01 05:33:06 +08:00
- run: meson test -C builddir
2019-12-01 07:41:02 +08:00
meson_debian_build:
executor: meson_debian_builder
2019-12-01 05:33:06 +08:00
steps:
- checkout
- run: meson setup builddir --backend ninja
2020-06-15 23:36:08 +08:00
- run: meson compile -C builddir
2019-12-01 05:33:06 +08:00
- run: meson test -C builddir
meson_fedora_build:
executor: meson_fedora_builder
steps:
- checkout
- run: meson setup builddir --backend ninja
2020-06-15 23:36:08 +08:00
- run: meson compile -C builddir
2019-12-01 05:33:06 +08:00
- run: meson test -C builddir
workflows:
version: 2
linux_workflow:
jobs:
- meson_ubuntu_build
2019-12-01 07:41:02 +08:00
- meson_debian_build
2019-12-01 05:33:06 +08:00
- meson_fedora_build
```
2017-03-30 02:03:43 +08:00
## AppVeyor for Windows
2019-12-01 07:41:02 +08:00
For CI on Windows, [AppVeyor ](https://www.appveyor.com/ ) has a wide selection of
[default configurations ](https://www.appveyor.com/docs/windows-images-software/ ).
AppVeyor also has [MacOS ](https://www.appveyor.com/docs/macos-images-software/ ) and
[Linux ](https://www.appveyor.com/docs/linux-images-software/ ) CI images.
This is a sample `appveyor.yml` file for Windows with Visual Studio 2015 and 2017.
2017-03-30 02:03:43 +08:00
```yaml
2019-12-01 07:41:02 +08:00
image: Visual Studio 2017
2017-03-30 02:03:43 +08:00
2017-11-18 19:41:18 +08:00
environment:
matrix:
- arch: x86
compiler: msvc2015
- arch: x64
compiler: msvc2015
2018-09-01 17:21:33 +08:00
- arch: x86
compiler: msvc2017
- arch: x64
compiler: msvc2017
2017-03-30 02:03:43 +08:00
platform:
- x64
install:
2018-09-01 17:21:33 +08:00
# Set paths to dependencies (based on architecture)
- cmd: if %arch%==x86 (set PYTHON_ROOT=C:\python37) else (set PYTHON_ROOT=C:\python37-x64)
# Print out dependency paths
- cmd: echo Using Python at %PYTHON_ROOT%
2019-11-06 21:49:00 +08:00
# Add necessary paths to PATH variable
2019-12-01 05:33:06 +08:00
- cmd: set PATH=%cd%;%PYTHON_ROOT%;%PYTHON_ROOT%\Scripts;%PATH%
# Install meson and ninja
- cmd: pip install ninja meson
2018-09-01 17:21:33 +08:00
# Set up the build environment
2017-03-30 02:03:43 +08:00
- cmd: if %compiler%==msvc2015 ( call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" %arch% )
2018-09-01 17:21:33 +08:00
- cmd: if %compiler%==msvc2017 ( call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" %arch% )
2017-03-30 02:03:43 +08:00
build_script:
- cmd: echo Building on %arch% with %compiler%
2018-09-01 17:21:33 +08:00
- cmd: meson --backend=ninja builddir
2020-06-15 23:36:08 +08:00
- cmd: meson compile -C builddir
2017-03-30 02:03:43 +08:00
test_script:
2020-06-15 23:36:08 +08:00
- cmd: meson test -C builddir
2018-09-01 17:21:33 +08:00
```
### Qt
For Qt 5, add the following line near the `PYTHON_ROOT` assignment:
2019-12-01 07:41:02 +08:00
2018-09-01 17:21:33 +08:00
```yaml
- cmd: if %arch%==x86 (set QT_ROOT=C:\Qt\5.11\%compiler%) else (set QT_ROOT=C:\Qt\5.11\%compiler%_64)
```
2019-12-01 07:41:02 +08:00
2018-09-01 17:21:33 +08:00
And afterwards add `%QT_ROOT%\bin` to the `PATH` variable.
You might have to adjust your build matrix as there are, for example, no msvc2017 32-bit builds. Visit the [Build Environment ](https://www.appveyor.com/docs/build-environment/ ) page in the AppVeyor docs for more details.
### Boost
The following statement is sufficient for meson to find Boost:
2019-12-01 07:41:02 +08:00
2018-09-01 17:21:33 +08:00
```yaml
- cmd: set BOOST_ROOT=C:\Libraries\boost_1_67_0
2017-03-30 02:03:43 +08:00
```
## Travis without Docker
2019-12-01 07:41:02 +08:00
Non-Docker Travis-CI builds can use Linux, MacOS or Windows.
Set the desired compiler(s) in the build **matrix** .
This example is for **Linux** (Ubuntu 18.04) and **C** .
2018-07-13 22:16:03 +08:00
```yaml
2019-12-01 07:41:02 +08:00
dist: bionic
group: travis_latest
2018-07-13 22:16:03 +08:00
os: linux
language: python
matrix:
include:
- env: CC=gcc
- env: CC=clang
install:
2019-12-01 07:41:02 +08:00
- pip install meson ninja
2018-07-13 22:16:03 +08:00
script:
- meson builddir
2020-06-15 23:36:08 +08:00
- meson compile -C builddir
- meson test -C builddir
2018-07-13 22:16:03 +08:00
```
2019-12-01 07:41:02 +08:00
## GitHub Actions
2017-03-30 02:03:43 +08:00
2019-12-01 07:41:02 +08:00
GitHub Actions are distinct from Azure Pipelines in their workflow syntax.
It can be easier to setup specific CI tasks in Actions than Pipelines, depending on the particular task.
This is an example file: .github/workflows/ci_meson.yml supposing the project is C-based, using GCC on Linux, Mac and Windows.
The optional `on:` parameters only run this CI when the C code is changed--corresponding ci_python.yml might run only on "**.py" file changes.
2017-03-30 02:03:43 +08:00
2019-12-01 07:41:02 +08:00
```yml
name: ci_meson
2017-03-30 02:03:43 +08:00
2019-12-01 07:41:02 +08:00
on:
push:
paths:
- "**.c"
- "**.h"
pull_request:
paths:
- "**.h"
- "**.h"
2017-03-30 02:03:43 +08:00
2019-12-01 07:41:02 +08:00
jobs:
linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- run: pip install meson ninja
- run: meson setup build
env:
CC: gcc
- run: meson test -C build -v
- uses: actions/upload-artifact@v1
if: failure()
with:
name: Linux_Meson_Testlog
path: build/meson-logs/testlog.txt
macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- run: brew install gcc
- run: pip install meson ninja
- run: meson setup build
env:
CC: gcc
- run: meson test -C build -v
- uses: actions/upload-artifact@v1
if: failure()
with:
name: MacOS_Meson_Testlog
path: build/meson-logs/testlog.txt
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v1
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- run: pip install meson ninja
- run: meson setup build
env:
CC: gcc
- run: meson test -C build -v
- uses: actions/upload-artifact@v1
if: failure()
with:
name: Windows_Meson_Testlog
path: build/meson-logs/testlog.txt
2017-03-30 02:03:43 +08:00
```