ci: Add IWYU job

The change in `src/crypto/hex_base.cpp` is because GCC 14 is not
affected by an IWYU bug.
See: https://github.com/include-what-you-use/include-what-you-use/issues/1763.
This commit is contained in:
Hennadii Stepanov 2025-12-17 20:29:25 +00:00
parent 94e4f04d7c
commit 2c78814e0e
No known key found for this signature in database
GPG Key ID: 410108112E7EA81F
6 changed files with 48 additions and 8 deletions

View File

@ -522,6 +522,12 @@ jobs:
fail-fast: false
matrix:
include:
- name: 'iwyu'
cirrus-runner: 'ghcr.io/cirruslabs/ubuntu-runner-amd64:24.04-md'
fallback-runner: 'ubuntu-24.04'
timeout-minutes: 120
file-env: './ci/test/00_setup_env_native_iwyu.sh'
- name: '32 bit ARM'
cirrus-runner: 'ubuntu-24.04-arm' # Cirrus' Arm runners are Apple (with virtual Linux aarch64), which doesn't support 32-bit mode
fallback-runner: 'ubuntu-24.04-arm'

View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
#
# Copyright (c) 2023-present The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
export LC_ALL=C.UTF-8
export CI_IMAGE_NAME_TAG="mirror.gcr.io/debian:trixie" # To build codegen, CMake must be 3.31 or newer.
export CONTAINER_NAME=ci_native_iwyu
export TIDY_LLVM_V="21"
export APT_LLVM_V="${TIDY_LLVM_V}"
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"
export NO_DEPENDS=1
export RUN_UNIT_TESTS=false
export RUN_FUNCTIONAL_TESTS=false
export RUN_FUZZ_TESTS=false
export RUN_CHECK_DEPS=false
export RUN_IWYU=true
export GOAL="codegen"
export BITCOIN_CONFIG="\
--preset dev-mode -DBUILD_GUI=OFF \
-DCMAKE_C_COMPILER=clang-${TIDY_LLVM_V} \
-DCMAKE_CXX_COMPILER=clang++-${TIDY_LLVM_V} \
"

View File

@ -79,7 +79,7 @@ if [[ -n "${USE_INSTRUMENTED_LIBCPP}" ]]; then
rm -rf /llvm-project
fi
if [[ "${RUN_TIDY}" == "true" ]]; then
if [[ "${RUN_IWYU}" == true ]]; then
${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
(cd /include-what-you-use && patch -p1 < /ci_container_base/ci/test/01_iwyu.patch)
cmake -B /iwyu-build/ -G 'Unix Makefiles' -DCMAKE_PREFIX_PATH=/usr/lib/llvm-"${TIDY_LLVM_V}" -S /include-what-you-use

View File

@ -41,10 +41,10 @@ echo "=== BEGIN env ==="
env
echo "=== END env ==="
# Don't apply patches in the tidy job, because it relies on the `git diff`
# command to detect IWYU errors. It is safe to skip this patch in the tidy job
# Don't apply patches in the iwyu job, because it relies on the `git diff`
# command to detect IWYU errors. It is safe to skip this patch in the iwyu job
# because it doesn't run a UB detector.
if [ "$RUN_TIDY" != "true" ]; then
if [[ "${RUN_IWYU}" != true ]]; then
# compact->outputs[i].file_size is uninitialized memory, so reading it is UB.
# The statistic bytes_written is only used for logging, which is disabled in
# 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}
BITCOIN_CONFIG_ALL="$BITCOIN_CONFIG_ALL -DCMAKE_INSTALL_PREFIX=$BASE_OUTDIR -Werror=dev"
if [[ "${RUN_TIDY}" == "true" ]]; then
if [[ "${RUN_IWYU}" == true || "${RUN_TIDY}" == true ]]; then
BITCOIN_CONFIG_ALL="$BITCOIN_CONFIG_ALL -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
fi
@ -132,11 +132,15 @@ cmake -S "$BASE_ROOT_DIR" -B "$BASE_BUILD_DIR" "${CMAKE_ARGS[@]}" || (
false
)
if [[ "${GOAL}" != all && "${GOAL}" != codegen ]]; then
GOAL="all ${GOAL}"
fi
# shellcheck disable=SC2086
cmake --build "${BASE_BUILD_DIR}" "$MAKEJOBS" --target all $GOAL || (
cmake --build "${BASE_BUILD_DIR}" "$MAKEJOBS" --target $GOAL || (
echo "Build failure. Verbose build follows."
# shellcheck disable=SC2086
cmake --build "${BASE_BUILD_DIR}" -j1 --target all $GOAL --verbose
cmake --build "${BASE_BUILD_DIR}" -j1 --target $GOAL --verbose
false
)
@ -204,7 +208,9 @@ if [ "${RUN_TIDY}" = "true" ]; then
echo "^^^ ⚠️ Failure generated from clang-tidy"
false
fi
fi
if [[ "${RUN_IWYU}" == true ]]; then
# TODO: Consider enforcing IWYU across the entire codebase.
FILES_WITH_ENFORCED_IWYU="/src/(crypto|index)/.*\\.cpp"
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"

View File

@ -13,4 +13,8 @@
{ "symbol": ["SEEK_CUR", "private", "<cstdio>", "public"] },
{ "symbol": ["SEEK_END", "private", "<cstdio>", "public"] },
{ "symbol": ["SEEK_SET", "private", "<cstdio>", "public"] },
# IWYU bug.
# See: https://github.com/include-what-you-use/include-what-you-use/issues/1863.
{ "symbol": ["std::vector", "private", "<vector>", "public"] },
]

View File

@ -8,7 +8,6 @@
#include <cassert>
#include <cstring>
#include <string>
#include <tuple>
namespace {