-
Notifications
You must be signed in to change notification settings - Fork 6.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve header structure and usage #41543
Comments
I generally like the ideas put forward in the description. However, in my experience we have always opted to put local includes first in the compiler include search path, but last in the list of Apart from that, the proposed order is the same as what I would recommend. |
The reason is explained in the Google C++ styleguide:
Some C projects, e.g. https://github.com/libgit2/libgit2 seem to follow this convention too. Could you provide an example of your usecase? |
I understand backward compatibility has always been king in C; explains why we're still stuck with the 50-years old From time to time I've (ab)used EDIT: I mean tools to not just order includes but to actually analyse dependencies, think |
There exists a tool for detecting indirect dependencies we could consider using: https://include-what-you-use.org/ Indirect dependencies / transitive includes are a reliance on a implementation detail and can break in the future. E.g:
If |
That's an interesting option to look at! |
Personal preferences:
|
Agreed, no reason to reinvent yet another style guide.
It should be easy to keep a compatibility option, i.e., include both |
Hmm ... watch what happens when we look at the bigger picture.
I completely agree - but I think your strategy is misdirected. The Zephyr build system must be able to compile code from outside the Zephyr project that the user cannot modify. In fact, when a platinum user needs to reuse the audit artifacts for a safety or security submission, they must use a specific SHA of zephyr itself. So to fulfill the Zephyr Project Mission Statement, the zephyr ecosystem must explicitly carve out subsets of identifiers in each global namespace. The header file pathnames are only one example of global namespaces that must be managed. Others include: Zephyr already has an established pattern for subsystem/driver/kernel header file pathnames that is dependent on subsystem/driver names and linker symbols. When we solve the linker symbols then we have a pattern that will (mostly) resolve the issues. What's a suitable pattern? Prefix linker symbols and subsystem/driver names with a multi-character abbreviation of the module name. I think this will address most of the problems across most (all?) of the global namespaces. Thoughts? |
Source? |
This has been debated and rejected by the TSC in the past, just FYI. I don't remember the reason why, but you can start digging here: Edit: 22 May 2019, found it:
https://docs.google.com/document/d/12p8Q4USdExsP3a8lIdhyqG-4vxb44kisccZ9TvlxWBA/edit# This was a long time ago and the project has grown a lot since then, so it may be worth revisiting this, but it would have to go through the TSC |
|
Thanks! This document says:
On the other hand, you wrote:
I think there are quite a few unconnected dots between the two. |
agree. It has been 3 years and we should be able to bring this topic back and revisit. |
Yes. Here is my thinking (and I am not an expert in this area). AFAICT:
Could Zephyr achieve "best in class" without fulfilling all of this? Temporarily, but the Zephyr Project should concede that competition is likely. The plan for sustaining "best in class" must plan for perpetually addressing shortcomings. Whatever is a recognized shortcoming will eventually be addressed by the Zephyr Project, either because competition already addressed it or they want to avoid it being a competition point. What am I missing? |
IMO you are missing the other advantages to platinum membership documented here: https://www.zephyrproject.org/become-a-member/ Focusing on the audit artifacts as the only carrot for becoming a platinum member seems a bit odd. But that's just me. |
The POSIX testsuite should be run with standard POSIX header locations. Additionally, reorder headers to follow the recommendation in zephyrproject-rtos#41543. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The POSIX testsuite should be run with standard POSIX header locations. Additionally, reorder headers to follow the recommendation in zephyrproject-rtos#41543. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The POSIX testsuite should be run with standard POSIX header locations. Additionally, reorder headers to follow the recommendation in zephyrproject-rtos#41543. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The POSIX testsuite should be run with standard POSIX header locations. Additionally, reorder headers to follow the recommendation in zephyrproject-rtos#41543. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The POSIX testsuite should be run with standard POSIX header locations. Additionally, reorder headers to follow the recommendation in zephyrproject-rtos#41543. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
The POSIX testsuite should be run with standard POSIX header locations. Additionally, reorder headers to follow the recommendation in #41543. Signed-off-by: Christopher Friedt <cfriedt@meta.com>
New item: two .h files directly including each other: |
Is anyone not on-board with this? Can we incorporate this into coding guidelines prior to LTSv3? I guess there were some treewide changes - what is the progress? Is there anything left to do? @gmarull - if there are problematic areas, feel free to delegate tasks for others to clean up headers. |
I think it's a generalized problem, I just try to improve the state of headers when I refactor or add new code. Kernel is specially messy, or the infamous soc.h. I do not have much energy to spend time on this right now. |
IWYU is a great tool for automating this kind of work. It does take some leverage to get setup. Having used it a little now, I'd also recommend starting a bit "lighter" with something like https://clang.llvm.org/extra/clang-tidy/checks/misc/include-cleaner.html as I believe there is already some clang-tidy work going on. |
Zephyr drivers have typically one log level defined per class. The video drivers were making exception. This adds the missing log level for video drivers. Since all headers had to be modified, this also: - Update the log initialization to the new syntax defined in commit 5e34681 - Sort the #include list to something like zephyrproject-rtos#41543 Signed-off-by: Josuah Demangeon <me@josuah.net>
Zephyr drivers have typically one log level defined per class. The video drivers were making exception. This adds the missing log level for video drivers. Since all headers had to be modified, this also: - Update the log initialization to the new syntax defined in commit 5e34681 - Sort the #include list to something like zephyrproject-rtos#41543 Signed-off-by: Josuah Demangeon <me@josuah.net>
Zephyr drivers have typically one log level defined per class. The video drivers were making exception. This adds the missing log level for video drivers. Since all headers had to be modified, this also: - Update the log initialization to the new syntax from 5e34681 - Sort the #include list to something like zephyrproject-rtos#41543 Signed-off-by: Josuah Demangeon <me@josuah.net>
Here's a good horror story if you need one: |
Zephyr drivers have typically one log level defined per class. The video drivers were making exception. This adds the missing log level for video drivers. Since all headers had to be modified, this also: - Update the log initialization to the new syntax from 5e34681 - Sort the #include list to something like zephyrproject-rtos#41543 Signed-off-by: Josuah Demangeon <me@josuah.net>
Zephyr drivers have typically one log level defined per class. The video drivers were making exception. This adds the missing log level for video drivers. Since all headers had to be modified, this also: - Update the log initialization to the new syntax from 5e34681 - Sort the #include list to something like #41543 Signed-off-by: Josuah Demangeon <me@josuah.net>
Zephyr drivers have typically one log level defined per class. The video drivers were making exception. This adds the missing log level for video drivers. Since all headers had to be modified, this also: - Update the log initialization to the new syntax from 5e34681 - Sort the #include list to something like zephyrproject-rtos#41543 Signed-off-by: Josuah Demangeon <me@josuah.net>
Zephyr drivers have typically one log level defined per class. The video drivers were making exception. This adds the missing log level for video drivers. Since all headers had to be modified, this also: - Update the log initialization to the new syntax from 5e34681 - Sort the #include list to something like zephyrproject-rtos#41543 Signed-off-by: Josuah Demangeon <me@josuah.net>
Is your enhancement proposal related to a problem? Please describe.
As of today one can observe a few issues with respect to C headers in Zephyr:
sys/time_units.h
.<windows.h>
" way. It happened withdevice.h
andpm/device.h
. Another common case issoc.h
including HAL headers (see related issue: Improve STM32 LL HAL usage #28822).All these issues may seem not relevant, but over time this translates to increased compile times, changes in a header that have a domino effect to many source files, etc.
I've opened this issue inspired by https://lwn.net/Articles/880175/.
Describe the solution you'd like
First establish certain rules. I think the rules used by Google C++ styleguide are a good starting point. Some of the rules:
clang-format
can assist on automatically sorting the inclusion list.Gradually improve the current situation
Add some minimal CI checks to keep things in good shape
Another interesting change that, I think, would be useful is to place all Zephyr headers into a
zephyr
folder, so that all Zephyr headers would then be used as:This would help a lot to identify Zephyr headers, to create a single clang-format sorting rule, etc.
Describe alternatives you've considered
Let the problem grow and open a PR in the future with 2,297 commits in to fix the issues :-)
Additional context
Include graph for
kernel.h
as generated by Doxygen (can likely be improved):The text was updated successfully, but these errors were encountered: