Skip to content

feat(repo): support compile on PC #11

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

Merged
merged 1 commit into from
Jun 3, 2025
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# ChangeLog

## v0.2.1 - 2025-04-29
## v0.2.1 - 2025-05-30

### Enhancements:

* feat(memory): add C++ global memory allocation
* feat(repo): support compile on PC

## v0.2.0 - 2025-02-07

Expand Down
18 changes: 14 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ set(SRC_DIR ./src)
file(GLOB_RECURSE SRCS_C ${SRC_DIR}/*.c)
file(GLOB_RECURSE SRCS_CPP ${SRC_DIR}/*.cpp)

idf_component_register(
SRCS ${SRCS_C} ${SRCS_CPP}
INCLUDE_DIRS ${SRC_DIR}
)
if(ESP_PLATFORM)
idf_component_register(
SRCS ${SRCS_C} ${SRCS_CPP}
INCLUDE_DIRS ${SRC_DIR}
)
else()
set(COMPONENT_LIB esp-lib-utils)
add_library(${COMPONENT_LIB} STATIC ${SRCS_C} ${SRCS_CPP})
target_include_directories(${COMPONENT_LIB} PUBLIC ${SRC_DIR})
endif()

target_compile_options(${COMPONENT_LIB}
PUBLIC
-Wno-missing-field-initializers
PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-std=gnu++20>
)

if(NOT ESP_PLATFORM)
target_compile_definitions(${COMPONENT_LIB} PUBLIC ESP_UTILS_KCONFIG_IGNORE)
endif()
8 changes: 8 additions & 0 deletions src/check/esp_utils_check.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#if defined(ESP_PLATFORM)
#include "esp_err.h"
#endif
#include "esp_utils_conf_internal.h"
#include "log/esp_utils_log.h"

Expand Down Expand Up @@ -91,6 +93,7 @@
} \
} while(0)

#if defined(ESP_PLATFORM)
/**
* @brief Check if the value is not `ESP_OK`; if not, return the specified value.
*
Expand Down Expand Up @@ -132,6 +135,7 @@
return; \
} \
} while(0)
#endif // ESP_PLATFORM

/**
* The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1`
Expand Down Expand Up @@ -281,6 +285,7 @@
} \
} while(0)

#if defined(ESP_PLATFORM)
/**
* @brief Check if the value is not `ESP_OK`; if not, log an error and return the specified value.
*
Expand Down Expand Up @@ -327,6 +332,7 @@
return; \
} \
} while(0)
#endif // ESP_PLATFORM

/**
* The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1`
Expand Down Expand Up @@ -408,6 +414,7 @@
} while (0)
#define ESP_UTILS_CHECK_FALSE_EXIT(x, ...) assert(x)

#if defined(ESP_PLATFORM)
#define ESP_UTILS_CHECK_ERROR_RETURN(x, ...) assert((x) == ESP_OK)
#define ESP_UTILS_CHECK_ERROR_GOTO(x, goto_tag, ...) do { \
assert((x) == ESP_OK); \
Expand All @@ -417,6 +424,7 @@
} \
} while (0)
#define ESP_UTILS_CHECK_ERROR_EXIT(x, ...) assert((x) == ESP_OK)
#endif // ESP_PLATFORM

/**
* The `try {} catch {}` block is only available in C++ and `CONFIG_COMPILER_CXX_EXCEPTIONS = 1`
Expand Down
2 changes: 0 additions & 2 deletions src/esp_utils_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

#pragma once

#include "sdkconfig.h"

/**
* @brief Macros for check handle method
*/
Expand Down
4 changes: 4 additions & 0 deletions src/memory/allocation/esp_utils_mem_esp.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
#pragma once

#if defined(ESP_PLATFORM)

#include "esp_heap_caps.h"

#if ESP_UTILS_MEM_ALLOC_ESP_CAPS == ESP_UTILS_MEM_ALLOC_ESP_CAPS_DEFAULT
Expand All @@ -23,3 +25,5 @@

#define MALLOC(x) heap_caps_aligned_alloc(ESP_UTILS_MEM_ALLOC_ESP_ALIGN, x, MEM_CAPS)
#define FREE(x) heap_caps_free(x)

#endif // ESP_PLATFORM
4 changes: 4 additions & 0 deletions src/memory/esp_utils_mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#if defined(ESP_PLATFORM)

#include "esp_heap_caps.h"
#include "check/esp_utils_check.h"
#include "log/esp_utils_log.h"
Expand Down Expand Up @@ -32,3 +34,5 @@ bool esp_utils_mem_print_info(void)

return true;
}

#endif // ESP_PLATFORM
5 changes: 4 additions & 1 deletion src/memory/esp_utils_mem.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#include <stdbool.h>
#include <stdlib.h>
#include "sdkconfig.h"
#include "esp_utils_mem_general.h"
#include "esp_utils_mem_cxx_global.h"
#ifdef __cplusplus
Expand All @@ -16,6 +15,8 @@
extern "C" {
#endif

#if defined(ESP_PLATFORM)

/**
* @brief Print memory information to the console
*
Expand All @@ -27,6 +28,8 @@ extern "C" {
*/
bool esp_utils_mem_print_info(void);

#endif // ESP_PLATFORM

#ifdef __cplusplus
}
#endif
4 changes: 2 additions & 2 deletions src/memory/esp_utils_mem_cxx_general.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <map>
#include <unordered_map>
#include <vector>
#include "sdkconfig.h"
#include "esp_utils_conf_internal.h"
#include "esp_utils_mem_general.h"

namespace esp_utils {
Expand All @@ -34,7 +34,7 @@ struct GeneralMemoryAllocator {
return nullptr;
}
void *ptr = esp_utils_mem_gen_malloc(n * sizeof(T));
#if CONFIG_COMPILER_CXX_EXCEPTIONS
#if !defined(ESP_PLATFORM) || CONFIG_COMPILER_CXX_EXCEPTIONS
if (ptr == nullptr) {
throw std::bad_alloc();
}
Expand Down
4 changes: 2 additions & 2 deletions src/memory/esp_utils_mem_cxx_global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void *operator new (std::size_t size)
}

ptr = MALLOC(size);
#if CONFIG_COMPILER_CXX_EXCEPTIONS
#if !defined(ESP_PLATFORM) || CONFIG_COMPILER_CXX_EXCEPTIONS
if (!ptr) {
throw std::bad_alloc();
}
Expand All @@ -51,7 +51,7 @@ void *operator new[](std::size_t size)
}

ptr = MALLOC(size);
#if CONFIG_COMPILER_CXX_EXCEPTIONS
#if !defined(ESP_PLATFORM) || CONFIG_COMPILER_CXX_EXCEPTIONS
if (!ptr) {
throw std::bad_alloc();
}
Expand Down
1 change: 1 addition & 0 deletions src/memory/esp_utils_mem_cxx_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
#pragma once

#include <stdbool.h>
#include "esp_utils_conf_internal.h"

#if ESP_UTILS_CONF_MEM_ENABLE_CXX_GLOB_ALLOC
Expand Down
Loading