Skip to content

Commit ec5ab82

Browse files
authored
Fix zephyr sample build errors (#1757)
1 parent 9c5e1cb commit ec5ab82

File tree

5 files changed

+41
-8
lines changed

5 files changed

+41
-8
lines changed

core/shared/platform/common/math/math.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -449,8 +449,6 @@ ivln2 = 1.44269504088896338700e+00, /* 0x3FF71547, 0x652B82FE =1/ln2 */
449449
ivln2_h = 1.44269502162933349609e+00, /* 0x3FF71547, 0x60000000 =24b 1/ln2*/
450450
ivln2_l = 1.92596299112661746887e-08; /* 0x3E54AE0B, 0xF85DDF44 =1/ln2 tail*/
451451

452-
static double
453-
freebsd_sqrt(double x);
454452
static double
455453
freebsd_floor(double x);
456454
static double
@@ -622,6 +620,7 @@ freebsd_atan2(double y, double x)
622620
}
623621
}
624622

623+
#ifndef BH_HAS_SQRTF
625624
static float
626625
freebsd_sqrtf(float x)
627626
{
@@ -689,7 +688,9 @@ freebsd_sqrtf(float x)
689688
SET_FLOAT_WORD(z, ix);
690689
return z;
691690
}
691+
#endif /* end of BH_HAS_SQRTF */
692692

693+
#ifndef BH_HAS_SQRT
693694
static double
694695
freebsd_sqrt(double x) /* wrapper sqrt */
695696
{
@@ -799,6 +800,7 @@ freebsd_sqrt(double x) /* wrapper sqrt */
799800

800801
return z;
801802
}
803+
#endif /* end of BH_HAS_SQRT */
802804

803805
static double
804806
freebsd_floor(double x)
@@ -1554,11 +1556,13 @@ atan2(double y, double x)
15541556
return freebsd_atan2(y, x);
15551557
}
15561558

1559+
#ifndef BH_HAS_SQRT
15571560
double
15581561
sqrt(double x)
15591562
{
15601563
return freebsd_sqrt(x);
15611564
}
1565+
#endif
15621566

15631567
double
15641568
floor(double x)
@@ -1656,11 +1660,13 @@ fmaxf(float x, float y)
16561660
return freebsd_fmaxf(x, y);
16571661
}
16581662

1663+
#ifndef BH_HAS_SQRTF
16591664
float
16601665
sqrtf(float x)
16611666
{
16621667
return freebsd_sqrtf(x);
16631668
}
1669+
#endif
16641670

16651671
double
16661672
pow(double x, double y)

core/shared/platform/include/platform_common.h

+4
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,10 @@ typedef void *(*thread_start_routine_t)(void *);
193193
#define SCNxPTR __PRIPTR_PREFIX "x"
194194
#endif
195195

196+
#ifndef NAN
197+
#define NAN (0.0 / 0.0)
198+
#endif
199+
196200
#ifdef __cplusplus
197201
}
198202
#endif

core/shared/platform/zephyr/platform_internal.h

+27-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,21 @@
77
#define _PLATFORM_INTERNAL_H
88

99
#include <autoconf.h>
10+
#include <version.h>
11+
12+
#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
1013
#include <zephyr.h>
1114
#include <kernel.h>
12-
#include <version.h>
1315
#if KERNEL_VERSION_NUMBER >= 0x020200 /* version 2.2.0 */
1416
#include <sys/printk.h>
1517
#else
1618
#include <misc/printk.h>
1719
#endif
20+
#else /* else of KERNEL_VERSION_NUMBER < 0x030200 */
21+
#include <zephyr/kernel.h>
22+
#include <zephyr/sys/printk.h>
23+
#endif /* end of KERNEL_VERSION_NUMBER < 0x030200 */
24+
1825
#include <inttypes.h>
1926
#include <stdarg.h>
2027
#include <ctype.h>
@@ -24,9 +31,12 @@
2431
#include <stdlib.h>
2532
#include <string.h>
2633
#include <strings.h>
34+
2735
#ifndef CONFIG_NET_BUF_USER_DATA_SIZE
2836
#define CONFIG_NET_BUF_USER_DATA_SIZE 0
2937
#endif
38+
39+
#if KERNEL_VERSION_NUMBER < 0x030200 /* version 3.2.0 */
3040
#include <net/net_pkt.h>
3141
#include <net/net_if.h>
3242
#include <net/net_ip.h>
@@ -36,6 +46,17 @@
3646
#ifdef CONFIG_ARM_MPU
3747
#include <arch/arm/aarch32/cortex_m/cmsis.h>
3848
#endif
49+
#else /* else of KERNEL_VERSION_NUMBER < 0x030200 */
50+
#include <zephyr/net/net_pkt.h>
51+
#include <zephyr/net/net_if.h>
52+
#include <zephyr/net/net_ip.h>
53+
#include <zephyr/net/net_core.h>
54+
#include <zephyr/net/net_context.h>
55+
56+
#ifdef CONFIG_ARM_MPU
57+
#include <zephyr/arch/arm/aarch32/cortex_m/cmsis.h>
58+
#endif
59+
#endif /* end of KERNEL_VERSION_NUMBER < 0x030200 */
3960

4061
#ifndef BH_PLATFORM_ZEPHYR
4162
#define BH_PLATFORM_ZEPHYR
@@ -96,6 +117,11 @@ double strtod(const char *nptr, char **endptr);
96117
float strtof(const char *nptr, char **endptr);
97118
/* clang-format on */
98119

120+
#if KERNEL_VERSION_NUMBER >= 0x030100 /* version 3.1.0 */
121+
#define BH_HAS_SQRT
122+
#define BH_HAS_SQRTF
123+
#endif
124+
99125
/**
100126
* @brief Allocate executable memroy
101127
*

product-mini/platforms/zephyr/simple/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ endif ()
4242

4343
# Override the global heap usage
4444
if (NOT DEFINED WAMR_BUILD_GLOBAL_HEAP_POOL)
45-
add_definitions (-DWASM_ENABLE_GLOBAL_HEAP_POOL=1)
45+
set (WAMR_BUILD_GLOBAL_HEAP_POOL 1)
4646
endif ()
4747

4848
# Override the global heap size for small devices
4949
if (NOT DEFINED WAMR_BUILD_GLOBAL_HEAP_SIZE)
50-
add_definitions (-DWASM_GLOBAL_HEAP_SIZE=131072) # 128 kB
50+
set (WAMR_BUILD_GLOBAL_HEAP_SIZE 131072) # 128 KB
5151
endif ()
5252

5353
set (WAMR_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../..)

product-mini/platforms/zephyr/simple/src/main.c

-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
#include "test_wasm.h"
1616
#endif /* end of BUILD_TARGET_RISCV64_LP64 || BUILD_TARGET_RISCV32_ILP32 */
1717

18-
#include <zephyr.h>
19-
#include <sys/printk.h>
20-
2118
#if defined(BUILD_TARGET_RISCV64_LP64) || defined(BUILD_TARGET_RISCV32_ILP32)
2219
#if defined(BUILD_TARGET_RISCV64_LP64)
2320
#define CONFIG_GLOBAL_HEAP_BUF_SIZE 4360

0 commit comments

Comments
 (0)