Skip to content

Commit 65ccd3a

Browse files
committed
tests: riscv: Add test to verify C++ compilation
Using clang to build for RISC-V with these configs: CONFIG_CPP=y CONFIG_USERSPACE=n CONFIG_SMP=n CONFIG_FPU_SHARING=n results in the following warnings: include/zephyr/arch/riscv/structs.h:11:1: error: empty struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat] 11 | struct _cpu_arch { | ^ include/zephyr/arch/riscv/thread.h:68:1: error: empty struct has size 0 in C, size 1 in C++ [-Werror,-Wextern-c-compat] 68 | struct _thread_arch { | ^ This commit adds a test with those configs to verify compilation succeeds. Although gcc doesn't emit these warnings, we can test with gcc as well with a BUILD_ASSERT in include/zephyr/arch/riscv/thread.h and include/zephyr/arch/riscv/structs.h. Signed-off-by: Tom Hughes <[email protected]>
1 parent da49c93 commit 65ccd3a

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 Google Inc.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(test_build_cpp)
7+
8+
FILE(GLOB app_sources src/*.cpp)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Copyright 2025 Google LLC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_CPP=y
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* Copyright (c) 2025 Google
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#include <zephyr/toolchain.h>
7+
8+
BUILD_ASSERT(CONFIG_CPP, "C++ must be enabled");
9+
10+
int main(void)
11+
{
12+
return 0;
13+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright (c) 2025 Google LLC
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
tests:
5+
# Verify struct _cpu_arch struct _thread_arch are compatible with C++
6+
# when specific configs are enabled.
7+
arch.riscv.test_build_cpp:
8+
build_only: true
9+
tags:
10+
- riscv
11+
arch_allow: riscv
12+
extra_configs:
13+
- CONFIG_USERSPACE=n
14+
- CONFIG_SMP=n
15+
- CONFIG_FPU_SHARING=n

0 commit comments

Comments
 (0)