持續整合
在這裡您將找到使用 Meson 搭配各種 CI(例如 Travis 和 AppVeyor)的程式碼片段。
如果這些指示對您不起作用,請提出問題。
使用 Docker 的 Travis-CI
使用 Docker 的 Travis 可讓您存取較新的非 LTS Ubuntu 版本,並預先安裝您選擇的程式庫。
此 yml
檔案衍生自 Meson 用於執行自身測試的組態。
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
適用於 Linux 主機的 CircleCI(使用自訂 Docker 映像)
CircleCi 可以為您想要的任何 Linux 映像執行。 以下是搭配使用的範例 yml
檔案。
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
適用於 Linux 主機的 CircleCI(不使用自訂 Docker 映像)
此 CircleCI 組態在名為 build
的工作流程中定義了兩個任務,build-linux
和 build-macos
。 build-linux
任務使用具有 Python 3.12.3 的 Docker 映像,而 build-macos
在具有 Xcode 15.3.0 的 macOS 上執行。每個任務都包含檢查程式碼、安裝 Meson 和 Ninja、組態專案、編譯專案以及使用 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
適用於 Windows 的 AppVeyor
對於 Windows 上的 CI,AppVeyor 有多種預設組態。 AppVeyor 也有 MacOS 和 Linux CI 映像。這是適用於具有 Visual Studio 2017、2019 和 2022 的 Windows 的範例 appveyor.yml
檔案。
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
對於 Qt 5,請在 PYTHON_ROOT
指派附近新增以下程式碼行
- cmd: if %arch%==x86 (set QT_ROOT=C:\Qt\5.11\%compiler%) else (set QT_ROOT=C:\Qt\5.11\%compiler%_64)
然後在之後將 %QT_ROOT%\bin
新增至 PATH
變數。
您可能需要調整建置矩陣,因為例如沒有 msvc2017 32 位元建置。 請瀏覽 AppVeyor 文件中的建置環境頁面以取得更多詳細資訊。
Boost
以下陳述足以讓 Meson 找到 Boost
- cmd: set BOOST_ROOT=C:\Libraries\boost_1_67_0
不使用 Docker 的 Travis
非 Docker Travis-CI 建置可以使用 Linux、MacOS 或 Windows。 在建置矩陣中設定所需的編譯器。 此範例適用於 Linux (Ubuntu 18.04) 和 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 為持續整合 (CI) 提供了一個多功能的平台。 此範例工作流程檔案 ci_meson.yml
是為使用 Linux、macOS 和 Windows 上 GCC 的 C 專案量身打造。 藉由變更 C 程式碼檔案觸發,它會使用不同版本的 Meson (1.0.0、1.1.0、1.2.0、1.3.0、1.4.0) 在各種作業系統上自動執行建置和測試程序。 工作流程中的每個任務都會處理檢查、相依性安裝、專案組態、測試執行以及失敗時選擇性地上傳測試記錄。
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
搜尋結果是