Skip to content

Commit 8954cc0

Browse files
committed
Merge #184: Add CI jobs and fix clang-tidy and iwyu errors
757e13a ci: add gnu32 cross-compiled 32-bit build (Ryan Ofsky) 15bf349 doc: fix typo found by DrahtBot (Ryan Ofsky) 1a598d5 clang-tidy: drop 'bitcoin-*' check (Ryan Ofsky) cbb1e43 ci: test libc++ instead of libstdc++ in one job (Ryan Ofsky) 7631345 type-context: disable clang-tidy UndefinedBinaryOperatorResult error (Ryan Ofsky) 4896e7f proxy-types: fix clang-tidy EnumCastOutOfRange error (Ryan Ofsky) 060a739 proxy-types: fix clang-tidy StackAddressEscape error (Ryan Ofsky) 977d721 ci: add github actions jobs testing gcc, clang-20, clang-tidy, and iwyu (Ryan Ofsky) 0d5f1fa iwyu: fix add/remove include errors (Ryan Ofsky) 753d2b1 util: fix clang-tidy modernize-use-equals-default error (Ryan Ofsky) ae4f1dc type-number: fix clang-tidy modernize-use-nullptr error (Ryan Ofsky) 07a741b proxy-types: fix clang-tidy bugprone-use-after-move error (Ryan Ofsky) 3673114 proxy-types: fix clang-tidy bugprone-use-after-move error (Ryan Ofsky) 422923f proxy-types: fix clang-tidy bugprone-use-after-move error (Ryan Ofsky) c6784c6 mpgen: disable clang-tidy misc-no-recursion error (Ryan Ofsky) c5498aa tidy: copy clang-tidy file from bitcoin core (Ryan Ofsky) Pull request description: The main thing this change does is add a simple github actions CI job to build the project, run tests, and do checks with iwyu and clang-tidy. It also fixes bitcoin CI warnings reported by fanquake in bitcoin/bitcoin#31802 (comment) that show up in the logs but do not cause errors, as well as a number of other warnings that do not seem to show up in bitcoin CI. Individual commit messages describe the fixes in detail. ACKs for top commit: Sjors: ACK 757e13a Tree-SHA512: 3adc3fa03ba432bc46370ec78118962dd9701a0a0ad09dbaab6ab4be2b9f48784a636ba95efde53957505ddc5307a1afac48e62040604b120480f3f698fa98af
2 parents 258a617 + 757e13a commit 8954cc0

26 files changed

+326
-107
lines changed

