-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBUILD.bazel
100 lines (96 loc) · 3.1 KB
/
BUILD.bazel
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")
# `binutils` library needs this.
configure_make(
name = "lzma",
configure_in_place = True,
env = select({
# Without this option on macOS we will have the following issue:
# .../libtool: no output file specified (specify with -o output).
"@bazel_tools//src/conditions:darwin": {"AR": ""},
"//conditions:default": {},
}),
lib_source = "@com_github_lzma//:all",
out_static_libs = [
"liblzma.a",
],
)
# Libunwind (https://github.com/libunwind/libunwind) unlike libunwind from
# libgcc provides, in some cases, a more accurate stacktrace as it knows
# to decode signal handler frames and lets us edit the context registers
# when unwinding, allowing stack traces over bad function references. On
# macOS clang provides a libunwind API compatible library as part of its
# environment, so no third party libraries are necessary.
# https://github.com/bombela/backward-cpp#libraries-to-unwind-the-stack
configure_make(
name = "libunwind",
configure_in_place = True,
lib_source = "@com_github_libunwind//:all",
out_static_libs = [
"libunwind.a",
],
)
# We need 'binutils' in order to read the debug info if we want to get
# the ultimate stack trace.
configure_make(
name = "binutils",
args = [
# Without this make argument binutils will not compile.
# https://www.linuxquestions.org/questions/linux-from-scratch-13/problem-compiling-binutils-575412/
"MAKEINFO=true",
],
configure_in_place = True,
configure_options = [
"--enable-install-libiberty",
],
env = select({
# Without this option on macOS we will have the following issue:
# .../libtool: no output file specified (specify with -o output).
"@bazel_tools//src/conditions:darwin": {"AR": ""},
"//conditions:default": {},
}),
lib_source = "@com_github_binutils//:all",
out_static_libs = [
"libbfd.a",
"libiberty.a",
],
)
cc_library(
name = "backward",
hdrs = [
"backward.hpp"
],
defines = [
# For binutils
"BACKWARD_HAS_BFD=1",
# For libunwind
"BACKWARD_HAS_LIBUNWIND=1",
],
linkopts = [
# For binutils
"-ldl",
"-lz",
],
visibility = ["//visibility:public"],
# For now we support this library for macOS and Linux. Maybe in
# future we will add the support for Windows too.
target_compatible_with = select({
"@platforms//os:osx": [],
"@platforms//os:linux": [],
"//conditions:default": ["@platforms//:incompatible"],
}),
deps = select({
"@bazel_tools//src/conditions:darwin": [
":binutils",
":lzma",
],
"//conditions:default": [
":binutils",
":libunwind",
":lzma",
],
}),
# Link any binary that depends (directly or indirectly) on this C++ library
# in all the object files for the files listed in srcs, even if some contain
# no symbols referenced by the binary.
alwayslink = True,
)