Skip to content
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

[cpp] support rt-thread CPP wrapper sub-switch macros #7660

Merged
merged 2 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion bsp/k210/drivers/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ if GetDepend('RT_USING_PWM'):
if GetDepend('RT_USING_WDT'):
src += ['drv_wdt.c']

group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH)
group = DefineGroup('Drivers', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES=['NNCASE_NO_EXCEPTIONS'])
Copy link
Member

Choose a reason for hiding this comment

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

这个是啥,怎么在这个pr里

Copy link
Member

Choose a reason for hiding this comment

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

不使用c++ exception 降低资源开销


objs = [group]

Expand Down
10 changes: 9 additions & 1 deletion components/libc/cplusplus/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@ menuconfig RT_USING_CPLUSPLUS
if RT_USING_CPLUSPLUS

config RT_USING_CPLUSPLUS11
bool "Enable c++11 threading feature support"
bool "Enable C++11 standard multi-threading feature support"
default n
select RT_USING_POSIX_FS
select RT_USING_POSIX_STDIO
select RT_USING_PTHREADS
select RT_USING_RTC

config RT_USING_CPP_WRAPPER
bool "Enable RT-Thread APIs C++ wrapper"
default n

config RT_USING_CPP_EXCEPTIONS
bool "Enable C++ exceptions (will increase overhead)"
default n

endif
27 changes: 14 additions & 13 deletions components/libc/cplusplus/SConscript
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
# RT-Thread building script for component

from building import *
import os
Import('rtconfig')

cwd = GetCurrentDir()
src = Glob('*.cpp') + Glob('*.c')
cwd = GetCurrentDir()
src = ['cxx_crt_init.c', 'cxx_crt.cpp']
CPPPATH = [cwd]
CXXFLAGS = ''


if rtconfig.PLATFORM in ['gcc', 'armclang', 'llvm-arm'] and not GetDepend('RT_USING_CPP_EXCEPTIONS'):
CXXFLAGS += ' -fno-exceptions -fno-rtti -ffunction-sections -fdata-sections -Wl,--gc-sections' # reduce resource consumptions

if GetDepend('RT_USING_CPLUSPLUS11'):
src += Glob('cpp11/*.cpp') + Glob('cpp11/*.c')
if rtconfig.PLATFORM in ['armclang']:
src += Glob('cpp11/armclang/*.cpp') + Glob('cpp11/armclang/*.c')
CPPPATH += [cwd + '/cpp11/armclang']
elif rtconfig.PLATFORM in ['gcc']:
src += Glob('cpp11/gcc/*.cpp') + Glob('cpp11/gcc/*.c')
CPPPATH += [cwd + '/cpp11/gcc']
group = DefineGroup('CPP', src, depend=['RT_USING_CPLUSPLUS'], CPPPATH=CPPPATH, CXXFLAGS=CXXFLAGS)

group = DefineGroup('CPlusPlus', src, depend = ['RT_USING_CPLUSPLUS'], CPPPATH = CPPPATH)
list = os.listdir(cwd)
for d in list:
path = os.path.join(cwd, d)
if os.path.isfile(os.path.join(path, 'SConscript')):
group = group + SConscript(os.path.join(d, 'SConscript'))

Return('group')
18 changes: 18 additions & 0 deletions components/libc/cplusplus/cpp11/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from building import *
Import('rtconfig')

cwd = GetCurrentDir()
src = []
CPPPATH = []

src += Glob('*.cpp') + Glob('*.c')
if rtconfig.PLATFORM in ['armclang']:
src += Glob('armclang/*.cpp') + Glob('armclang/*.c')
CPPPATH += [cwd + '/armclang']
elif rtconfig.PLATFORM in ['gcc']:
src += Glob('gcc/*.cpp') + Glob('gcc/*.c')
CPPPATH += [cwd + '/gcc']

group = DefineGroup('CPP', src, depend=['RT_USING_CPLUSPLUS11'], CPPPATH=CPPPATH)

Return('group')
4 changes: 1 addition & 3 deletions components/libc/cplusplus/cpp11/gcc/__utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@

#include <rtthread.h>

#define RT_USING_CPP_EXCEPTION

inline void throw_system_error(int err, const char *what_msg)
{
#ifdef RT_USING_CPP_EXCEPTION
#ifdef RT_USING_CPP_EXCEPTIONS
throw std::system_error(std::error_code(err, std::system_category()), what_msg);
#else
(void)err;
Expand Down
8 changes: 8 additions & 0 deletions components/libc/cplusplus/os/SConscript
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from building import *

cwd = GetCurrentDir()
src = Glob('*.cpp')
CPPPATH = [cwd]
group = DefineGroup('CPP', src, depend=['RT_USING_CPP_WRAPPER'], CPPPATH=CPPPATH)

Return('group')