From 944f2974bf72fa8a7692143d6a2ec2d460cd1a06 Mon Sep 17 00:00:00 2001 From: Sam Clegg Date: Wed, 15 Jan 2025 08:23:40 -0800 Subject: [PATCH] Fix compat between libc++ and emscripten's xlocale.h libc++ was assuming that musl doesn't have `xlocale.h` which is true, but emscripten adds xlocale.h for compatibility (I'm not sure we really need to, but we do). Fixes: #23413 --- system/lib/libcxx/include/__locale_dir/locale_base_api.h | 6 +++--- test/other/test_xlocale.c | 5 +++++ test/test_other.py | 1 + 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/system/lib/libcxx/include/__locale_dir/locale_base_api.h b/system/lib/libcxx/include/__locale_dir/locale_base_api.h index 8c000c558c527..242441e22b7f5 100644 --- a/system/lib/libcxx/include/__locale_dir/locale_base_api.h +++ b/system/lib/libcxx/include/__locale_dir/locale_base_api.h @@ -9,7 +9,9 @@ #ifndef _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H #define _LIBCPP___LOCALE_DIR_LOCALE_BASE_API_H -#if defined(_LIBCPP_MSVCRT_LIKE) +#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__EMSCRIPTEN__) +# include +#elif defined(_LIBCPP_MSVCRT_LIKE) # include <__locale_dir/locale_base_api/win32.h> #elif defined(_AIX) || defined(__MVS__) # include <__locale_dir/locale_base_api/ibm.h> @@ -25,8 +27,6 @@ # include <__locale_dir/locale_base_api/fuchsia.h> #elif defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC) # include <__locale_dir/locale_base_api/musl.h> -#elif defined(__APPLE__) || defined(__FreeBSD__) -# include #endif #if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) diff --git a/test/other/test_xlocale.c b/test/other/test_xlocale.c index ebe2ec6d98d64..da327c9a09382 100644 --- a/test/other/test_xlocale.c +++ b/test/other/test_xlocale.c @@ -1,3 +1,8 @@ +#ifdef __cplusplus +// Test compatibility with libc++'s locale header +#include +#endif + #include #include diff --git a/test/test_other.py b/test/test_other.py index 0948eff60741b..754b0f35a6b9b 100644 --- a/test/test_other.py +++ b/test/test_other.py @@ -14279,6 +14279,7 @@ def test_prejs_unicode(self): def test_xlocale(self): # Test for xlocale.h compatibility header self.do_other_test('test_xlocale.c') + self.do_other_test('test_xlocale.c', emcc_args=['-x', 'c++']) def test_print_map(self): self.run_process([EMCC, '-c', test_file('hello_world.c')])