Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions core/shared/platform/zephyr/platform_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,24 @@
#ifndef _PLATFORM_INTERNAL_H
#define _PLATFORM_INTERNAL_H

/*
* Modern Zephyr uses zephyr/ namespace.
*
* Note: Cannot use KERNEL_VERSION_NUMBER here as it's defined in version.h
* which we're trying to include. Must use feature detection instead.
*/
#ifdef __has_include
#if __has_include(<zephyr/autoconf.h>)
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this (the use of __has_include) recommended by zephyr?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think Zephyr doesn't give advices to how-to support older platforms and generally advices to follow porting guides, which at 4.x versions just say do not have zephyr/ prefixes at all.

Since wamr includes below depend on the version, at this point we don't know whether we shall include generated files with or without zephyr/'s prefix. __has_include is a complier specific macro, and if we don't have it, we fallback to the zephyr/ prefixed generated files, which might work even with the never versions.

I'm fine with other methods determining which includes do we need, I just found this one as most appropriate one based on my experience. As another solution, we could just stop supporting older zephyr as a platform. We could also leave it as it is, but I feel that more and more projects would fail in the future if we don't follow Zephyr's changes.

#include <zephyr/autoconf.h>
#include <zephyr/version.h>
#else
#include <autoconf.h>
#include <version.h>
#endif
#else
#include <autoconf.h>
#include <version.h>
#endif

#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
#include <zephyr.h>
Expand Down
Loading