Skip to content

Add CI jobs and fix clang-tidy and iwyu errors #184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 16 commits into from
Jun 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 33 additions & 34 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -1,41 +1,40 @@
Checks: '
-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-bugprone-move-forwarding-reference,
-bugprone-narrowing-conversions,
-bugprone-reserved-identifier,
misc-*,
-misc-non-private-member-variables-in-classes,
-misc-no-recursion,
-misc-unconventional-assign-operator,
-misc-unused-parameters,
-misc-use-anonymous-namespace,
modernize-*,
-modernize-avoid-c-arrays,
-modernize-concat-nested-namespaces,
-modernize-deprecated-headers,
-modernize-use-nodiscard,
-modernize-use-trailing-return-type,
-modernize-use-using,
bugprone-argument-comment,
bugprone-move-forwarding-reference,
bugprone-string-constructor,
bugprone-use-after-move,
bugprone-lambda-function-name,
bugprone-unhandled-self-assignment,
misc-unused-using-decls,
misc-no-recursion,
modernize-deprecated-headers,
modernize-use-default-member-init,
modernize-use-emplace,
modernize-use-equals-default,
modernize-use-noexcept,
modernize-use-nullptr,
modernize-use-starts-ends-with,
performance-*,
-performance-avoid-endl,
-performance-enum-size,
-performance-inefficient-string-concatenation,
-performance-no-int-to-ptr,
-performance-noexcept-move-constructor,
readability-*,
-readability-braces-around-statements,
-readability-convert-member-functions-to-static,
-readability-else-after-return,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-implicit-bool-conversion,
-readability-inconsistent-declaration-parameter-name,
-readability-magic-numbers,
-readability-named-parameter,
-readability-uppercase-literal-suffix,
-readability-use-anyofallof,
-performance-unnecessary-value-param,
readability-const-return-type,
readability-redundant-declaration,
readability-redundant-string-init,
clang-analyzer-core.*,
-clang-analyzer-core.UndefinedBinaryOperatorResult,
clang-analyzer-optin.core.*,
'
HeaderFilterRegex: '.'
WarningsAsErrors: '*'
CheckOptions:
- key: modernize-use-override.IgnoreDestructors
value: true
HeaderFilterRegex: 'example/calculator.h|example/init.h|example/printer.h|include/mp/proxy-io.h|include/mp/proxy-types.h|include/mp/proxy.h|include/mp/util.h|test/mp/test/foo-types.h|test/mp/test/foo.h'
- key: modernize-deprecated-headers.CheckHeaderFile
value: false
- key: performance-move-const-arg.CheckTriviallyCopyableMove
value: false
- key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField
value: false
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: CI

on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
config: [default, llvm, gnu32]

name: build • ${{ matrix.config }}

steps:
- uses: actions/checkout@v4

- name: Install Nix
uses: cachix/install-nix-action@v31 # 2025-05-27, from https://github.com/cachix/install-nix-action/tags
with:
nix_path: nixpkgs=channel:nixos-25.05 # latest release

- name: Run CI script
env:
CI_CONFIG: ci/configs/${{ matrix.config }}.sh
run: ci/scripts/run.sh
28 changes: 24 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,35 @@ include("cmake/compat_find.cmake")
find_package(CapnProto REQUIRED)
find_package(Threads REQUIRED)

option(Libmultiprocess_ENABLE_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
if(Libmultiprocess_ENABLE_CLANG_TIDY)
set(MPGEN_EXECUTABLE "" CACHE FILEPATH "If specified, should be full path to an external mpgen binary to use rather than the one built internally.")

option(MP_ENABLE_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
if(MP_ENABLE_CLANG_TIDY)
find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy)
if(NOT CLANG_TIDY_EXECUTABLE)
message(FATAL_ERROR "Libmultiprocess_ENABLE_CLANG_TIDY is ON but clang-tidy is not found.")
message(FATAL_ERROR "MP_ENABLE_CLANG_TIDY is ON but clang-tidy is not found.")
endif()
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}")

# Workaround for nix from https://gitlab.kitware.com/cmake/cmake/-/issues/20912#note_793338
# Nix injects header paths via $NIX_CFLAGS_COMPILE; CMake tags these as
# CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES and omits them from the compile
# database, so clang-tidy, which ignores $NIX_CFLAGS_COMPILE, can't find capnp
# headers. Setting them as standard passes them to clang-tidy.
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
endif()

