Skip to content

Commit 6bf450c

Browse files
authored
[Support] Remove terminfo dependency (#92865)
The terminfo dependency introduces a significant nonhermeticity into the build. It doesn't respect `--no-undefined-version` meaning that it's not a dependency that can be built with Clang 17+. This forces maintainers of source-based distributions to implement patches or ignore linker errors. Remove it to reduce the closure size and improve portability of LLVM-based tools. Users can still use command line arguments to toggle color support expliticly. Fixes #75490 Closes #53294 #23355
1 parent 8c718a3 commit 6bf450c

File tree

26 files changed

+12
-218
lines changed

26 files changed

+12
-218
lines changed

clang/cmake/caches/Fuchsia-stage2.cmake

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ set(LLVM_ENABLE_LLD ON CACHE BOOL "")
1919
set(LLVM_ENABLE_LTO ON CACHE BOOL "")
2020
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
2121
set(LLVM_ENABLE_PLUGINS OFF CACHE BOOL "")
22-
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
2322
set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
2423
set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")
2524
set(LLVM_ENABLE_ZLIB ON CACHE BOOL "")

clang/cmake/caches/Fuchsia.cmake

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ set(LLVM_ENABLE_DIA_SDK OFF CACHE BOOL "")
1212
set(LLVM_ENABLE_LIBEDIT OFF CACHE BOOL "")
1313
set(LLVM_ENABLE_LIBXML2 OFF CACHE BOOL "")
1414
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
15-
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
1615
set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
1716
set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")
1817
set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
@@ -34,7 +33,6 @@ set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
3433
LibXml2_ROOT
3534
LLVM_ENABLE_CURL
3635
LLVM_ENABLE_HTTPLIB
37-
LLVM_ENABLE_TERMINFO
3836
LLVM_ENABLE_LIBEDIT
3937
CURL_ROOT
4038
OpenSSL_ROOT
@@ -47,11 +45,6 @@ set(_FUCHSIA_BOOTSTRAP_PASSTHROUGH
4745
CURSES_LIBRARIES
4846
PANEL_LIBRARIES
4947

50-
# Deprecated
51-
Terminfo_ROOT
52-
53-
Terminfo_LIBRARIES
54-
5548
# Deprecated
5649
LibEdit_ROOT
5750

clang/cmake/caches/VectorEngine.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
# ninja
1414
#
1515

16-
# Disable TERMINFO, ZLIB, and ZSTD for VE since there is no pre-compiled
17-
# libraries.
18-
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
16+
# Disable ZLIB, and ZSTD for VE since there is no pre-compiled libraries.
1917
set(LLVM_ENABLE_ZLIB OFF CACHE BOOL "")
2018
set(LLVM_ENABLE_ZSTD OFF CACHE BOOL "")
2119

clang/utils/analyzer/entrypoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def is_cmake_needed():
5454
"cmake -G Ninja -DCMAKE_BUILD_TYPE=Release "
5555
"-DCMAKE_INSTALL_PREFIX=/analyzer -DLLVM_TARGETS_TO_BUILD=X86 "
5656
'-DLLVM_ENABLE_PROJECTS="clang;openmp" -DLLVM_BUILD_RUNTIME=OFF '
57-
"-DLLVM_ENABLE_TERMINFO=OFF -DCLANG_ENABLE_ARCMT=OFF "
57+
"-DCLANG_ENABLE_ARCMT=OFF "
5858
"-DCLANG_ENABLE_STATIC_ANALYZER=ON"
5959
)
6060

compiler-rt/cmake/config-ix.cmake

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -182,21 +182,6 @@ check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
182182
check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
183183
check_library_exists(execinfo backtrace "" COMPILER_RT_HAS_LIBEXECINFO)
184184

185-
# Look for terminfo library, used in unittests that depend on LLVMSupport.
186-
if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON)
187-
set(MAYBE_REQUIRED REQUIRED)
188-
else()
189-
set(MAYBE_REQUIRED)
190-
endif()
191-
if(LLVM_ENABLE_TERMINFO)
192-
find_library(COMPILER_RT_TERMINFO_LIB NAMES terminfo tinfo curses ncurses ncursesw ${MAYBE_REQUIRED})
193-
endif()
194-
if(COMPILER_RT_TERMINFO_LIB)
195-
set(LLVM_ENABLE_TERMINFO 1)
196-
else()
197-
set(LLVM_ENABLE_TERMINFO 0)
198-
endif()
199-
200185
if (ANDROID AND COMPILER_RT_HAS_LIBDL)
201186
# Android's libstdc++ has a dependency on libdl.
202187
list(APPEND CMAKE_REQUIRED_LIBRARIES dl)

