[libcxx-commits] [libcxx] r359703 - [WebAssembly] WASI support for libcxx

Dan Gohman via libcxx-commits libcxx-commits at lists.llvm.org
Wed May 1 09:47:31 PDT 2019


Author: djg
Date: Wed May  1 09:47:30 2019
New Revision: 359703

URL: http://llvm.org/viewvc/llvm-project?rev=359703&view=rev
Log:
[WebAssembly] WASI support for libcxx

This adds explicit support for the WASI platform to libcxx.

WASI libc uses some components from musl, however it's not fully compatible
with musl, so we're planning to stop using _LIBCPP_HAS_MUSL_LIBC and
customize for WASI libc specifically.

Differential Revision: https://reviews.llvm.org/D61336

Reviewers: sbc100, ldionne

Modified:
    libcxx/trunk/include/__config
    libcxx/trunk/include/__locale
    libcxx/trunk/src/include/config_elast.h
    libcxx/trunk/src/thread.cpp
    libcxx/trunk/test/support/test_macros.h

Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=359703&r1=359702&r2=359703&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Wed May  1 09:47:30 2019
@@ -307,7 +307,7 @@
    // random data even when using sandboxing mechanisms such as chroots,
    // Capsicum, etc.
 #  define _LIBCPP_USING_ARC4_RANDOM
-#elif defined(__Fuchsia__)
+#elif defined(__Fuchsia__) || defined(__wasi__)
 #  define _LIBCPP_USING_GETENTROPY
 #elif defined(__native_client__)
    // NaCl's sandbox (which PNaCl also runs in) doesn't allow filesystem access,
@@ -341,7 +341,7 @@
 #  if defined(__FreeBSD__)
 #    define _LIBCPP_HAS_QUICK_EXIT
 #    define _LIBCPP_HAS_C11_FEATURES
-#  elif defined(__Fuchsia__)
+#  elif defined(__Fuchsia__) || defined(__wasi__)
 #    define _LIBCPP_HAS_QUICK_EXIT
 #    define _LIBCPP_HAS_TIMESPEC_GET
 #    define _LIBCPP_HAS_C11_FEATURES
@@ -1133,6 +1133,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
     !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 #  if defined(__FreeBSD__) || \
       defined(__Fuchsia__) || \
+      defined(__wasi__) || \
       defined(__NetBSD__) || \
       defined(__linux__) || \
       defined(__GNU__) || \
@@ -1179,7 +1180,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 #endif
 
 #if defined(__BIONIC__) || defined(__CloudABI__) ||                            \
-    defined(__Fuchsia__) || defined(_LIBCPP_HAS_MUSL_LIBC)
+    defined(__Fuchsia__) || defined(__wasi__) || defined(_LIBCPP_HAS_MUSL_LIBC)
 #define _LIBCPP_PROVIDES_DEFAULT_RUNE_TABLE
 #endif
 

Modified: libcxx/trunk/include/__locale
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__locale?rev=359703&r1=359702&r2=359703&view=diff
==============================================================================
--- libcxx/trunk/include/__locale (original)
+++ libcxx/trunk/include/__locale Wed May  1 09:47:30 2019
@@ -35,6 +35,9 @@
 # include <xlocale.h>
 #elif defined(__Fuchsia__)
 # include <support/fuchsia/xlocale.h>
+#elif defined(__wasi__)
+// WASI libc uses musl's locales support.
+# include <support/musl/xlocale.h>
 #elif defined(_LIBCPP_HAS_MUSL_LIBC)
 # include <support/musl/xlocale.h>
 #endif

Modified: libcxx/trunk/src/include/config_elast.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/include/config_elast.h?rev=359703&r1=359702&r2=359703&view=diff
==============================================================================
--- libcxx/trunk/src/include/config_elast.h (original)
+++ libcxx/trunk/src/include/config_elast.h Wed May  1 09:47:30 2019
@@ -23,6 +23,8 @@
 #define _LIBCPP_ELAST __ELASTERROR
 #elif defined(__Fuchsia__)
 // No _LIBCPP_ELAST needed on Fuchsia
+#elif defined(__wasi__)
+// No _LIBCPP_ELAST needed on WASI
 #elif defined(__linux__) || defined(_LIBCPP_HAS_MUSL_LIBC)
 #define _LIBCPP_ELAST 4095
 #elif defined(__APPLE__)

Modified: libcxx/trunk/src/thread.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/src/thread.cpp?rev=359703&r1=359702&r2=359703&view=diff
==============================================================================
--- libcxx/trunk/src/thread.cpp (original)
+++ libcxx/trunk/src/thread.cpp Wed May  1 09:47:30 2019
@@ -23,9 +23,9 @@
 # endif
 #endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
 
-#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__)
+#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__)
 # include <unistd.h>
-#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__)
+#endif // defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__CloudABI__) || defined(__Fuchsia__) || defined(__wasi__)
 
 #if defined(__NetBSD__)
 #pragma weak pthread_create // Do not create libpthread dependency

Modified: libcxx/trunk/test/support/test_macros.h
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/support/test_macros.h?rev=359703&r1=359702&r2=359703&view=diff
==============================================================================
--- libcxx/trunk/test/support/test_macros.h (original)
+++ libcxx/trunk/test/support/test_macros.h Wed May  1 09:47:30 2019
@@ -148,7 +148,7 @@
 //  Specifically, FreeBSD does NOT have timespec_get, even though they have all
 //  the rest of C11 - this is PR#38495
 #    define TEST_HAS_C11_FEATURES
-#  elif defined(__Fuchsia__)
+#  elif defined(__Fuchsia__) || defined(__wasi__)
 #    define TEST_HAS_C11_FEATURES
 #    define TEST_HAS_TIMESPEC_GET
 #  elif defined(__linux__)




More information about the libcxx-commits mailing list