Skip to content

Commit dfd7346

Browse files
authored
Bring strip_level configuration up to top level (#3434)
This adds a path for configuring `strip_level` in the same way as `opt_level`. This will allow configuration away from the default of: ``` default = { "dbg": "none", "fastbuild": "none", "opt": "debuginfo", }, ``` through `rust_register_toolchains`.
1 parent db2fe8d commit dfd7346

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

rust/private/repository_utils.bzl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,7 @@ rust_toolchain(
269269
extra_rustc_flags = {extra_rustc_flags},
270270
extra_exec_rustc_flags = {extra_exec_rustc_flags},
271271
opt_level = {opt_level},
272+
strip_level = {strip_level},
272273
tags = ["rust_version={version}"],
273274
)
274275
"""
@@ -286,7 +287,8 @@ def BUILD_for_rust_toolchain(
286287
stdlib_linkflags = None,
287288
extra_rustc_flags = None,
288289
extra_exec_rustc_flags = None,
289-
opt_level = None):
290+
opt_level = None,
291+
strip_level = None):
290292
"""Emits a toolchain declaration to match an existing compiler and stdlib.
291293
292294
Args:
@@ -307,6 +309,7 @@ def BUILD_for_rust_toolchain(
307309
extra_rustc_flags (list, optional): Extra flags to pass to rustc in non-exec configuration.
308310
extra_exec_rustc_flags (list, optional): Extra flags to pass to rustc in exec configuration.
309311
opt_level (dict, optional): Optimization level config for this toolchain.
312+
strip_level (dict, optional): Strip level config for this toolchain.
310313
311314
Returns:
312315
str: A rendered template of a `rust_toolchain` declaration
@@ -346,6 +349,7 @@ def BUILD_for_rust_toolchain(
346349
extra_rustc_flags = extra_rustc_flags,
347350
extra_exec_rustc_flags = extra_exec_rustc_flags,
348351
opt_level = opt_level,
352+
strip_level = strip_level,
349353
version = version,
350354
)
351355

rust/repositories.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ def rust_register_toolchains(
152152
extra_target_triples = DEFAULT_EXTRA_TARGET_TRIPLES,
153153
extra_rustc_flags = None,
154154
extra_exec_rustc_flags = None,
155+
strip_level = None,
155156
urls = DEFAULT_STATIC_RUST_URL_TEMPLATES,
156157
versions = _RUST_TOOLCHAIN_VERSIONS,
157158
aliases = {},
@@ -191,6 +192,7 @@ def rust_register_toolchains(
191192
extra_target_triples (list, optional): Additional rust-style targets that rust toolchains should support.
192193
extra_rustc_flags (dict, list, optional): Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration.
193194
extra_exec_rustc_flags (list, optional): Extra flags to pass to rustc in exec configuration.
195+
strip_level (dict, dict, optional): Dictionary of target triples to strip config.
194196
urls (list, optional): A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format).
195197
versions (list, optional): A list of toolchain versions to download. This parameter only accepts one versions
196198
per channel. E.g. `["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]`.
@@ -269,6 +271,7 @@ def rust_register_toolchains(
269271
rustfmt_version = rustfmt_version,
270272
extra_rustc_flags = extra_rustc_flags,
271273
extra_exec_rustc_flags = extra_exec_rustc_flags,
274+
strip_level = strip_level,
272275
sha256s = sha256s,
273276
urls = urls,
274277
versions = versions,
@@ -395,6 +398,9 @@ _RUST_TOOLCHAIN_REPOSITORY_ATTRS = {
395398
"opt_level": attr.string_dict(
396399
doc = "Rustc optimization levels. For more details see the documentation for `rust_toolchain.opt_level`.",
397400
),
401+
"strip_level": attr.string_dict(
402+
doc = "Rustc strip levels. For more details see the documentation for `rust_toolchain.strip_level`.",
403+
),
398404
"rustfmt_version": attr.string(
399405
doc = "The version of the tool among \"nightly\", \"beta\", or an exact version.",
400406
),
@@ -515,6 +521,7 @@ def _rust_toolchain_tools_repository_impl(ctx):
515521
extra_rustc_flags = ctx.attr.extra_rustc_flags,
516522
extra_exec_rustc_flags = ctx.attr.extra_exec_rustc_flags,
517523
opt_level = ctx.attr.opt_level if ctx.attr.opt_level else None,
524+
strip_level = ctx.attr.strip_level if ctx.attr.strip_level else None,
518525
version = ctx.attr.version,
519526
))
520527

@@ -619,6 +626,7 @@ def rust_toolchain_repository(
619626
extra_rustc_flags = None,
620627
extra_exec_rustc_flags = None,
621628
opt_level = None,
629+
strip_level = None,
622630
sha256s = None,
623631
urls = DEFAULT_STATIC_RUST_URL_TEMPLATES,
624632
auth = None,
@@ -646,6 +654,7 @@ def rust_toolchain_repository(
646654
extra_rustc_flags (list, optional): Extra flags to pass to rustc in non-exec configuration.
647655
extra_exec_rustc_flags (list, optional): Extra flags to pass to rustc in exec configuration.
648656
opt_level (dict, optional): Optimization level config for this toolchain.
657+
strip_level (dict, optional): Strip level config for this toolchain.
649658
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
650659
[rust_register_toolchains](#rust_register_toolchains) for more details.
651660
urls (list, optional): A list of mirror urls containing the tools from the Rust-lang static file server. These must contain the '{}' used to substitute the tool being fetched (using .format). Defaults to ['https://static.rust-lang.org/dist/{}.tar.xz']
@@ -678,6 +687,7 @@ def rust_toolchain_repository(
678687
extra_rustc_flags = extra_rustc_flags,
679688
extra_exec_rustc_flags = extra_exec_rustc_flags,
680689
opt_level = opt_level,
690+
strip_level = strip_level,
681691
sha256s = sha256s,
682692
urls = urls,
683693
auth = auth,
@@ -1120,6 +1130,7 @@ def rust_repository_set(
11201130
extra_rustc_flags = None,
11211131
extra_exec_rustc_flags = None,
11221132
opt_level = None,
1133+
strip_level = None,
11231134
sha256s = None,
11241135
urls = DEFAULT_STATIC_RUST_URL_TEMPLATES,
11251136
auth = None,
@@ -1153,6 +1164,7 @@ def rust_repository_set(
11531164
extra_rustc_flags (dict, list, optional): Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration.
11541165
extra_exec_rustc_flags (list, optional): Extra flags to pass to rustc in exec configuration.
11551166
opt_level (dict, dict, optional): Dictionary of target triples to optimiztion config.
1167+
strip_level (dict, dict, optional): Dictionary of target triples to strip config.
11561168
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
11571169
[rust_register_toolchains](#rust_register_toolchains) for more details.
11581170
urls (list, optional): A list of mirror urls containing the tools from the Rust-lang static file server. These
@@ -1208,6 +1220,7 @@ def rust_repository_set(
12081220
extra_exec_rustc_flags = extra_exec_rustc_flags,
12091221
extra_rustc_flags = toolchain_extra_rustc_flags,
12101222
opt_level = opt_level.get(toolchain.target_triple) if opt_level != None else None,
1223+
strip_level = strip_level.get(toolchain.target_triple) if strip_level != None else None,
12111224
target_settings = target_settings,
12121225
rustfmt_version = rustfmt_version,
12131226
sha256s = sha256s,

0 commit comments

Comments
 (0)