diff --git a/libcxx/include/__config b/libcxx/include/__config --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -10,6 +10,35 @@ #ifndef _LIBCPP_CONFIG #define _LIBCPP_CONFIG +// 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. +#if defined(__NuttX__) +#undef __linux__ +#undef __APPLE__ +#undef __FreeBSD__ +#undef __GLIBC__ +#undef __NetBSD__ +#undef _WIN32 +#undef __sun__ +#undef _AIX +// For the current use of the __unix__ macro in this library, +// NuttX is not __unix__. +// This might need to be revisited in future. +#undef __unix__ +#endif + #if defined(_MSC_VER) && !defined(__clang__) # if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) # define _LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER @@ -1125,6 +1154,7 @@ # if defined(__FreeBSD__) || \ defined(__wasi__) || \ defined(__NetBSD__) || \ + defined(__NuttX__) || \ defined(__linux__) || \ defined(__GNU__) || \ defined(__APPLE__) || \ @@ -1227,7 +1257,7 @@ # endif #endif -#if defined(__BIONIC__) || defined(__CloudABI__) || \ +#if defined(__BIONIC__) || defined(__CloudABI__) || defined(__NuttX__) || \ defined(__Fuchsia__) || defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC) #define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE #endif diff --git a/libcxx/include/__locale b/libcxx/include/__locale --- a/libcxx/include/__locale +++ b/libcxx/include/__locale @@ -21,6 +21,8 @@ #if defined(_LIBCPP_MSVCRT_LIKE) # include # include +#elif defined(__NuttX__) +# include #elif defined(_AIX) # include #elif defined(__ANDROID__) diff --git a/libcxx/include/support/nuttx/xlocale.h b/libcxx/include/support/nuttx/xlocale.h new file mode 100644 --- /dev/null +++ b/libcxx/include/support/nuttx/xlocale.h @@ -0,0 +1,18 @@ +// -*- C++ -*- +//===-------------------- support/nuttx/xlocale.h -------------------------===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef _LIBCPP_SUPPORT_NUTTX_XLOCALE_H +#define _LIBCPP_SUPPORT_NUTTX_XLOCALE_H + +#if defined(__NuttX__) +#include +#include +#endif // __NuttX__ + +#endif diff --git a/libcxx/src/include/config_elast.h b/libcxx/src/include/config_elast.h --- a/libcxx/src/include/config_elast.h +++ b/libcxx/src/include/config_elast.h @@ -17,10 +17,14 @@ #include #endif +// Note: _LIBCPP_ELAST needs to be defined only on platforms +// where strerror/strerror_r can't handle out-of-range errno values. #if defined(ELAST) #define _LIBCPP_ELAST ELAST #elif defined(_NEWLIB_VERSION) #define _LIBCPP_ELAST __ELASTERROR +#elif defined(__NuttX__) +// No _LIBCPP_ELAST needed on NuttX #elif defined(__Fuchsia__) // No _LIBCPP_ELAST needed on Fuchsia #elif defined(__wasi__) diff --git a/libcxx/src/locale.cpp b/libcxx/src/locale.cpp --- a/libcxx/src/locale.cpp +++ b/libcxx/src/locale.cpp @@ -30,7 +30,7 @@ #include "__sso_allocator" #if defined(_LIBCPP_MSVCRT) || defined(__MINGW32__) #include "support/win32/locale_win32.h" -#elif !defined(__BIONIC__) +#elif !defined(__BIONIC__) && !defined(__NuttX__) #include #endif #include