.clang-tidy

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,40 @@
11
Checks: '
22
-*,
3-
bugprone-*,
4-
-bugprone-easily-swappable-parameters,
5-
-bugprone-exception-escape,
6-
-bugprone-move-forwarding-reference,
7-
-bugprone-narrowing-conversions,
8-
-bugprone-reserved-identifier,
9-
misc-*,
10-
-misc-non-private-member-variables-in-classes,
11-
-misc-no-recursion,
12-
-misc-unconventional-assign-operator,
13-
-misc-unused-parameters,
14-
-misc-use-anonymous-namespace,
15-
modernize-*,
16-
-modernize-avoid-c-arrays,
17-
-modernize-concat-nested-namespaces,
18-
-modernize-deprecated-headers,
19-
-modernize-use-nodiscard,
20-
-modernize-use-trailing-return-type,
21-
-modernize-use-using,
3+
bugprone-argument-comment,
4+
bugprone-move-forwarding-reference,
5+
bugprone-string-constructor,
6+
bugprone-use-after-move,
7+
bugprone-lambda-function-name,
8+
bugprone-unhandled-self-assignment,
9+
misc-unused-using-decls,
10+
misc-no-recursion,
11+
modernize-deprecated-headers,
12+
modernize-use-default-member-init,
13+
modernize-use-emplace,
14+
modernize-use-equals-default,
15+
modernize-use-noexcept,
16+
modernize-use-nullptr,
17+
modernize-use-starts-ends-with,
2218
performance-*,
2319
-performance-avoid-endl,
20+
-performance-enum-size,
21+
-performance-inefficient-string-concatenation,
22+
-performance-no-int-to-ptr,
2423
-performance-noexcept-move-constructor,
25-
readability-*,
26-
-readability-braces-around-statements,
27-
-readability-convert-member-functions-to-static,
28-
-readability-else-after-return,
29-
-readability-function-cognitive-complexity,
30-
-readability-identifier-length,
31-
-readability-implicit-bool-conversion,
32-
-readability-inconsistent-declaration-parameter-name,
33-
-readability-magic-numbers,
34-
-readability-named-parameter,
35-
-readability-uppercase-literal-suffix,
36-
-readability-use-anyofallof,
24+
-performance-unnecessary-value-param,
25+
readability-const-return-type,
26+
readability-redundant-declaration,
27+
readability-redundant-string-init,
28+
clang-analyzer-core.*,
29+
-clang-analyzer-core.UndefinedBinaryOperatorResult,
30+
clang-analyzer-optin.core.*,
3731
'
32+
HeaderFilterRegex: '.'
33+
WarningsAsErrors: '*'
3834
CheckOptions:
39-
- key: modernize-use-override.IgnoreDestructors
40-
value: true
41-
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'
35+
- key: modernize-deprecated-headers.CheckHeaderFile
36+
value: false
37+
- key: performance-move-const-arg.CheckTriviallyCopyableMove
38+
value: false
39+
- key: bugprone-unhandled-self-assignment.WarnOnlyIfThisHasSuspiciousField
40+
value: false

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
11+
strategy:
12+
fail-fast: false
13+
matrix:
14+
config: [default, llvm, gnu32]
15+
16+
name: build • ${{ matrix.config }}
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Install Nix
22+
uses: cachix/install-nix-action@v31 # 2025-05-27, from https://github.com/cachix/install-nix-action/tags
23+
with:
24+
nix_path: nixpkgs=channel:nixos-25.05 # latest release
25+
26+
- name: Run CI script
27+
env:
28+
CI_CONFIG: ci/configs/${{ matrix.config }}.sh
29+
run: ci/scripts/run.sh

CMakeLists.txt

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,35 @@ include("cmake/compat_find.cmake")
1515
find_package(CapnProto REQUIRED)
1616
find_package(Threads REQUIRED)
1717

18-
option(Libmultiprocess_ENABLE_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
19-
if(Libmultiprocess_ENABLE_CLANG_TIDY)
18+
set(MPGEN_EXECUTABLE "" CACHE FILEPATH "If specified, should be full path to an external mpgen binary to use rather than the one built internally.")
19+
20+
option(MP_ENABLE_CLANG_TIDY "Run clang-tidy with the compiler." OFF)
21+
if(MP_ENABLE_CLANG_TIDY)
2022
find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy)
2123
if(NOT CLANG_TIDY_EXECUTABLE)
22-
message(FATAL_ERROR "Libmultiprocess_ENABLE_CLANG_TIDY is ON but clang-tidy is not found.")
24+
message(FATAL_ERROR "MP_ENABLE_CLANG_TIDY is ON but clang-tidy is not found.")
2325
endif()
2426
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}")
27+
28+
# Workaround for nix from https://gitlab.kitware.com/cmake/cmake/-/issues/20912#note_793338
29+
# Nix injects header paths via $NIX_CFLAGS_COMPILE; CMake tags these as
30+
# CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES and omits them from the compile
31+
# database, so clang-tidy, which ignores $NIX_CFLAGS_COMPILE, can't find capnp
32+
# headers. Setting them as standard passes them to clang-tidy.
33+
set(CMAKE_CXX_STANDARD_INCLUDE_DIRECTORIES ${CMAKE_CXX_IMPLICIT_INCLUDE_DIRECTORIES})
2534
endif()
2635

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

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

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

5575
# util library
5676
add_library(mputil OBJECT src/mp/util.cpp)

