Allow rust toolchain repositories from custom repo rules (#1036)

This change allows `crate_universe` to use a custom repo for the rust toolchain. I.e. suppose that `cargo` and `rustc` come from a custom repo rule and have different paths inside the repo rule (compared to the standard "upstream")

Fixes #1019
This commit is contained in:
Ivan Kalchev 2021-11-29 17:18:08 +02:00 committed by GitHub
parent 87b74a1d72
commit dc66c1612b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 7 deletions

View File

@ -8,6 +8,7 @@
Google Inc.
Spotify AB
VMware Inc.
Damien Martin-Guillerez <dmarting@google.com>
David Chen <dzc@google.com>
Florian Weikert <fwe@google.com>

View File

@ -20,3 +20,4 @@ Philipp Wollermann <philwo@google.com>
Ulf Adams <ulfjack@google.com>
Justine Alexandra Roberts Tunney <jart@google.com>
John Edmonds <jedmonds@spotify.com>
Ivan Kalchev <kivan@vmware.com>

View File

@ -226,6 +226,13 @@ Dict of registry_name: index_url.
),
default = "rust_{system}_{arch}",
),
"rust_toolchain_repository_tool_path": attr.string_dict(
doc = "The relative path of the tools in the repository",
default = {
"cargo": ":bin/cargo",
"rustc": ":bin/rustc",
},
),
"sha256s": attr.string_dict(
doc = "The sha256 checksum of the desired rust artifacts",
),

View File

