Skip to content

feat: Strip debug info from opt builds #2512

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

Closed
wants to merge 1 commit into from
Closed
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 rust/private/rustc.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,7 @@ def construct_arguments(
compilation_mode = get_compilation_mode_opts(ctx, toolchain)
rustc_flags.add(compilation_mode.opt_level, format = "--codegen=opt-level=%s")
rustc_flags.add(compilation_mode.debug_info, format = "--codegen=debuginfo=%s")
rustc_flags.add(compilation_mode.strip_level, format = "--codegen=strip=%s")

# For determinism to help with build distribution and such
if remap_path_prefix != None:
Expand Down
14 changes: 12 additions & 2 deletions rust/toolchain.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -464,10 +464,12 @@ def _rust_toolchain_impl(ctx):
list: A list containing the target's toolchain Provider info
"""
compilation_mode_opts = {}
for k, v in ctx.attr.opt_level.items():
for k, opt_level in ctx.attr.opt_level.items():
if not k in ctx.attr.debug_info:
fail("Compilation mode {} is not defined in debug_info but is defined opt_level".format(k))
compilation_mode_opts[k] = struct(debug_info = ctx.attr.debug_info[k], opt_level = v)
if not k in ctx.attr.strip_level:
fail("Compilation mode {} is not defined in strip_level but is defined opt_level".format(k))
compilation_mode_opts[k] = struct(debug_info = ctx.attr.debug_info[k], opt_level = opt_level, strip_level = ctx.attr.strip_level[k])
for k, v in ctx.attr.debug_info.items():
if not k in ctx.attr.opt_level:
fail("Compilation mode {} is not defined in opt_level but is defined debug_info".format(k))
Expand Down Expand Up @@ -738,6 +740,14 @@ rust_toolchain = rule(
"opt": "3",
},
),
"strip_level": attr.string_dict(
doc = "Rustc strip levels.",
default = {
"dbg": "none",
"fastbuild": "none",
"opt": "debuginfo",
},
),
"per_crate_rustc_flags": attr.string_list(
doc = "Extra flags to pass to rustc in non-exec configuration",
),
Expand Down