Skip to content

Commit 2c78814

Browse files
committed
ci: Add IWYU job
The change in `src/crypto/hex_base.cpp` is because GCC 14 is not affected by an IWYU bug. See: include-what-you-use/include-what-you-use#1763.
1 parent 94e4f04 commit 2c78814

File tree

6 files changed

+48
-8
lines changed

6 files changed

+48
-8
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -522,6 +522,12 @@ jobs:
522522
fail-fast: false
523523
matrix:
524524
include:
525+
- name: 'iwyu'
526+
cirrus-runner: 'ghcr.io/cirruslabs/ubuntu-runner-amd64:24.04-md'
527+
fallback-runner: 'ubuntu-24.04'
528+
timeout-minutes: 120
529+
file-env: './ci/test/00_setup_env_native_iwyu.sh'
530+
525531
- name: '32 bit ARM'
526532
cirrus-runner: 'ubuntu-24.04-arm' # Cirrus' Arm runners are Apple (with virtual Linux aarch64), which doesn't support 32-bit mode
527533
fallback-runner: 'ubuntu-24.04-arm'
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright (c) 2023-present The Bitcoin Core developers
4+
# Distributed under the MIT software license, see the accompanying
5+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
7+
export LC_ALL=C.UTF-8
8+
9+
export CI_IMAGE_NAME_TAG="mirror.gcr.io/debian:trixie" # To build codegen, CMake must be 3.31 or newer.
10+
export CONTAINER_NAME=ci_native_iwyu
11+
export TIDY_LLVM_V="21"
12+
export APT_LLVM_V="${TIDY_LLVM_V}"
13+
export PACKAGES="clang-${TIDY_LLVM_V} libclang-${TIDY_LLVM_V}-dev llvm-${TIDY_LLVM_V}-dev jq libevent-dev libboost-dev libzmq3-dev systemtap-sdt-dev qt6-base-dev qt6-tools-dev qt6-l10n-tools libqrencode-dev libsqlite3-dev libcapnp-dev capnproto"
14+
export NO_DEPENDS=1
15+
export RUN_UNIT_TESTS=false
16+
export RUN_FUNCTIONAL_TESTS=false
17+
export RUN_FUZZ_TESTS=false
18+
export RUN_CHECK_DEPS=false
19+
export RUN_IWYU=true
20+
export GOAL="codegen"
21+
export BITCOIN_CONFIG="\
22+
--preset dev-mode -DBUILD_GUI=OFF \
23+
-DCMAKE_C_COMPILER=clang-${TIDY_LLVM_V} \
24+
-DCMAKE_CXX_COMPILER=clang++-${TIDY_LLVM_V} \
25+
"

ci/test/01_base_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ if [[ -n "${USE_INSTRUMENTED_LIBCPP}" ]]; then
7979
rm -rf /llvm-project
8080
fi
8181

82-
if [[ "${RUN_TIDY}" == "true" ]]; then
82+
if [[ "${RUN_IWYU}" == true ]]; then
8383
${CI_RETRY_EXE} git clone --depth=1 https://github.com/include-what-you-use/include-what-you-use -b clang_"${TIDY_LLVM_V}" /include-what-you-use
8484
(cd /include-what-you-use && patch -p1 < /ci_container_base/ci/test/01_iwyu.patch)
8585
cmake -B /iwyu-build/ -G 'Unix Makefiles' -DCMAKE_PREFIX_PATH=/usr/lib/llvm-"${TIDY_LLVM_V}" -S /include-what-you-use

ci/test/03_test_script.sh

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ echo "=== BEGIN env ==="
4141
env
4242
echo "=== END env ==="
4343

44-
# Don't apply patches in the tidy job, because it relies on the `git diff`
45-
# command to detect IWYU errors. It is safe to skip this patch in the tidy job
44+
# Don't apply patches in the iwyu job, because it relies on the `git diff`
45+
# command to detect IWYU errors. It is safe to skip this patch in the iwyu job
4646
# because it doesn't run a UB detector.
47-
if [ "$RUN_TIDY" != "true" ]; then
47+
if [[ "${RUN_IWYU}" != true ]]; then
4848
# compact->outputs[i].file_size is uninitialized memory, so reading it is UB.
4949
# The statistic bytes_written is only used for logging, which is disabled in
5050
# CI, so as a temporary minimal fix to work around UB and CI failures, leave
@@ -120,7 +120,7 @@ BASE_BUILD_DIR=${BASE_BUILD_DIR:-$BASE_SCRATCH_DIR/build-$HOST}
120120

121121
BITCOIN_CONFIG_ALL="$BITCOIN_CONFIG_ALL -DCMAKE_INSTALL_PREFIX=$BASE_OUTDIR -Werror=dev"
122122

123-
if [[ "${RUN_TIDY}" == "true" ]]; then
123+
if [[ "${RUN_IWYU}" == true || "${RUN_TIDY}" == true ]]; then
124124
BITCOIN_CONFIG_ALL="$BITCOIN_CONFIG_ALL -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
125125
fi
126126

@@ -132,11 +132,15 @@ cmake -S "$BASE_ROOT_DIR" -B "$BASE_BUILD_DIR" "${CMAKE_ARGS[@]}" || (
132132
false
133133
)
134134

135+
if [[ "${GOAL}" != all && "${GOAL}" != codegen ]]; then
136+
GOAL="all ${GOAL}"
137+
fi
138+
135139
# shellcheck disable=SC2086
136-
cmake --build "${BASE_BUILD_DIR}" "$MAKEJOBS" --target all $GOAL || (
140+
cmake --build "${BASE_BUILD_DIR}" "$MAKEJOBS" --target $GOAL || (
137141
echo "Build failure. Verbose build follows."
138142
# shellcheck disable=SC2086
139-
cmake --build "${BASE_BUILD_DIR}" -j1 --target all $GOAL --verbose
143+
cmake --build "${BASE_BUILD_DIR}" -j1 --target $GOAL --verbose
140144
false
141145
)
142146

@@ -204,7 +208,9 @@ if [ "${RUN_TIDY}" = "true" ]; then
204208
echo "^^^ ⚠️ Failure generated from clang-tidy"
205209
false
206210
fi
211+
fi
207212

213+
if [[ "${RUN_IWYU}" == true ]]; then
208214
# TODO: Consider enforcing IWYU across the entire codebase.
209215
FILES_WITH_ENFORCED_IWYU="/src/(crypto|index)/.*\\.cpp"
210216
jq --arg patterns "$FILES_WITH_ENFORCED_IWYU" 'map(select(.file | test($patterns)))' "${BASE_BUILD_DIR}/compile_commands.json" > "${BASE_BUILD_DIR}/compile_commands_iwyu_errors.json"

contrib/devtools/iwyu/bitcoin.core.imp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,8 @@
1313
{ "symbol": ["SEEK_CUR", "private", "<cstdio>", "public"] },
1414
{ "symbol": ["SEEK_END", "private", "<cstdio>", "public"] },
1515
{ "symbol": ["SEEK_SET", "private", "<cstdio>", "public"] },
16+
17+
# IWYU bug.
18+
# See: https://github.com/include-what-you-use/include-what-you-use/issues/1863.
19+
{ "symbol": ["std::vector", "private", "<vector>", "public"] },
1620
]

src/crypto/hex_base.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include <cassert>
99
#include <cstring>
1010
#include <string>
11-
#include <tuple>
1211

1312
namespace {
1413

0 commit comments

Comments
 (0)