@ -134,8 +134,17 @@ def get_cargo_and_rustc(repository_ctx, host_triple):
rust_toolchain_repository = rust_toolchain_repository.replace("{triple}", host_triple)
rust_toolchain_repository = rust_toolchain_repository.replace("{arch}", arch)
cargo_path = repository_ctx.path(Label("@{}{}".format(rust_toolchain_repository, "//:bin/cargo" + extension)))
rustc_path = repository_ctx.path(Label("@{}{}".format(rust_toolchain_repository, "//:bin/rustc" + extension)))
tool_path = repository_ctx.attr.rust_toolchain_repository_tool_path
cargo_path = repository_ctx.path(Label("@{}//{}{}".format(
rust_toolchain_repository,
tool_path["cargo"],
extension,
)))
rustc_path = repository_ctx.path(Label("@{}//{}{}".format(
rust_toolchain_repository,
tool_path["rustc"],
extension,
)))
return struct(
cargo = cargo_path,

View File

@ -127,7 +127,8 @@ See [some more examples](../examples/crate_universe) and the documentation below
crate_universe(<a href="#crate_universe-name">name</a>, <a href="#crate_universe-additional_registries">additional_registries</a>, <a href="#crate_universe-cargo_toml_files">cargo_toml_files</a>,
<a href="#crate_universe-default_registry_download_url_template">default_registry_download_url_template</a>, <a href="#crate_universe-iso_date">iso_date</a>, <a href="#crate_universe-lockfile">lockfile</a>, <a href="#crate_universe-overrides">overrides</a>, <a href="#crate_universe-packages">packages</a>,
<a href="#crate_universe-repo_mapping">repo_mapping</a>, <a href="#crate_universe-resolver">resolver</a>, <a href="#crate_universe-resolver_download_url_template">resolver_download_url_template</a>, <a href="#crate_universe-resolver_sha256s">resolver_sha256s</a>,
<a href="#crate_universe-rust_toolchain_repository_template">rust_toolchain_repository_template</a>, <a href="#crate_universe-sha256s">sha256s</a>, <a href="#crate_universe-supported_targets">supported_targets</a>, <a href="#crate_universe-version">version</a>)
<a href="#crate_universe-rust_toolchain_repository_template">rust_toolchain_repository_template</a>, <a href="#crate_universe-rust_toolchain_repository_tool_path">rust_toolchain_repository_tool_path</a>, <a href="#crate_universe-sha256s">sha256s</a>,
<a href="#crate_universe-supported_targets">supported_targets</a>, <a href="#crate_universe-version">version</a>)
</pre>
A rule for downloading Rust dependencies (crates).
@ -160,6 +161,7 @@ Environment Variables:
| <a id="crate_universe-resolver_download_url_template"></a>resolver_download_url_template | URL template from which to download the resolver binary. {host_triple} and {extension} will be filled in according to the host platform. | String | optional | "{host_triple}{extension}" |
| <a id="crate_universe-resolver_sha256s"></a>resolver_sha256s | Dictionary of host_triple -&gt; sha256 for resolver binary. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {"aarch64-apple-darwin": "{aarch64-apple-darwin--sha256}", "aarch64-unknown-linux-gnu": "{aarch64-unknown-linux-gnu--sha256}", "x86_64-apple-darwin": "{x86_64-apple-darwin--sha256}", "x86_64-pc-windows-gnu": "{x86_64-pc-windows-gnu--sha256}", "x86_64-unknown-linux-gnu": "{x86_64-unknown-linux-gnu--sha256}"} |
| <a id="crate_universe-rust_toolchain_repository_template"></a>rust_toolchain_repository_template | The template to use for finding the host <code>rust_toolchain</code> repository. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{system}</code> (eg. 'darwin'), and <code>{arch}</code> (eg. 'aarch64') will be replaced in the string if present. | String | optional | "rust_{system}_{arch}" |
| <a id="crate_universe-rust_toolchain_repository_tool_path"></a>rust_toolchain_repository_tool_path | The relative path of the tools in the repository | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {"cargo": ":bin/cargo", "rustc": ":bin/rustc"} |
| <a id="crate_universe-sha256s"></a>sha256s | The sha256 checksum of the desired rust artifacts | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="crate_universe-supported_targets"></a>supported_targets | A list of supported [platform triples](https://doc.rust-lang.org/nightly/rustc/platform-support.html) to consider when resoliving dependencies. | List of strings | optional | ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"] |
| <a id="crate_universe-version"></a>version | The version of cargo the resolver should use | String | optional | "1.56.1" |

View File

@ -104,7 +104,8 @@ A rule for bootstrapping a Rust binary using [Cargo](https://doc.rust-lang.org/c
crate_universe(<a href="#crate_universe-name">name</a>, <a href="#crate_universe-additional_registries">additional_registries</a>, <a href="#crate_universe-cargo_toml_files">cargo_toml_files</a>,
<a href="#crate_universe-default_registry_download_url_template">default_registry_download_url_template</a>, <a href="#crate_universe-iso_date">iso_date</a>, <a href="#crate_universe-lockfile">lockfile</a>, <a href="#crate_universe-overrides">overrides</a>, <a href="#crate_universe-packages">packages</a>,
<a href="#crate_universe-repo_mapping">repo_mapping</a>, <a href="#crate_universe-resolver">resolver</a>, <a href="#crate_universe-resolver_download_url_template">resolver_download_url_template</a>, <a href="#crate_universe-resolver_sha256s">resolver_sha256s</a>,
<a href="#crate_universe-rust_toolchain_repository_template">rust_toolchain_repository_template</a>, <a href="#crate_universe-sha256s">sha256s</a>, <a href="#crate_universe-supported_targets">supported_targets</a>, <a href="#crate_universe-version">version</a>)
<a href="#crate_universe-rust_toolchain_repository_template">rust_toolchain_repository_template</a>, <a href="#crate_universe-rust_toolchain_repository_tool_path">rust_toolchain_repository_tool_path</a>, <a href="#crate_universe-sha256s">sha256s</a>,
<a href="#crate_universe-supported_targets">supported_targets</a>, <a href="#crate_universe-version">version</a>)
</pre>
A rule for downloading Rust dependencies (crates).
@ -137,6 +138,7 @@ Environment Variables:
| <a id="crate_universe-resolver_download_url_template"></a>resolver_download_url_template | URL template from which to download the resolver binary. {host_triple} and {extension} will be filled in according to the host platform. | String | optional | "{host_triple}{extension}" |
| <a id="crate_universe-resolver_sha256s"></a>resolver_sha256s | Dictionary of host_triple -&gt; sha256 for resolver binary. | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {"aarch64-apple-darwin": "{aarch64-apple-darwin--sha256}", "aarch64-unknown-linux-gnu": "{aarch64-unknown-linux-gnu--sha256}", "x86_64-apple-darwin": "{x86_64-apple-darwin--sha256}", "x86_64-pc-windows-gnu": "{x86_64-pc-windows-gnu--sha256}", "x86_64-unknown-linux-gnu": "{x86_64-unknown-linux-gnu--sha256}"} |
| <a id="crate_universe-rust_toolchain_repository_template"></a>rust_toolchain_repository_template | The template to use for finding the host <code>rust_toolchain</code> repository. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{system}</code> (eg. 'darwin'), and <code>{arch}</code> (eg. 'aarch64') will be replaced in the string if present. | String | optional | "rust_{system}_{arch}" |
| <a id="crate_universe-rust_toolchain_repository_tool_path"></a>rust_toolchain_repository_tool_path | The relative path of the tools in the repository | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {"cargo": ":bin/cargo", "rustc": ":bin/rustc"} |
| <a id="crate_universe-sha256s"></a>sha256s | The sha256 checksum of the desired rust artifacts | <a href="https://bazel.build/docs/skylark/lib/dict.html">Dictionary: String -> String</a> | optional | {} |
| <a id="crate_universe-supported_targets"></a>supported_targets | A list of supported [platform triples](https://doc.rust-lang.org/nightly/rustc/platform-support.html) to consider when resoliving dependencies. | List of strings | optional | ["aarch64-apple-darwin", "aarch64-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "x86_64-unknown-freebsd", "x86_64-unknown-linux-gnu"] |
| <a id="crate_universe-version"></a>version | The version of cargo the resolver should use | String | optional | "1.56.1" |