Skip to content

Conversation

fzakaria
Copy link
Contributor

@fzakaria fzakaria commented Oct 15, 2025

This is in the same vein as #14251

Motivation

I ran include-what-you-use over libflake as it seemed small to start.

steps:

> iwyu_tool.py -p build/ src/libfetchers -j 100 -- -Xiwyu --mapping_file=/nix/store/0zqzzg1mm1fman18svxkf5p4km4yq85p-include-what-you-use-0.24/share/include-what-you-use/boost-all.imp -Xiwyu --cxx17ns -Xiwyu --no_fwd_decls -Xiwyu --mapping_file=$(realpath iwyu.imp) > iwyu.out

> cd build

> fix_includes.py < ../iwyu.out

I then went through the header files and now I can more safely remove the header files clangd warns that are "not used".

Context

There is an ongoing debate on whether to do include-what-you-use (iwyu).

For:

Against:

Note: You may still see "unused" header declaration warnings by clangd. From what I can understand, since I am running iwyu only on partial codebase, it is putting exactly the necessary includes for what is needed however includes from other parts of the codebase may still be giving the declarations for some headers that are included.
I saw this notably with includes for <mutex> for instance.


Add 👍 to pull requests you find important.

The Nix maintainer team uses a GitHub project board to schedule and track reviews.

@fzakaria fzakaria requested a review from edolstra as a code owner October 15, 2025 20:20
@github-actions github-actions bot added fetching Networking with the outside (non-Nix) world, input locking c api Nix as a C library with a stable interface labels Oct 15, 2025
Comment on lines +1 to +7
[
{ "include": ["@<nlohmann/.*>", "private", "<nlohmann/json.hpp>", "public"] },

# "<git2/XXX.h> => <git2.h> where XXX doesn't contain '/'
{ "include": ["@<git2/[^/]+\\.h>", "private", "<git2.h>", "public"] },

] No newline at end of file
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file now can handle the common mappings we want here as it grows.

@@ -1,4 +1,12 @@
#pragma once
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed like a small bug missing the pragma
I bet this could be an easy lint?

@fzakaria fzakaria force-pushed the fzakaria/iwyu-libflake-2 branch from 97de67e to d8fa3ef Compare October 15, 2025 20:49
Comment on lines +4 to +7
#include <git2/repository.h>
#include <nlohmann/json_fwd.hpp>
#include <git2/oid.h>
#include <git2/types.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting that sometimes my mapping file just converts these to git2.h but othertimes it replaces it with more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c api Nix as a C library with a stable interface fetching Networking with the outside (non-Nix) world, input locking

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant