[libc-commits] [libc] [libc][MacOS] Enable wchar conversion and rpc_server (PR #191065)

Michael Jones via libc-commits libc-commits at lists.llvm.org
Wed Apr 8 15:15:17 PDT 2026


https://github.com/michaelrj-google created https://github.com/llvm/llvm-project/pull/191065

Originally the wchar conversion was disabled due to MacOS not providing
uchar.h. We only needed it for char32_t so this PR just provides it
directly from our headers on MacOS. This also fixes fwrite_unlocked not
being available on MacOS which is needed for rpc_server.h.


>From e75f23a5600ef37eaecf35a96d352a5286395c56 Mon Sep 17 00:00:00 2001
From: Michael Jones <michaelrj at google.com>
Date: Wed, 8 Apr 2026 22:13:21 +0000
Subject: [PATCH] [libc][MacOS] Enable wchar conversion and rpc_server

Originally the wchar conversion was disabled due to MacOS not providing
uchar.h. We only needed it for char32_t so this PR just provides it
directly from our headers on MacOS. This also fixes fwrite_unlocked not
being available on MacOS which is needed for rpc_server.h.
---
 libc/hdr/types/char32_t.h              | 7 ++++++-
 libc/shared/rpc_server.h               | 4 ++++
 libc/src/__support/CMakeLists.txt      | 8 ++------
 libc/test/src/__support/CMakeLists.txt | 8 ++------
 4 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/libc/hdr/types/char32_t.h b/libc/hdr/types/char32_t.h
index 94fe5747d3415..df629d44edd3b 100644
--- a/libc/hdr/types/char32_t.h
+++ b/libc/hdr/types/char32_t.h
@@ -15,8 +15,13 @@
 
 #else // overlay mode
 
+// MacOS doesn't provide uchar.h so we use the types provided by LLVM-libc.
+#ifdef __APPLE__
+#include "include/llvm-libc-types/char32_t.h"
+#else
 #include "hdr/uchar_overlay.h"
+#endif
 
-#endif // LLVM_LIBC_FULL_BUILD
+#endif // LIBC_FULL_BUILD
 
 #endif // LLVM_LIBC_HDR_TYPES_CHAR32_T_H
diff --git a/libc/shared/rpc_server.h b/libc/shared/rpc_server.h
index ad72eb16c74fa..175f91dd34b01 100644
--- a/libc/shared/rpc_server.h
+++ b/libc/shared/rpc_server.h
@@ -20,6 +20,10 @@
 #define flockfile _lock_file
 #define funlockfile _unlock_file
 #define fwrite_unlocked _fwrite_nolock
+#elif defined(__APPLE__)
+// MacOS doesn't have an equivalent of fwrite_unlocked so we just use
+// fwrite.
+#define fwrite_unlocked fwrite
 #endif
 
 namespace rpc {
diff --git a/libc/src/__support/CMakeLists.txt b/libc/src/__support/CMakeLists.txt
index 08a4db8e49a73..ce69d4e6f69ac 100644
--- a/libc/src/__support/CMakeLists.txt
+++ b/libc/src/__support/CMakeLists.txt
@@ -452,12 +452,8 @@ add_subdirectory(fixed_point)
 
 add_subdirectory(time)
 
-# Requires access to uchar header which is not on macos
-# Therefore, cannot currently build this on macos in overlay mode
-if(NOT (LIBC_TARGET_OS_IS_DARWIN))
-  add_subdirectory(wchar)
-  add_subdirectory(wctype)
-endif()
+add_subdirectory(wchar)
+add_subdirectory(wctype)
 
 add_subdirectory(math)
 if(LIBC_COMPILER_HAS_EXT_VECTOR_TYPE)
diff --git a/libc/test/src/__support/CMakeLists.txt b/libc/test/src/__support/CMakeLists.txt
index 64e15852c2ec3..6b9c1b4ac8cc7 100644
--- a/libc/test/src/__support/CMakeLists.txt
+++ b/libc/test/src/__support/CMakeLists.txt
@@ -311,9 +311,5 @@ add_subdirectory(fixed_point)
 add_subdirectory(HashTable)
 add_subdirectory(time)
 add_subdirectory(threads)
-# Requires access to uchar header which is not on MacOS
-# Cannot currently build this on MacOS in overlay mode
-if(NOT(LIBC_TARGET_OS_IS_DARWIN))
-  add_subdirectory(wchar)
-  add_subdirectory(wctype)
-endif()
+add_subdirectory(wchar)
+add_subdirectory(wctype)



More information about the libc-commits mailing list