Skip to content

Commit

Permalink
Merge pull request redpanda-data#24373 from redpanda-data/stephan/baz…
Browse files Browse the repository at this point in the history
…el-lto

bazel: Enable LTO for redpanda
  • Loading branch information
StephanDollberg authored Dec 6, 2024
2 parents dc46444 + 5532d32 commit c4d57ee
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ build:secure --config=relro
build:release --compilation_mode opt
build:release --config=secure
build:release --copt -mllvm --copt -inline-threshold=2500
build:release --linkopt=-flto
build:release --@seastar//:stack_guards=False
build:release --//src/v/redpanda:lto=True
build:release --copt -flto=thin --copt -ffat-lto-objects

build:stamp --stamp --workspace_status_command=./bazel/stamp_vars.sh

Expand Down
2 changes: 2 additions & 0 deletions bazel/build.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def redpanda_cc_binary(
local_defines = [],
visibility = None,
copts = [],
linkopts = [],
deps = []):
"""
Define a Redpanda C++ binary.
Expand All @@ -64,6 +65,7 @@ def redpanda_cc_binary(
visibility = visibility,
deps = deps,
copts = redpanda_copts() + copts,
linkopts = linkopts,
features = [
"layering_check",
],
Expand Down
4 changes: 4 additions & 0 deletions bazel/thirdparty/krb5.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ configure_make(
"--disable-static",
"--enable-asan=$(SANITIZERS)",
],
# Need to pass this additionally here because of a bug in the kerberos build where it doesn't properly pass the linker flag down
copts = [
"-fuse-ld=lld",
],
env = {
"KRB5_BUILD_JOBS": "$(BUILD_JOBS)",
},
Expand Down
24 changes: 24 additions & 0 deletions src/v/redpanda/BUILD
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("//bazel:build.bzl", "redpanda_cc_binary", "redpanda_cc_library")

redpanda_cc_library(
Expand Down Expand Up @@ -95,11 +96,34 @@ redpanda_cc_library(
],
)

# Enable or disable (thin) LTO for the redpanda binary (only)
bool_flag(
name = "lto",
build_setting_default = False,
)

config_setting(
name = "use_lto",
flag_values = {
":lto": "true",
},
visibility = ["//visibility:public"],
)

redpanda_cc_binary(
name = "redpanda",
srcs = [
"main.cc",
],
linkopts =
select({
":use_lto": [
"-flto=thin",
"-ffat-lto-objects",
],
"//conditions:default": [
],
}),
visibility = ["//visibility:public"],
deps = [
":application",
Expand Down

0 comments on commit c4d57ee

Please sign in to comment.