This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 5e96e72cb6 X86_64: Add libcxx availability macros.
5e96e72cb6 is described below

commit 5e96e72cb6d59d4c17972cb7fa6397cf59ccc86e
Author: cuiziwei <[email protected]>
AuthorDate: Mon Apr 1 14:09:54 2024 +0800

    X86_64: Add libcxx availability macros.
    
    Signed-off-by: cuiziwei <[email protected]>
---
 arch/x86_64/src/common/Toolchain.defs | 36 +++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/arch/x86_64/src/common/Toolchain.defs 
b/arch/x86_64/src/common/Toolchain.defs
index b8e19bbf48..879e5818b2 100644
--- a/arch/x86_64/src/common/Toolchain.defs
+++ b/arch/x86_64/src/common/Toolchain.defs
@@ -18,6 +18,25 @@
 #
 ############################################################################
 
+# NuttX is sometimes built as a native target.
+# In that case, the __NuttX__ macro is predefined by the compiler.
+# https://github.com/NuttX/buildroot
+#
+# In other cases, __NuttX__ is an ordinary user-definded macro.
+# It's especially the case for NuttX sim, which is a target to run
+# the entire NuttX as a program on the host OS, which can be Linux,
+# macOS, Windows, etc.
+# https://cwiki.apache.org/confluence/display/NUTTX/NuttX+Simulation
+# In that case, the host OS compiler is used to build NuttX.
+# Thus, eg. NuttX sim on macOS is built with __APPLE__.
+# We #undef predefined macros for those possible host OSes here
+# because the OS APIs this library should use are of NuttX,
+# not the host OS.
+
+ARCHDEFINES += -U_AIX -U_WIN32 -U__APPLE__ -U__FreeBSD__
+ARCHDEFINES += -U__NetBSD__ -U__linux__ -U__sun__ -U__unix__
+ARCHDEFINES += -U__ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__
+
 ifeq ($(CONFIG_DEBUG_SYMBOLS),y)
   ARCHOPTIMIZATION = $(CONFIG_DEBUG_SYMBOLS_LEVEL)
 endif
@@ -58,6 +77,23 @@ ifeq ($(CONFIG_DEBUG_LINK_WHOLE_ARCHIVE),y)
   LDFLAGS += --whole-archive
 endif
 
+ifeq ($(CONFIG_LIBCXX),y)
+  # Linux C++ ABI seems vary.
+  # Probably __GLIBCXX__ is the best bet.
+  # XXX what to do for windows?
+
+  CXXFLAGS += -D__GLIBCXX__
+
+  # Disable availability macros.
+  # The availability on Host OS is not likely appropriate for NuttX.
+  #
+  # Note: When compiling NuttX apps, we undefine __APPLE__.
+  # It makes libcxx __availability header unhappy.
+  # 
https://github.com/llvm/llvm-project/blob/2e2999cd44f6ec9a5e396fa0113497ea82582f69/libcxx/include/__availability#L258
+
+  CXXFLAGS += -D_LIBCPP_DISABLE_AVAILABILITY
+endif
+
 CC = $(CROSSDEV)gcc
 CPP = $(CROSSDEV)gcc -E -x c
 LD = $(CROSSDEV)ld

Reply via email to