@@ -5,6 +5,21 @@ set(LLVM_CMAKE_FLAGS "" CACHE STRING "Extra cmake flags to pass to LLVM's build"
55set (RUST_TARGET "" CACHE STRING "Target to build Rust code for, if not the host" )
66set (WASI_SDK_ARTIFACT "" CACHE STRING "Name of the wasi-sdk artifact being produced" )
77
8+ option (WASI_SDK_LLDB "Include a build of LLDB" ON )
9+
10+ set (LIBEDIT_DEFAULT ON )
11+ # I don't want to deal with running a `./configure` script on Windows, disable
12+ # it by default.
13+ if (WIN32 )
14+ set (LIBEDIT_DEFAULT OFF )
15+ endif ()
16+ # I don't know how to resolve build failures when building libedit for x86_64
17+ # from arm64 on macos, so disable it for now.
18+ if (CMAKE_SYSTEM_PROCESSOR MATCHES "arm64" AND LLVM_CMAKE_FLAGS MATCHES "x86_64" )
19+ set (LIBEDIT_DEFAULT OFF )
20+ endif ()
21+ option (WASI_SDK_LIBEDIT "Whether or not to build libedit for LLDB" ${LIBEDIT_DEFAULT} )
22+
823string (REGEX REPLACE "[ ]+" ";" llvm_cmake_flags_list "${LLVM_CMAKE_FLAGS} " )
924
1025set (wasi_tmp_install ${CMAKE_CURRENT_BINARY_DIR} /install )
@@ -73,6 +88,66 @@ if(NOT WIN32)
7388 list (APPEND tools LLVM clang-cpp)
7489endif ()
7590
91+ # Configure/add LLDB if requested.
92+ #
93+ # Note that LLDB depends on `libedit` which is more-or-less required to get a
94+ # reasonable command-line experience, so this is built custom here to ensure
95+ # that it's available for LLDB.
96+ if (WASI_SDK_LLDB)
97+ list (APPEND projects lldb)
98+ list (APPEND tools lldb liblldb)
99+ list (APPEND default_cmake_args
100+ -DLLDB_INCLUDE_TESTS=OFF
101+ -DLLDB_INCLUDE_UNITTESTS=OFF
102+ -DLLDB_ENABLE_SWIG=OFF
103+ -DLLDB_ENABLE_CURSES=OFF
104+ -DLLDB_ENABLE_LZMA=OFF
105+ -DLLDB_ENABLE_LUA=OFF
106+ -DLLDB_ENABLE_PYTHON=OFF
107+ -DLLDB_ENABLE_LIBXML2=OFF
108+ -DLLDB_ENABLE_FBSDVMCORE=OFF
109+ -DLLDB_ENABLE_LINUXPTY=OFF
110+ )
111+
112+ if (WASI_SDK_LIBEDIT)
113+ include (ProcessorCount)
114+ ProcessorCount(nproc)
115+ find_program (MAKE_EXECUTABLE make REQUIRED)
116+ ExternalProject_Add(libedit
117+ URL https://thrysoee.dk/editline/libedit-20251016-3.1.tar.gz
118+ URL_HASH SHA256=21362b00653bbfc1c71f71a7578da66b5b5203559d43134d2dd7719e313ce041
119+
120+ # Without this the build system tries to find and use `aclocal-1.18` where
121+ # with this it doesn't so turn this on.
122+ DOWNLOAD_EXTRACT_TIMESTAMP ON
123+
124+ CONFIGURE_COMMAND
125+ <SOURCE_DIR>/configure
126+ --prefix =${wasi_tmp_install}
127+ --enable-pic
128+ --disable-examples
129+ CC=${CMAKE_C_COMPILER}
130+ CFLAGS=${libedit_cflags}
131+ LDFLAGS=${libedit_cflags}
132+ BUILD_COMMAND
133+ ${MAKE_EXECUTABLE} -j${nproc} V=1
134+
135+ USES_TERMINAL_CONFIGURE ON
136+ USES_TERMINAL_BUILD ON
137+ USES_TERMINAL_INSTALL ON
138+ )
139+ list (APPEND default_cmake_args
140+ -DLLDB_ENABLE_LIBEDIT=ON
141+ -DLibEdit_ROOT=${wasi_tmp_install}
142+ )
143+ else ()
144+ list (APPEND default_cmake_args -DLLDB_ENABLE_LIBEDIT=OFF )
145+ add_custom_target (libedit)
146+ endif ()
147+ else ()
148+ add_custom_target (libedit)
149+ endif ()
150+
76151list (TRANSFORM tools PREPEND --target = OUTPUT_VARIABLE build_targets)
77152list (TRANSFORM tools PREPEND --target =install - OUTPUT_VARIABLE install_targets)
78153
@@ -110,6 +185,7 @@ ExternalProject_Add(llvm-build
110185)
111186
112187add_custom_target (build ALL DEPENDS llvm-build )
188+ ExternalProject_Add_StepDependencies(llvm-build configure libedit)
113189
114190# Installation target for this outer project for installing the toolchain to the
115191# system.
0 commit comments