set(MPGEN_EXECUTABLE "" CACHE FILEPATH "If specified, should be full path to an external mpgen binary to use rather than the one built internally.")
option(MP_ENABLE_IWYU "Run include-what-you-use with the compiler." OFF)
if(MP_ENABLE_IWYU)
find_program(IWYU_EXECUTABLE NAMES include-what-you-use iwyu)
if(NOT IWYU_EXECUTABLE)
message(FATAL_ERROR "MP_ENABLE_IWYU is ON but include-what-you-use was not found.")
endif()
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_EXECUTABLE};-Xiwyu;--error")
if(DEFINED ENV{IWYU_MAPPING_FILE})
list(APPEND CMAKE_CXX_INCLUDE_WHAT_YOU_USE "-Xiwyu" "--mapping_file=$ENV{IWYU_MAPPING_FILE}")
endif()
endif()

include("cmake/compat_config.cmake")
include("cmake/pthread_checks.cmake")
Expand All @@ -51,6 +70,7 @@ configure_file(include/mp/config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/mp/co

# Generated C++ Capn'Proto schema files
capnp_generate_cpp(MP_PROXY_SRCS MP_PROXY_HDRS include/mp/proxy.capnp)
set_source_files_properties("${MP_PROXY_SRCS}" PROPERTIES SKIP_LINTING TRUE) # Ignored before cmake 3.27

# util library
add_library(mputil OBJECT src/mp/util.cpp)
Expand Down
24 changes: 24 additions & 0 deletions ci/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
### CI quick-reference

All CI is just bash and nix.

* **Workflow**:
- `.github/workflows/ci.yml` – lists the jobs (`default`, `llvm`, …).
* **Scripts**:
- `ci/scripts/run.sh` – spins up the Nix shell then calls…
- `ci/scripts/ci.sh` – …to configure, build, and test.
* **Configuration**:
- `ci/configs/*.sh` – defines flags for each job.
- `shell.nix` – defines build environment (compilers, tools, libraries).
* **Build directories**:
- `build-*/` – separate build directories (like `build-default`, `build-llvm`) will be created for each job.

To run jobs locally:

```bash
CI_CONFIG=ci/configs/default.sh ci/scripts/run.sh
CI_CONFIG=ci/configs/llvm.sh ci/scripts/run.sh
CI_CONFIG=ci/configs/gnu32.sh ci/scripts/run.sh
```

By default CI jobs will reuse their build directories. `CI_CLEAN=1` can be specified to delete them before running instead.
5 changes: 5 additions & 0 deletions ci/configs/default.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
CI_DESC="CI job using default libraries and tools, and running IWYU"
CI_DIR=build-default
export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter"
CMAKE_ARGS=(-DMP_ENABLE_IWYU=ON)
BUILD_ARGS=(-k)
9 changes: 9 additions & 0 deletions ci/configs/gnu32.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CI_DESC="CI job cross-compiling to 32-bit"
CI_DIR=build-gnu32
NIX_ARGS=(
--arg minimal true
--arg crossPkgs 'import <nixpkgs> { crossSystem = { config = "i686-unknown-linux-gnu"; }; }'
)
export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter"
CMAKE_ARGS=(-G Ninja)
BUILD_ARGS=(-k 0)
11 changes: 11 additions & 0 deletions ci/configs/llvm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
CI_DESC="CI job using LLVM-based libraries and tools (clang, libc++, clang-tidy, iwyu) and testing Ninja"
CI_DIR=build-llvm
NIX_ARGS=(--arg enableLibcxx true)
export CXX=clang++
export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wthread-safety-analysis -Wno-unused-parameter"
CMAKE_ARGS=(
-G Ninja
-DMP_ENABLE_CLANG_TIDY=ON
-DMP_ENABLE_IWYU=ON
)
BUILD_ARGS=(-k 0)
12 changes: 12 additions & 0 deletions ci/scripts/ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail -o xtrace

[ "${CI_CONFIG+x}" ] && source "$CI_CONFIG"

: "${CI_DIR:=build}"

[ -n "${CI_CLEAN-}" ] && rm -rf "${CI_DIR}"

cmake -B "$CI_DIR" "${CMAKE_ARGS[@]+"${CMAKE_ARGS[@]}"}"
cmake --build "$CI_DIR" -t all tests mpexamples -- "${BUILD_ARGS[@]+"${BUILD_ARGS[@]}"}"
ctest --test-dir "$CI_DIR" --output-on-failure
6 changes: 6 additions & 0 deletions ci/scripts/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail -o xtrace

[ "${CI_CONFIG+x}" ] && source "$CI_CONFIG"

nix-shell --pure --keep CI_CONFIG --keep CI_CLEAN "${NIX_ARGS[@]+"${NIX_ARGS[@]}"}" --run ci/scripts/ci.sh shell.nix
2 changes: 2 additions & 0 deletions cmake/TargetCapnpSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ function(target_capnp_sources target include_prefix)
DEPENDS ${capnp_file}
VERBATIM
)
# Skip linting for capnp-generated files but keep it for mpgen-generated ones
set_source_files_properties(${capnp_file}.c++ PROPERTIES SKIP_LINTING TRUE) # Ignored before cmake 3.27
target_sources(${target} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.c++
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-client.c++
Expand Down
12 changes: 8 additions & 4 deletions example/calculator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <calculator.h>
#include <init.capnp.h>
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner) // IWYU pragma: keep

