mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
pkg/etl: Add the embedded template library (etl)
This commit is contained in:
parent
07a4756242
commit
01f502b753
@ -20,6 +20,7 @@ rsource "emlearn/Kconfig"
|
||||
rsource "esp32_sdk/Kconfig"
|
||||
rsource "esp32_sdk_libs/Kconfig"
|
||||
rsource "esp8266_sdk/Kconfig"
|
||||
rsource "etl/Kconfig"
|
||||
rsource "fff/Kconfig"
|
||||
rsource "gecko_sdk/Kconfig"
|
||||
rsource "gemmlowp/Kconfig"
|
||||
|
16
pkg/etl/Kconfig
Normal file
16
pkg/etl/Kconfig
Normal file
@ -0,0 +1,16 @@
|
||||
# Copyright (c) 2022 Jens Wetterich <jens@wetterich-net.de>
|
||||
#
|
||||
# This file is subject to the terms and conditions of the GNU Lesser
|
||||
# General Public License v2.1. See the file LICENSE in the top level
|
||||
# directory for more details.
|
||||
#
|
||||
|
||||
config PACKAGE_ETL
|
||||
bool "Embedded Template Library"
|
||||
depends on TEST_KCONFIG
|
||||
depends on HAS_CPP
|
||||
select MODULE_CPP
|
||||
help
|
||||
This is a drop-in replacement for the C++ standard library with fixed-size containers.
|
||||
It does not rely on dynamic memory. It also provides type-traits for boards without standard library.
|
||||
See the website for more details.
|
9
pkg/etl/Makefile
Normal file
9
pkg/etl/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
PKG_NAME=etl
|
||||
PKG_URL=https://github.com/ETLCPP/etl
|
||||
PKG_VERSION=734df1a3725f9eeab3048a2a18cb84e3a82fbd8f # v20.24.1
|
||||
PKG_LICENSE=MIT
|
||||
|
||||
include $(RIOTBASE)/pkg/pkg.mk
|
||||
|
||||
all:
|
||||
@:
|
1
pkg/etl/Makefile.dep
Normal file
1
pkg/etl/Makefile.dep
Normal file
@ -0,0 +1 @@
|
||||
FEATURES_REQUIRED += cpp
|
35
pkg/etl/Makefile.include
Normal file
35
pkg/etl/Makefile.include
Normal file
@ -0,0 +1,35 @@
|
||||
INCLUDES += -I$(PKGDIRBASE)/etl/include
|
||||
INCLUDES += -I$(RIOTPKG)/etl/config
|
||||
|
||||
# There's nothing to build in this package, it's used as a header only library.
|
||||
# So it's declared as a pseudo-module
|
||||
PSEUDOMODULES += etl
|
||||
|
||||
# Activate the usage of libstdcpp types and features if available
|
||||
# This prevents unnecessary reimplementations
|
||||
ifneq (,$(filter libstdcpp,$(FEATURES_USED)))
|
||||
CXXEXFLAGS += -DFEATURE_LIBSTDCPP
|
||||
# Kconfig alternative
|
||||
else ifdef CONFIG_KCONFIG_HAS_LIBSTDCPP
|
||||
CXXEXFLAGS += -DFEATURE_LIBSTDCPP
|
||||
endif
|
||||
|
||||
# Some boards don't provide NAN or by default don't define limits like UINT8_MAX in CPP context
|
||||
# This activates the appropriate workarounds
|
||||
ifneq (,$(filter arch_avr8,$(FEATURES_USED)))
|
||||
CXXEXFLAGS += -DNO_CPP_NAN_SUPPORT
|
||||
CXXEXFLAGS += -D__STDC_LIMIT_MACROS
|
||||
else ifneq (,$(filter arch_riscv,$(FEATURES_USED)))
|
||||
CXXEXFLAGS += -DNO_CPP_NAN_SUPPORT
|
||||
CXXEXFLAGS += -D__STDC_LIMIT_MACROS
|
||||
# Kconfig alternatives
|
||||
else ifdef CONFIG_CPU_ARCH_AVR8
|
||||
CXXEXFLAGS += -DNO_CPP_NAN_SUPPORT
|
||||
CXXEXFLAGS += -D__STDC_LIMIT_MACROS
|
||||
else ifdef CONFIG_CPU_ARCH_RISCV
|
||||
CXXEXFLAGS += -DNO_CPP_NAN_SUPPORT
|
||||
CXXEXFLAGS += -D__STDC_LIMIT_MACROS
|
||||
endif
|
||||
|
||||
# Some compilers generate this warning. Due to -Werror it prevents this header-only library from compiling when included
|
||||
CXXEXFLAGS += -Wno-unused-function
|
54
pkg/etl/config/etl_profile.h
Normal file
54
pkg/etl/config/etl_profile.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Jens Wetterich <jens@wetterich-net.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup pkg_etl
|
||||
* @brief
|
||||
* @{
|
||||
*
|
||||
* @file
|
||||
* @brief Common settings for etl
|
||||
* @details This activates the usage of the STL if available and/or the usage of
|
||||
workarounds for missing NAN macros.
|
||||
* This is configured by compiler defines the in Makefile.include
|
||||
* @author Jens Wetterich <jens@wetterich-net.de>
|
||||
*/
|
||||
#ifndef ETL_PROFILE_H
|
||||
#define ETL_PROFILE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef FEATURE_LIBSTDCPP
|
||||
/**
|
||||
* @internal
|
||||
* @brief Deactivate the usage of the stdlib in ETL
|
||||
*/
|
||||
#define ETL_NO_STL
|
||||
#endif
|
||||
|
||||
#ifdef NO_CPP_NAN_SUPPORT
|
||||
/**
|
||||
* @internal
|
||||
* @brief Activate the ETL workarounds when NAN macros are not supported
|
||||
*/
|
||||
#define ETL_NO_CPP_NAN_SUPPORT
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @internal
|
||||
* @brief Activate the checking of bounds in push and pop operations in ETL containers
|
||||
*/
|
||||
#define ETL_CHECK_PUSH_POP
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* ETL_PROFILE_H */
|
||||
/** @} */
|
12
pkg/etl/doc.txt
Normal file
12
pkg/etl/doc.txt
Normal file
@ -0,0 +1,12 @@
|
||||
/**
|
||||
* @defgroup pkg_etl Embedded Template Library
|
||||
* @ingroup cpp
|
||||
* @ingroup pkg
|
||||
* @brief Embedded Template Library (etl)
|
||||
* @details This is a drop-in replacement for the C++ standard library with fixed-size containers.
|
||||
* It does not rely on dynamic memory. It also provides type-traits for boards without standard library.
|
||||
* See the website for more details.
|
||||
*
|
||||
* @see https://www.etlcpp.com
|
||||
* @see https://github.com/ETLCPP/etl
|
||||
*/
|
9
tests/pkg_etl/Makefile
Normal file
9
tests/pkg_etl/Makefile
Normal file
@ -0,0 +1,9 @@
|
||||
include ../Makefile.tests_common
|
||||
USEPKG += etl
|
||||
|
||||
# Kconfig build is broken due to invalid module resolution with Kconfig for this board
|
||||
BOARD_BLACKLIST := \
|
||||
6lowpan-clicker \
|
||||
#
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
5
tests/pkg_etl/Makefile.ci
Normal file
5
tests/pkg_etl/Makefile.ci
Normal file
@ -0,0 +1,5 @@
|
||||
BOARD_INSUFFICIENT_MEMORY := \
|
||||
nucleo-l011k4 \
|
||||
stm32f030f4-demo \
|
||||
samd10-xmini \
|
||||
#
|
1
tests/pkg_etl/app.config.test
Normal file
1
tests/pkg_etl/app.config.test
Normal file
@ -0,0 +1 @@
|
||||
CONFIG_PACKAGE_ETL=y
|
64
tests/pkg_etl/main.cpp
Normal file
64
tests/pkg_etl/main.cpp
Normal file
@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) 2022 Jens Wetterich <jens@wetterich-net.de>
|
||||
*
|
||||
* This file is subject to the terms and conditions of the GNU Lesser
|
||||
* General Public License v2.1. See the file LICENSE in the top level
|
||||
* directory for more details.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @ingroup tests
|
||||
* @{
|
||||
* @file
|
||||
* @brief Unit test to test the usage of @ref pkg_etl package
|
||||
* @author Jens Wetterich <jens@wetterich-net.de>
|
||||
*/
|
||||
#include "etl/string.h"
|
||||
#include "etl/to_string.h"
|
||||
#include "etl/type_traits.h"
|
||||
#include "etl/vector.h"
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
puts("Testing etl");
|
||||
|
||||
/* Create test string */
|
||||
etl::string<100> teststr = "Test: is_same: ";
|
||||
|
||||
/* Append some type_trait tests */
|
||||
etl::to_string(etl::is_same<bool, bool>::value, teststr, true);
|
||||
teststr += ", is_unsigned: ";
|
||||
etl::to_string(etl::is_unsigned<int>::value, teststr, true);
|
||||
teststr += ", vector: ";
|
||||
|
||||
/* Do some vector testing and append to the string */
|
||||
etl::vector<char, 5> testvec;
|
||||
testvec.push_back('a');
|
||||
testvec.push_back('b');
|
||||
testvec.clear();
|
||||
testvec.push_back('c');
|
||||
testvec.push_back('d');
|
||||
testvec.push_back('e');
|
||||
testvec.push_back('a');
|
||||
testvec.push_back('b');
|
||||
teststr += testvec[0];
|
||||
teststr += testvec[1];
|
||||
teststr += testvec[2];
|
||||
teststr += testvec[3];
|
||||
teststr += testvec[4];
|
||||
teststr += ", size: ";
|
||||
|
||||
/* Test string size */
|
||||
etl::to_string(teststr.size(), teststr, true);
|
||||
|
||||
/* Test string compare */
|
||||
if (teststr == "Test: is_same: 1, is_unsigned: 0, vector: cdeab, size: 55") {
|
||||
teststr += " -> valid";
|
||||
} else {
|
||||
teststr += " -> false";
|
||||
}
|
||||
|
||||
puts(teststr.c_str());
|
||||
return 0;
|
||||
}
|
||||
/** @} */
|
19
tests/pkg_etl/tests/01-run.py
Executable file
19
tests/pkg_etl/tests/01-run.py
Executable file
@ -0,0 +1,19 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
# Copyright (C) 2022 Jens Wetterich <jens@wetterich-net.de>
|
||||
#
|
||||
# This file is subject to the terms and conditions of the GNU Lesser
|
||||
# General Public License v2.1. See the file LICENSE in the top level
|
||||
# directory for more details.
|
||||
|
||||
import sys
|
||||
from testrunner import run
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
child.expect_exact("Test: is_same: 1, is_unsigned: 0, vector: cdeab, size: 55 -> valid")
|
||||
print("All tests successful")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(run(testfunc, timeout=1, echo=True, traceback=True))
|
Loading…
Reference in New Issue
Block a user