-
Notifications
You must be signed in to change notification settings - Fork 8.4k
samples: hello_world: headers cleanup #43624
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
Conversation
samples/hello_world/src/main.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What motivated this change?
Using zephyr.h as a sort of "go-to" header, rather than identifying and manually specifying the required individual headers, is much simpler and less confusing to the beginners; in fact, that is why this header exists in the first place.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref.
<zephyr.h> in particular is confusing, as it's just <kernel.h> + __ZEPHYR__. It's like a <Windows.h>. Btw, I think it would be nice to have all public headers in zephyr/ so that we could have <zephyr/kernel.h>.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... someone needs it. Zephyr leans heavily on header inlining (LTO is always just over the horizon, but right now inlined code is our tool), especially at the arch layer, and all those seemingly internal headers are needed to expose implementations to the APIs apps "need".
I think there's an excellent argument to be made that a(nother) cleanup pass on our header tangle is probably due. And there's at least a vaguely justifiable bikeshed discussion to be had[1] about whether a "catchall" header for "the whole Zephyr API" should exist, whether it should be named "zephyr.h" or "kernel.h" (and why they are separate files at all), and whether or not code in samples/ and tests/ should be using it.
But I mean, if we have such a header, clearly we'd want to be using it in hello_world, the basic archetype of "A Zephyr App".
[1] Not by me!
(FWIW: this bug was totally worth it just to see that graph)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well... someone needs it.
Maybe kernel.h itself, but not the main.c in hello_world sample.
I think there's an excellent argument to be made that a(nother) cleanup pass on our header tangle is probably due. And there's at least a vaguely justifiable bikeshed discussion to be had[1] about whether a "catchall" header for "the whole Zephyr API" should exist, whether it should be named "zephyr.h" or "kernel.h" (and why they are separate files at all), and whether or not code in samples/ and tests/ should be using it.
Any inputs on #41543 are welcome :-)
nashif
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where in our docs we talk about autoconf.h and ask for it to be included?
This is a SAMPLE, this is not intended for anything else but show in the most direct way possible and without going into details how to say hello world.
C'MON
So, then I assume
So, I assume we recommend using Btw, with this change I'm not suggesting that |
|
Windows has I don't see anything out of ordinary and/or particularly problematic here. |
IMO the scope of diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c
index 6c5c8a27dc..987728bbf2 100644
--- a/samples/hello_world/src/main.c
+++ b/samples/hello_world/src/main.c
@@ -5,7 +5,6 @@
*/
#include <zephyr.h>
-#include <sys/printk.h>
void main(void)
{diff --git a/samples/hello_world/src/main.c b/samples/hello_world/src/main.c
index 6c5c8a27dc..b8cedd3678 100644
--- a/samples/hello_world/src/main.c
+++ b/samples/hello_world/src/main.c
@@ -4,7 +4,6 @@
* SPDX-License-Identifier: Apache-2.0
*/
-#include <zephyr.h>
#include <sys/printk.h>
void main(void)why? should I never use |
How about we analyze how those platforms mentioned above deal with individual components like |
<zephyr.h> ends up pulling <sys/printk.h> via <kernel_includes.h>, so simplify the sample. Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2fe39f6 to
f23d77e
Compare
|
In general, I like the idea of |

<zephyr.h> ends up pulling <sys/printk.h> via <kernel_includes.h>, so
simplify the sample.
Note: this change assumes
<zephyr.h>is a "catch-all" header for applications.