Skip to content

New way of building backtrace #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions BUILD.backward-stacktrace.bazel

This file was deleted.

20 changes: 13 additions & 7 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ configure_make(
# We need 'binutils' in order to read the debug info if we want to get
# the ultimate stack trace.
configure_make(
name = "binutils",
name = "binutils_bazelified",
args = [
# Without this make argument binutils will not compile.
# https://www.linuxquestions.org/questions/linux-from-scratch-13/problem-compiling-binutils-575412/
Expand All @@ -59,9 +59,12 @@ configure_make(
)

cc_library(
name = "backward",
name = "backward-stacktrace",
srcs = [
"backward-stacktrace.cc",
],
hdrs = [
"backward.hpp"
"backward-stacktrace.h",
],
defines = [
# For binutils
Expand All @@ -71,26 +74,29 @@ cc_library(
],
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"],
}),
visibility = ["//visibility:public"],
deps = select({
"@bazel_tools//src/conditions:darwin": [
":binutils",
":binutils_bazelified",
":lzma",
"@com_github_backward_cpp//:backward",
"@com_github_google_googletest//:gtest",
],
"//conditions:default": [
":binutils",
":binutils_bazelified",
":libunwind",
":lzma",
"@com_github_backward_cpp//:backward",
"@com_github_google_googletest//:gtest",
],
}),
# Link any binary that depends (directly or indirectly) on this C++ library
Expand Down
2 changes: 1 addition & 1 deletion backward-stacktrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace backward_stacktrace {
// (check_line_length skip)
// https://github.com/YOU-i-Labs/googletest/blob/master/googletest/docs/V1_7_AdvancedGuide.md#global-set-up-and-tear-down
class BackwardStackTrace : public ::testing::Environment {
private:
private:
// A simple helper class that registers for you the most
// common signals and other callbacks to segfault,
// hardware exception, un-handled exception etc.
Expand Down
18 changes: 18 additions & 0 deletions backward_cpp.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
diff --git a/BUILD.bazel b/BUILD.bazel
new file mode 100644
index 0000000..83e888a
--- /dev/null
+++ b/BUILD.bazel
@@ -0,0 +1,5 @@
+cc_library(
+ name = "backward",
+ hdrs = ["backward.hpp"],
+ visibility = ["//visibility:public"],
+)
diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel
new file mode 100644
index 0000000..2a5377b
--- /dev/null
+++ b/WORKSPACE.bazel
@@ -0,0 +1 @@
+workspace(name = "backward_cpp")
84 changes: 0 additions & 84 deletions bazel/deps.bzl
Original file line number Diff line number Diff line change
@@ -1,90 +1,6 @@
"""Dependency specific initialization."""

load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")

_ALL_CONTENT = """\
filegroup(
name = "all",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
"""

def deps(repo_mapping = {}):
rules_foreign_cc_dependencies()

# Get the latest rules for building C/C++ projects.
maybe(
http_archive,
name = "rules_foreign_cc",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.8.0.tar.gz",
sha256 = "6041f1374ff32ba711564374ad8e007aef77f71561a7ce784123b9b4b88614fc",
strip_prefix = "rules_foreign_cc-0.8.0",
repo_mapping = repo_mapping,
)

# Get the latest texinfo version. 'binutils' doesn't compile
# without this binary.
maybe(
http_archive,
name = "com_github_texinfo",
url = "https://ftp.gnu.org/gnu/texinfo/texinfo-6.8.tar.xz",
build_file_content = _ALL_CONTENT,
sha256 = "8eb753ed28bca21f8f56c1a180362aed789229bd62fff58bf8368e9beb59fec4",
strip_prefix = "texinfo-6.8",
)

# Get the latest binutils version to read the debug info.
maybe(
http_archive,
name = "com_github_binutils",
url = "https://ftp.gnu.org/gnu/binutils/binutils-2.38.tar.gz",
build_file_content = _ALL_CONTENT,
sha256 = "b3f1dc5b17e75328f19bd88250bee2ef9f91fc8cbb7bd48bdb31390338636052",
strip_prefix = "binutils-2.38",
)

# Get the latest libunwind version to unwind the stack. (There is no need
# in this library on macOS, because on macOS clang provides a libunwind API
# compatible library as part of its environment).
maybe(
http_archive,
name = "com_github_libunwind",
url = "https://github.com/libunwind/libunwind/releases/download/v1.6.2/libunwind-1.6.2.tar.gz",
build_file_content = _ALL_CONTENT,
sha256 = "4a6aec666991fb45d0889c44aede8ad6eb108071c3554fcdff671f9c94794976",
strip_prefix = "libunwind-1.6.2",
)

# Get the latest lzma version.
maybe(
new_git_repository,
name = "com_github_lzma",
remote = "https://github.com/kobolabs/liblzma.git",
build_file_content = _ALL_CONTENT,
commit = "87b7682ce4b1c849504e2b3641cebaad62aaef87",
shallow_since = "1385587354 -0500",
)

# Get the latest gtest version.
maybe(
http_archive,
name = "com_github_google_googletest",
url = "https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz",
sha256 = "81964fe578e9bd7c94dfdb09c8e4d6e6759e19967e397dbea48d1c10e45d0df2",
strip_prefix = "googletest-release-1.12.1",
repo_mapping = repo_mapping,
)

maybe(
http_archive,
name = "com_github_backward_cpp",
url = "https://github.com/bombela/backward-cpp/archive/refs/tags/v1.6.tar.gz",
sha256 = "c654d0923d43f1cea23d086729673498e4741fb2457e806cfaeaea7b20c97c10",
strip_prefix = "backward-cpp-1.6",
repo_mapping = repo_mapping,
build_file = "@com_github_3rdparty_bazel_rules_backward_cpp//:BUILD.bazel",
)
87 changes: 75 additions & 12 deletions bazel/repos.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,87 @@
# instructions at https://github.com/3rdparty/bazel-rules-backward-cpp.
########################################################################

load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:utils.bzl", "maybe")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "new_git_repository")

def repos(external = True, repo_mapping = {}):
_ALL_CONTENT = """\
filegroup(
name = "all",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
)
"""

def repos(external = True, repo_mapping = {}, workspace_prefix = ""):
maybe(
git_repository,
name = "com_github_3rdparty_bazel_rules_backward_cpp",
remote = "https://github.com/3rdparty/bazel-rules-backward-cpp",
commit = "69449957a41619e9b8b8be2e9bfaca2ac0642760",
shallow_since = "1658132015 +0300",
http_archive,
name = "rules_foreign_cc",
url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
strip_prefix = "rules_foreign_cc-0.9.0",
repo_mapping = repo_mapping,
)

# Get version. 'binutils' doesn't compile
# without this binary.
maybe(
http_archive,
name = "com_github_texinfo",
url = "https://ftp.gnu.org/gnu/texinfo/texinfo-6.8.tar.xz",
build_file_content = _ALL_CONTENT,
sha256 = "8eb753ed28bca21f8f56c1a180362aed789229bd62fff58bf8368e9beb59fec4",
strip_prefix = "texinfo-6.8",
)

# Get binutils to read the debug info.
maybe(
http_archive,
name = "com_github_binutils",
url = "https://ftp.gnu.org/gnu/binutils/binutils-2.38.tar.gz",
build_file_content = _ALL_CONTENT,
sha256 = "b3f1dc5b17e75328f19bd88250bee2ef9f91fc8cbb7bd48bdb31390338636052",
strip_prefix = "binutils-2.38",
)

# Get libunwind to unwind the stack. (There is no need
# in this library on macOS, because on macOS clang provides a libunwind API
# compatible library as part of its environment).
maybe(
http_archive,
name = "com_github_libunwind",
url = "https://github.com/libunwind/libunwind/releases/download/v1.6.2/libunwind-1.6.2.tar.gz",
build_file_content = _ALL_CONTENT,
sha256 = "4a6aec666991fb45d0889c44aede8ad6eb108071c3554fcdff671f9c94794976",
strip_prefix = "libunwind-1.6.2",
)

maybe(
new_git_repository,
name = "com_github_3rdparty_bazel_rules_backward_cpp_stacktrace",
remote = "https://github.com/3rdparty/bazel-rules-backward-cpp",
build_file = "@com_github_3rdparty_bazel_rules_backward_cpp//:BUILD.backward-stacktrace.bazel",
commit = "69449957a41619e9b8b8be2e9bfaca2ac0642760",
shallow_since = "1658132015 +0300",
name = "com_github_lzma",
remote = "https://github.com/kobolabs/liblzma.git",
build_file_content = _ALL_CONTENT,
commit = "87b7682ce4b1c849504e2b3641cebaad62aaef87",
shallow_since = "1385587354 -0500",
)

# Get the latest gtest version.
maybe(
http_archive,
name = "com_github_google_googletest",
url = "https://github.com/google/googletest/archive/refs/tags/release-1.12.1.tar.gz",
sha256 = "81964fe578e9bd7c94dfdb09c8e4d6e6759e19967e397dbea48d1c10e45d0df2",
strip_prefix = "googletest-release-1.12.1",
repo_mapping = repo_mapping,
)

maybe(
http_archive,
name = "com_github_backward_cpp",
url = "https://github.com/bombela/backward-cpp/archive/refs/tags/v1.6.tar.gz",
sha256 = "c654d0923d43f1cea23d086729673498e4741fb2457e806cfaeaea7b20c97c10",
strip_prefix = "backward-cpp-1.6",
repo_mapping = repo_mapping,
patch_args = ["-p1"],
patches = [workspace_prefix + "//:backward_cpp.patch"],
)