xref: /llvm-project/utils/bazel/llvm-project-overlay/lldb/BUILD.bazel (revision 287a17de15d87b0d56e25841d2226f65a1973883)
1# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2# See https://llvm.org/LICENSE.txt for license information.
3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5load("@bazel_skylib//lib:selects.bzl", "selects")
6load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
7load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
8load("@build_bazel_apple_support//rules:apple_genrule.bzl", "apple_genrule")
9load("@rules_python//python:defs.bzl", "py_binary")
10load("//:vars.bzl", "LLVM_VERSION_MAJOR", "LLVM_VERSION_MINOR", "LLVM_VERSION_PATCH", "LLVM_VERSION_SUFFIX", "PACKAGE_VERSION")
11load("//lldb/source/Plugins:plugin_config.bzl", "DEFAULT_PLUGINS", "DEFAULT_SCRIPT_PLUGINS", "OBJCPP_COPTS")
12load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")
13
14package(
15    default_visibility = ["//visibility:public"],
16    features = ["layering_check"],
17)
18
19licenses(["notice"])
20
21exports_files([
22    "LICENSE.TXT",
23    "source/API/liblldb-private.exports",
24    "source/API/liblldb.exports",
25])
26
27bool_flag(
28    name = "enable_curses",
29    build_setting_default = False,
30)
31
32config_setting(
33    name = "curses_enabled_setting",
34    flag_values = {":enable_curses": "true"},
35)
36
37selects.config_setting_group(
38    name = "curses_enabled",
39    match_any = [
40        ":curses_enabled_setting",
41        "@platforms//os:macos",
42    ],
43)
44
45bool_flag(
46    name = "enable_libedit",
47    build_setting_default = False,
48)
49
50config_setting(
51    name = "libedit_enabled_setting",
52    flag_values = {":enable_libedit": "true"},
53)
54
55selects.config_setting_group(
56    name = "libedit_enabled",
57    match_any = [
58        ":libedit_enabled_setting",
59        "@platforms//os:macos",
60    ],
61)
62
63_VERSION_SUBSTITUTIONS = {
64    "@LLDB_VERSION@": PACKAGE_VERSION,
65    "@LLDB_VERSION_MAJOR@": LLVM_VERSION_MAJOR,
66    "@LLDB_VERSION_MINOR@": LLVM_VERSION_MINOR,
67    "@LLDB_VERSION_PATCH@": LLVM_VERSION_PATCH,
68    "@LLDB_VERSION_SUFFIX@": LLVM_VERSION_SUFFIX,
69    '#cmakedefine LLDB_FULL_VERSION_STRING "@LLDB_FULL_VERSION_STRING@"': "/* #undef LLDB_FULL_VERSION_STRING */",
70}
71
72genrule(
73    name = "vcs_version_gen",
74    outs = ["VCSVersion.inc"],
75    cmd = "echo '#undef LLDB_REVISION' >> $@\n" +
76          "echo '#undef LLDB_REPOSITORY' >> $@\n",
77)
78
79expand_template(
80    name = "version_inc_gen",
81    out = "Version/Version.inc",
82    substitutions = _VERSION_SUBSTITUTIONS,
83    template = "include/lldb/Version/Version.inc.in",
84)
85
86cc_library(
87    name = "Version",
88    srcs = [
89        "source/Version/Version.cpp",
90        ":vcs_version_gen",
91        ":version_inc_gen",
92    ],
93    hdrs = ["include/lldb/Version/Version.h"],
94    features = ["-layering_check"],  # Version.inc breaks this unintentionally
95    strip_include_prefix = "include",
96    deps = ["//clang:basic"],
97)
98
99expand_template(
100    name = "ConfigHeader",
101    out = "include/lldb/Host/Config.h",
102    substitutions = {
103        "#cmakedefine01 HAVE_PTSNAME_R": "#define HAVE_PTSNAME_R 1",
104        "#cmakedefine01 LLDB_ENABLE_TERMIOS": "#define LLDB_ENABLE_TERMIOS 1",
105
106        # TODO: Add LZMA support by including the library in bazel
107        "#cmakedefine01 LLDB_ENABLE_LZMA": "#define LLDB_ENABLE_LZMA 0",
108
109        # TODO: lua support
110        "#cmakedefine01 LLDB_ENABLE_LUA": "#define LLDB_ENABLE_LUA 0",
111
112        # TODO: curl support
113        "#cmakedefine01 LLVM_ENABLE_CURL": "#define LLVM_ENABLE_CURL 0",
114
115        # TODO: python support
116        "#cmakedefine01 LLDB_ENABLE_PYTHON": "#define LLDB_ENABLE_PYTHON 0",
117        # Only enabled by default on Windows
118        "#cmakedefine01 LLDB_EMBED_PYTHON_HOME": "#define LLDB_EMBED_PYTHON_HOME 0",
119        # Only used if LLDB_EMBED_PYTHON_HOME is true
120        "#cmakedefine LLDB_PYTHON_HOME R\"(${LLDB_PYTHON_HOME})\"": "#define LLDB_PYTHON_HOME \"\"",
121
122        # Unsupported
123        "#cmakedefine01 CURSES_HAVE_NCURSES_CURSES_H": "#define CURSES_HAVE_NCURSES_CURSES_H 0",
124        "#cmakedefine01 LLDB_ENABLE_FBSDVMCORE": "#define LLDB_ENABLE_FBSDVMCORE 0",
125
126        # Defaults that could be configurable if needed
127        "#cmakedefine01 LLDB_ENABLE_POSIX": "#define LLDB_ENABLE_POSIX 1",
128        "#cmakedefine LLDB_GLOBAL_INIT_DIRECTORY R\"(${LLDB_GLOBAL_INIT_DIRECTORY})\"": "#define LLDB_GLOBAL_INIT_DIRECTORY \"\"",
129        "${LLDB_INSTALL_LIBDIR_BASENAME}": "lib",
130        "${LLDB_BUG_REPORT_URL}": "",
131    } | select({
132        "@platforms//os:macos": {
133            "#cmakedefine HAVE_LIBCOMPRESSION": "#define HAVE_LIBCOMPRESSION",
134            "#cmakedefine01 HAVE_NR_PROCESS_VM_READV": "#define HAVE_NR_PROCESS_VM_READV 0",
135            "#cmakedefine01 HAVE_PPOLL": "#define HAVE_PPOLL 0",
136            "#cmakedefine01 HAVE_PROCESS_VM_READV": "#define HAVE_PROCESS_VM_READV 0",
137            "#cmakedefine01 HAVE_SYS_EVENT_H": "#define HAVE_SYS_EVENT_H 1",
138            "#cmakedefine01 LLDB_ENABLE_LIBXML2": "#define LLDB_ENABLE_LIBXML2 1",
139            "#cmakedefine01 LLDB_HAVE_EL_RFUNC_T": "#define LLDB_HAVE_EL_RFUNC_T 0",
140        },
141        "@platforms//os:linux": {
142            "#cmakedefine HAVE_LIBCOMPRESSION": "/* #undef HAVE_LIBCOMPRESSION */",
143            "#cmakedefine01 HAVE_NR_PROCESS_VM_READV": "#define HAVE_NR_PROCESS_VM_READV 1",
144            "#cmakedefine01 HAVE_PPOLL": "#define HAVE_PPOLL 1",
145            "#cmakedefine01 HAVE_PROCESS_VM_READV": "#define HAVE_PROCESS_VM_READV 1",
146            "#cmakedefine01 HAVE_SYS_EVENT_H": "#define HAVE_SYS_EVENT_H 0",
147            "#cmakedefine01 LLDB_ENABLE_LIBXML2": "#define LLDB_ENABLE_LIBXML2 0",
148            "#cmakedefine01 LLDB_HAVE_EL_RFUNC_T": "#define LLDB_HAVE_EL_RFUNC_T 1",
149        },
150    }) | select({
151        ":curses_enabled": {
152            "#cmakedefine01 LLDB_ENABLE_CURSES": "#define LLDB_ENABLE_CURSES 1",
153        },
154        "//conditions:default": {
155            "#cmakedefine01 LLDB_ENABLE_CURSES": "#define LLDB_ENABLE_CURSES 0",
156        },
157    }) | select({
158        ":libedit_enabled": {
159            "#cmakedefine01 LLDB_EDITLINE_USE_WCHAR": "#define LLDB_EDITLINE_USE_WCHAR 1",
160            "#cmakedefine01 LLDB_ENABLE_LIBEDIT": "#define LLDB_ENABLE_LIBEDIT 1",
161        },
162        "//conditions:default": {
163            "#cmakedefine01 LLDB_EDITLINE_USE_WCHAR": "#define LLDB_EDITLINE_USE_WCHAR 0",
164            "#cmakedefine01 LLDB_ENABLE_LIBEDIT": "#define LLDB_ENABLE_LIBEDIT 0",
165        },
166    }),
167    template = "include/lldb/Host/Config.h.cmake",
168)
169
170cc_library(
171    name = "Config",
172    hdrs = [":ConfigHeader"],
173    include_prefix = "lldb/Host",
174)
175
176cc_binary(
177    name = "lldb-tblgen",
178    srcs = glob([
179        "utils/TableGen/*.cpp",
180        "utils/TableGen/*.h",
181    ]),
182    deps = [
183        "//llvm:CodeGenTypes",
184        "//llvm:Support",
185        "//llvm:TableGen",
186        "//llvm:TargetParser",
187        "//llvm:config",
188    ],
189)
190
191py_binary(
192    name = "generate-sbapi-dwarf-enum",
193    srcs = ["scripts/generate-sbapi-dwarf-enum.py"],
194)
195
196genrule(
197    name = "lldb-sbapi-dwarf-enums",
198    srcs = ["//llvm:include/llvm/BinaryFormat/Dwarf.def"],
199    outs = ["include/lldb/API/SBLanguages.h"],
200    cmd = "$(location :generate-sbapi-dwarf-enum) $(location //llvm:include/llvm/BinaryFormat/Dwarf.def) --output $@",
201    tools = [":generate-sbapi-dwarf-enum"],
202)
203
204cc_library(
205    name = "API",
206    srcs = glob([
207        "source/API/**/*.cpp",
208        "source/API/**/*.h",
209    ]),
210    hdrs = glob(["include/lldb/API/**/*.h"]) + [":lldb-sbapi-dwarf-enums"],
211    strip_include_prefix = "include",
212    deps = [
213        ":Breakpoint",
214        ":Commands",
215        ":Core",
216        ":DataFormatters",
217        ":Expression",
218        ":Headers",
219        ":Host",
220        ":Initialization",
221        ":InterpreterHeaders",
222        ":Symbol",
223        ":SymbolHeaders",
224        ":Target",
225        ":TargetHeaders",
226        ":Utility",
227        ":Version",
228        "//lldb/source/Plugins:PluginExpressionParserClang",
229        "//lldb/source/Plugins:PluginExpressionParserClangHeaders",
230        "//lldb/source/Plugins:PluginsConfig",
231        "//llvm:AllTargetsDisassemblers",
232        "//llvm:ExecutionEngine",
233        "//llvm:MCJIT",
234        "//llvm:Support",
235        "//llvm:config",
236    ] + [
237        "//lldb/source/Plugins:Plugin{}".format(x)
238        for x in DEFAULT_PLUGINS + DEFAULT_SCRIPT_PLUGINS
239    ] + select({
240        "@platforms//os:macos": [
241            "//lldb/source/Plugins:PluginProcessMacOSXKernel",
242            "//lldb/source/Plugins:PluginSymbolLocatorDebugSymbols",
243            "//lldb/source/Plugins:PluginSymbolVendorMacOSX",
244        ],
245        "@platforms//os:linux": [
246            "//lldb/source/Plugins:PluginProcessLinux",
247        ],
248        "//conditions:default": [],
249    }),
250    alwayslink = True,
251)
252
253cc_library(
254    name = "Breakpoint",
255    srcs = glob(["source/Breakpoint/**/*.cpp"]),
256    hdrs = glob(["include/lldb/Breakpoint/**/*.h"]),
257    strip_include_prefix = "include",
258    deps = [
259        ":Core",
260        ":DataFormattersHeaders",
261        ":Expression",
262        ":Headers",
263        ":InterpreterHeaders",
264        ":SymbolHeaders",
265        ":TargetHeaders",
266        ":Utility",
267        "//llvm:Support",
268    ],
269)
270
271cc_library(
272    name = "DataFormatters",
273    srcs = glob([
274        "source/DataFormatters/**/*.cpp",
275        "source/DataFormatters/**/*.h",
276    ]),
277    hdrs = glob(["include/lldb/DataFormatters/**/*.h"]),
278    strip_include_prefix = "include",
279    textual_hdrs = glob(["source/DataFormatters/**/*.def"]),
280    deps = [
281        ":CoreHeaders",
282        ":Headers",
283        ":InterpreterHeaders",
284        ":SymbolHeaders",
285        ":TargetHeaders",
286        ":Utility",
287        "//llvm:Support",
288    ],
289)
290
291cc_library(
292    name = "Expression",
293    srcs = glob(["source/Expression/**/*.cpp"]),
294    hdrs = glob(["include/lldb/Expression/**/*.h"]) + [":lldb-sbapi-dwarf-enums"],
295    strip_include_prefix = "include",
296    deps = [
297        ":Core",
298        ":Headers",
299        ":Host",
300        ":InterpreterHeaders",
301        ":SymbolHeaders",
302        ":TargetHeaders",
303        ":Utility",
304        "//lldb/source/Plugins:PluginSymbolFileDWARFHeaders",
305        "//llvm:BinaryFormat",
306        "//llvm:Core",
307        "//llvm:DebugInfoDWARF",
308        "//llvm:ExecutionEngine",
309        "//llvm:Support",
310    ],
311)
312
313cc_library(
314    name = "Initialization",
315    srcs = glob(["source/Initialization/**/*.cpp"]),
316    hdrs = glob(["include/lldb/Initialization/**/*.h"]),
317    strip_include_prefix = "include",
318    deps = [
319        ":Core",
320        ":Headers",
321        ":Host",
322        ":TargetHeaders",
323        ":Utility",
324        ":Version",
325        "//lldb/source/Plugins:PluginProcessGDBRemote",
326        "//lldb/source/Plugins:PluginProcessPOSIX",
327        "//llvm:Support",
328    ],
329)
330
331gentbl_cc_library(
332    name = "InterpreterProperties",
333    strip_include_prefix = "source/Interpreter",
334    tbl_outs = [
335        (
336            ["-gen-lldb-property-defs"],
337            "source/Interpreter/InterpreterProperties.inc",
338        ),
339        (
340            ["-gen-lldb-property-enum-defs"],
341            "source/Interpreter/InterpreterPropertiesEnum.inc",
342        ),
343    ],
344    tblgen = ":lldb-tblgen",
345    td_file = "source/Interpreter/InterpreterProperties.td",
346    deps = [":CoreTdFiles"],
347)
348
349cc_library(
350    name = "APIHeaders",
351    hdrs = glob(["include/lldb/API/**/*.h"]),
352    strip_include_prefix = "include",
353)
354
355cc_library(
356    name = "InterpreterHeaders",
357    hdrs = glob(["include/lldb/Interpreter/**/*.h"]),
358    strip_include_prefix = "include",
359    deps = [":APIHeaders"],
360)
361
362cc_library(
363    name = "BreakpointHeaders",
364    hdrs = glob(["include/lldb/Breakpoint/**/*.h"]),
365    strip_include_prefix = "include",
366)
367
368cc_library(
369    name = "ExpressionHeaders",
370    hdrs = glob(["include/lldb/Expression/**/*.h"]) + [":lldb-sbapi-dwarf-enums"],
371    strip_include_prefix = "include",
372    deps = ["//llvm:ExecutionEngine"],
373)
374
375cc_library(
376    name = "DataFormattersHeaders",
377    hdrs = glob(["include/lldb/DataFormatters/**/*.h"]),
378    strip_include_prefix = "include",
379)
380
381cc_library(
382    name = "Interpreter",
383    srcs = glob(["source/Interpreter/**/*.cpp"]),
384    deps = [
385        ":API",
386        ":Commands",
387        ":Core",
388        ":DataFormatters",
389        ":Headers",
390        ":Host",
391        ":InterpreterHeaders",
392        ":InterpreterProperties",
393        ":SymbolHeaders",
394        ":TargetHeaders",
395        ":Utility",
396        "//llvm:Support",
397    ],
398)
399
400td_library(
401    name = "CommandsTdFiles",
402    srcs = glob(["source/Commands/**/*.td"]),
403)
404
405gentbl_cc_library(
406    name = "CommandOptions",
407    strip_include_prefix = "source/Commands",
408    tbl_outs = [
409        (
410            ["-gen-lldb-option-defs"],
411            "source/Commands/CommandOptions.inc",
412        ),
413    ],
414    tblgen = ":lldb-tblgen",
415    td_file = "source/Commands/Options.td",
416    deps = [":CommandsTdFiles"],
417)
418
419cc_library(
420    name = "Commands",
421    srcs = glob(["source/Commands/**/*.cpp"]),
422    hdrs = glob(["source/Commands/**/*.h"]),
423    strip_include_prefix = "source",
424    deps = [
425        ":Breakpoint",
426        ":CommandOptions",
427        ":Core",
428        ":DataFormatters",
429        ":Expression",
430        ":Headers",
431        ":Host",
432        ":InterpreterHeaders",
433        ":SymbolHeaders",
434        ":Target",
435        ":TargetHeaders",
436        ":Utility",
437        ":Version",
438        "//clang:codegen",
439        "//clang:frontend",
440        "//clang:serialization",
441        "//llvm:Support",
442    ],
443)
444
445cc_library(
446    name = "SymbolHeaders",
447    hdrs = glob(["include/lldb/Symbol/**/*.h"]),
448    strip_include_prefix = "include",
449)
450
451cc_library(
452    name = "Symbol",
453    srcs = glob(["source/Symbol/**/*.cpp"]),
454    deps = [
455        ":Core",
456        ":Expression",
457        ":Headers",
458        ":Host",
459        ":SymbolHeaders",
460        ":TargetHeaders",
461        ":Utility",
462        ":UtilityPrivateHeaders",
463        "//llvm:DebugInfo",
464        "//llvm:DebugInfoDWARF",
465        "//llvm:Support",
466    ],
467)
468
469cc_library(
470    name = "HostMacOSXHeaders",
471    hdrs = glob([
472        "include/lldb/Host/*.h",
473        "include/lldb/Host/macosx/*.h",
474        "include/lldb/Host/posix/*.h",
475    ]),
476    strip_include_prefix = "include",
477    deps = [":UtilityHeaders"],
478)
479
480cc_library(
481    name = "HostMacOSXPrivateHeaders",
482    hdrs = glob([
483        "source/Host/macosx/cfcpp/*.h",
484        "source/Host/macosx/objcxx/*.h",
485    ]),
486    strip_include_prefix = "source",
487    tags = ["nobuildkite"],
488    target_compatible_with = select({
489        "@platforms//os:macos": [],
490        "//conditions:default": ["@platforms//:incompatible"],
491    }),
492    deps = [":UtilityHeaders"],
493)
494
495objc_library(
496    name = "HostMacOSXObjCXX",
497    srcs = glob([
498        "source/Host/macosx/objcxx/*.mm",
499    ]),
500    copts = OBJCPP_COPTS,
501    tags = ["nobuildkite"],
502    target_compatible_with = select({
503        "@platforms//os:macos": [],
504        "//conditions:default": ["@platforms//:incompatible"],
505    }),
506    deps = [
507        ":Headers",
508        ":HostMacOSXHeaders",
509        ":HostMacOSXPrivateHeaders",
510        ":UtilityHeaders",
511        "//llvm:Support",
512        "//llvm:TargetParser",
513    ],
514)
515
516cc_library(
517    name = "Host",
518    srcs = glob([
519        "source/Host/common/**/*.cpp",
520    ]) + select({
521        "@platforms//os:linux": glob(
522            [
523                "source/Host/posix/**/*.cpp",
524                "source/Host/linux/**/*.cpp",
525            ],
526            exclude = ["source/Host/linux/android/**/*.cpp"],
527        ),
528        "@platforms//os:macos": glob(
529            [
530                "source/Host/macosx/cfcpp/*.cpp",
531                "source/Host/posix/**/*.cpp",
532            ],
533        ),
534    }),
535    hdrs = [":ConfigHeader"] + glob([
536        "include/lldb/Host/*.h",
537        "include/lldb/Host/common/*.h",
538    ]) + select({
539        "@platforms//os:macos": glob([
540            "include/lldb/Host/macosx/*.h",
541            "include/lldb/Host/posix/*.h",
542        ]),
543        "@platforms//os:linux": glob([
544            "include/lldb/Host/linux/*.h",
545            "include/lldb/Host/posix/*.h",
546        ]),
547    }),
548    # TODO: Move this to Config library when https://github.com/bazelbuild/bazel/issues/21884 is fixed
549    linkopts = select({
550        "@platforms//os:macos": [
551            "-lcompression",
552            "-lxml2",
553            "-Wl,-framework,CoreServices",
554            "-Wl,-framework,Security",
555        ],
556        "//conditions:default": [],
557    }) + select({
558        ":curses_enabled": [
559            "-lcurses",
560            "-lpanel",
561        ],
562        "//conditions:default": [],
563    }) + select({
564        ":libedit_enabled": [
565            "-ledit",
566        ],
567        "//conditions:default": [],
568    }),
569    strip_include_prefix = "include",
570    deps = [
571        ":Headers",
572        ":UtilityHeaders",
573        "//llvm:Object",
574        "//llvm:Support",
575        "//llvm:TargetParser",
576        "//llvm:config",
577    ] + select({
578        "@platforms//os:macos": [
579            ":HostMacOSXObjCXX",
580            ":HostMacOSXPrivateHeaders",
581        ],
582        "//conditions:default": [],
583    }),
584)
585
586td_library(
587    name = "CoreTdFiles",
588    srcs = glob([
589        "source/Core/**/*.td",
590        "include/lldb/Core/*.td",
591    ]),
592)
593
594gentbl_cc_library(
595    name = "CoreProperties",
596    strip_include_prefix = "source/Core",
597    tbl_outs = [
598        (
599            ["-gen-lldb-property-defs"],
600            "source/Core/CoreProperties.inc",
601        ),
602        (
603            ["-gen-lldb-property-enum-defs"],
604            "source/Core/CorePropertiesEnum.inc",
605        ),
606    ],
607    tblgen = ":lldb-tblgen",
608    td_file = "source/Core/CoreProperties.td",
609    deps = [":CoreTdFiles"],
610)
611
612cc_library(
613    name = "CoreHeaders",
614    hdrs = glob([
615        "include/lldb/Core/**/*.h",
616        "include/lldb/ValueObject/**/*.h",  # This should be its own library.
617    ]),
618    strip_include_prefix = "include",
619    deps = [
620        ":BreakpointHeaders",
621        ":CoreProperties",
622        ":DataFormattersHeaders",
623        ":ExpressionHeaders",
624        ":Host",
625        ":InterpreterHeaders",
626        ":SymbolHeaders",
627        ":TargetHeaders",
628        "//clang:driver",
629        "//llvm:Demangle",
630        "//llvm:Support",
631        "//llvm:TargetParser",
632    ],
633)
634
635cc_library(
636    name = "Core",
637    srcs = glob([
638        "source/Core/**/*.cpp",
639        "source/ValueObject/**/*.cpp",  # This should be its own library.
640    ]),
641    hdrs = glob([
642        "include/lldb/Core/**/*.h",
643        "include/lldb/ValueObject/**/*.h",  # This should be its own library.
644    ]),
645    strip_include_prefix = "include",
646    deps = [
647        ":BreakpointHeaders",
648        ":CoreHeaders",
649        ":CoreProperties",
650        ":DataFormattersHeaders",
651        ":ExpressionHeaders",
652        ":Headers",
653        ":Host",
654        ":InterpreterHeaders",
655        ":SymbolHeaders",
656        ":TargetHeaders",
657        ":Utility",
658        "//clang:driver",
659        "//lldb/source/Plugins:PluginCPlusPlusLanguageHeaders",
660        "//lldb/source/Plugins:PluginObjCLanguageHeaders",
661        "//llvm:Demangle",
662        "//llvm:Support",
663        "//llvm:TargetParser",
664    ],
665)
666
667gentbl_cc_library(
668    name = "TargetProperties",
669    strip_include_prefix = "source/Target",
670    tbl_outs = [
671        (
672            ["-gen-lldb-property-defs"],
673            "source/Target/TargetProperties.inc",
674        ),
675        (
676            ["-gen-lldb-property-enum-defs"],
677            "source/Target/TargetPropertiesEnum.inc",
678        ),
679    ],
680    tblgen = ":lldb-tblgen",
681    td_file = "source/Target/TargetProperties.td",
682    deps = [":CoreTdFiles"],
683)
684
685cc_library(
686    name = "AppleArm64ExceptionClass",
687    hdrs = ["include/lldb/Target/AppleArm64ExceptionClass.def"],
688    strip_include_prefix = "include/lldb/Target",
689)
690
691cc_library(
692    name = "TargetHeaders",
693    hdrs = glob(["include/lldb/Target/**/*.h"]),
694    strip_include_prefix = "include",
695    deps = [
696        ":AppleArm64ExceptionClass",
697        ":BreakpointHeaders",
698    ],
699)
700
701cc_library(
702    name = "Target",
703    srcs = glob(["source/Target/**/*.cpp"]),
704    deps = [
705        ":BreakpointHeaders",
706        ":Core",
707        ":DataFormattersHeaders",
708        ":ExpressionHeaders",
709        ":Headers",
710        ":Host",
711        ":InterpreterHeaders",
712        ":Symbol",
713        ":SymbolHeaders",
714        ":TargetHeaders",
715        ":TargetProperties",
716        ":Utility",
717        "//clang:codegen",
718        "//lldb/source/Plugins:PluginProcessUtility",
719        "//llvm:BinaryFormat",
720        "//llvm:MC",
721        "//llvm:Support",
722    ],
723)
724
725cc_library(
726    name = "Headers",
727    hdrs = glob(["include/lldb/lldb-*.h"]) + [
728        "include/lldb/Symbol/SaveCoreOptions.h",
729    ],
730    strip_include_prefix = "include",
731)
732
733cc_library(
734    name = "UtilityPrivateHeaders",
735    hdrs = glob(["source/Utility/**/*.h"]),
736    strip_include_prefix = "source",
737    deps = [":Headers"],
738)
739
740cc_library(
741    name = "UtilityHeaders",
742    hdrs = glob(["include/lldb/Utility/**/*.h"]),
743    strip_include_prefix = "include",
744)
745
746cc_library(
747    name = "Utility",
748    srcs = glob(["source/Utility/**/*.cpp"]),
749    hdrs = glob(["include/lldb/Utility/**/*.h"]),
750    strip_include_prefix = "include",
751    deps = [
752        ":CoreHeaders",
753        ":Headers",
754        ":TargetHeaders",
755        ":UtilityPrivateHeaders",
756        "//llvm:BinaryFormat",
757        "//llvm:Support",
758        "//llvm:TargetParser",
759        "//llvm:config",
760    ],
761)
762
763genrule(
764    name = "gen_exports_file_linux",
765    srcs = ["//lldb:source/API/liblldb-private.exports"],
766    outs = ["exports_linux.txt"],
767    cmd = """
768cat > $(OUTS) <<EOF
769{
770  global:
771    $$(sed 's/$$/;/g' $(SRCS))
772};
773EOF
774""",
775)
776
777genrule(
778    name = "gen_exports_file_macos",
779    srcs = ["//lldb:source/API/liblldb-private.exports"],
780    outs = ["exports_macos.txt"],
781    cmd = "sed 's/^/_/g' $(SRCS) > $(OUTS)",
782)
783
784# Create a shared library using linkshared=True for liblldb. This uses
785# cc_binary instead of cc_shared_library since the latter expects you to
786# re-export all transitive dependencies vs them being relinked into other
787# binaries.
788cc_binary(
789    name = "lldb{}".format(PACKAGE_VERSION),
790    additional_linker_inputs = select({
791        "@platforms//os:linux": [
792            ":gen_exports_file_linux",
793        ],
794        "@platforms//os:macos": [
795            ":gen_exports_file_macos",
796        ],
797        "//conditions:default": [],
798    }),
799    linkopts = select({
800        "@platforms//os:linux": [
801            "-Wl,--export-dynamic-symbol-list=$(location :gen_exports_file_linux)",
802        ],
803        "@platforms//os:macos": [
804            "-Wl,-exported_symbols_list,$(location :gen_exports_file_macos)",
805        ],
806        "//conditions:default": [],
807    }),
808    linkshared = True,
809    deps = [
810        ":API",
811        ":Interpreter",
812    ],
813)
814
815# cc_binary targets using linkshared=True to build a shared library cannot be
816# imported directly and instead need to be referenced indirectly through
817# cc_import
818cc_import(
819    name = "liblldb.wrapper",
820    shared_library = "lldb{}".format(PACKAGE_VERSION),
821)
822
823gentbl_cc_library(
824    name = "lldb_options_inc_gen",
825    strip_include_prefix = ".",
826    tbl_outs = [(
827        ["-gen-opt-parser-defs"],
828        "Options.inc",
829    )],
830    tblgen = "//llvm:llvm-tblgen",
831    td_file = "tools/driver/Options.td",
832    deps = ["//llvm:OptParserTdFiles"],
833)
834
835alias(
836    name = "gdb-server",
837    actual = select({
838        "@platforms//os:macos": ":debugserver",
839        "//conditions:default": ":lldb-server",
840    }),
841)
842
843cc_binary(
844    name = "lldb",
845    srcs = glob([
846        "tools/driver/*.cpp",
847        "tools/driver/*.h",
848    ]),
849    deps = [
850        ":APIHeaders",
851        ":Host",
852        ":liblldb.wrapper",
853        ":lldb_options_inc_gen",
854        "//llvm:Option",
855        "//llvm:Support",
856    ],
857)
858
859cc_library(
860    name = "DebugServerCommonMacOSXHeaders",
861    hdrs = glob(["tools/debugserver/source/MacOSX/**/*.h"]),
862    strip_include_prefix = "tools/debugserver/source/MacOSX",
863)
864
865cc_library(
866    name = "DebugServerCommonHeaders",
867    hdrs = glob(["tools/debugserver/source/**/*.h"]),
868    strip_include_prefix = "tools/debugserver/source",
869    deps = [":DebugServerCommonMacOSXHeaders"],
870)
871
872objc_library(
873    name = "DebugServerMacOSX",
874    srcs = glob(["tools/debugserver/source/MacOSX/*.mm"]),
875    copts = OBJCPP_COPTS,
876    tags = ["nobuildkite"],
877    target_compatible_with = select({
878        "@platforms//os:macos": [],
879        "//conditions:default": ["@platforms//:incompatible"],
880    }),
881    deps = [
882        ":DebugServerCommonHeaders",
883        ":DebugServerCommonMacOSXHeaders",
884    ],
885)
886
887cc_library(
888    name = "DebugServerCommon",
889    srcs = glob(
890        ["tools/debugserver/source/**/*.cpp"],
891        exclude = ["tools/debugserver/source/debugserver.cpp"],
892    ),
893    local_defines = ["LLDB_USE_OS_LOG"],
894    tags = ["nobuildkite"],
895    deps = [
896        ":DebugServerCommonHeaders",
897        ":DebugServerCommonMacOSXHeaders",
898        ":DebugServerMacOSX",
899        ":Host",
900    ],
901)
902
903apple_genrule(
904    name = "mach_gen",
905    srcs = ["tools/debugserver/source/MacOSX/dbgnub-mig.defs"],
906    outs = [
907        "mach_exc.h",
908        "mach_excServer.c",
909        "mach_excUser.c",
910    ],
911    cmd = "mig -header $(location :mach_exc.h) -server $(location :mach_excServer.c) -user $(location :mach_excUser.c) $(SRCS)",
912    tags = [
913        "manual",
914        "nobuildkite",
915    ],
916    target_compatible_with = select({
917        "@platforms//os:macos": [],
918        "//conditions:default": ["@platforms//:incompatible"],
919    }),
920)
921
922expand_template(
923    name = "debugserver_version_gen",
924    out = "debugserver_vers.c",
925    substitutions = _VERSION_SUBSTITUTIONS,
926    template = "tools/debugserver/source/debugserver_vers.c.in",
927)
928
929cc_binary(
930    name = "debugserver_unsigned",
931    srcs = [
932        "tools/debugserver/source/debugserver.cpp",
933        ":debugserver_version_gen",
934        ":mach_gen",
935    ],
936    tags = ["nobuildkite"],
937    target_compatible_with = select({
938        "@platforms//os:macos": [],
939        "//conditions:default": ["@platforms//:incompatible"],
940    }),
941    deps = [
942        ":DebugServerCommon",
943        ":DebugServerCommonHeaders",
944        ":DebugServerCommonMacOSXHeaders",
945    ],
946)
947
948apple_genrule(
949    name = "debugserver_signed",
950    srcs = [":debugserver_unsigned"],
951    outs = ["debugserver"],
952    cmd = "cp $(SRCS) $(OUTS) && xcrun codesign -f -s - --entitlements $(location tools/debugserver/resources/debugserver-macosx-entitlements.plist) $(OUTS)",
953    tags = [
954        "manual",
955        "nobuildkite",
956    ],
957    target_compatible_with = select({
958        "@platforms//os:macos": [],
959        "//conditions:default": ["@platforms//:incompatible"],
960    }),
961    tools = [
962        "tools/debugserver/resources/debugserver-macosx-entitlements.plist",
963    ],
964)
965
966cc_binary(
967    name = "lldb-argdumper",
968    srcs = glob(["tools/argdumper/*.cpp"]),
969    deps = ["//llvm:Support"],
970)
971
972gentbl_cc_library(
973    name = "lldb_server_opts_gen",
974    strip_include_prefix = ".",
975    tbl_outs = [(
976        ["-gen-opt-parser-defs"],
977        "LLGSOptions.inc",
978    )],
979    tblgen = "//llvm:llvm-tblgen",
980    td_file = "tools/lldb-server/LLGSOptions.td",
981    deps = ["//llvm:OptParserTdFiles"],
982)
983
984cc_binary(
985    name = "lldb-server",
986    srcs = glob([
987        "tools/lldb-server/*.cpp",
988        "tools/lldb-server/*.h",
989    ]),
990    target_compatible_with = select({
991        "@platforms//os:linux": [],
992        "@platforms//os:macos": [],
993        # TODO: This can theoretically support more platforms, but it hasn't been tested yet
994        "//conditions:default": ["@platforms//:incompatible"],
995    }),
996    deps = [
997        ":Host",
998        ":Initialization",
999        ":Interpreter",
1000        ":Utility",
1001        ":Version",
1002        ":lldb_server_opts_gen",
1003        "//lldb:Target",
1004        "//lldb:TargetHeaders",
1005        "//lldb/source/Plugins:PluginCPlusPlusLanguage",
1006        "//lldb/source/Plugins:PluginExpressionParserClang",
1007        "//lldb/source/Plugins:PluginInstructionARM",
1008        "//lldb/source/Plugins:PluginInstructionARM64",
1009        "//lldb/source/Plugins:PluginInstructionLoongArch",
1010        "//lldb/source/Plugins:PluginInstructionMIPS",
1011        "//lldb/source/Plugins:PluginInstructionMIPS64",
1012        "//lldb/source/Plugins:PluginInstructionRISCV",
1013        "//lldb/source/Plugins:PluginObjCLanguage",
1014        "//lldb/source/Plugins:PluginProcessGDBRemote",
1015        "//lldb/source/Plugins:PluginSymbolFileDWARF",
1016        "//lldb/source/Plugins:PluginSymbolFileNativePDB",
1017        "//lldb/source/Plugins:PluginSymbolFilePDB",
1018        "//lldb/source/Plugins:PluginTypeSystemClang",
1019        "//llvm:Option",
1020        "//llvm:Support",
1021    ] + select({
1022        "@platforms//os:linux": [
1023            "//lldb/source/Plugins:PluginObjectFileELF",
1024            "//lldb/source/Plugins:PluginProcessLinux",
1025        ],
1026        "@platforms//os:macos": [
1027            "//lldb/source/Plugins:PluginObjectFileMachO",
1028        ],
1029        "//conditions:default": [],
1030    }),
1031)
1032
1033expand_template(
1034    name = "lldb-dap-plist",
1035    out = "lldb-dap-Info.plist",
1036    substitutions = {
1037        "${LLDB_VERSION}": PACKAGE_VERSION,
1038    },
1039    template = "tools/lldb-dap/lldb-dap-Info.plist.in",
1040)
1041
1042gentbl_cc_library(
1043    name = "lldb_dap_opts_gen",
1044    strip_include_prefix = "tools/lldb-dap",
1045    tbl_outs = [(
1046        ["-gen-opt-parser-defs"],
1047        "tools/lldb-dap/Options.inc",
1048    )],
1049    tblgen = "//llvm:llvm-tblgen",
1050    td_file = "tools/lldb-dap/Options.td",
1051    deps = ["//llvm:OptParserTdFiles"],
1052)
1053
1054cc_binary(
1055    name = "lldb-dap",
1056    srcs = glob([
1057        "tools/lldb-dap/*.cpp",
1058        "tools/lldb-dap/*.h",
1059    ]),
1060    additional_linker_inputs = [
1061        ":lldb-dap-plist",
1062    ],
1063    linkopts = select({
1064        "@platforms//os:macos": [
1065            "-Wl,-sectcreate,__TEXT,__info_plist,$(location :lldb-dap-plist)",
1066        ],
1067        "//conditions:default": [],
1068    }),
1069    deps = [
1070        ":lldb_dap_opts_gen",
1071        "//lldb:APIHeaders",
1072        "//lldb:Headers",
1073        "//lldb:Host",
1074        "//lldb:Utility",
1075        "//lldb:liblldb.wrapper",
1076        "//llvm:Option",
1077        "//llvm:Support",
1078        "//llvm:config",
1079    ],
1080)
1081