From 1bd417ad683e3bdc90913be42255a217df069d5e Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 27 Nov 2023 10:51:15 +0100 Subject: [PATCH 1/4] fix(cmake): don't add Clang flags not supported in Apple toolchain --- CMakeLists.txt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a033c3d478..153d9e24f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -121,8 +121,10 @@ if(CMAKE_C_COMPILER_ID MATCHES "Clang") list(APPEND compile_options "-Wno-c2x-extensions") # warning on xMPU_SETTINGS for esp32s2 has size 0 for C and 1 for C++ list(APPEND compile_options "-Wno-extern-c-compat") - # warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 - list(APPEND compile_options "-Wno-single-bit-bitfield-constant-conversion") + if(NOT (CONFIG_IDF_TARGET_LINUX AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin")) + # warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 + list(APPEND compile_options "-Wno-single-bit-bitfield-constant-conversion") + endif() endif() # More warnings may exist in unit tests and example projects. From 6f9038809ae5965df199d24dc66c9abfc38457c1 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Thu, 23 Nov 2023 17:01:55 +0100 Subject: [PATCH 2/4] fix(esp_netif): move endian.h to linux component, fix macOS build Co-authored-by: Radek Tandler --- components/esp_netif/CMakeLists.txt | 8 -------- .../esp_netif/linux/stubs/include/machine/endian.h | 8 -------- components/linux/include/machine/endian.h | 11 +++++++++++ 3 files changed, 11 insertions(+), 16 deletions(-) delete mode 100644 components/esp_netif/linux/stubs/include/machine/endian.h create mode 100644 components/linux/include/machine/endian.h diff --git a/components/esp_netif/CMakeLists.txt b/components/esp_netif/CMakeLists.txt index 7c6f04e41b..d1aa21974b 100644 --- a/components/esp_netif/CMakeLists.txt +++ b/components/esp_netif/CMakeLists.txt @@ -1,5 +1,3 @@ -idf_build_get_property(target IDF_TARGET) - set(srcs_lwip "lwip/esp_netif_lwip.c" "lwip/esp_netif_sntp.c" @@ -17,12 +15,6 @@ set(srcs set(include_dirs "include") set(priv_include_dirs "private_include") -idf_build_get_property(target IDF_TARGET) -if(${target} STREQUAL "linux") - list(APPEND include_dirs - "linux/stubs/include") -endif() - if(CONFIG_PPP_SUPPORT) list(APPEND srcs_lwip lwip/esp_netif_lwip_ppp.c lwip/netif/ppp.c) endif() diff --git a/components/esp_netif/linux/stubs/include/machine/endian.h b/components/esp_netif/linux/stubs/include/machine/endian.h deleted file mode 100644 index 120152bdab..0000000000 --- a/components/esp_netif/linux/stubs/include/machine/endian.h +++ /dev/null @@ -1,8 +0,0 @@ -/* - * SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD - * - * SPDX-License-Identifier: Apache-2.0 - */ -#pragma once - -#include_next diff --git a/components/linux/include/machine/endian.h b/components/linux/include/machine/endian.h new file mode 100644 index 0000000000..8f6fe5d458 --- /dev/null +++ b/components/linux/include/machine/endian.h @@ -0,0 +1,11 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ +#pragma once +#if __APPLE__ +#include_next +#else +#include +#endif From b56bb7d8e4ea3f2a20eb39cf65e1dd3a223d0603 Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Mon, 27 Nov 2023 10:44:56 +0100 Subject: [PATCH 3/4] fix(cmake): don't emit section directive when embedding files on host --- tools/cmake/scripts/data_file_embed_asm.cmake | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/cmake/scripts/data_file_embed_asm.cmake b/tools/cmake/scripts/data_file_embed_asm.cmake index 5a86d70335..1cbdb66129 100644 --- a/tools/cmake/scripts/data_file_embed_asm.cmake +++ b/tools/cmake/scripts/data_file_embed_asm.cmake @@ -71,7 +71,9 @@ endif() append_line(" */") append_line(".data") +append_line("#if !defined (__APPLE__) && !defined (__linux__)") append_line(".section .rodata.embedded") +append_line("#endif") make_and_append_identifier("${varname}") make_and_append_identifier("_binary_${varname}_start" "for objcopy compatibility") append("${data}") From c90b6c18c9365e86c50a4cd81cf0f95124ea144e Mon Sep 17 00:00:00 2001 From: Ivan Grokhotkov Date: Tue, 19 Dec 2023 15:10:00 +0100 Subject: [PATCH 4/4] fix(linux): define __assert_func for IDF_TARGET=linux on macOS --- components/linux/CMakeLists.txt | 2 +- components/linux/assert_func.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 components/linux/assert_func.c diff --git a/components/linux/CMakeLists.txt b/components/linux/CMakeLists.txt index e29218d213..c3b72b56bc 100644 --- a/components/linux/CMakeLists.txt +++ b/components/linux/CMakeLists.txt @@ -4,7 +4,7 @@ if(NOT "${target}" STREQUAL "linux") endif() if(CMAKE_HOST_SYSTEM_NAME STREQUAL "Darwin") - list(APPEND srcs getrandom.c) + list(APPEND srcs getrandom.c assert_func.c) endif() idf_component_register(INCLUDE_DIRS include diff --git a/components/linux/assert_func.c b/components/linux/assert_func.c new file mode 100644 index 0000000000..6d2312b487 --- /dev/null +++ b/components/linux/assert_func.c @@ -0,0 +1,23 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include "hal/assert.h" + +// Implementation of __assert_func for macOS. +void __assert_func(const char *file, int line, const char *func, const char *expr) +{ + fprintf(stderr, "assert failed at %s:%d (%s): %s\n", file, line, func, expr); + abort(); +} + +// Defining this symbol as well, since `hal` component will add "-U __assert_func" linker option, +// and symbols are prefixed with an additional underscore on macOS. +// (Can't use __attribute__((alias)) because aliases are not supported on macOS.) +void _assert_func(const char *file, int line, const char *func, const char *expr) +{ + __assert_func(file, line, func, expr); +}