-
-
Notifications
You must be signed in to change notification settings - Fork 166
Bazel build on windows and linux #292
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
base: main
Are you sure you want to change the base?
Changes from all commits
4c79312
db09137
ccb9f9c
492f806
7900553
9d23a04
42d2ecf
71686d7
1a43cfe
e04602e
34b0ea9
68e10a2
1527943
28096ec
6be3065
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| cmake-build-debug |
This file was deleted.
| 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 | ||
| build --compilation_mode=dbg | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it'd be better to not force debug mode globally? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 8.4.1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,3 +13,7 @@ bazel-*/ | |
| cmake-build-*/ | ||
|
|
||
| test/jank/data | ||
|
|
||
| # bazel out | ||
| bazel-* | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: duplicate with above |
||
| MODULE.bazel.lock | ||
| 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", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor: Duplicate |
||
| ] | ||
|
|
||
| GCC_FLAGS = COMMON_FLAGS + [ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is |
||
| "-Wuseless-cast", | ||
| "-Wmaybe-uninitialized", | ||
| "-fdiagnostics-color=always", | ||
| ] | ||
|
|
||
| CLANG_FLAGS = COMMON_FLAGS + ["-fcolor-diagnostics"] | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"], | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bazel's |
||
| 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
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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", | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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": [], | ||
| }), | ||
| ) | ||
| 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) |
There was a problem hiding this comment.
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=localdefeat much of the purpose of bazel, i.e. hermetic builds?