Skip to content

Commit

Permalink
[gn build] Add build files for LLDB
Browse files Browse the repository at this point in the history
This is enough to get the lit-based tests to pass on macOS.

Doesn't yet add build targets for:
- Any LLDB unit tests
- swig bindings
- various targets not needed by lit tests

LLDB has many dependency cycles, something GN doesn't allow. For
that reason, I've omitted some dependency edges. Hopefully we can
clean up the cycles one day.

LLDB has a public/private header distinction, but mostly ignores it.
Many libraries include private headers from other modules.

Since LLDB is the first target the LLVM/GN build that uses Objective-C++
code, add some machinery to the toolchain file to handle that.

Differential Revision: https://reviews.llvm.org/D109185
  • Loading branch information
nico committed Sep 7, 2021
1 parent 4b05341 commit cfe0284
Show file tree
Hide file tree
Showing 81 changed files with 2,899 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lldb/source/Symbol/CMakeLists.txt
@@ -1,7 +1,9 @@
set(LLVM_OPTIONAL_SOURCES LocateSymbolFileMacOSX.cpp)

if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
set(PLATFORM_SOURCES LocateSymbolFileMacOSX.cpp)
set(PLATFORM_SOURCES
LocateSymbolFileMacOSX.cpp
)
endif()

add_lldb_library(lldbSymbol
Expand Down
14 changes: 14 additions & 0 deletions llvm/utils/gn/build/BUILD.gn
Expand Up @@ -348,12 +348,15 @@ config("compiler_defaults") {
]
}
}

cflags_objcc = cflags_cc
}

config("no_exceptions") {
if (host_os != "win") {
cflags_cc = [ "-fno-exceptions" ]
}
cflags_objcc = cflags_cc
}

config("no_rtti") {
Expand All @@ -362,6 +365,7 @@ config("no_rtti") {
} else {
cflags_cc = [ "-fno-rtti" ]
}
cflags_objcc = cflags_cc
}

# To make an archive that can be distributed, you need to remove this config and
Expand Down Expand Up @@ -416,6 +420,16 @@ config("crt_code") {
}
}

config("lldb_code") {
if (host_os != "win") {
cflags = [ "-fno-strict-aliasing" ]
}
include_dirs = [
"//lldb/include",
"$root_gen_dir/lldb/include",
]
}