compiler-rt/lib/sanitizer_common/symbolizer/scripts/build_symbolizer.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,6 @@ if [[ ! -f ${LLVM_BUILD}/build.ninja ]]; then
139139
-DLLVM_INCLUDE_TESTS=OFF \
140140
-DLLVM_ENABLE_ZLIB=ON \
141141
-DLLVM_ENABLE_ZSTD=OFF \
142-
-DLLVM_ENABLE_TERMINFO=OFF \
143142
-DLLVM_ENABLE_THREADS=OFF \
144143
$LLVM_SRC
145144
fi

compiler-rt/lib/xray/tests/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,6 @@ set(XRAY_UNITTEST_LINK_FLAGS
5454
${COMPILER_RT_CXX_LINK_LIBS})
5555

5656
if (NOT APPLE)
57-
# Needed by LLVMSupport.
58-
append_list_if(
59-
LLVM_ENABLE_TERMINFO
60-
-l${COMPILER_RT_TERMINFO_LIB} XRAY_UNITTEST_LINK_FLAGS)
61-
6257
# We add the library directories one at a time in our CFLAGS.
6358
foreach (DIR ${LLVM_LIBRARY_DIR})
6459
list(APPEND XRAY_UNITTEST_LINK_FLAGS -L${DIR})

lldb/docs/resources/build.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,6 @@ further by passing the appropriate cmake options, such as:
477477
-DLLDB_ENABLE_PYTHON=0
478478
-DLLDB_ENABLE_LIBEDIT=0
479479
-DLLDB_ENABLE_CURSES=0
480-
-DLLVM_ENABLE_TERMINFO=0
481480

482481
(see :ref:`Optional Dependencies` for more)
483482

lldb/source/Core/CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ set(LLDB_LIBEDIT_LIBS)
1111

1212
if (LLDB_ENABLE_CURSES)
1313
list(APPEND LLDB_CURSES_LIBS ${PANEL_LIBRARIES} ${CURSES_LIBRARIES})
14-
if(LLVM_ENABLE_TERMINFO)
15-
list(APPEND LLDB_CURSES_LIBS ${Terminfo_LIBRARIES})
16-
endif()
1714
if (LLVM_BUILD_STATIC)
1815
list(APPEND LLDB_CURSES_LIBS gpm)
1916
endif()

llvm/CMakeLists.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,8 +539,6 @@ set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should sear
539539
set(LLVM_TARGET_ARCH "host"
540540
CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
541541

542-
option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
543-
544542
set(LLVM_ENABLE_LIBXML2 "ON" CACHE STRING "Use libxml2 if available. Can be ON, OFF, or FORCE_ON")
545543

546544
option(LLVM_ENABLE_LIBEDIT "Use libedit if available." ON)

llvm/cmake/config-ix.cmake

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,21 +240,11 @@ if(NOT LLVM_USE_SANITIZER MATCHES "Memory.*")
240240
else()
241241
set(HAVE_LIBEDIT 0)
242242
endif()
243-
if(LLVM_ENABLE_TERMINFO)
244-
if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON)
245-
find_package(Terminfo REQUIRED)
246-
else()
247-
find_package(Terminfo)
248-
endif()
249-
set(LLVM_ENABLE_TERMINFO "${Terminfo_FOUND}")
250-
endif()
251243
else()
252244
set(HAVE_LIBEDIT 0)
253-
set(LLVM_ENABLE_TERMINFO 0)
254245
endif()
255246
else()
256247
set(HAVE_LIBEDIT 0)
257-
set(LLVM_ENABLE_TERMINFO 0)
258248
endif()
259249

260250
# function checks

llvm/cmake/modules/FindTerminfo.cmake

Lines changed: 0 additions & 55 deletions
This file was deleted.

llvm/cmake/modules/LLVMConfig.cmake.in

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ if(LLVM_ENABLE_LIBEDIT)
6060
find_package(LibEdit)
6161
endif()
6262

63-
set(LLVM_ENABLE_TERMINFO @LLVM_ENABLE_TERMINFO@)
64-
if(LLVM_ENABLE_TERMINFO)
65-
find_package(Terminfo)
66-
endif()
67-
6863
set(LLVM_ENABLE_THREADS @LLVM_ENABLE_THREADS@)
6964

