diff --git a/components/console/CMakeLists.txt b/components/console/CMakeLists.txt index 0e188d6f88..684eb69d19 100644 --- a/components/console/CMakeLists.txt +++ b/components/console/CMakeLists.txt @@ -35,13 +35,3 @@ idf_component_register(SRCS ${srcs} PRIV_REQUIRES esp_driver_uart esp_driver_usb_serial_jtag ) - -if(${target} STREQUAL "linux") - # link bsd library for strlcpy - find_library(LIB_BSD bsd) - if(LIB_BSD) - target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD}) - elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.") - endif() -endif() diff --git a/components/console/commands.c b/components/console/commands.c index 7f5cd39c07..a91e4fc337 100644 --- a/components/console/commands.c +++ b/components/console/commands.c @@ -6,10 +6,6 @@ #include #include -#if __has_include() -// for strlcpy -#include -#endif #include #include #include "esp_heap_caps.h" diff --git a/components/console/esp_console_common.c b/components/console/esp_console_common.c index 5c1a95ef04..416976dccb 100644 --- a/components/console/esp_console_common.c +++ b/components/console/esp_console_common.c @@ -1,17 +1,15 @@ /* - * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #include "sdkconfig.h" +#include // __containerof #include "esp_console.h" #include "console_private.h" #include "esp_log.h" #include "linenoise/linenoise.h" -#if CONFIG_IDF_TARGET_LINUX -#include "esp_linux_helper.h" // __containerof -#endif static const char *TAG = "console.common"; diff --git a/components/console/esp_console_repl_linux.c b/components/console/esp_console_repl_linux.c index 7d616e1129..a01d2f8134 100644 --- a/components/console/esp_console_repl_linux.c +++ b/components/console/esp_console_repl_linux.c @@ -12,10 +12,10 @@ #include #include #include +#include #include "sdkconfig.h" #include "esp_log.h" -#include "esp_linux_helper.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" diff --git a/components/esp-tls/esp_tls_error_capture.c b/components/esp-tls/esp_tls_error_capture.c index f91d22773e..67d6ec90cb 100644 --- a/components/esp-tls/esp_tls_error_capture.c +++ b/components/esp-tls/esp_tls_error_capture.c @@ -1,16 +1,13 @@ /* - * SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ +#include #include "esp_tls.h" #include "esp_tls_error_capture_internal.h" -#if CONFIG_IDF_TARGET_LINUX -#include "esp_linux_helper.h" -#endif - typedef struct esp_tls_error_storage { struct esp_tls_last_error parent; /*!< standard esp-tls last error container */ int sock_errno; /*!< last socket error captured in esp-tls */ diff --git a/components/esp_common/CMakeLists.txt b/components/esp_common/CMakeLists.txt index 1f86d92b9e..ba77a6b87f 100644 --- a/components/esp_common/CMakeLists.txt +++ b/components/esp_common/CMakeLists.txt @@ -43,12 +43,3 @@ foreach(req ${optional_reqs}) target_link_libraries(${COMPONENT_LIB} PRIVATE ${req_lib}) endif() endforeach() - -if(${IDF_TARGET} STREQUAL "linux" AND CONFIG_ESP_ERR_TO_NAME_LOOKUP) - find_library(LIB_BSD bsd) - if(LIB_BSD) - target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD}) - elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.") - endif() -endif() diff --git a/components/esp_common/src/esp_err_to_name.c b/components/esp_common/src/esp_err_to_name.c index bf0197f0ed..95d2249f91 100644 --- a/components/esp_common/src/esp_err_to_name.c +++ b/components/esp_common/src/esp_err_to_name.c @@ -7,10 +7,6 @@ //Do not edit this file because it is autogenerated by gen_esp_err_to_name.py #include -#if __has_include() -// for strlcpy -#include -#endif #include "esp_err.h" #if __has_include("soc/soc.h") #include "soc/soc.h" diff --git a/components/esp_common/src/esp_err_to_name.c.in b/components/esp_common/src/esp_err_to_name.c.in index 203f218171..36b40071e4 100644 --- a/components/esp_common/src/esp_err_to_name.c.in +++ b/components/esp_common/src/esp_err_to_name.c.in @@ -7,10 +7,6 @@ @COMMENT@ #include -#if __has_include() -// for strlcpy -#include -#endif #include "esp_err.h" #if __has_include("soc/soc.h") #include "soc/soc.h" diff --git a/components/esp_http_server/CMakeLists.txt b/components/esp_http_server/CMakeLists.txt index af0a5ad559..7f069c877e 100644 --- a/components/esp_http_server/CMakeLists.txt +++ b/components/esp_http_server/CMakeLists.txt @@ -20,12 +20,3 @@ idf_component_register(SRCS "src/httpd_main.c" PRIV_INCLUDE_DIRS ${priv_inc_dir} REQUIRES ${requires} PRIV_REQUIRES ${priv_req}) - -if(${IDF_TARGET} STREQUAL "linux") - find_library(LIB_BSD bsd) - if(LIB_BSD) - target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD}) - elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.") - endif() -endif() diff --git a/components/esp_http_server/src/httpd_parse.c b/components/esp_http_server/src/httpd_parse.c index aceb832f21..3d76380a8b 100644 --- a/components/esp_http_server/src/httpd_parse.c +++ b/components/esp_http_server/src/httpd_parse.c @@ -7,10 +7,6 @@ #include #include -#if __has_include() -// for strlcpy -#include -#endif #include #include #include diff --git a/components/esp_partition/CMakeLists.txt b/components/esp_partition/CMakeLists.txt index 1f0ecb38fb..66693ec127 100644 --- a/components/esp_partition/CMakeLists.txt +++ b/components/esp_partition/CMakeLists.txt @@ -26,14 +26,6 @@ idf_component_register(SRCS "${srcs}" if(${target} STREQUAL "linux") # set BUILD_DIR because partition_linux.c uses a file created in the build directory target_compile_definitions(${COMPONENT_LIB} PRIVATE "BUILD_DIR=\"${build_dir}\"") - - # link bsd library for strlcpy - find_library(LIB_BSD bsd) - if(LIB_BSD) - target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD}) - elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.") - endif() endif() if(CMAKE_C_COMPILER_ID MATCHES "GNU") diff --git a/components/esp_partition/host_test/partition_api_test/main/partition_api_test.c b/components/esp_partition/host_test/partition_api_test/main/partition_api_test.c index 572ed8659b..21ef84f36c 100644 --- a/components/esp_partition/host_test/partition_api_test/main/partition_api_test.c +++ b/components/esp_partition/host_test/partition_api_test/main/partition_api_test.c @@ -7,9 +7,6 @@ */ #include -#if __has_include() -#include -#endif #include #include #include "esp_err.h" diff --git a/components/esp_partition/partition.c b/components/esp_partition/partition.c index 66cc84c2fa..174d1c1f0d 100644 --- a/components/esp_partition/partition.c +++ b/components/esp_partition/partition.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -14,7 +14,7 @@ * should go back to #include "sys/queue.h" once the tests are switched to CMake * see IDF-7000 */ -#if __has_include() +#if __has_include() #include #else #include "sys/queue.h" @@ -33,9 +33,6 @@ #include "bootloader_util.h" #if CONFIG_IDF_TARGET_LINUX -#if __has_include() -#include -#endif #include "esp_private/partition_linux.h" #endif diff --git a/components/esp_partition/partition_linux.c b/components/esp_partition/partition_linux.c index b086e57f65..58d33e05c5 100644 --- a/components/esp_partition/partition_linux.c +++ b/components/esp_partition/partition_linux.c @@ -8,10 +8,6 @@ #include #include #include -#if __has_include() -// for strlcpy -#include -#endif #include #include #include diff --git a/components/linux/CMakeLists.txt b/components/linux/CMakeLists.txt index 0bb5d4918c..7d044d860e 100644 --- a/components/linux/CMakeLists.txt +++ b/components/linux/CMakeLists.txt @@ -14,3 +14,12 @@ endif() idf_component_register(INCLUDE_DIRS ${includes} REQUIRED_IDF_TARGETS linux SRCS ${srcs}) + +if(${IDF_TARGET} STREQUAL "linux") + find_library(LIB_BSD bsd) + if(LIB_BSD) + target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD}) + elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") + message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.") + endif() +endif() diff --git a/components/linux/include/esp_linux_helper.h b/components/linux/include/esp_linux_helper.h index ecc7ec50ae..3ffb4417e0 100644 --- a/components/linux/include/esp_linux_helper.h +++ b/components/linux/include/esp_linux_helper.h @@ -1,10 +1,16 @@ /* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2022-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ #pragma once +/* + * NOTE: This file is deprecated and will be removed in the future. + * Use include sys/cdefs.h instead, it will also include + * the corresponding libbsd header. TODO: IDF-9391 + */ + #ifdef __cplusplus extern "C" { #endif diff --git a/components/linux/linux_include/string.h b/components/linux/linux_include/string.h new file mode 100644 index 0000000000..b59f63c62e --- /dev/null +++ b/components/linux/linux_include/string.h @@ -0,0 +1,15 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * This header file also includes the additional libbsd string.h with functions such as strlcpy(), + * which are present in the ESP-IDF toolchain and on MacOS, but not on Linux. + */ + +#pragma once + +#include +#include_next diff --git a/components/linux/linux_include/sys/cdefs.h b/components/linux/linux_include/sys/cdefs.h new file mode 100644 index 0000000000..2b34193912 --- /dev/null +++ b/components/linux/linux_include/sys/cdefs.h @@ -0,0 +1,22 @@ +/* + * SPDX-FileCopyrightText: 2024 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/* + * This header file adds the libbsd defines of header cdefs.h. + * It also defines __uintptr_t which is still used by older libbsd versions (< 0.11.3) + * but not (or not guaranteed to be) defined on Linux. + */ + +#pragma once + +#include + +// We need a define. We can't typedef here since, depending on the include order, +// uintptr_t may not be defined yet. +#define __uintptr_t uintptr_t + +#include_next +#include diff --git a/components/lwip/port/linux/include/arch/cc.h b/components/lwip/port/linux/include/arch/cc.h index 07d7b73c42..6f013f1f6d 100644 --- a/components/lwip/port/linux/include/arch/cc.h +++ b/components/lwip/port/linux/include/arch/cc.h @@ -25,7 +25,7 @@ #define LWIP_TIMEVAL_PRIVATE 0 #include -#include "esp_linux_helper.h" +#include #define LWIP_ERRNO_INCLUDE diff --git a/components/nvs_flash/CMakeLists.txt b/components/nvs_flash/CMakeLists.txt index 270f37ce49..fd6700978c 100644 --- a/components/nvs_flash/CMakeLists.txt +++ b/components/nvs_flash/CMakeLists.txt @@ -30,13 +30,6 @@ if(${target} STREQUAL "linux") target_compile_options(${COMPONENT_LIB} PUBLIC "-DLINUX_TARGET") target_compile_options(${COMPONENT_LIB} PUBLIC --coverage) target_link_libraries(${COMPONENT_LIB} PUBLIC --coverage) - - find_library(LIB_BSD bsd) - if(LIB_BSD) - target_link_libraries(${COMPONENT_LIB} PRIVATE ${LIB_BSD}) - elseif(NOT CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - message(WARNING "Missing LIBBSD library. Install libbsd-dev package and/or check linker directories.") - endif() else() target_sources(${COMPONENT_LIB} PRIVATE "src/nvs_encrypted_partition.cpp") target_link_libraries(${COMPONENT_LIB} PRIVATE idf::mbedtls)