From 2046760e71d3cb1880c372b545d037222026ee9c Mon Sep 17 00:00:00 2001 From: David Brown Date: Fri, 26 Jul 2024 08:48:22 -0600 Subject: [PATCH] include: Add dummy field for Rust as well as CPP For CPP builds, a few structs that end up empty in some configurations will generate compile errors. With the Rust tools, bindgen ends up producing empty structsw for these as well. Although the code compiles, it generates warnings. For now, add CONFIG_RUST to the ifdef checks so that these structs don't end up empty with Rust either. Signed-off-by: David Brown --- include/zephyr/kernel/thread.h | 2 +- include/zephyr/spinlock.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/zephyr/kernel/thread.h b/include/zephyr/kernel/thread.h index fd8e4c02f235e8..45c8164001fbb1 100644 --- a/include/zephyr/kernel/thread.h +++ b/include/zephyr/kernel/thread.h @@ -237,7 +237,7 @@ typedef struct k_thread_runtime_stats { uint64_t idle_cycles; #endif /* CONFIG_SCHED_THREAD_USAGE_ALL */ -#if defined(__cplusplus) && !defined(CONFIG_SCHED_THREAD_USAGE) && \ +#if (defined(__cplusplus) || CONFIG_RUST) && !defined(CONFIG_SCHED_THREAD_USAGE) && \ !defined(CONFIG_SCHED_THREAD_USAGE_ANALYSIS) && !defined(CONFIG_SCHED_THREAD_USAGE_ALL) /* If none of the above Kconfig values are defined, this struct will have a size 0 in C * which is not allowed in C++ (it'll have a size 1). To prevent this, we add a 1 byte dummy diff --git a/include/zephyr/spinlock.h b/include/zephyr/spinlock.h index 451e91cbd54756..452c57e95ca0cf 100644 --- a/include/zephyr/spinlock.h +++ b/include/zephyr/spinlock.h @@ -78,7 +78,7 @@ struct k_spinlock { #endif /* CONFIG_SPIN_LOCK_TIME_LIMIT */ #endif /* CONFIG_SPIN_VALIDATE */ -#if defined(CONFIG_CPP) && !defined(CONFIG_SMP) && \ +#if (defined(CONFIG_CPP) || defined(CONFIG_RUST)) && !defined(CONFIG_SMP) && \ !defined(CONFIG_SPIN_VALIDATE) /* If CONFIG_SMP and CONFIG_SPIN_VALIDATE are both not defined * the k_spinlock struct will have no members. The result