#include <charconv>
#include <cstring>
#include <fstream>
#include <init.capnp.h>
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner)
#include <init.h>
#include <iostream>
#include <kj/async.h>
#include <kj/common.h>
#include <kj/memory.h>
#include <memory>
#include <mp/proxy-io.h>
#include <printer.h>
#include <stdexcept>
#include <string>
#include <system_error>
#include <utility>

class CalculatorImpl : public Calculator
Expand Down
9 changes: 7 additions & 2 deletions example/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <init.capnp.h>
#include <init.capnp.proxy.h>

#include <cstring> // IWYU pragma: keep
#include <filesystem>
#include <fstream>
#include <future>
#include <init.capnp.h>
#include <init.capnp.proxy.h>
#include <iostream>
#include <kj/async.h>
#include <kj/common.h>
#include <memory>
#include <mp/proxy-io.h>
#include <mp/util.h>
#include <stdexcept>
Expand Down
3 changes: 1 addition & 2 deletions example/init.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ using Printer = import "printer.capnp";
$Proxy.include("calculator.h");
$Proxy.include("init.h");
$Proxy.include("printer.h");
$Proxy.includeTypes("calculator.capnp.proxy-types.h");
$Proxy.includeTypes("printer.capnp.proxy-types.h");
$Proxy.includeTypes("types.h");

interface InitInterface $Proxy.wrap("Init") {
construct @0 (threadMap: Proxy.ThreadMap) -> (threadMap :Proxy.ThreadMap);
Expand Down
14 changes: 10 additions & 4 deletions example/printer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <printer.h>

#include <init.capnp.h>
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner) // IWYU pragma: keep

#include <charconv>
#include <cstring>
#include <fstream>
#include <init.capnp.h>
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner)
#include <init.h>
#include <iostream>
#include <kj/async.h>
#include <kj/common.h>
#include <kj/memory.h>
#include <memory>
#include <mp/proxy-io.h>
#include <printer.h>
#include <stdexcept>
#include <string>
#include <system_error>

class PrinterImpl : public Printer
{
Expand Down
9 changes: 9 additions & 0 deletions example/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
#ifndef EXAMPLE_TYPES_H
#define EXAMPLE_TYPES_H

#include <calculator.capnp.proxy-types.h>
#include <printer.capnp.proxy-types.h>

// IWYU pragma: begin_exports
#include <mp/type-context.h>
#include <mp/type-decay.h>
#include <mp/type-interface.h>
#include <mp/type-string.h>
#include <mp/type-threadmap.h>
// IWYU pragma: end_exports

struct InitInterface; // IWYU pragma: export
struct CalculatorInterface; // IWYU pragma: export
struct PrinterInterface; // IWYU pragma: export

#endif // EXAMPLE_TYPES_H
2 changes: 2 additions & 0 deletions include/mp/proxy-io.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,15 @@
#include <capnp/rpc-twoparty.h>

#include <assert.h>
#include <condition_variable>
#include <functional>
#include <kj/function.h>
#include <map>
#include <memory>
#include <optional>
#include <sstream>
#include <string>
#include <thread>

namespace mp {
struct ThreadContext;
Expand Down
Loading