Skip to content

Commit 18d8464

Browse files
aaronmondallamb-j
authored andcommitted
[Support] Remove terminfo dependency (llvm#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 llvm#75490 Closes llvm#53294 llvm#23355 Change-Id: Ib4a5c725f845d77780472b7608fa587c1ad3ead6
1 parent b4ccc61 commit 18d8464

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
@@ -18,7 +18,6 @@ set(LLVM_ENABLE_LLD ON CACHE BOOL "")
1818
set(LLVM_ENABLE_LTO ON CACHE BOOL "")
1919
set(LLVM_ENABLE_PER_TARGET_RUNTIME_DIR ON CACHE BOOL "")
2020
set(LLVM_ENABLE_PLUGINS OFF CACHE BOOL "")
21-
set(LLVM_ENABLE_TERMINFO OFF CACHE BOOL "")
2221
set(LLVM_ENABLE_UNWIND_TABLES OFF CACHE BOOL "")
2322
set(LLVM_ENABLE_Z3_SOLVER OFF CACHE BOOL "")
2423
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
@@ -181,21 +181,6 @@ check_library_exists(m pow "" COMPILER_RT_HAS_LIBM)
181181
check_library_exists(pthread pthread_create "" COMPILER_RT_HAS_LIBPTHREAD)
182182
check_library_exists(execinfo backtrace "" COMPILER_RT_HAS_LIBEXECINFO)
183183

184-
# Look for terminfo library, used in unittests that depend on LLVMSupport.
185-
if(LLVM_ENABLE_TERMINFO STREQUAL FORCE_ON)
186-
set(MAYBE_REQUIRED REQUIRED)
187-
else()
188-
set(MAYBE_REQUIRED)
189-
endif()
190-
if(LLVM_ENABLE_TERMINFO)
191-
find_library(COMPILER_RT_TERMINFO_LIB NAMES terminfo tinfo curses ncurses ncursesw ${MAYBE_REQUIRED})
192-
endif()
193-
if(COMPILER_RT_TERMINFO_LIB)
194-
set(LLVM_ENABLE_TERMINFO 1)
195-
else()
196-
set(LLVM_ENABLE_TERMINFO 0)
197-
endif()
198-
199184
if (ANDROID AND COMPILER_RT_HAS_LIBDL)
200185
# Android's libstdc++ has a dependency on libdl.
201186
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
@@ -467,7 +467,6 @@ further by passing the appropriate cmake options, such as:
467467
-DLLDB_ENABLE_PYTHON=0
468468
-DLLDB_ENABLE_LIBEDIT=0
469469
-DLLDB_ENABLE_CURSES=0
470-
-DLLVM_ENABLE_TERMINFO=0
471470

472471
(see :ref:`Optional Dependencies` for more)
473472

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
@@ -520,8 +520,6 @@ set(FFI_INCLUDE_DIR "" CACHE PATH "Additional directory, where CMake should sear
520520
set(LLVM_TARGET_ARCH "host"
521521
CACHE STRING "Set target to use for LLVM JIT or use \"host\" for automatic detection.")
522522

523-
option(LLVM_ENABLE_TERMINFO "Use terminfo database if available." ON)
524-
525523
set(LLVM_ENABLE_LIBXML2 "ON" CACHE STRING "Use libxml2 if available. Can be ON, OFF, or FORCE_ON")
526524

527525
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
@@ -78,6 +78,10 @@ Changes to LLVM infrastructure
7878
Changes to building LLVM
7979
------------------------
8080

81+
- The ``LLVM_ENABLE_TERMINFO`` flag has been removed. LLVM no longer depends on
82+
terminfo and now always uses the ``TERM`` environment variable for color
83+
support autodetection.
84+
8185
Changes to TableGen
8286
-------------------
8387

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) )
@@ -322,14 +319,6 @@ if(LLVM_ENABLE_ZSTD)
322319
set(llvm_system_libs ${llvm_system_libs} "${zstd_library}")
323320
endif()
324321

325-
if(LLVM_ENABLE_TERMINFO)
326-
if(NOT terminfo_library)
327-
get_property(terminfo_library TARGET Terminfo::terminfo PROPERTY LOCATION)
328-
endif()
329-
get_library_name(${terminfo_library} terminfo_library)
330-
set(llvm_system_libs ${llvm_system_libs} "${terminfo_library}")
331-
endif()
332-
333322
set_property(TARGET LLVMSupport PROPERTY LLVM_SYSTEM_LIBS "${llvm_system_libs}")
334323

335324

llvm/lib/Support/Unix/Process.inc

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,9 @@ unsigned Process::StandardErrColumns() {
322322
return getColumns();
323323
}
324324

325-
#ifdef LLVM_ENABLE_TERMINFO
326-
// We manually declare these extern functions because finding the correct
327-
// headers from various terminfo, curses, or other sources is harder than
328-
// writing their specs down.
329-
extern "C" int setupterm(char *term, int filedes, int *errret);
330-
extern "C" struct term *set_curterm(struct term *termp);
331-
extern "C" int del_curterm(struct term *termp);
332-
extern "C" int tigetnum(char *capname);
333-
#endif
334-
335-
bool checkTerminalEnvironmentForColors() {
325+
static bool terminalHasColors() {
326+
// Check if the current terminal is one of terminals that are known to support
327+
// ANSI color escape codes.
336328
if (const char *TermStr = std::getenv("TERM")) {
337329
return StringSwitch<bool>(TermStr)
338330
.Case("ansi", true)
@@ -349,54 +341,10 @@ bool checkTerminalEnvironmentForColors() {
349341
return false;
350342
}
351343

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

402350
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")
@@ -293,12 +292,6 @@ write_cmake_config("config") {
293292
values += [ "HAVE_LIBEDIT=" ]
294293
}
295294

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

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

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

0 commit comments

Comments
 (0)