Kontinuierliche Integration

Hier finden Sie Codeausschnitte für die Verwendung von Meson mit verschiedenen CI-Systemen wie Travis und AppVeyor.

Bitte eröffnen Sie ein Issue, wenn diese Anleitungen nicht für Sie funktionieren.

Travis-CI mit Docker

Travis mit Docker bietet Zugriff auf neuere, nicht LTS Ubuntu-Versionen mit vorinstallierten Bibliotheken Ihrer Wahl.

Diese yml-Datei ist von der Konfiguration abgeleitet, die Meson für seine eigenen Tests verwendet.

os:
  - linux
  - osx

language:
  - cpp

services:
  - docker

before_install:
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew install python3 ninja; fi
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then pip3 install meson; fi
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker pull YOUR/REPO:eoan; fi

script:
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo FROM YOUR/REPO:eoan > Dockerfile; fi
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then echo ADD . /root >> Dockerfile; fi
  - if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then docker build -t withgit .; fi
  - 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
  - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then SDKROOT=$(xcodebuild -version -sdk macosx Path) meson setup builddir && meson test -C builddir; fi

CircleCI für Linux-Host (mit benutzerdefinierten Docker-Images)

CircleCi kann für das Erstellen aller gewünschten Linux-Images verwendet werden. Hier ist eine Beispiel-yml-Datei für die Verwendung damit.

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

  meson_debian_builder:
    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:
          name: Configure Project
          command: meson setup builddir --backend ninja
      - run:
          name: Compile Project
          command: meson compile -C builddir
      - run:
          name: Run Tests
          command: meson test -C builddir

  meson_debian_build:
    executor: meson_debian_builder
    steps:
      - checkout
      - run:
          name: Configure Project
          command: meson setup builddir --backend ninja
      - run:
          name: Compile Project
          command: meson compile -C builddir
      - run:
          name: Run Tests
          command: meson test -C builddir

  meson_fedora_build:
    executor: meson_fedora_builder
    steps:
      - checkout
      - run:
          name: Configure Project
          command: meson setup builddir --backend ninja
      - run:
          name: Compile Project
          command: meson compile -C builddir
      - run:
          name: Run Tests
          command: meson test -C builddir

workflows:
  version: 2
  linux_workflow:
    jobs:
      - meson_ubuntu_build
      - meson_debian_build
      - meson_fedora_build

CircleCI für Linux-Host (ohne benutzerdefinierte Docker-Images)

Diese CircleCI-Konfiguration definiert zwei Jobs, build-linux und build-macos, innerhalb eines Workflows namens build. Der Job build-linux verwendet ein Docker-Image mit Python 3.12.3, während build-macos unter macOS mit Xcode 15.3.0 läuft. Jeder Job beinhaltet das Auschecken des Codes, die Installation von Meson und Ninja, die Konfiguration des Projekts, die Kompilierung und die Ausführung von Tests mit Meson.

version: 2.1

jobs:
  build-linux:
    docker:
      - image: cimg/python:3.12.3
    steps:
      - checkout
      - run:
          name: Install Meson and Ninja
          command: |
            python -m pip install --user meson ninja
      - run:
          name: Configure Project
          command: |
            meson setup builddir
      - run:
          name: Compile Project
          command: |
            meson compile -C builddir
      - run:
          name: Run Tests
          command: |
            meson test -C builddir

  build-macos:
    macos:
      xcode: 15.3.0
    steps:
      - checkout
      - run:
          name: Install Meson and Ninja
          command: |
            python -m pip install meson ninja
      - run:
          name: Configure Project
          command: |
            meson setup builddir
      - run:
          name: Compile Project
          command: |
            meson compile -C builddir
      - run:
          name: Run Tests
          command: |
            meson test -C builddir

workflows:
  version: 2.1
  build:
    jobs:
      - build-linux
      - build-macos

AppVeyor für Windows

Für CI unter Windows bietet AppVeyor eine breite Auswahl an Standardkonfigurationen. AppVeyor verfügt auch über MacOS- und Linux-CI-Images. Dies ist eine Beispiel-appveyor.yml-Datei für Windows mit Visual Studio 2017, 2019 und 2022.

version: 1.0.{build}
image:
- Visual Studio 2022
- Visual Studio 2019
- Visual Studio 2017

install:
- cmd: python -m pip install meson ninja

build_script:
- cmd: >-
    meson setup builddir
    meson compile -C builddir

test_script:
- cmd: meson test -C builddir

Qt

Für Qt 5 fügen Sie die folgende Zeile in der Nähe der PYTHON_ROOT-Zuweisung hinzu

 - cmd: if %arch%==x86 (set QT_ROOT=C:\Qt\5.11\%compiler%) else (set QT_ROOT=C:\Qt\5.11\%compiler%_64)

Und fügen Sie anschließend %QT_ROOT%\bin zur PATH-Umgebungsvariablen hinzu.

Sie müssen möglicherweise Ihre Build-Matrix anpassen, da es beispielsweise keine 32-Bit-Builds für msvc2017 gibt. Besuchen Sie die Seite Build Environment in der AppVeyor-Dokumentation für weitere Details.

Boost

Die folgende Anweisung reicht aus, damit Meson Boost findet

 - cmd: set BOOST_ROOT=C:\Libraries\boost_1_67_0

Travis ohne Docker

Nicht-Docker Travis-CI-Builds können Linux, MacOS oder Windows verwenden. Legen Sie den/die gewünschte(n) Compiler in der Build-Matrix fest. Dieses Beispiel ist für Linux (Ubuntu 18.04) und C.

dist: bionic
group: travis_latest

os: linux
language: python

matrix:
  include:
    - env: CC=gcc
    - env: CC=clang

install:
  - pip install meson ninja

script:
  - meson setup builddir
  - meson compile -C builddir
  - meson test -C builddir

GitHub Actions

GitHub Actions bietet eine vielseitige Plattform für Continuous Integration (CI). Diese Beispiel-Workflow-Datei, ci_meson.yml, ist für C-basierte Projekte mit GCC unter Linux, macOS und Windows maßgeschneidert. Ausgelöst durch Änderungen an C-Code-Dateien automatisiert sie Build- und Testprozesse mit verschiedenen Meson-Versionen (1.0.0, 1.1.0, 1.2.0, 1.3.0, 1.4.0) auf verschiedenen Betriebssystemen. Jeder Job im Workflow kümmert sich um das Auschecken, die Installation von Abhängigkeiten, die Projektkonfiguration, die Ausführung von Tests und das optionale Hochladen von Testprotokollen bei Fehlern.

name: CI Meson

on:
  push:
    paths:
      - "**.c"
      - "**.h"
  pull_request:
    paths:
      - "**.c"
      - "**.h"

jobs:
  build:
    name: Build and Test on ${{ matrix.os }} with Meson v${{ matrix.meson_version }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]
        meson_version: ["1.2.0", "1.3.0", "1.4.0"]
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: '3.x'
      - name: Install dependencies
        run: python -m pip install meson==${{ matrix.meson_version }} ninja
      - name: Configure Project
        run: meson setup builddir/
        env:
          CC: gcc
      - name: Run Tests
        run: meson test -C builddir/ -v
      - name: Upload Test Log
        uses: actions/upload-artifact@v4
        if: failure()
        with:
          name: ${{ matrix.os }}_Meson_Testlog
          path: builddir/meson-logs/testlog.txt

Die Ergebnisse der Suche sind