Skip to content
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
1 change: 1 addition & 0 deletions .bazelignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cmake-build-debug
1 change: 0 additions & 1 deletion .bazeliskrc

This file was deleted.

6 changes: 5 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
test --strip=never
test --test_output=all
test --copt=-g
test --spawn_strategy=local
test --compilation_mode=dbg
build --strip=never
build --spawn_strategy=local
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't setting --spawn_strategy=local defeat much of the purpose of bazel, i.e. hermetic builds?

build --compilation_mode=dbg
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it'd be better to not force debug mode globally?

1 change: 1 addition & 0 deletions .bazelversion
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
8.4.1
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ jobs:
- uses: actions/checkout@v4
- name: dependencies
run: |
sudo apt install -y libtool libncurses5
sudo apt install -y libtool libncurses5 libc6-dev
- name: test dbg
run: |
bazel test //... -c dbg
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ bazel-*/
cmake-build-*/

test/jank/data

# bazel out
bazel-*
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: duplicate with above

MODULE.bazel.lock
108 changes: 89 additions & 19 deletions BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,34 +1,104 @@
load("@rules_cc//cc:defs.bzl", "cc_library")

COMMON_FLAGS = [
"--std=c++11",
"-fPIC",
"-Wall",
"-Wextra",
"-Werror=return-type",
"-Wundef",
"-g",
"-O0",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this going to force -O0 for the library build?

"-gdwarf-4",
"-fPIC",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: Duplicate

]

GCC_FLAGS = COMMON_FLAGS + [
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is GCC_FLAGS used?

"-Wuseless-cast",
"-Wmaybe-uninitialized",
"-fdiagnostics-color=always",
]

CLANG_FLAGS = COMMON_FLAGS + ["-fcolor-diagnostics"]
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Color diagnostics is useful to set in cmake because otherwise compilers don't emit color diagnostics under ninja, but I think this might not be needed in bazel?


cc_library(
name = "cpptrace",
srcs = glob([
"src/**/*.hpp",
"src/**/*.cpp",
]),
local_defines = [
"CPPTRACE_GET_SYMBOLS_WITH_LIBDWARF",
"CPPTRACE_DEMANGLE_WITH_CXXABI",
"CPPTRACE_UNWIND_WITH_LIBUNWIND"
],
hdrs = glob([
"include/cpptrace/*.hpp",
"include/ctrace/*.h",
]),
copts = select(
{
"@rules_cc//cc/compiler:msvc-cl": [
"/W4",
"/permissive-",
"/FS",
],
"@rules_cc//cc/compiler:gcc": [
"-Wall",
"-Wextra",
"-Werror=return-type",
"-Wundef",
"-Wuninitialized",
"-fPIC",
"-std=c++11",
],
"@rules_cc//cc/compiler:clang": CLANG_FLAGS,
"//conditions:default": COMMON_FLAGS,
},
),
defines = ["CPPTRACE_STATIC_DEFINE"],
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an option that needs to be specified by anyone using the static cpptrace build, it shouldn't be set by cpptrace itself for cpptrace's sources.

Copy link
Copy Markdown
Author

@hugooole hugooole Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bazel's cc_library is static by default, so I add this option by default

includes = [
"include",
"src"
],
deps = [
"@libdwarf//:libdwarf",
"@libunwind//:libunwind"
],
copts = [
"-Wall",
"-Wextra",
"-Werror=return-type",
"-Wundef",
"-Wuninitialized",
"-fPIC",
"-std=c++11"
"src",
],
linkopts = select({
"@platforms//os:windows": ["dbghelp.lib"],
"//conditions:default": [],
}),
linkstatic = select({
"@platforms//os:windows": False,
"//conditions:default": True,
}),
Comment on lines +63 to +66
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the reason to force dynamic linkage on windows?

local_defines = select({
"@platforms//os:windows": [
"CPPTRACE_DEMANGLE_WITH_WINAPI",
"CPPTRACE_GET_SYMBOLS_WITH_DBGHELP",
"CPPTRACE_UNWIND_WITH_DBGHELP",
],
"@platforms//os:linux": [
"CPPTRACE_HAS_DL_FIND_OBJECT",
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard-coding this will likely cause problems since _dl_find_object support requires a relatively new glibc (which many mainstream linux distributions are behind). Is there a way to dynamically detect support in bazel like we do in cmake?

"CPPTRACE_DEMANGLE_WITH_CXXABI",
"CPPTRACE_UNWIND_WITH_LIBUNWIND",
"CPPTRACE_GET_SYMBOLS_WITH_LIBDWARF",
],
"@platforms//os:macos": [
"CPPTRACE_HAS_MACH_VM",
"CPPTRACE_DEMANGLE_WITH_CXXABI",
"CPPTRACE_GET_SYMBOLS_WITH_LIBDWARF",
"CPPTRACE_UNWIND_WITH_EXECINFO",
],
"//conditions:default": ["NOMINMAX"],
}) + select({
"@rules_cc//cc/compiler:msvc-cl": [],
"//conditions:default": [
"HAS_ATTRIBUTE_PACKED",
"CPPTRACE_HAS_CXX_EXCEPTION_TYPE",
],
}),
visibility = ["//visibility:public"],
deps = select({
"@platforms//os:linux": [
"@libdwarf",
"@libunwind",
],
"@platforms//os:macos": [
"@libdwarf",
],
"//conditions:default": [],
}),
)
116 changes: 14 additions & 102 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,104 +1,16 @@
"""cpptrace"""

module(
name = "cpptrace",
)

bazel_dep(name = "googletest", version = "1.14.0")
bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "rules_foreign_cc", version = "0.11.1")
bazel_dep(name = "zstd", version = "1.5.6")
bazel_dep(name = "zlib", version = "1.3.1")
bazel_dep(name = "xz", version = "5.4.5.bcr.2")
bazel_dep(name = "toolchains_llvm", version = "1.1.2")

# Configure and register the toolchain.
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm", dev_dependency = True)

llvm.toolchain(
llvm_versions = {
"": "18.1.8",
},
sha256 = {
"": "54ec30358afcc9fb8aa74307db3046f5187f9fb89fb37064cdde906e062ebf36",
},
strip_prefix = {
"": "clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04",
},
urls = {
"": ["https://github.com/llvm/llvm-project/releases/download/llvmorg-18.1.8/clang+llvm-18.1.8-x86_64-linux-gnu-ubuntu-18.04.tar.xz"],
},
)

use_repo(llvm, "llvm_toolchain")

register_toolchains("@llvm_toolchain//:all", dev_dependency = True)

http_archive = use_repo_rule("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
name = "libdwarf",
build_file_content =
"""
package(default_visibility = ["//visibility:public"])
load("@rules_foreign_cc//foreign_cc:defs.bzl", "cmake")

filegroup(
name = "sources",
srcs = glob(["**/*"]),
)
cmake(
name = "libdwarf",
build_args = ["-j12"],
lib_source = ":sources",
out_static_libs = ["libdwarf.a"],
copts = ["-Wall", "-Werror"],
deps = [
"@zstd",
"@zlib"
]
)
""",
sha256 = "4ab8ae7b4b7aa42453725054b348f4fdb2460d5ba644199a1305311c718ff416",
strip_prefix = "libdwarf-code-0.10.1",
url = "https://github.com/davea42/libdwarf-code/archive/refs/tags/v0.10.1.tar.gz",
)



http_archive(
name = "libunwind",
build_file_content =
"""
package(default_visibility = ["//visibility:public"])
load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make")

filegroup(
name = "sources",
srcs = glob(["**/*"]),
)
configure_make(
name = "libunwind",
args = ["-j12"],
autoreconf = True,
configure_in_place = True,
autoreconf_options = [
"-i",
],
lib_source = ":sources",
out_static_libs = [
"libunwind.a",
"libunwind-coredump.a",
"libunwind-ptrace.a",
"libunwind-x86_64.a",
"libunwind-generic.a",
"libunwind-setjmp.a"
],
deps = [
"@xz//:lzma"
]
)
""",
sha256 = "38833b7b1582db7d76485a62a213706c9252b3dab7380069fea5824e823d8e41",
strip_prefix = "libunwind-1.8.1",
url = "https://github.com/libunwind/libunwind/archive/refs/tags/v1.8.1.tar.gz",
)

version = "1.0.4",
compatibility_level = 1,
bazel_compatibility = [">=8.0.0"],
)

bazel_dep(name = "apple_support", version = "1.24.3", repo_name = "build_bazel_apple_support")
bazel_dep(name = "rules_cc", version = "0.2.8")
bazel_dep(name = "libdwarf", version = "2.2.0")
bazel_dep(name = "libunwind", version = "1.8.1")
bazel_dep(name = "platforms", version = "1.0.0")
bazel_dep(name = "bazel_skylib", version = "1.8.2")
bazel_dep(name = "googletest", version = "1.17.0.bcr.1", dev_dependency = True)
Loading
Loading