ci/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
### CI quick-reference
2+
3+
All CI is just bash and nix.
4+
5+
* **Workflow**:
6+
- `.github/workflows/ci.yml` – lists the jobs (`default`, `llvm`, …).
7+
* **Scripts**:
8+
- `ci/scripts/run.sh` – spins up the Nix shell then calls…
9+
- `ci/scripts/ci.sh` – …to configure, build, and test.
10+
* **Configuration**:
11+
- `ci/configs/*.sh` – defines flags for each job.
12+
- `shell.nix` – defines build environment (compilers, tools, libraries).
13+
* **Build directories**:
14+
- `build-*/` – separate build directories (like `build-default`, `build-llvm`) will be created for each job.
15+
16+
To run jobs locally:
17+
18+
```bash
19+
CI_CONFIG=ci/configs/default.sh ci/scripts/run.sh
20+
CI_CONFIG=ci/configs/llvm.sh ci/scripts/run.sh
21+
CI_CONFIG=ci/configs/gnu32.sh ci/scripts/run.sh
22+
```
23+
24+
By default CI jobs will reuse their build directories. `CI_CLEAN=1` can be specified to delete them before running instead.

ci/configs/default.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
CI_DESC="CI job using default libraries and tools, and running IWYU"
2+
CI_DIR=build-default
3+
export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter"
4+
CMAKE_ARGS=(-DMP_ENABLE_IWYU=ON)
5+
BUILD_ARGS=(-k)

ci/configs/gnu32.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
CI_DESC="CI job cross-compiling to 32-bit"
2+
CI_DIR=build-gnu32
3+
NIX_ARGS=(
4+
--arg minimal true
5+
--arg crossPkgs 'import <nixpkgs> { crossSystem = { config = "i686-unknown-linux-gnu"; }; }'
6+
)
7+
export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wno-unused-parameter"
8+
CMAKE_ARGS=(-G Ninja)
9+
BUILD_ARGS=(-k 0)

ci/configs/llvm.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CI_DESC="CI job using LLVM-based libraries and tools (clang, libc++, clang-tidy, iwyu) and testing Ninja"
2+
CI_DIR=build-llvm
3+
NIX_ARGS=(--arg enableLibcxx true)
4+
export CXX=clang++
5+
export CXXFLAGS="-Werror -Wall -Wextra -Wpedantic -Wthread-safety-analysis -Wno-unused-parameter"
6+
CMAKE_ARGS=(
7+
-G Ninja
8+
-DMP_ENABLE_CLANG_TIDY=ON
9+
-DMP_ENABLE_IWYU=ON
10+
)
11+
BUILD_ARGS=(-k 0)

ci/scripts/ci.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
set -o errexit -o nounset -o pipefail -o xtrace
3+
4+
[ "${CI_CONFIG+x}" ] && source "$CI_CONFIG"
5+
6+
: "${CI_DIR:=build}"
7+
8+
[ -n "${CI_CLEAN-}" ] && rm -rf "${CI_DIR}"
9+
10+
cmake -B "$CI_DIR" "${CMAKE_ARGS[@]+"${CMAKE_ARGS[@]}"}"
11+
cmake --build "$CI_DIR" -t all tests mpexamples -- "${BUILD_ARGS[@]+"${BUILD_ARGS[@]}"}"
12+
ctest --test-dir "$CI_DIR" --output-on-failure

ci/scripts/run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -o errexit -o nounset -o pipefail -o xtrace
3+
4+
[ "${CI_CONFIG+x}" ] && source "$CI_CONFIG"
5+
6+
nix-shell --pure --keep CI_CONFIG --keep CI_CLEAN "${NIX_ARGS[@]+"${NIX_ARGS[@]}"}" --run ci/scripts/ci.sh shell.nix

