-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Stop using gcc's "-include" flag #7216
Comments
Mynewt has an interesting solution to this problem. They disallow directly accessing CONFIG_ARM, and instead require that one accesses the options through a macro with an argument, CONFIG(ARM), since macro's with arguments can't be undefined, you get an error, and can therefore be safe that autoconf.h has been defined. This would require search replacement of all Kconfig's in and out of tree, but might be worth it in the long term ... |
In case anyone is reading this issue in 2020 (couldn't resist a YouTube comment), Fast forwarding a few seasons (tig blame is so much more fun than TV), in commits v2.0.0-rc1~1380-g f57ba2d / #16645 and v2.0.0-rc1~1072-g e53c0d0 / #17267
Kudos to @jajanusz for remembering about this issue, always a pleasure to watch some old @SebastianBoe :-) PS: I've been told @SebastianBoe is "off the grid" right now and his github status seems to confirm that. |
Which has now been resolved and has been introduced with the new Toolchain abstration:
|
AFAIK this was addressed, so closing |
Both the linux kernel and Zephyr uses gcc's "-include" feature to insert Kconfig defines into the top of every source file that is built.
The main advantage of using "-include" is that it is impossible for a C source file to accidentally forget to include the Kconfig header file[0].
But protecting the user from this user-error has several disadvantages.
IDE support
IDE's and other C tooling that rely on best-effort parsing of C source code will struggle to resolve where the CONFIG_ defines come from because there is no #include that points to where the CONFIG_ defines come from.
E.g. opening a hello world Zephyr application with Eclipse presents the user with a compilation error because CONFIG_ARCH is not being resolved.
Even CLion, which is supposed to have CMake-integration had for many years an open bug about "-include" not being parsed correctly.
Human readability
Not only tools, but also humans are more confused by "-include" than "#include". If a firmware developer
wants to get familiar with Zephyr and find out where the CONFIG_ macros come from he will be able to follow "#include's" without assistance or reading documentation. But self-discovering that the build system is using the niche "-include" flag is not as easy.
It is not clear-cut, but I believe that out-of-the-box IDE support and a simplified build system will outweigh the confusion from accidentally omitting #include "conf.h". The best resolution to this issue however would be some mechanism that could verify that all C sources include directly or indirectly autoconf.h, then we would have all of the advantages, but none of the disadvantages of -include.
EDIT: After thinking more about this, testing for this would be very difficult, because not only would you need to prove that #include "conf.h" occurs, but also that it occurs before any CONFIG_ define is used ...
[0] TODO: Is there any way to automatically enforce/test that all C source files either directly or indirectly #include autoconf.h ?
The text was updated successfully, but these errors were encountered: