diff --git a/BUILD.backward-stacktrace.bazel b/BUILD.backward-stacktrace.bazel deleted file mode 100644 index 52188a0..0000000 --- a/BUILD.backward-stacktrace.bazel +++ /dev/null @@ -1,13 +0,0 @@ -# Use this library in order to get more consistent -# stack trace on any failure. -cc_library( - name = "backward-stacktrace", - srcs = ["backward-stacktrace.cc"], - hdrs = ["backward-stacktrace.h"], - visibility = ["//visibility:public"], - deps = [ - "@com_github_backward_cpp//:backward", - "@com_github_google_googletest//:gtest", - ], - alwayslink = True, -) diff --git a/BUILD.bazel b/BUILD.bazel index d6a7ef7..84a7a00 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -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/ @@ -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 @@ -71,10 +74,8 @@ 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({ @@ -82,15 +83,20 @@ cc_library( "@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 diff --git a/backward-stacktrace.h b/backward-stacktrace.h index 0915dde..4b9d022 100644 --- a/backward-stacktrace.h +++ b/backward-stacktrace.h @@ -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. diff --git a/backward_cpp.patch b/backward_cpp.patch new file mode 100644 index 0000000..d9ade02 --- /dev/null +++ b/backward_cpp.patch @@ -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") diff --git a/bazel/deps.bzl b/bazel/deps.bzl index ddd8d71..e541786 100644 --- a/bazel/deps.bzl +++ b/bazel/deps.bzl @@ -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", - ) diff --git a/bazel/repos.bzl b/bazel/repos.bzl index d37bf49..61fbe53 100644 --- a/bazel/repos.bzl +++ b/bazel/repos.bzl @@ -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"], )