blob: 3ab9ac81db5acf7a1ab9ba83c9665a7a1d772a25 [file] [log] [blame]
From c8ea89704b63622a9863aa6a1ceaa297c7b80377 Mon Sep 17 00:00:00 2001
From: Erik Gilling <konkers@google.com>
Date: Tue, 27 Jun 2023 18:01:41 +0000
Subject: [PATCH 2/2] Add `opt_level` argument to `rust_repository_set`.
`rust_toolchain` allows setting of optimization level. This changes
plumbs that into `rust_repository_set` to allow control when
declaring toolchains through that rule.
---
docs/flatten.md | 16 ++++++++++------
docs/rust_repositories.md | 16 ++++++++++------
rust/private/repository_utils.bzl | 6 +++++-
rust/repositories.bzl | 10 ++++++++++
4 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/docs/flatten.md b/docs/flatten.md
index 40550451..584fcede 100644
--- a/docs/flatten.md
+++ b/docs/flatten.md
@@ -1284,8 +1284,8 @@ Generates a toolchain-bearing repository that declares the toolchains from some
<pre>
rust_toolchain_tools_repository(<a href="#rust_toolchain_tools_repository-name">name</a>, <a href="#rust_toolchain_tools_repository-allocator_library">allocator_library</a>, <a href="#rust_toolchain_tools_repository-auth">auth</a>, <a href="#rust_toolchain_tools_repository-dev_components">dev_components</a>, <a href="#rust_toolchain_tools_repository-edition">edition</a>, <a href="#rust_toolchain_tools_repository-exec_triple">exec_triple</a>,
<a href="#rust_toolchain_tools_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_toolchain_tools_repository-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_toolchain_tools_repository-global_allocator_library">global_allocator_library</a>,
- <a href="#rust_toolchain_tools_repository-iso_date">iso_date</a>, <a href="#rust_toolchain_tools_repository-repo_mapping">repo_mapping</a>, <a href="#rust_toolchain_tools_repository-rustfmt_version">rustfmt_version</a>, <a href="#rust_toolchain_tools_repository-sha256s">sha256s</a>, <a href="#rust_toolchain_tools_repository-target_triple">target_triple</a>, <a href="#rust_toolchain_tools_repository-urls">urls</a>,
- <a href="#rust_toolchain_tools_repository-version">version</a>)
+ <a href="#rust_toolchain_tools_repository-iso_date">iso_date</a>, <a href="#rust_toolchain_tools_repository-opt_level">opt_level</a>, <a href="#rust_toolchain_tools_repository-repo_mapping">repo_mapping</a>, <a href="#rust_toolchain_tools_repository-rustfmt_version">rustfmt_version</a>, <a href="#rust_toolchain_tools_repository-sha256s">sha256s</a>,
+ <a href="#rust_toolchain_tools_repository-target_triple">target_triple</a>, <a href="#rust_toolchain_tools_repository-urls">urls</a>, <a href="#rust_toolchain_tools_repository-version">version</a>)
</pre>
Composes a single workspace containing the toolchain components for compiling on a given platform to a series of target platforms.
@@ -1307,6 +1307,7 @@ A given instance of this rule should be accompanied by a toolchain_repository_pr
| <a id="rust_toolchain_tools_repository-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration | List of strings | optional | <code>[]</code> |
| <a id="rust_toolchain_tools_repository-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions when a global allocator is used with cc_common.link. | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-iso_date"></a>iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | <code>""</code> |
+| <a id="rust_toolchain_tools_repository-opt_level"></a>opt_level | Rustc optimization levels. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="rust_toolchain_tools_repository-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |
| <a id="rust_toolchain_tools_repository-rustfmt_version"></a>rustfmt_version | The version of the tool among "nightly", "beta", or an exact version. | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
@@ -1933,8 +1934,9 @@ rust_repositories(<a href="#rust_repositories-kwargs">kwargs</a>)
<pre>
rust_repository_set(<a href="#rust_repository_set-name">name</a>, <a href="#rust_repository_set-exec_triple">exec_triple</a>, <a href="#rust_repository_set-target_settings">target_settings</a>, <a href="#rust_repository_set-version">version</a>, <a href="#rust_repository_set-versions">versions</a>, <a href="#rust_repository_set-allocator_library">allocator_library</a>,
<a href="#rust_repository_set-global_allocator_library">global_allocator_library</a>, <a href="#rust_repository_set-extra_target_triples">extra_target_triples</a>, <a href="#rust_repository_set-iso_date">iso_date</a>, <a href="#rust_repository_set-rustfmt_version">rustfmt_version</a>,
- <a href="#rust_repository_set-edition">edition</a>, <a href="#rust_repository_set-dev_components">dev_components</a>, <a href="#rust_repository_set-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_repository_set-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_repository_set-sha256s">sha256s</a>, <a href="#rust_repository_set-urls">urls</a>,
- <a href="#rust_repository_set-auth">auth</a>, <a href="#rust_repository_set-register_toolchain">register_toolchain</a>, <a href="#rust_repository_set-exec_compatible_with">exec_compatible_with</a>, <a href="#rust_repository_set-default_target_compatible_with">default_target_compatible_with</a>)
+ <a href="#rust_repository_set-edition">edition</a>, <a href="#rust_repository_set-dev_components">dev_components</a>, <a href="#rust_repository_set-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_repository_set-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_repository_set-opt_level">opt_level</a>,
+ <a href="#rust_repository_set-sha256s">sha256s</a>, <a href="#rust_repository_set-urls">urls</a>, <a href="#rust_repository_set-auth">auth</a>, <a href="#rust_repository_set-register_toolchain">register_toolchain</a>, <a href="#rust_repository_set-exec_compatible_with">exec_compatible_with</a>,
+ <a href="#rust_repository_set-default_target_compatible_with">default_target_compatible_with</a>)
</pre>
Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains.
@@ -1958,6 +1960,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
| <a id="rust_repository_set-dev_components"></a>dev_components | Whether to download the rustc-dev components. Requires version to be "nightly". | `False` |
| <a id="rust_repository_set-extra_rustc_flags"></a>extra_rustc_flags | Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration. | `None` |
| <a id="rust_repository_set-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
+| <a id="rust_repository_set-opt_level"></a>opt_level | Dictionary of target triples to optimiztion config. | `None` |
| <a id="rust_repository_set-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | `None` |
| <a id="rust_repository_set-urls"></a>urls | 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). | `["https://static.rust-lang.org/dist/{}.tar.gz"]` |
| <a id="rust_repository_set-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` |
@@ -2038,8 +2041,8 @@ rust_test_suite(
rust_toolchain_repository(<a href="#rust_toolchain_repository-name">name</a>, <a href="#rust_toolchain_repository-version">version</a>, <a href="#rust_toolchain_repository-exec_triple">exec_triple</a>, <a href="#rust_toolchain_repository-target_triple">target_triple</a>, <a href="#rust_toolchain_repository-exec_compatible_with">exec_compatible_with</a>,
<a href="#rust_toolchain_repository-target_compatible_with">target_compatible_with</a>, <a href="#rust_toolchain_repository-target_settings">target_settings</a>, <a href="#rust_toolchain_repository-channel">channel</a>, <a href="#rust_toolchain_repository-allocator_library">allocator_library</a>,
<a href="#rust_toolchain_repository-global_allocator_library">global_allocator_library</a>, <a href="#rust_toolchain_repository-iso_date">iso_date</a>, <a href="#rust_toolchain_repository-rustfmt_version">rustfmt_version</a>, <a href="#rust_toolchain_repository-edition">edition</a>,
- <a href="#rust_toolchain_repository-dev_components">dev_components</a>, <a href="#rust_toolchain_repository-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_toolchain_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_toolchain_repository-sha256s">sha256s</a>, <a href="#rust_toolchain_repository-urls">urls</a>,
- <a href="#rust_toolchain_repository-auth">auth</a>)
+ <a href="#rust_toolchain_repository-dev_components">dev_components</a>, <a href="#rust_toolchain_repository-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_toolchain_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_toolchain_repository-opt_level">opt_level</a>,
+ <a href="#rust_toolchain_repository-sha256s">sha256s</a>, <a href="#rust_toolchain_repository-urls">urls</a>, <a href="#rust_toolchain_repository-auth">auth</a>)
</pre>
Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains.
@@ -2065,6 +2068,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
| <a id="rust_toolchain_repository-dev_components"></a>dev_components | Whether to download the rustc-dev components. Requires version to be "nightly". Defaults to False. | `False` |
| <a id="rust_toolchain_repository-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration. | `None` |
| <a id="rust_toolchain_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
+| <a id="rust_toolchain_repository-opt_level"></a>opt_level | Optimization level config for this toolchain. | `None` |
| <a id="rust_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | `None` |
| <a id="rust_toolchain_repository-urls"></a>urls | 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.gz'] | `["https://static.rust-lang.org/dist/{}.tar.gz"]` |
| <a id="rust_toolchain_repository-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` |
diff --git a/docs/rust_repositories.md b/docs/rust_repositories.md
index 831e9ca4..69633581 100644
--- a/docs/rust_repositories.md
+++ b/docs/rust_repositories.md
@@ -154,8 +154,8 @@ Generates a toolchain-bearing repository that declares the toolchains from some
<pre>
rust_toolchain_tools_repository(<a href="#rust_toolchain_tools_repository-name">name</a>, <a href="#rust_toolchain_tools_repository-allocator_library">allocator_library</a>, <a href="#rust_toolchain_tools_repository-auth">auth</a>, <a href="#rust_toolchain_tools_repository-dev_components">dev_components</a>, <a href="#rust_toolchain_tools_repository-edition">edition</a>, <a href="#rust_toolchain_tools_repository-exec_triple">exec_triple</a>,
<a href="#rust_toolchain_tools_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_toolchain_tools_repository-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_toolchain_tools_repository-global_allocator_library">global_allocator_library</a>,
- <a href="#rust_toolchain_tools_repository-iso_date">iso_date</a>, <a href="#rust_toolchain_tools_repository-repo_mapping">repo_mapping</a>, <a href="#rust_toolchain_tools_repository-rustfmt_version">rustfmt_version</a>, <a href="#rust_toolchain_tools_repository-sha256s">sha256s</a>, <a href="#rust_toolchain_tools_repository-target_triple">target_triple</a>, <a href="#rust_toolchain_tools_repository-urls">urls</a>,
- <a href="#rust_toolchain_tools_repository-version">version</a>)
+ <a href="#rust_toolchain_tools_repository-iso_date">iso_date</a>, <a href="#rust_toolchain_tools_repository-opt_level">opt_level</a>, <a href="#rust_toolchain_tools_repository-repo_mapping">repo_mapping</a>, <a href="#rust_toolchain_tools_repository-rustfmt_version">rustfmt_version</a>, <a href="#rust_toolchain_tools_repository-sha256s">sha256s</a>,
+ <a href="#rust_toolchain_tools_repository-target_triple">target_triple</a>, <a href="#rust_toolchain_tools_repository-urls">urls</a>, <a href="#rust_toolchain_tools_repository-version">version</a>)
</pre>
Composes a single workspace containing the toolchain components for compiling on a given platform to a series of target platforms.
@@ -177,6 +177,7 @@ A given instance of this rule should be accompanied by a toolchain_repository_pr
| <a id="rust_toolchain_tools_repository-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration | List of strings | optional | <code>[]</code> |
| <a id="rust_toolchain_tools_repository-global_allocator_library"></a>global_allocator_library | Target that provides allocator functions when a global allocator is used with cc_common.link. | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-iso_date"></a>iso_date | The date of the tool (or None, if the version is a specific version). | String | optional | <code>""</code> |
+| <a id="rust_toolchain_tools_repository-opt_level"></a>opt_level | Rustc optimization levels. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="rust_toolchain_tools_repository-repo_mapping"></a>repo_mapping | A dictionary from local repository name to global repository name. This allows controls over workspace dependency resolution for dependencies of this repository.&lt;p&gt;For example, an entry <code>"@foo": "@bar"</code> declares that, for any time this repository depends on <code>@foo</code> (such as a dependency on <code>@foo//some:target</code>, it should actually resolve that dependency within globally-declared <code>@bar</code> (<code>@bar//some:target</code>). | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | required | |
| <a id="rust_toolchain_tools_repository-rustfmt_version"></a>rustfmt_version | The version of the tool among "nightly", "beta", or an exact version. | String | optional | <code>""</code> |
| <a id="rust_toolchain_tools_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
@@ -302,8 +303,9 @@ rust_repositories(<a href="#rust_repositories-kwargs">kwargs</a>)
<pre>
rust_repository_set(<a href="#rust_repository_set-name">name</a>, <a href="#rust_repository_set-exec_triple">exec_triple</a>, <a href="#rust_repository_set-target_settings">target_settings</a>, <a href="#rust_repository_set-version">version</a>, <a href="#rust_repository_set-versions">versions</a>, <a href="#rust_repository_set-allocator_library">allocator_library</a>,
<a href="#rust_repository_set-global_allocator_library">global_allocator_library</a>, <a href="#rust_repository_set-extra_target_triples">extra_target_triples</a>, <a href="#rust_repository_set-iso_date">iso_date</a>, <a href="#rust_repository_set-rustfmt_version">rustfmt_version</a>,
- <a href="#rust_repository_set-edition">edition</a>, <a href="#rust_repository_set-dev_components">dev_components</a>, <a href="#rust_repository_set-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_repository_set-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_repository_set-sha256s">sha256s</a>, <a href="#rust_repository_set-urls">urls</a>,
- <a href="#rust_repository_set-auth">auth</a>, <a href="#rust_repository_set-register_toolchain">register_toolchain</a>, <a href="#rust_repository_set-exec_compatible_with">exec_compatible_with</a>, <a href="#rust_repository_set-default_target_compatible_with">default_target_compatible_with</a>)
+ <a href="#rust_repository_set-edition">edition</a>, <a href="#rust_repository_set-dev_components">dev_components</a>, <a href="#rust_repository_set-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_repository_set-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_repository_set-opt_level">opt_level</a>,
+ <a href="#rust_repository_set-sha256s">sha256s</a>, <a href="#rust_repository_set-urls">urls</a>, <a href="#rust_repository_set-auth">auth</a>, <a href="#rust_repository_set-register_toolchain">register_toolchain</a>, <a href="#rust_repository_set-exec_compatible_with">exec_compatible_with</a>,
+ <a href="#rust_repository_set-default_target_compatible_with">default_target_compatible_with</a>)
</pre>
Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains.
@@ -327,6 +329,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
| <a id="rust_repository_set-dev_components"></a>dev_components | Whether to download the rustc-dev components. Requires version to be "nightly". | `False` |
| <a id="rust_repository_set-extra_rustc_flags"></a>extra_rustc_flags | Dictionary of target triples to list of extra flags to pass to rustc in non-exec configuration. | `None` |
| <a id="rust_repository_set-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
+| <a id="rust_repository_set-opt_level"></a>opt_level | Dictionary of target triples to optimiztion config. | `None` |
| <a id="rust_repository_set-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | `None` |
| <a id="rust_repository_set-urls"></a>urls | 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). | `["https://static.rust-lang.org/dist/{}.tar.gz"]` |
| <a id="rust_repository_set-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` |
@@ -343,8 +346,8 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
rust_toolchain_repository(<a href="#rust_toolchain_repository-name">name</a>, <a href="#rust_toolchain_repository-version">version</a>, <a href="#rust_toolchain_repository-exec_triple">exec_triple</a>, <a href="#rust_toolchain_repository-target_triple">target_triple</a>, <a href="#rust_toolchain_repository-exec_compatible_with">exec_compatible_with</a>,
<a href="#rust_toolchain_repository-target_compatible_with">target_compatible_with</a>, <a href="#rust_toolchain_repository-target_settings">target_settings</a>, <a href="#rust_toolchain_repository-channel">channel</a>, <a href="#rust_toolchain_repository-allocator_library">allocator_library</a>,
<a href="#rust_toolchain_repository-global_allocator_library">global_allocator_library</a>, <a href="#rust_toolchain_repository-iso_date">iso_date</a>, <a href="#rust_toolchain_repository-rustfmt_version">rustfmt_version</a>, <a href="#rust_toolchain_repository-edition">edition</a>,
- <a href="#rust_toolchain_repository-dev_components">dev_components</a>, <a href="#rust_toolchain_repository-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_toolchain_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_toolchain_repository-sha256s">sha256s</a>, <a href="#rust_toolchain_repository-urls">urls</a>,
- <a href="#rust_toolchain_repository-auth">auth</a>)
+ <a href="#rust_toolchain_repository-dev_components">dev_components</a>, <a href="#rust_toolchain_repository-extra_rustc_flags">extra_rustc_flags</a>, <a href="#rust_toolchain_repository-extra_exec_rustc_flags">extra_exec_rustc_flags</a>, <a href="#rust_toolchain_repository-opt_level">opt_level</a>,
+ <a href="#rust_toolchain_repository-sha256s">sha256s</a>, <a href="#rust_toolchain_repository-urls">urls</a>, <a href="#rust_toolchain_repository-auth">auth</a>)
</pre>
Assembles a remote repository for the given toolchain params, produces a proxy repository to contain the toolchain declaration, and registers the toolchains.
@@ -370,6 +373,7 @@ Assembles a remote repository for the given toolchain params, produces a proxy r
| <a id="rust_toolchain_repository-dev_components"></a>dev_components | Whether to download the rustc-dev components. Requires version to be "nightly". Defaults to False. | `False` |
| <a id="rust_toolchain_repository-extra_rustc_flags"></a>extra_rustc_flags | Extra flags to pass to rustc in non-exec configuration. | `None` |
| <a id="rust_toolchain_repository-extra_exec_rustc_flags"></a>extra_exec_rustc_flags | Extra flags to pass to rustc in exec configuration. | `None` |
+| <a id="rust_toolchain_repository-opt_level"></a>opt_level | Optimization level config for this toolchain. | `None` |
| <a id="rust_toolchain_repository-sha256s"></a>sha256s | A dict associating tool subdirectories to sha256 hashes. See [rust_repositories](#rust_repositories) for more details. | `None` |
| <a id="rust_toolchain_repository-urls"></a>urls | 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.gz'] | `["https://static.rust-lang.org/dist/{}.tar.gz"]` |
| <a id="rust_toolchain_repository-auth"></a>auth | Auth object compatible with repository_ctx.download to use when downloading files. See [repository_ctx.download](https://docs.bazel.build/versions/main/skylark/lib/repository_ctx.html#download) for more details. | `None` |
diff --git a/rust/private/repository_utils.bzl b/rust/private/repository_utils.bzl
index 1f5a01aa..80c51ff8 100644
--- a/rust/private/repository_utils.bzl
+++ b/rust/private/repository_utils.bzl
@@ -253,6 +253,7 @@ rust_toolchain(
visibility = ["//visibility:public"],
extra_rustc_flags = {extra_rustc_flags},
extra_exec_rustc_flags = {extra_exec_rustc_flags},
+ opt_level = {opt_level},
)
"""
@@ -267,7 +268,8 @@ def BUILD_for_rust_toolchain(
include_llvm_tools,
stdlib_linkflags = None,
extra_rustc_flags = None,
- extra_exec_rustc_flags = None):
+ extra_exec_rustc_flags = None,
+ opt_level = None):
"""Emits a toolchain declaration to match an existing compiler and stdlib.
Args:
@@ -286,6 +288,7 @@ def BUILD_for_rust_toolchain(
None.
extra_rustc_flags (list, optional): Extra flags to pass to rustc in non-exec configuration.
extra_exec_rustc_flags (list, optional): Extra flags to pass to rustc in exec configuration.
+ opt_level (dict, optional): Optimization level config for this toolchain.
Returns:
str: A rendered template of a `rust_toolchain` declaration
@@ -324,6 +327,7 @@ def BUILD_for_rust_toolchain(
llvm_profdata_label = llvm_profdata_label,
extra_rustc_flags = extra_rustc_flags,
extra_exec_rustc_flags = extra_exec_rustc_flags,
+ opt_level = opt_level,
)
_build_file_for_toolchain_template = """\
diff --git a/rust/repositories.bzl b/rust/repositories.bzl
index b7c26b76..0cb61571 100644
--- a/rust/repositories.bzl
+++ b/rust/repositories.bzl
@@ -359,6 +359,7 @@ def _rust_toolchain_tools_repository_impl(ctx):
include_llvm_tools = include_llvm_tools,
extra_rustc_flags = ctx.attr.extra_rustc_flags,
extra_exec_rustc_flags = ctx.attr.extra_exec_rustc_flags,
+ opt_level = ctx.attr.opt_level if ctx.attr.opt_level else None,
))
# Not all target triples are expected to have dev components
@@ -413,6 +414,9 @@ rust_toolchain_tools_repository = repository_rule(
"iso_date": attr.string(
doc = "The date of the tool (or None, if the version is a specific version).",
),
+ "opt_level": attr.string_dict(
+ doc = "Rustc optimization levels.",
+ ),
"rustfmt_version": attr.string(
doc = "The version of the tool among \"nightly\", \"beta\", or an exact version.",
),
@@ -498,6 +502,7 @@ def rust_toolchain_repository(
dev_components = False,
extra_rustc_flags = None,
extra_exec_rustc_flags = None,
+ opt_level = None,
sha256s = None,
urls = DEFAULT_STATIC_RUST_URL_TEMPLATES,
auth = None):
@@ -523,6 +528,7 @@ def rust_toolchain_repository(
Requires version to be "nightly". Defaults to False.
extra_rustc_flags (list, optional): Extra flags to pass to rustc in non-exec configuration.
extra_exec_rustc_flags (list, optional): Extra flags to pass to rustc in exec configuration.
+ opt_level (dict, optional): Optimization level config for this toolchain.
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
[rust_repositories](#rust_repositories) for more details.
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.gz']
@@ -559,6 +565,7 @@ def rust_toolchain_repository(
dev_components = dev_components,
extra_rustc_flags = extra_rustc_flags,
extra_exec_rustc_flags = extra_exec_rustc_flags,
+ opt_level = opt_level,
sha256s = sha256s,
urls = urls,
auth = auth,
@@ -888,6 +895,7 @@ def rust_repository_set(
dev_components = False,
extra_rustc_flags = None,
extra_exec_rustc_flags = None,
+ opt_level = None,
sha256s = None,
urls = DEFAULT_STATIC_RUST_URL_TEMPLATES,
auth = None,
@@ -918,6 +926,7 @@ def rust_repository_set(
Requires version to be "nightly".
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 (list, optional): Extra flags to pass to rustc in exec configuration.
+ opt_level (dict, dict, optional): Dictionary of target triples to optimiztion config.
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes. See
[rust_repositories](#rust_repositories) for more details.
urls (list, optional): A list of mirror urls containing the tools from the Rust-lang static file server. These
@@ -971,6 +980,7 @@ def rust_repository_set(
exec_triple = exec_triple,
extra_exec_rustc_flags = extra_exec_rustc_flags,
extra_rustc_flags = extra_rustc_flags.get(toolchain.target_triple) if extra_rustc_flags != None else None,
+ opt_level = opt_level.get(toolchain.target_triple) if opt_level != None else None,
target_settings = target_settings,
iso_date = toolchain.channel.iso_date,
rustfmt_version = rustfmt_version,
--
2.41.0.255.g8b1d071c50-goog