Skip to content

Commit bbbaffe

Browse files
committed
Add include-what-you-use CI job in advisory mode (#73)
1 parent 131f976 commit bbbaffe

3 files changed

Lines changed: 201 additions & 0 deletions

File tree

.github/workflows/iwyu.yml

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: IWYU
19+
20+
on:
21+
push:
22+
branches:
23+
- main
24+
paths-ignore:
25+
- 'ci/**'
26+
- 'docs/**'
27+
- 'mkdocs/**'
28+
pull_request:
29+
types: [opened, synchronize, reopened, ready_for_review]
30+
branches:
31+
- main
32+
paths-ignore:
33+
- 'ci/**'
34+
- 'docs/**'
35+
- 'mkdocs/**'
36+
37+
concurrency:
38+
group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }}
39+
cancel-in-progress: true
40+
41+
permissions:
42+
contents: read
43+
44+
jobs:
45+
iwyu:
46+
if: ${{ github.event_name != 'pull_request' || github.event.pull_request.draft == false }}
47+
name: Include-What-You-Use (Advisory)
48+
runs-on: ubuntu-26.04
49+
timeout-minutes: 30
50+
env:
51+
SCCACHE_DIR: ${{ github.workspace }}/.sccache
52+
SCCACHE_CACHE_SIZE: "2G"
53+
steps:
54+
- name: Checkout iceberg-cpp
55+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
56+
with:
57+
persist-credentials: false
58+
59+
- name: Install dependencies
60+
run: |
61+
sudo apt-get update
62+
sudo apt-get install -y \
63+
libcurl4-openssl-dev \
64+
clang-20 \
65+
iwyu \
66+
ninja-build
67+
68+
- name: Restore sccache cache
69+
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
70+
with:
71+
path: ${{ github.workspace }}/.sccache
72+
key: sccache-iwyu-${{ github.run_id }}
73+
restore-keys: |
74+
sccache-iwyu-
75+
76+
- name: Setup sccache
77+
uses: mozilla-actions/sccache-action@9e7fa8a12102821edf02ca5dbea1acd0f89a2696 # v0.0.10
78+
79+
- name: Configure (Clang + compile_commands.json)
80+
run: |
81+
mkdir build && cd build
82+
cmake .. -G Ninja \
83+
-DCMAKE_C_COMPILER=clang-20 \
84+
-DCMAKE_CXX_COMPILER=clang++-20 \
85+
-DCMAKE_C_COMPILER_LAUNCHER=sccache \
86+
-DCMAKE_CXX_COMPILER_LAUNCHER=sccache \
87+
-DCMAKE_EXPORT_COMPILE_COMMANDS=ON \
88+
-DCMAKE_BUILD_TYPE=Debug \
89+
-DICEBERG_BUILD_STATIC=ON \
90+
-DICEBERG_BUILD_SHARED=OFF
91+
92+
- name: Build
93+
run: cmake --build build
94+
95+
- name: Show sccache stats
96+
run: sccache --show-stats
97+
98+
- name: Save sccache cache
99+
if: github.ref == 'refs/heads/main'
100+
uses: actions/cache/save@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
101+
with:
102+
path: ${{ github.workspace }}/.sccache
103+
key: sccache-iwyu-${{ github.run_id }}
104+
105+
- name: Run IWYU (advisory)
106+
run: |
107+
# iwyu_tool may be named iwyu_tool.py or iwyu_tool depending on distro
108+
IWYU_TOOL=$(command -v iwyu_tool.py || command -v iwyu_tool)
109+
echo "Using: $IWYU_TOOL"
110+
111+
$IWYU_TOOL -p build \
112+
-j $(nproc) \
113+
-- \
114+
-Xiwyu --mapping_file=${{ github.workspace }}/iwyu.imp \
115+
-Xiwyu --no_fwd_decls \
116+
-Xiwyu --max_line_length=100 \
117+
2>&1 | tee iwyu-full-report.txt || true
118+
119+
# Filter to only project sources (exclude build/_deps and tests)
120+
grep "src/iceberg/" iwyu-full-report.txt \
121+
> iwyu-filtered.txt || true
122+
123+
echo "::notice::IWYU report generated (advisory only, not blocking)"
124+
125+
if [ -s iwyu-filtered.txt ]; then
126+
echo "## IWYU Findings (advisory — not blocking)" >> "$GITHUB_STEP_SUMMARY"
127+
echo '```' >> "$GITHUB_STEP_SUMMARY"
128+
head -200 iwyu-filtered.txt >> "$GITHUB_STEP_SUMMARY"
129+
echo '```' >> "$GITHUB_STEP_SUMMARY"
130+
else
131+
echo "## IWYU: No issues found ✓" >> "$GITHUB_STEP_SUMMARY"
132+
fi
133+
134+
- name: Upload IWYU report
135+
if: always()
136+
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
137+
with:
138+
name: iwyu-report
139+
path: |
140+
iwyu-full-report.txt
141+
iwyu-filtered.txt

