Skip to content
Open
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
4 changes: 4 additions & 0 deletions rust/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def _rust_impl(module_ctx):
rust_analyzer_version = toolchain.rust_analyzer_version,
sha256s = toolchain.sha256s,
extra_target_triples = toolchain.extra_target_triples,
opt_level = toolchain.opt_level if toolchain.opt_level else None,
strip_level = toolchain.strip_level if toolchain.strip_level else None,
urls = toolchain.urls,
versions = toolchain.versions,
Expand Down Expand Up @@ -270,6 +271,9 @@ _RUST_TOOLCHAIN_TAG = tag_class(
"extra_target_triples": attr.string_list(
default = DEFAULT_EXTRA_TARGET_TRIPLES,
),
"opt_level": attr.string_dict(
doc = "Rustc optimization levels. For more details see the documentation for `rust_toolchain.opt_level`.",
),
"rust_analyzer_version": attr.string(
doc = "The version of Rustc to pair with rust-analyzer.",
),
Expand Down
6 changes: 6 additions & 0 deletions rust/private/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def rust_register_toolchains(
extra_target_triples = DEFAULT_EXTRA_TARGET_TRIPLES,
extra_rustc_flags = None,
extra_exec_rustc_flags = None,
opt_level = None,
strip_level = None,
urls = DEFAULT_STATIC_RUST_URL_TEMPLATES,
versions = _RUST_TOOLCHAIN_VERSIONS,
Expand Down Expand Up @@ -100,6 +101,7 @@ def rust_register_toolchains(
extra_target_triples (list, optional): Additional rust-style targets that rust toolchains should support.
extra_rustc_flags (dict, list, optional): Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration.
extra_exec_rustc_flags (dict, list, optional): Dictionary of target triples to list of extra flags to pass to rustc in exec configuration.
opt_level (dict, optional): Rustc optimization levels. For more details see the documentation for `rust_toolchain.opt_level`.
strip_level (dict, dict, optional): Dictionary of target triples to strip config.
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).
versions (list, optional): A list of toolchain versions to download. This parameter only accepts one versions
Expand Down Expand Up @@ -168,6 +170,9 @@ def rust_register_toolchains(

# Rust toolchains per exec triple
for exec_triple, name in toolchain_triples.items():
extra = extra_target_triples.keys() if type(extra_target_triples) == "dict" else extra_target_triples
opt_level_by_triple = {t: opt_level for t in depset([exec_triple] + list(extra)).to_list()} if opt_level else None

maybe(
rust_repository_set,
name = name,
Expand All @@ -180,6 +185,7 @@ def rust_register_toolchains(
rustfmt_version = rustfmt_version,
extra_rustc_flags = extra_rustc_flags,
extra_exec_rustc_flags = extra_exec_rustc_flags,
opt_level = opt_level_by_triple,
strip_level = strip_level,
sha256s = sha256s,
urls = urls,
Expand Down
Loading