Skip to content
Draft
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
108 changes: 108 additions & 0 deletions .github/workflows/iwyu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Include What You Use

on:
push:
branches:
- master
pull_request:
branches:
- master

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

jobs:
iwyu-check:
name: IWYU Header Dependencies Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install LLVM and IWYU from apt.llvm.org
run: |
# Add LLVM repository
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo "deb http://apt.llvm.org/$(lsb_release -cs)/ llvm-toolchain-$(lsb_release -cs)-18 main" | sudo tee /etc/apt/sources.list.d/llvm.list

# Update and install packages
sudo apt-get update
sudo apt-get install -y \
llvm-18 \
llvm-18-dev \
clang-18 \
libclang-18-dev

# Install IWYU from Ubuntu repos (compatible with clang-18)
sudo apt-get install -y iwyu

# Create symlink if needed
if [ ! -f /usr/bin/include-what-you-use ] && [ -f /usr/bin/iwyu ]; then
sudo ln -s /usr/bin/iwyu /usr/bin/include-what-you-use
fi

# Verify IWYU installation
include-what-you-use --version || iwyu --version || echo "Warning: IWYU version check failed"

- name: Install dependencies
run: |
sudo apt-get install -y \
libbz2-dev \
libxml2-dev \
libzip-dev \
liblua5.2-dev \
ccache

# Install TBB
TBB_VERSION=2021.12.0
TBB_URL="https://github.com/oneapi-src/oneTBB/releases/download/v${TBB_VERSION}/oneapi-tbb-${TBB_VERSION}-lin.tgz"
wget --tries 5 ${TBB_URL} -O onetbb.tgz
tar zxvf onetbb.tgz
sudo cp -a oneapi-tbb-${TBB_VERSION}/lib/. /usr/local/lib/
sudo cp -a oneapi-tbb-${TBB_VERSION}/include/. /usr/local/include/

- name: Install boost
uses: MarkusJx/install-boost@v2
id: install-boost
with:
boost_version: 1.85.0

- name: Configure CMake with IWYU
run: |
mkdir build
cd build
cmake .. \
-DCMAKE_BUILD_TYPE=Debug \
-DCMAKE_CXX_COMPILER=clang++-18 \
-DCMAKE_C_COMPILER=clang-18 \
-DENABLE_IWYU=ON \
-DENABLE_LTO=OFF
env:
Boost_ROOT: ${{ steps.install-boost.outputs.BOOST_ROOT }}

- name: Run IWYU
run: |
cd build
# Build to trigger IWYU checks (only building libraries, not all targets)
make -j$(nproc) osrm 2>&1 | tee iwyu.log || true

# Check if there are any IWYU warnings
if grep -q "should add these lines:" iwyu.log || grep -q "should remove these lines:" iwyu.log; then
echo "::warning::IWYU found issues with header dependencies"
echo "To fix header dependencies locally:"
echo " 1. Configure cmake with -DENABLE_IWYU=ON"
echo " 2. Build the project: make -j\$(nproc)"
echo " 3. Review IWYU suggestions and apply fixes"
echo " 4. You can use iwyu_tool.py and fix_includes.py for automated fixes"
# Don't fail the build for now, just warn
exit 0
else
echo "No IWYU issues found or IWYU not properly configured"
fi

- name: Upload IWYU log
uses: actions/upload-artifact@v4
if: always()
with:
name: iwyu-log
path: build/iwyu.log
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ option(ENABLE_CONAN "Use conan for dependencies" OFF)
option(ENABLE_COVERAGE "Build with coverage instrumentalisation" OFF)
option(ENABLE_DEBUG_LOGGING "Use debug logging in release mode" OFF)
option(ENABLE_FUZZING "Fuzz testing using LLVM's libFuzzer" OFF)
option(ENABLE_IWYU "Enable include-what-you-use checks" OFF)
option(ENABLE_LTO "Use Link Time Optimisation" ON)
option(ENABLE_NODE_BINDINGS "Build NodeJs bindings" OFF)
option(ENABLE_SANITIZER "Use memory sanitizer for Debug build" OFF)
Expand Down Expand Up @@ -67,6 +68,22 @@ if (ENABLE_CLANG_TIDY)
endif()
endif()

if (ENABLE_IWYU)
find_program(IWYU_COMMAND NAMES include-what-you-use iwyu)
if(NOT IWYU_COMMAND)
message(FATAL_ERROR "ENABLE_IWYU is ON but include-what-you-use is not found!")
else()
message(STATUS "Found include-what-you-use at ${IWYU_COMMAND}")
# Check if mapping file exists
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/iwyu.imp")
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_COMMAND};-Xiwyu;--mapping_file=${CMAKE_CURRENT_SOURCE_DIR}/iwyu.imp")
message(STATUS "Using IWYU mapping file: ${CMAKE_CURRENT_SOURCE_DIR}/iwyu.imp")
else()
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE "${IWYU_COMMAND}")
endif()
endif()
endif()

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

project(OSRM C CXX)
Expand Down
18 changes: 18 additions & 0 deletions iwyu.imp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[
# Standard library mappings
{ "include": ["<bits/fcntl-linux.h>", "private", "<fcntl.h>", "public"] },
{ "include": ["<bits/shared_ptr.h>", "private", "<memory>", "public"] },
{ "include": ["<bits/unique_ptr.h>", "private", "<memory>", "public"] },
{ "include": ["<bits/std_function.h>", "private", "<functional>", "public"] },
{ "include": ["<sys/types.h>", "public", "<cstdint>", "public"] },

# Third-party library mappings
{ "include": ["<expat_external.h>", "public", "<expat.h>", "public"] },
{ "include": ["<zconf.h>", "public", "<zlib.h>", "public"] },

# Boost mappings
{ "include": ["@<boost/.*>", "public", "<boost/boost.hpp>", "public"] },

# TBB mappings
{ "include": ["@<tbb/.*>", "public", "<tbb/tbb.h>", "public"] }
]
Loading