Skip to content
Merged
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
96 changes: 96 additions & 0 deletions .github/workflows/includes-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Check includes
on: [push, pull_request]

defaults:
run:
shell: bash

jobs:
includes-check:
runs-on: ubuntu-latest
container:
image: "debian:13"
options: --user 0
strategy:
matrix:
board: ['HACKRF_ONE', 'JAWBREAKER', 'RAD1O', 'PRALINE']
cmake: ['3.10.0', 'latest']

# Don't cancel all builds when one fails
fail-fast: false

steps:

- name: Make it work on debian
run: |
apt update
apt install -y git python3 python3-pip python3-venv nodejs
# actions/checkout insists on putting the checkout in the
# working directory rather than ${{ github.workspace }}.
#
# This may just be because the 'runner' user does not exist
# in the docker image at startup.
#
# also see: https://github.com/actions/runner/issues/878
useradd -ms /bin/bash runner
ln -s /__w /home/runner/work

- name: Checkout repository
uses: actions/checkout@v6
with:
submodules: true

- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v2
with:
cmake-version: ${{ matrix.cmake }}

- name: Install Arm GNU Toolchain
uses: carlosperate/arm-none-eabi-gcc-action@v1

- name: Install dependencies
run: |
python3 -m venv environment && source environment/bin/activate
python3 -m pip install PyYAML
apt install -y iwyu
iwyu --version

- name: Build libopencm3
working-directory: ${{github.workspace}}/firmware/libopencm3/
run: |
source ../../environment/bin/activate
make

- name: Create Build Environment
run: cmake -E make_directory ${{github.workspace}}/firmware/build

- name: Configure CMake
working-directory: ${{github.workspace}}/firmware/build
run: cmake ${{github.workspace}}/firmware/ -DCMAKE_BUILD_TYPE=Release -DBOARD=${{ matrix.board }} -DCHECK_INCLUDES=1

- name: Build
working-directory: ${{github.workspace}}/firmware/build
run: |
source ../../environment/bin/activate
output="$(cmake --build . --config Release 2>&1)"
while IFS= read -r line
do
if [[ "${line}" == "Warning: include-what-you-use"* ]]; then
exit_code=1
dump=1
echo
elif [[ "${line}" == "---" ]]; then
dump=0
echo
fi
if [[ ${dump} == "1" ]]; then
echo "${line}"
fi
done <<< ${output}
if [[ ${exit_code} == "1" ]]; then
echo "Includes check failed for board target: ${{ matrix.board }}"
else
echo "Includes check succeeded for board target: ${{ matrix.board }}"
fi
echo $(include-what-you-use --version)
exit ${exit_code}
7 changes: 7 additions & 0 deletions firmware/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,17 @@

# Top directory CMake project for HackRF firmware

option(CHECK_INCLUDES
"Check firmware sources for unused includes and transitive dependencies. (Requires iwyu)" OFF)

cmake_minimum_required(VERSION 3.10.0)
set(CMAKE_TOOLCHAIN_FILE toolchain-arm-cortex-m.cmake)

project (hackrf_firmware_all C)

if(CHECK_INCLUDES)
include(include-what-you-use.cmake)
endif()

add_subdirectory(blinky)
add_subdirectory(hackrf_usb)
38 changes: 38 additions & 0 deletions firmware/include-what-you-use.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Copyright 2026 Great Scott Gadgets <info@greatscottgadgets.com>
#
# This file is part of HackRF.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#

cmake_minimum_required(VERSION 3.10.0)

find_program(IWYU_COMMAND NAMES include-what-you-use)
if(NOT IWYU_COMMAND)
message(FATAL_ERROR "Could not find the include-what-you-use executable.")
endif()

# include-what-you-use arguments:
#
# --no_fwd_decls - Disable forward declaration suggestions.
# --mapping_file - Specify mapping files for excluding suggestions.
#
list(APPEND IWYU_COMMAND
-Xiwyu --no_fwd_decls
-Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/libopencm3.imp)

set(CMAKE_C_INCLUDE_WHAT_YOU_USE ${IWYU_COMMAND})
set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_COMMAND})
Loading