bazelbuild / bazelbuild/rules_rust

Cannot specify per-target strip_level in MODULE.bazel

Open
#3,730 3 comments 0 reactions 0 assignees View on GitHub
help wanted
Dominant language
Starlark
Stars
843
Forks
651
Avg merge
2d 18h
Merged PRs (30d)
15

Description

When registering a toolchain with `WORKSPACE.bazel` once can specify per-target strip levels. For instance:

```python
rust_register_toolchains(
edition = "2024",
strip_level = {"x86_64-unknown-linux-gnu": {
"dbg": "none",
"fastbuild": "none",
"opt": "none",
}},
versions = ["1.90.0"],
)
```

This is unfortunately not possible with `MODULE.bazel`.

It is unfortunately not enough to forward the `strip_level` parameter:

```diff
diff --git a/rust/extensions.bzl b/rust/extensions.bzl
index 99868b0df..1098d65d9 100644
--- a/rust/extensions.bzl
+++ b/rust/extensions.bzl
@@ -115,6 +115,7 @@ def _rust_impl(module_ctx):
rust_analyzer_version = toolchain.rust_analyzer_version,
sha256s = toolchain.sha256s,
extra_target_triples = toolchain.extra_target_triples,
+ strip_level = toolchain.strip_level,
urls = toolchain.urls,
versions = toolchain.versions,
register_toolchains = False,
@@ -219,6 +220,9 @@ _RUST_TOOLCHAIN_TAG = tag_class(
"rust_analyzer_version": attr.string(
doc = "The version of Rustc to pair with rust-analyzer.",
),
+ "strip_level": attr.string_dict(
+ doc = "Rustc strip levels. For more details see the documentation for `rust_toolchain.strip_level`.",
+ ),
"target_settings": attr.label_list(
doc = "A list of `config_settings` that must be satisfied by the target configuration in order for this toolchain to be selected during toolchain resolution.",
),
```

As far as I can tell, a tag class cannot access a `dict` of `dict` as an attribute, meaning we can't have 1-to-1 compatibility with a direct call to `rust_register_toolchains` like in `WORKSPACE.bazel`.

Contributor guide

Open the contributing guide

Research direction

Start in rust/extensions.bzl at _rust_impl and _RUST_TOOLCHAIN_TAG, then compare the module extension path with rust_register_toolchains and its strip_level handling. Review Bazel module tag attribute limitations for nested dictionaries. Done means MODULE.bazel can express per-target strip levels with compatibility matching WORKSPACE.bazel.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.