7065
set(LLVM_ENABLE_UNWIND_TABLES @LLVM_ENABLE_UNWIND_TABLES@)

llvm/docs/ReleaseNotes.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ Changes to LLVM infrastructure
6262
Changes to building LLVM
6363
------------------------
6464

65+
- The ``LLVM_ENABLE_TERMINFO`` flag has been removed. LLVM no longer depends on
66+
terminfo and now always uses the ``TERM`` environment variable for color
67+
support autodetection.
68+
6569
Changes to TableGen
6670
-------------------
6771

llvm/include/llvm/Config/config.h.cmake

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,6 @@
209209
/* Define to 1 if you have the <sys/types.h> header file. */
210210
#cmakedefine HAVE_SYS_TYPES_H ${HAVE_SYS_TYPES_H}
211211

212-
/* Define if the setupterm() function is supported this platform. */
213-
#cmakedefine LLVM_ENABLE_TERMINFO ${LLVM_ENABLE_TERMINFO}
214-
215212
/* Define to 1 if you have the <termios.h> header file. */
216213
#cmakedefine HAVE_TERMIOS_H ${HAVE_TERMIOS_H}
217214

llvm/lib/Support/CMakeLists.txt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ elseif( CMAKE_HOST_UNIX )
5656
STRING(REGEX REPLACE "^lib" "" Backtrace_LIBFILE ${Backtrace_LIBFILE})
5757
set(system_libs ${system_libs} ${Backtrace_LIBFILE})
5858
endif()
59-
if( LLVM_ENABLE_TERMINFO )
60-
set(imported_libs ${imported_libs} Terminfo::terminfo)
61-
endif()
6259
set(system_libs ${system_libs} ${LLVM_ATOMIC_LIB})
6360
set(system_libs ${system_libs} ${LLVM_PTHREAD_LIB})
6461
if( UNIX AND NOT (BEOS OR HAIKU) )
@@ -325,14 +322,6 @@ if(LLVM_ENABLE_ZSTD)
325322
set(llvm_system_libs ${llvm_system_libs} "${zstd_library}")
326323
endif()
327324

328-
if(LLVM_ENABLE_TERMINFO)
329-
if(NOT terminfo_library)
330-
get_property(terminfo_library TARGET Terminfo::terminfo PROPERTY LOCATION)
331-
endif()
332-
get_library_name(${terminfo_library} terminfo_library)
333-
set(llvm_system_libs ${llvm_system_libs} "${terminfo_library}")
334-
endif()
335-
336325
set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}")
337326

338327

llvm/lib/Support/Unix/Process.inc

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -341,17 +341,9 @@ unsigned Process::StandardErrColumns() {
341341
return getColumns();
342342
}
343343

