diff --git a/rust/private/rustc.bzl b/rust/private/rustc.bzl index 4abfdba15f..095724135f 100644 --- a/rust/private/rustc.bzl +++ b/rust/private/rustc.bzl @@ -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: diff --git a/rust/toolchain.bzl b/rust/toolchain.bzl index 9580d7cfc4..676d5c95d3 100644 --- a/rust/toolchain.bzl +++ b/rust/toolchain.bzl @@ -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)) @@ -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", ),