config("warn_covered_switch_default") {
if (is_clang) {
cflags = [ "-Wcovered-switch-default" ]
Expand Down
8 changes: 8 additions & 0 deletions llvm/utils/gn/build/toolchain/BUILD.gn
Expand Up @@ -51,6 +51,14 @@ template("unix_toolchain") {
outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o" ]
}

tool("objcxx") {
depfile = "{{output}}.d"
command = "$cxx -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{cflags}} {{cflags_objcc}}"
depsformat = "gcc"
description = "OBJCXX {{output}}"
outputs = [ "{{source_out_dir}}/{{label_name}}.{{source_name_part}}.o" ]
}

tool("asm") {
depfile = "{{output}}.d"
command = "$cc -MMD -MF $depfile -o {{output}} -c {{source}} {{defines}} {{include_dirs}} {{asmflags}}"
Expand Down
3 changes: 3 additions & 0 deletions llvm/utils/gn/secondary/BUILD.gn
Expand Up @@ -20,6 +20,9 @@ group("default") {
"//libcxxabi",
]
}
if (current_os == "mac") {
deps += [ "//lldb/test" ]
}
if (current_os == "linux" || current_os == "android") {
deps += [ "//compiler-rt/test/hwasan" ]
}
Expand Down
58 changes: 58 additions & 0 deletions llvm/utils/gn/secondary/lldb/include/lldb/Host/BUILD.gn
@@ -0,0 +1,58 @@
import("//llvm/utils/gn/build/libs/xml/enable.gni")
import("//llvm/utils/gn/build/write_cmake_config.gni")
import("libedit.gni")

# In lldb/cmake/modules/LLDBGenerateConfig.cmake,
# brought in by lldb/cmake/modules/LLDBConfig.cmake,
# brought in by lldb/CMakeLists.txt in the CMake build.
write_cmake_config("Config") {
input = "Config.h.cmake"
output = "$target_gen_dir/Config.h"
values = [
# FIXME: Actual values for everything.
"LLDB_EDITLINE_USE_WCHAR=",
"LLDB_HAVE_EL_RFUNC_T=",
"HAVE_PPOLL=",
"HAVE_PTSNAME_R=",
"HAVE_PROCESS_VM_READV=",
"HAVE_NR_PROCESS_VM_READV=",
"LLDB_ENABLE_LZMA=",
"LLDB_ENABLE_CURSES=",
"CURSES_HAVE_NCURSES_CURSES_H=",
"LLDB_ENABLE_LUA=",
"LLDB_ENABLE_PYTHON=",
"LLDB_EMBED_PYTHON_HOME=",

"LLDB_PYTHON_HOME=",

"LLVM_LIBDIR_SUFFIX=",

"HAVE_LIBCOMPRESSION=",
]

if (lldb_enable_libedit) {
values += [ "LLDB_ENABLE_LIBEDIT=1" ]
} else {
values += [ "LLDB_ENABLE_LIBEDIT=" ]
}

if (llvm_enable_libxml2) {
values += [ "LLDB_ENABLE_LIBXML2=1" ]
} else {
values += [ "LLDB_ENABLE_LIBXML2=" ]
}

if (current_os == "win") {
values += [
"HAVE_SYS_EVENT_H=",
"LLDB_ENABLE_POSIX=",
"LLDB_ENABLE_TERMIOS=",
]
} else {
values += [
"HAVE_SYS_EVENT_H=1",
"LLDB_ENABLE_POSIX=1",
"LLDB_ENABLE_TERMIOS=1",
]
}
}
9 changes: 9 additions & 0 deletions llvm/utils/gn/secondary/lldb/include/lldb/Host/libedit.gni
@@ -0,0 +1,9 @@
declare_args() {
# Whether lldb links against libedit. Set to `true` or `false`, or to
# `"default"` to get the platform default.
lldb_enable_libedit = "default"
}

if (lldb_enable_libedit == "default") {
lldb_enable_libedit = current_os == "mac"
}
105 changes: 105 additions & 0 deletions llvm/utils/gn/secondary/lldb/source/API/BUILD.gn
@@ -0,0 +1,105 @@
static_library("liblldb") {
# XXX if win -DEXPORT_LIBLLDB

# XXX LLDB_BUILD_FRAMEWORK
# XXX LLDB_ENABLE_PYTHON
# XXX LLDB_ENABLE_LUA

output_name = "liblldb" # XXX lib prefix?
configs += [ "//llvm/utils/gn/build:lldb_code" ]
deps = [
"//lldb/include/lldb/Host:Config",
"//lldb/source:lldbBase",
"//lldb/source/Breakpoint",
"//lldb/source/Core",
"//lldb/source/DataFormatters",
"//lldb/source/Expression",
"//lldb/source/Host",
"//lldb/source/Initialization",
"//lldb/source/Interpreter",
"//lldb/source/Plugins:LldbAllPlugins",
"//lldb/source/Symbol",
"//lldb/source/Target",
"//lldb/source/Utility",
"//lldb/tools/argdumper:lldb-argdumper",
"//llvm/lib/Support",
]

# SBTarget.cpp includes Commands-internal header Commands/CommandObjectBreakpoint.h
include_dirs = [ ".." ]
sources = [
"SBAddress.cpp",
"SBAttachInfo.cpp",
"SBBlock.cpp",
"SBBreakpoint.cpp",
"SBBreakpointLocation.cpp",
"SBBreakpointName.cpp",
"SBBreakpointOptionCommon.cpp",
"SBBroadcaster.cpp",
"SBCommandInterpreter.cpp",
"SBCommandInterpreterRunOptions.cpp",
"SBCommandReturnObject.cpp",
"SBCommunication.cpp",
"SBCompileUnit.cpp",
"SBData.cpp",
"SBDebugger.cpp",
"SBDeclaration.cpp",
"SBEnvironment.cpp",
"SBError.cpp",
"SBEvent.cpp",
"SBExecutionContext.cpp",
"SBExpressionOptions.cpp",
"SBFile.cpp",
"SBFileSpec.cpp",
"SBFileSpecList.cpp",
"SBFrame.cpp",
"SBFunction.cpp",
"SBHostOS.cpp",
"SBInstruction.cpp",
"SBInstructionList.cpp",
"SBLanguageRuntime.cpp",
"SBLaunchInfo.cpp",
"SBLineEntry.cpp",
"SBListener.cpp",
"SBMemoryRegionInfo.cpp",
"SBMemoryRegionInfoList.cpp",
"SBModule.cpp",
"SBModuleSpec.cpp",
"SBPlatform.cpp",
"SBProcess.cpp",
"SBProcessInfo.cpp",
"SBQueue.cpp",
"SBQueueItem.cpp",
"SBReproducer.cpp",
"SBSection.cpp",
"SBSourceManager.cpp",
"SBStream.cpp",
"SBStringList.cpp",
"SBStructuredData.cpp",
"SBSymbol.cpp",
"SBSymbolContext.cpp",
"SBSymbolContextList.cpp",
"SBTarget.cpp",
"SBThread.cpp",
"SBThreadCollection.cpp",
"SBThreadPlan.cpp",
"SBTrace.cpp",
"SBType.cpp",
"SBTypeCategory.cpp",
"SBTypeEnumMember.cpp",
"SBTypeFilter.cpp",
"SBTypeFormat.cpp",
"SBTypeNameSpecifier.cpp",
"SBTypeSummary.cpp",
"SBTypeSynthetic.cpp",
"SBUnixSignals.cpp",
"SBValue.cpp",
"SBValueList.cpp",
"SBVariablesOptions.cpp",
"SBWatchpoint.cpp",
"SystemInitializerFull.cpp",
]

# XXX liblldb.exports or liblldb-private.expoorts
# XXX dep on clang resource directory
}
30 changes: 30 additions & 0 deletions llvm/utils/gn/secondary/lldb/source/BUILD.gn
@@ -0,0 +1,30 @@
import("//llvm/utils/gn/build/write_vcsrevision.gni")

config("write_vcsrevision_config") {
# To pick up the generated inc file.
include_dirs = [ target_gen_dir ]
visibility = [ ":write_vcsrevision" ]
}

write_vcsrevision("write_vcsversion") {
visibility = [ ":lldbBase" ]
header = "$target_gen_dir/VCSVersion.inc"
names = [ "LLDB" ]
public_configs = [ ":write_vcsrevision_config" ]
}

static_library("lldbBase") {
configs += [
"//llvm/utils/gn/build:lldb_code",

# To pick up clang/Basic/Version.h.
"//llvm/utils/gn/build:clang_code",
]
sources = [ "lldb.cpp" ]
deps = [
":write_vcsversion",
"//clang/lib/Basic",
]

# XXX define LLDB_VERSION_STRING
}
40 changes: 40 additions & 0 deletions llvm/utils/gn/secondary/lldb/source/Breakpoint/BUILD.gn
@@ -0,0 +1,40 @@
static_library("Breakpoint") {
output_name = "lldbBreakpoint"
configs += [ "//llvm/utils/gn/build:lldb_code" ]
deps = [
"//lldb/include/lldb/Host:Config",
"//lldb/source/Core",
"//lldb/source/Expression",
"//lldb/source/Interpreter",
"//lldb/source/Symbol",
"//lldb/source/Target",
"//lldb/source/Utility",
"//llvm/lib/Support",
]
sources = [
"Breakpoint.cpp",
"BreakpointID.cpp",
"BreakpointIDList.cpp",
"BreakpointList.cpp",
"BreakpointLocation.cpp",
"BreakpointLocationCollection.cpp",
"BreakpointLocationList.cpp",
"BreakpointName.cpp",
"BreakpointOptions.cpp",
"BreakpointPrecondition.cpp",
"BreakpointResolver.cpp",
"BreakpointResolverAddress.cpp",
"BreakpointResolverFileLine.cpp",
"BreakpointResolverFileRegex.cpp",
"BreakpointResolverName.cpp",
"BreakpointResolverScripted.cpp",
"BreakpointSite.cpp",
"BreakpointSiteList.cpp",
"Stoppoint.cpp",
"StoppointCallbackContext.cpp",
"StoppointSite.cpp",
"Watchpoint.cpp",
"WatchpointList.cpp",
"WatchpointOptions.cpp",
]
}
66 changes: 66 additions & 0 deletions llvm/utils/gn/secondary/lldb/source/Commands/BUILD.gn
@@ -0,0 +1,66 @@
import("//lldb/utils/TableGen/lldb_tablegen.gni")

lldb_tablegen("CommandOptions") {
args = [ "-gen-lldb-option-defs" ]
td_file = "Options.td" # FIXME: rename?
}

static_library("Commands") {
output_name = "lldbCommands"
configs += [ "//llvm/utils/gn/build:lldb_code" ]
deps = [
":CommandOptions",
"//lldb/source:lldbBase",
"//llvm/lib/Support",

#"//lldb/source/Breakpoint", # FIXME: many-hop dependency cycle.
"//lldb/source/Core",
"//lldb/source/DataFormatters",

#"//lldb/source/Expression", # FIXME: 2-hop dependency cycle.
"//lldb/source/Host",

#"//lldb/source/Interpreter", # FIXME: Dependency cycle.
#"//lldb/source/Symbol", # FIXME: many-hop dependency cycle.
#"//lldb/source/Target", # FIXME: 2-hop dependency cycle.
"//lldb/source/Utility",
]
sources = [
"CommandCompletions.cpp",
"CommandObjectApropos.cpp",
"CommandObjectBreakpoint.cpp",
"CommandObjectBreakpointCommand.cpp",
"CommandObjectCommands.cpp",
"CommandObjectDisassemble.cpp",
"CommandObjectExpression.cpp",
"CommandObjectFrame.cpp",
"CommandObjectGUI.cpp",
"CommandObjectHelp.cpp",
"CommandObjectLanguage.cpp",
"CommandObjectLog.cpp",
"CommandObjectMemory.cpp",
"CommandObjectMemoryTag.cpp",
"CommandObjectMultiword.cpp",
"CommandObjectPlatform.cpp",
"CommandObjectPlugin.cpp",
"CommandObjectProcess.cpp",
"CommandObjectQuit.cpp",
"CommandObjectRegexCommand.cpp",
"CommandObjectRegister.cpp",
"CommandObjectReproducer.cpp",
"CommandObjectScript.cpp",
"CommandObjectSession.cpp",
"CommandObjectSettings.cpp",
"CommandObjectSource.cpp",
"CommandObjectStats.cpp",
"CommandObjectTarget.cpp",
"CommandObjectThread.cpp",
"CommandObjectThreadUtil.cpp",
"CommandObjectTrace.cpp",
"CommandObjectType.cpp",
"CommandObjectVersion.cpp",
"CommandObjectWatchpoint.cpp",
"CommandObjectWatchpointCommand.cpp",
"CommandOptionsProcessLaunch.cpp",
]
}

0 comments on commit cfe0284

Please sign in to comment.