IWYU could be useful for developers, e.g., #924 etc.
Example of usage on Ubuntu 22.04:
0$ cmake -S . -B build -DSECP256K1_ENABLE_IWYU=ON -DCMAKE_C_COMPILER=clang
1$ cmake --build build
include-what-you-use
with compiler
#1204
I fear include-what-you-use
is too dump for our file organization and won’t help towards making files self-contained #924.
For example, it suggests:
0The full include-list for /home/tim/bs/dev/secp256k1/src/secp256k1.c:
1(...)
2#include "field_5x52_impl.h" // for secp256k1_fe_get_b32
3(...)
We don’t want to include field_5x52_impl.h
because we include field_impl.h
(which handles selection of the right full file)
Also, it suggests includes only for .c files and not for .h files… If we want to have self-contained files, it may be much better to simply check that every file complies individually as suggested in #924.
Also, it suggests includes only for .c files and not for .h files…
For example:
0/home/hebasto/git/secp256k1/src/precomputed_ecmult.h should add these lines:
1#include "ecmult.h" // for ECMULT_TABLE_SIZE
I fear
include-what-you-use
is too dump for our file organization…
Sure, it is not a panacea. However, it can be useful. For instance, consider the demo branch (a mix with #1231):
0$ cmake -S . -B build -DSECP256K1_ENABLE_IWYU=ON -DCMAKE_C_COMPILER=clang
1$ cmake --build build --target precomputed # no IWYU diagnostic
We don’t want to include
field_5x52_impl.h
because we includefield_impl.h
(which handles selection of the right full file)
True. And it can be achieved and nicely self documented as follows:
0/* IWYU pragma: begin_exports */
1#if defined(SECP256K1_WIDEMUL_INT128)
2#include "field_5x52_impl.h"
3#elif defined(SECP256K1_WIDEMUL_INT64)
4#include "field_10x26_impl.h"
5#else
6#error "Please select wide multiplication implementation"
7#endif
8/* IWYU pragma: end_exports */
FWIW, another demo branch has no IWYU diagnostics for secp256k1
and secp256k1_static
targets.
Concept ~0. Cores experience with IWYU has been mixed. We’ve found plenty of bugs/nonsensical include suggestions, and it’s not ideal if by default you have to add comments all over the code. We should probably look at migrating to something else, maybe LLVMs clang-include-fixer
tool.
Generally I’m not sure that “convenience option for running an include fixer” is something that needs to exists in libsecp256k1s build system. Running include-what-you-use
yourself is pretty straight forward.
Running
include-what-you-use
yourself is pretty straight forward.
I agree with that. For example,
0cmake -S . -B build -DCMAKE_C_COMPILER=clang -DCMAKE_C_INCLUDE_WHAT_YOU_USE=$(command -v include-what-you-use)
1cmake --build build
Closing.