ci(windows): add native SITL build coverage

Add the Windows SITL workflow for MinGW and MSVC builds, extend unit-test coverage to Windows runners, and make the macOS build use the configured Python environment consistently.
This commit is contained in:
Nuno Marques
2026-05-11 10:33:40 -07:00
parent 279bec0fb6
commit 0bdb3680e1
3 changed files with 272 additions and 2 deletions
+104 -2
View File
@@ -48,8 +48,8 @@ jobs:
PX4_SBOM_DISABLE: 1
run: make ${{ matrix.check }}
tests:
name: Unit Tests
tests-linux:
name: Unit Tests (linux)
runs-on: [runs-on,runner=8cpu-linux-x64,image=ubuntu24-full-x64,"run-id=${{ github.run_id }}",spot=false,extras=s3-cache]
container:
image: ghcr.io/px4/px4-dev:v1.17.0-rc2
@@ -97,3 +97,105 @@ jobs:
- name: Check for EKF functional changes
run: git diff --exit-code
working-directory: src/modules/ekf2/test/change_indication
tests-windows:
name: Unit Tests (windows-${{ matrix.compiler }})
# Native Windows host is required: the gtest binaries under
# platforms/posix/src/px4/windows/tests/ exercise the _MSC_VER paths
# in the shim headers and the MSVC-only sources (socket_msvc.cpp,
# sys/time.cpp, etc.). The shim CMakeLists is gated on WIN32 in
# platforms/posix/CMakeLists.txt, so a Linux runner cannot stand in.
# The compiler axis covers both native MSVC (cl.exe) and the LLVM
# clang-cl.exe driver against the same MSVC headers/CRT so we catch
# toolchain-specific shim regressions before they hit the SITL build.
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
compiler: [msvc, clang-cl]
steps:
- uses: actions/checkout@v6
with:
submodules: recursive
fetch-depth: 1
- name: Setup Python
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install Python deps
shell: pwsh
run: |
python -m pip install --upgrade pip
# empy pinned <4: PX4 generators use the empy 3.x Interpreter API
# removed in 4.x. Matches Tools/setup/requirements.txt and the
# compile_windows workflow.
python -m pip install jinja2 pyyaml toml numpy packaging jsonschema future "empy>=3.3,<4" pyros-genmsg kconfiglib
# Verify kconfiglib import on the same Python that CMake will
# pick so we fail loud here rather than during cmake configure.
python -c "import kconfiglib; print(kconfiglib.__file__)"
- name: Install Ninja
uses: seanmiddleditch/gha-setup-ninja@v5
- name: Enable MSVC environment (x64)
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
# Configure with the px4_sitl_test board, which flips
# CMAKE_TESTING=ON and pulls in the Windows shim test subdirectory
# via px4_posix_windows_add_tests() (see platforms/posix/CMakeLists.txt).
# Pin Python3_ROOT_DIR to the setup-python interpreter so cmake's
# find_package(Python3) does not pick the runner image's other Python
# where kconfiglib is not installed. The CC/CXX env vars decide which
# toolchain CMake picks: empty for native MSVC (the default cl.exe
# discovered via vcvars), or clang-cl.exe for the LLVM driver. We
# invoke cmake directly here rather than `make px4_sitl_test` so we
# only configure and can then build a narrow set of targets next.
- name: Configure (px4_sitl_test)
shell: pwsh
env:
CC: ${{ matrix.compiler == 'clang-cl' && 'clang-cl' || '' }}
CXX: ${{ matrix.compiler == 'clang-cl' && 'clang-cl' || '' }}
run: |
cmake -S . -B build/px4_sitl_test -G Ninja `
-DCONFIG=px4_sitl_test `
-DPython3_ROOT_DIR="$env:pythonLocation" `
-DPython3_FIND_STRATEGY=LOCATION
# Build only the Windows shim gtest binaries. The full test_results
# ctest target also pulls in fuzztest and the px4 binary, neither of
# which we need to gate the shim layer here. Names are emitted by
# px4_add_unit_gtest() with a `unit-` prefix (see cmake/px4_add_gtest.cmake).
- name: Build Windows shim unit tests
shell: pwsh
run: |
cmake --build build/px4_sitl_test --target unit-test_windows_shim_headers unit-test_windows_shim_runtime unit-test_windows_shim_poll unit-test_windows_shim_io
- name: Run Windows shim unit tests
shell: pwsh
run: |
$tests = @(
'unit-test_windows_shim_headers',
'unit-test_windows_shim_runtime',
'unit-test_windows_shim_poll',
'unit-test_windows_shim_io'
)
$failed = $false
foreach ($name in $tests) {
$exe = Get-ChildItem -Path build\px4_sitl_test -Filter "$name.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
if ($null -eq $exe) {
Write-Host "::error::Test binary not found: $name"
$failed = $true
continue
}
Write-Host "=== Running $($exe.Name) ==="
& $exe.FullName --gtest_color=yes
if ($LASTEXITCODE -ne 0) {
Write-Host "::error::$name failed with exit $LASTEXITCODE"
$failed = $true
}
}
if ($failed) { exit 1 }
+11
View File
@@ -46,7 +46,18 @@ jobs:
- name: setup
run: |
./Tools/setup/macos.sh
# Make the venv created by macos.sh the active Python for all
# subsequent steps. Prepending .venv/bin to PATH alone is not
# enough: actions/setup-python exports Python3_ROOT_DIR /
# pythonLocation pointing at the hostedtoolcache interpreter,
# and find_package(Python3) honours those hints over PATH. The
# PX4 Python deps (kconfiglib, empy, etc.) only live in the
# venv, so configure fails at the kconfiglib import otherwise.
echo "${{ github.workspace }}/.venv/bin" >> $GITHUB_PATH
echo "VIRTUAL_ENV=${{ github.workspace }}/.venv" >> $GITHUB_ENV
echo "Python3_ROOT_DIR=${{ github.workspace }}/.venv" >> $GITHUB_ENV
echo "Python_ROOT_DIR=${{ github.workspace }}/.venv" >> $GITHUB_ENV
echo "pythonLocation=${{ github.workspace }}/.venv" >> $GITHUB_ENV
- uses: ./.github/actions/setup-ccache
id: ccache
+157
View File
@@ -0,0 +1,157 @@
name: Windows SITL build
# Build px4_sitl_default for Windows on both supported toolchains:
# - MinGW-w64 cross-compile from Ubuntu (gate for the platforms/posix
# Windows shim layer and ld --wrap socket plumbing)
# - Native MSVC on a Windows runner (gate for the _MSC_VER paths in
# the shim headers and the MSVC-only sources under
# src/px4/windows/posix, e.g. socket_msvc.cpp / sys/time.cpp)
on:
push:
branches:
- 'main'
- 'stable'
- 'beta'
- 'release/**'
paths-ignore:
- 'docs/**'
pull_request:
branches:
- '**'
paths-ignore:
- 'docs/**'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
build:
name: Windows SITL (${{ matrix.toolchain }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- toolchain: MinGW
runner: ubuntu-24.04
artifact: px4-sitl-windows-x86_64-mingw
- toolchain: MSVC
runner: windows-2022
artifact: px4-sitl-windows-x86_64-msvc
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0
# ---- MinGW cross-build path (Ubuntu host) ----
- name: Install MinGW-w64 + PX4 base deps
if: matrix.toolchain == 'MinGW'
run: |
sudo apt-get update
# The *-posix variants of gcc/g++ ship winpthreads which PX4
# needs for std::thread and pthread_*.
sudo apt-get install -y --no-install-recommends \
mingw-w64 \
g++-mingw-w64-x86-64-posix \
gcc-mingw-w64-x86-64-posix \
cmake ninja-build ccache \
python3 python3-pip python3-jinja2 python3-yaml \
python3-toml python3-numpy python3-packaging \
python3-jsonschema python3-future \
python3-kconfiglib
# python3-pyros-genmsg is not packaged in Ubuntu noble; install
# it via pip alongside empy. PX4's msg/uxrce_dds/flight_tasks/
# zenoh generators rely on the empy 3.x Interpreter API, hence
# the <4 pin (matches Tools/setup/requirements.txt). Use
# --break-system-packages on Ubuntu 24.04 where pip refuses to
# touch the system site-packages by default.
python3 -m pip install --user --break-system-packages "empy>=3.3,<4" pyros-genmsg || \
python3 -m pip install --user "empy>=3.3,<4" pyros-genmsg
- name: Setup ccache (MinGW)
if: matrix.toolchain == 'MinGW'
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ccache-windows-sitl-mingw
max-size: 500M
- name: Cross-build px4.exe (MinGW)
if: matrix.toolchain == 'MinGW'
env:
CMAKE_ARGS: -DCMAKE_TOOLCHAIN_FILE=Toolchain-mingw-w64-x86_64
run: make px4_sitl_default
# ---- MSVC native path (Windows host) ----
- name: Setup Python (MSVC)
if: matrix.toolchain == 'MSVC'
uses: actions/setup-python@v6
with:
python-version: '3.11'
- name: Install Python deps (MSVC)
if: matrix.toolchain == 'MSVC'
shell: pwsh
run: |
python -m pip install --upgrade pip
# empy pinned <4: PX4's msg/uxrce_dds/flight_tasks/zenoh generators
# use the empy 3.x Interpreter(...options={em.RAW_OPT: True,
# em.BUFFERED_OPT: True}) API removed in empy 4.x. Matches the pin
# in Tools/setup/requirements.txt and Tools/setup/windows.ps1.
python -m pip install jinja2 pyyaml toml numpy packaging jsonschema future "empy>=3.3,<4" pyros-genmsg kconfiglib
# Verify kconfiglib import on the same Python that CMake will pick
# so we fail loud here rather than deep in cmake configure. Use
# `import kconfiglib` (not `menuconfig`) because the menuconfig
# entry point pulls in the standard `curses` module which is not
# shipped on Windows Pythons by default.
python -c "import kconfiglib; print(kconfiglib.__file__)"
- name: Install Ninja (MSVC)
if: matrix.toolchain == 'MSVC'
uses: seanmiddleditch/gha-setup-ninja@v5
- name: Install GNU make (MSVC)
if: matrix.toolchain == 'MSVC'
shell: pwsh
run: choco install -y make --no-progress
- name: Enable MSVC environment (x64)
if: matrix.toolchain == 'MSVC'
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
# Run the standard top-level make target. With cl.exe + ninja on
# PATH (the previous step exports them via $GITHUB_ENV), the
# Makefile's existing Ninja branch picks the Ninja generator and
# cmake auto-detects MSVC as the host compiler — same entry point
# as Linux/macOS, no toolchain file needed.
#
# Pin Python3_ROOT_DIR to the setup-python interpreter so cmake's
# find_package(Python3) does not pick up the runner-image's other
# Python (3.12) where kconfiglib is not installed.
- name: Native-build px4.exe (MSVC)
if: matrix.toolchain == 'MSVC'
shell: bash
env:
CMAKE_ARGS: -DPython3_ROOT_DIR=${{ env.pythonLocation }} -DPython3_FIND_STRATEGY=LOCATION
run: make px4_sitl_default
# ---- Common ----
- name: Upload px4.exe artifact
if: success()
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact }}
path: build/px4_sitl_default/bin/px4.exe
if-no-files-found: error
retention-days: 14