[libcxx-commits] [libcxx] [libcxx] Make terminal check always false for `print` on GPU (PR #99259)

Joseph Huber via libcxx-commits libcxx-commits at lists.llvm.org
Wed Jul 31 08:05:01 PDT 2024


https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/99259

>From 454bcc3c547c0225761b78f8c91d206c267d1329 Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 16 Jul 2024 18:49:38 -0500
Subject: [PATCH] [libcxx] Make terminal check always false for `print` on GPU

Summary:
This check must be handled in order to compile. The GPU cannot easily
determine if a given `FILE *` is a terminal because the `stdio`
interface is actually a wrapper over the system's `FILE *`, so we can't
really detect it easily. An RPC call could be made to `isatty` if we
really need to support this in the future.
---
 libcxx/CMakeLists.txt           | 2 ++
 libcxx/include/__config_site.in | 1 +
 libcxx/include/print            | 2 +-
 3 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/libcxx/CMakeLists.txt b/libcxx/CMakeLists.txt
index 08406076236e9..094d3048ba330 100644
--- a/libcxx/CMakeLists.txt
+++ b/libcxx/CMakeLists.txt
@@ -297,6 +297,7 @@ option(LIBCXX_HAS_WIN32_THREAD_API "Ignore auto-detection and force use of win32
 option(LIBCXX_HAS_EXTERNAL_THREAD_API
   "Build libc++ with an externalized threading API.
    This option may only be set to ON when LIBCXX_ENABLE_THREADS=ON." OFF)
+option(LIBCXX_HAS_TERMINAL_AVAILABLE "Build libc++ with terminal checking support" ON)
 
 if (LIBCXX_ENABLE_THREADS)
   set(LIBCXX_PSTL_BACKEND "std_thread" CACHE STRING "Which PSTL backend to use")
@@ -744,6 +745,7 @@ config_define_if(LIBCXX_ABI_FORCE_ITANIUM _LIBCPP_ABI_FORCE_ITANIUM)
 config_define_if(LIBCXX_ABI_FORCE_MICROSOFT _LIBCPP_ABI_FORCE_MICROSOFT)
 config_define_if_not(LIBCXX_ENABLE_THREADS _LIBCPP_HAS_NO_THREADS)
 config_define_if_not(LIBCXX_ENABLE_MONOTONIC_CLOCK _LIBCPP_HAS_NO_MONOTONIC_CLOCK)
+config_define_if_not(LIBCXX_HAS_TERMINAL_AVAILABLE _LIBCPP_HAS_NO_TERMINAL)
 if (NOT LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION STREQUAL "default")
   config_define("${LIBCXX_TYPEINFO_COMPARISON_IMPLEMENTATION}" _LIBCPP_TYPEINFO_COMPARISON_IMPLEMENTATION)
 endif()
diff --git a/libcxx/include/__config_site.in b/libcxx/include/__config_site.in
index 67022146c9082..bf2d31d8eeb1b 100644
--- a/libcxx/include/__config_site.in
+++ b/libcxx/include/__config_site.in
@@ -15,6 +15,7 @@
 #cmakedefine _LIBCPP_ABI_FORCE_MICROSOFT
 #cmakedefine _LIBCPP_HAS_NO_THREADS
 #cmakedefine _LIBCPP_HAS_NO_MONOTONIC_CLOCK
+#cmakedefine _LIBCPP_HAS_NO_TERMINAL
 #cmakedefine _LIBCPP_HAS_MUSL_LIBC
 #cmakedefine _LIBCPP_HAS_THREAD_API_PTHREAD
 #cmakedefine _LIBCPP_HAS_THREAD_API_EXTERNAL
diff --git a/libcxx/include/print b/libcxx/include/print
index 1a579daff270f..24fd50e8001e4 100644
--- a/libcxx/include/print
+++ b/libcxx/include/print
@@ -199,7 +199,7 @@ _LIBCPP_HIDE_FROM_ABI inline bool __is_terminal([[maybe_unused]] FILE* __stream)
   // the behavior in the test. This is not part of the public API.
 #  ifdef _LIBCPP_TESTING_PRINT_IS_TERMINAL
   return _LIBCPP_TESTING_PRINT_IS_TERMINAL(__stream);
-#  elif _LIBCPP_AVAILABILITY_HAS_PRINT == 0
+#  elif _LIBCPP_AVAILABILITY_HAS_PRINT == 0 || _LIBCPP_HAS_NO_TERMINAL
   return false;
 #  elif defined(_LIBCPP_WIN32API)
   return std::__is_windows_terminal(__stream);



More information about the libcxx-commits mailing list