cmake/TargetCapnpSources.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ function(target_capnp_sources target include_prefix)
8181
DEPENDS ${capnp_file}
8282
VERBATIM
8383
)
84+
# Skip linting for capnp-generated files but keep it for mpgen-generated ones
85+
set_source_files_properties(${capnp_file}.c++ PROPERTIES SKIP_LINTING TRUE) # Ignored before cmake 3.27
8486
target_sources(${target} PRIVATE
8587
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.c++
8688
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-client.c++

example/calculator.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

55
#include <calculator.h>
6+
#include <init.capnp.h>
7+
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner) // IWYU pragma: keep
8+
69
#include <charconv>
10+
#include <cstring>
711
#include <fstream>
8-
#include <init.capnp.h>
9-
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner)
10-
#include <init.h>
1112
#include <iostream>
13+
#include <kj/async.h>
14+
#include <kj/common.h>
15+
#include <kj/memory.h>
1216
#include <memory>
1317
#include <mp/proxy-io.h>
14-
#include <printer.h>
1518
#include <stdexcept>
1619
#include <string>
20+
#include <system_error>
1721
#include <utility>
1822

1923
class CalculatorImpl : public Calculator

example/example.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <init.capnp.h>
6+
#include <init.capnp.proxy.h>
7+
8+
#include <cstring> // IWYU pragma: keep
59
#include <filesystem>
610
#include <fstream>
711
#include <future>
8-
#include <init.capnp.h>
9-
#include <init.capnp.proxy.h>
1012
#include <iostream>
13+
#include <kj/async.h>
14+
#include <kj/common.h>
15+
#include <memory>
1116
#include <mp/proxy-io.h>
1217
#include <mp/util.h>
1318
#include <stdexcept>

example/init.capnp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ using Printer = import "printer.capnp";
1212
$Proxy.include("calculator.h");
1313
$Proxy.include("init.h");
1414
$Proxy.include("printer.h");
15-
$Proxy.includeTypes("calculator.capnp.proxy-types.h");
16-
$Proxy.includeTypes("printer.capnp.proxy-types.h");
15+
$Proxy.includeTypes("types.h");
1716

1817
interface InitInterface $Proxy.wrap("Init") {
1918
construct @0 (threadMap: Proxy.ThreadMap) -> (threadMap :Proxy.ThreadMap);

example/printer.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <printer.h>
6+
7+
#include <init.capnp.h>
8+
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner) // IWYU pragma: keep
9+
510
#include <charconv>
11+
#include <cstring>
612
#include <fstream>
7-
#include <init.capnp.h>
8-
#include <init.capnp.proxy.h> // NOLINT(misc-include-cleaner)
9-
#include <init.h>
1013
#include <iostream>
14+
#include <kj/async.h>
15+
#include <kj/common.h>
16+
#include <kj/memory.h>
1117
#include <memory>
1218
#include <mp/proxy-io.h>
13-
#include <printer.h>
1419
#include <stdexcept>
1520
#include <string>
21+
#include <system_error>
1622

1723
class PrinterImpl : public Printer
1824
{

example/types.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,19 @@
55
#ifndef EXAMPLE_TYPES_H
66
#define EXAMPLE_TYPES_H
77

8+
#include <calculator.capnp.proxy-types.h>
9+
#include <printer.capnp.proxy-types.h>
10+
11+
// IWYU pragma: begin_exports
812
#include <mp/type-context.h>
913
#include <mp/type-decay.h>
1014
#include <mp/type-interface.h>
1115
#include <mp/type-string.h>
1216
#include <mp/type-threadmap.h>
17+
// IWYU pragma: end_exports
18+
19+
struct InitInterface; // IWYU pragma: export
20+
struct CalculatorInterface; // IWYU pragma: export
21+
struct PrinterInterface; // IWYU pragma: export
1322

1423
#endif // EXAMPLE_TYPES_H

include/mp/proxy-io.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
#include <capnp/rpc-twoparty.h>
1414

1515
#include <assert.h>
16+
#include <condition_variable>
1617
#include <functional>
1718
#include <kj/function.h>
1819
#include <map>
1920
#include <memory>
2021
#include <optional>
2122
#include <sstream>
2223
#include <string>
24+
#include <thread>
2325

2426
namespace mp {
2527
struct ThreadContext;

0 commit comments

Comments
 (0)