344-
#ifdef LLVM_ENABLE_TERMINFO
345-
// We manually declare these extern functions because finding the correct
346-
// headers from various terminfo, curses, or other sources is harder than
347-
// writing their specs down.
348-
extern "C" int setupterm(char *term, int filedes, int *errret);
349-
extern "C" struct term *set_curterm(struct term *termp);
350-
extern "C" int del_curterm(struct term *termp);
351-
extern "C" int tigetnum(char *capname);
352-
#endif
353-
354-
bool checkTerminalEnvironmentForColors() {
344+
static bool terminalHasColors() {
345+
// Check if the current terminal is one of terminals that are known to support
346+
// ANSI color escape codes.
355347
if (const char *TermStr = std::getenv("TERM")) {
356348
return StringSwitch<bool>(TermStr)
357349
.Case("ansi", true)
@@ -368,54 +360,10 @@ bool checkTerminalEnvironmentForColors() {
368360
return false;
369361
}
370362

371-
static bool terminalHasColors(int fd) {
372-
#ifdef LLVM_ENABLE_TERMINFO
373-
// First, acquire a global lock because these C routines are thread hostile.
374-
static std::mutex TermColorMutex;
375-
std::lock_guard<std::mutex> G(TermColorMutex);
376-
377-
struct term *previous_term = set_curterm(nullptr);
378-
int errret = 0;
379-
if (setupterm(nullptr, fd, &errret) != 0)
380-
// Regardless of why, if we can't get terminfo, we shouldn't try to print
381-
// colors.
382-
return false;
383-
384-
// Test whether the terminal as set up supports color output. How to do this
385-
// isn't entirely obvious. We can use the curses routine 'has_colors' but it
386-
// would be nice to avoid a dependency on curses proper when we can make do
387-
// with a minimal terminfo parsing library. Also, we don't really care whether
388-
// the terminal supports the curses-specific color changing routines, merely
389-
// if it will interpret ANSI color escape codes in a reasonable way. Thus, the
390-
// strategy here is just to query the baseline colors capability and if it
391-
// supports colors at all to assume it will translate the escape codes into
392-
// whatever range of colors it does support. We can add more detailed tests
393-
// here if users report them as necessary.
394-
//
395-
// The 'tigetnum' routine returns -2 or -1 on errors, and might return 0 if
396-
// the terminfo says that no colors are supported.
397-
int colors_ti = tigetnum(const_cast<char *>("colors"));
398-
bool HasColors =
399-
colors_ti >= 0 ? colors_ti : checkTerminalEnvironmentForColors();
400-
401-
// Now extract the structure allocated by setupterm and free its memory
402-
// through a really silly dance.
403-
struct term *termp = set_curterm(previous_term);
404-
(void)del_curterm(termp); // Drop any errors here.
405-
406-
// Return true if we found a color capabilities for the current terminal.
407-
return HasColors;
408-
#else
409-
// When the terminfo database is not available, check if the current terminal
410-
// is one of terminals that are known to support ANSI color escape codes.
411-
return checkTerminalEnvironmentForColors();
412-
#endif
413-
}
414-
415363
bool Process::FileDescriptorHasColors(int fd) {
416364
// A file descriptor has colors if it is displayed and the terminal has
417365
// colors.
418-
return FileDescriptorIsDisplayed(fd) && terminalHasColors(fd);
366+
return FileDescriptorIsDisplayed(fd) && terminalHasColors();
419367
}
420368

421369
bool Process::StandardOutHasColors() {

llvm/utils/gn/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ configure is used for three classes of feature checks:
131131

132132
For the last two points, it would be nice if LLVM didn't have a single
133133
``config.h`` header, but one header per toggle. That way, when e.g.
134-
``llvm_enable_terminfo`` is toggled, only the 3 files caring about that setting
134+
``llvm_enable_zlib`` is toggled, only the 3 files caring about that setting
135135
would need to be rebuilt, instead of everything including ``config.h``.
136136

137137
GN doesn't believe in users setting arbitrary cflags from an environment

llvm/utils/gn/build/libs/terminfo/BUILD.gn

Lines changed: 0 additions & 12 deletions
This file was deleted.

llvm/utils/gn/build/libs/terminfo/enable.gni

Lines changed: 0 additions & 4 deletions
This file was deleted.

llvm/utils/gn/secondary/llvm/include/llvm/Config/BUILD.gn

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import("//llvm/utils/gn/build/buildflags.gni")
1010
import("//llvm/utils/gn/build/libs/curl/enable.gni")
1111
import("//llvm/utils/gn/build/libs/edit/enable.gni")
1212
import("//llvm/utils/gn/build/libs/pthread/enable.gni")
13-
import("//llvm/utils/gn/build/libs/terminfo/enable.gni")
1413
import("//llvm/utils/gn/build/libs/xar/enable.gni")
1514
import("//llvm/utils/gn/build/libs/xml/enable.gni")
1615
import("//llvm/utils/gn/build/libs/zlib/enable.gni")
@@ -294,12 +293,6 @@ write_cmake_config("config") {
294293
values += [ "HAVE_LIBEDIT=" ]
295294
}
296295

297-
if (llvm_enable_terminfo) {
298-
values += [ "LLVM_ENABLE_TERMINFO=1" ]
299-
} else {
300-
values += [ "LLVM_ENABLE_TERMINFO=" ]
301-
}
302-
303296
if (llvm_enable_libxml2) {
304297
values += [ "LLVM_ENABLE_LIBXML2=1" ]
305298
} else {

llvm/utils/gn/secondary/llvm/lib/Support/BUILD.gn

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ static_library("Support") {
66
"//llvm/include/llvm/Support:write_vcsrevision",
77
"//llvm/lib/Demangle",
88
"//llvm/utils/gn/build/libs/pthread",
9-
"//llvm/utils/gn/build/libs/terminfo",
109
"//llvm/utils/gn/build/libs/zlib",
1110
]
1211

0 commit comments

Comments
 (0)