Skip to content
Merged
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
5 changes: 5 additions & 0 deletions bazel/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ config_setting(
name = "debug_symbols",
values = {"define": "debug_symbols=yes"},
)

config_setting(
name = "disable_tcmalloc",
values = {"define": "tcmalloc=disabled"},
)
24 changes: 24 additions & 0 deletions bazel/envoy_build_system.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ ENVOY_COPTS = [
"//bazel:opt_build": [],
"//bazel:fastbuild_build": [],
"//bazel:dbg_build": ["-ggdb3"],
}) + select({
"//bazel:disable_tcmalloc": [],
"//conditions:default": ["-DTCMALLOC"],
}) + select({
# Allow debug symbols to be added to opt/fastbuild as well.
"//bazel:debug_symbols": ["-ggdb3"],
Expand All @@ -26,6 +29,22 @@ ENVOY_COPTS = [
def envoy_external_dep_path(dep):
return "//external:%s" % dep

# Dependencies on tcmalloc_and_profiler should be wrapped with this function.
def tcmalloc_external_dep():
return select({
"//bazel:disable_tcmalloc": None,
"//conditions:default": envoy_external_dep_path("tcmalloc_and_profiler"),
})

# As above, but wrapped in list form for adding to dep lists. This smell seems needed as
# SelectorValue values have to match the attribute type. See
# https://github.com/bazelbuild/bazel/issues/2273.
def tcmalloc_external_deps():
return select({
"//bazel:disable_tcmalloc": [],
"//conditions:default": [envoy_external_dep_path("tcmalloc_and_profiler")],
})

# Transform the package path (e.g. include/envoy/common) into a path for
# exporting the package headers at (e.g. envoy/common). Source files can then
# include using this path scheme (e.g. #include "envoy/common/time.h").
Expand All @@ -41,8 +60,11 @@ def envoy_cc_library(name,
copts = [],
visibility = None,
external_deps = [],
tcmalloc_dep = None,
repository = "",
deps = []):
if tcmalloc_dep:
deps += tcmalloc_external_deps()
native.cc_library(
name = name,
srcs = srcs,
Expand Down Expand Up @@ -77,6 +99,7 @@ def envoy_cc_binary(name,
],
linkstatic = 1,
visibility = visibility,
malloc = tcmalloc_external_dep(),
deps = deps + [
repository + "//source/precompiled:precompiled_includes",
],
Expand Down Expand Up @@ -108,6 +131,7 @@ def envoy_cc_test(name,
copts = ENVOY_COPTS,
linkopts = ["-pthread"],
linkstatic = 1,
malloc = tcmalloc_external_dep(),
deps = [
":" + name + "_lib",
repository + "//test:main"
Expand Down
2 changes: 1 addition & 1 deletion bazel/target_recipes.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ TARGET_RECIPES = {
# that is external to Bazel.
"gcovr": "gcovr",
"googletest": "googletest",
"gperftools": "gperftools",
"tcmalloc_and_profiler": "gperftools",
"http_parser": "http-parser",
"lightstep": "lightstep",
"nghttp2": "nghttp2",
Expand Down
7 changes: 7 additions & 0 deletions ci/prebuilt/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,10 @@ cc_library(
hdrs = glob(["thirdparty/tclap-1.2.1/include/**/*.h"]),
includes = ["thirdparty/tclap-1.2.1/include"],
)

cc_library(
name = "tcmalloc_and_profiler",
srcs = ["thirdparty_build/lib/libtcmalloc_and_profiler.a"],
hdrs = glob(["thirdparty_build/include/gperftools/**/*.h"]),
strip_include_prefix = "thirdparty_build/include",
)
1 change: 1 addition & 0 deletions source/common/memory/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ envoy_cc_library(
name = "stats_lib",
srcs = ["stats.cc"],
hdrs = ["stats.h"],
tcmalloc_dep = 1,
)
1 change: 1 addition & 0 deletions source/common/profiler/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ envoy_cc_library(
name = "profiler_lib",
srcs = ["profiler.cc"],
hdrs = ["profiler.h"],
tcmalloc_dep = 1,
)
1 change: 1 addition & 0 deletions tools/bazel.rc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
build:asan --copt -fsanitize=address
build:asan --linkopt -fsanitize=address
build:asan --linkopt -ldl
build:asan --define tcmalloc=disabled