CMakeLists.txt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ option(ICEBERG_BUNDLE_AWSSDK "Bundle AWS SDK for S3/SigV4 support" ON)
5858
option(ICEBERG_BUNDLE_THRIFT "Bundle Thrift (from Arrow) for Hive catalog" ON)
5959
option(ICEBERG_ENABLE_ASAN "Enable Address Sanitizer" OFF)
6060
option(ICEBERG_ENABLE_UBSAN "Enable Undefined Behavior Sanitizer" OFF)
61+
option(ICEBERG_ENABLE_IWYU "Enable include-what-you-use during build" OFF)
6162

6263
include(GNUInstallDirs)
6364
include(FetchContent)
@@ -83,6 +84,21 @@ include(CMakeParseArguments)
8384
include(IcebergBuildUtils)
8485
include(IcebergSanitizer)
8586
include(IcebergSccache)
87+
88+
if(ICEBERG_ENABLE_IWYU)
89+
find_program(IWYU_PROGRAM NAMES include-what-you-use iwyu)
90+
if(IWYU_PROGRAM)
91+
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
92+
"${IWYU_PROGRAM};-Xiwyu;--mapping_file=${PROJECT_SOURCE_DIR}/iwyu.imp;-Xiwyu;--no_fwd_decls"
93+
)
94+
# IWYU output looks like compiler warnings; don't let -Werror block it
95+
set(CMAKE_COMPILE_WARNING_AS_ERROR OFF)
96+
message(STATUS "IWYU enabled: ${IWYU_PROGRAM}")
97+
else()
98+
message(WARNING "IWYU requested but include-what-you-use not found")
99+
endif()
100+
endif()
101+
86102
include(IcebergThirdpartyToolchain)
87103

88104
if(ICEBERG_BUILD_TESTS)

iwyu.imp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# IWYU mapping file for apache/iceberg-cpp
19+
# See: https://github.com/include-what-you-use/include-what-you-use/blob/master/docs/IWYUMappings.md
20+
[
21+
# --- nlohmann/json ---
22+
{ include: ["@\"nlohmann/detail/.*\"", "private", "\"nlohmann/json.hpp\"", "public"] },
23+
{ include: ["@<nlohmann/detail/.*>", "private", "<nlohmann/json.hpp>", "public"] },
24+
25+
# --- spdlog ---
26+
{ include: ["@\"spdlog/details/.*\"", "private", "\"spdlog/spdlog.h\"", "public"] },
27+
{ include: ["@<spdlog/details/.*>", "private", "<spdlog/spdlog.h>", "public"] },
28+
{ include: ["@<spdlog/fmt/.*>", "private", "<spdlog/spdlog.h>", "public"] },
29+
30+
# --- nanoarrow ---
31+
{ include: ["\"nanoarrow/nanoarrow_types.h\"", "private", "\"nanoarrow/nanoarrow.h\"", "public"] },
32+
{ include: ["<nanoarrow/nanoarrow_types.h>", "private", "<nanoarrow/nanoarrow.h>", "public"] },
33+
34+
# --- CRoaring ---
35+
{ include: ["\"roaring/roaring_types.h\"", "private", "\"roaring/roaring.hh\"", "public"] },
36+
37+
# --- cpr ---
38+
{ include: ["@\"cpr/.*\"", "private", "\"cpr/cpr.h\"", "public"] },
39+
{ include: ["@<cpr/.*>", "private", "<cpr/cpr.h>", "public"] },
40+
41+
# --- Arrow ---
42+
{ include: ["@\"arrow/util/.*\"", "private", "\"arrow/api.h\"", "public"] },
43+
{ include: ["@<arrow/util/.*>", "private", "<arrow/api.h>", "public"] },
44+
]

0 commit comments

Comments
 (0)