Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow rust toolchain repositories from custom repo rules #1036

Merged
merged 5 commits into from
Nov 29, 2021
Merged
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
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -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>
9 changes: 8 additions & 1 deletion crate_universe/defs.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ __WARNING__: This rule experimental and subject to change without warning.
Environment Variables:
- `REPIN`: Re-pin the lockfile if set (useful for repinning deps from multiple rulesets).
- `RULES_RUST_REPIN`: Re-pin the lockfile if set (useful for only repinning Rust deps).
- `RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE`: Override URL to use to download resolver binary
- `RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE`: Override URL to use to download resolver binary
- for local paths use a `file://` URL.
- `RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE_SHA256`: An optional sha256 value for the binary at the override url location.
""",
Expand Down Expand Up @@ -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",
),
Expand Down
13 changes: 11 additions & 2 deletions crate_universe/private/util.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
6 changes: 4 additions & 2 deletions docs/crate_universe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -137,7 +138,7 @@ __WARNING__: This rule experimental and subject to change without warning.
Environment Variables:
- `REPIN`: Re-pin the lockfile if set (useful for repinning deps from multiple rulesets).
- `RULES_RUST_REPIN`: Re-pin the lockfile if set (useful for only repinning Rust deps).
- `RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE`: Override URL to use to download resolver binary
- `RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE`: Override URL to use to download resolver binary
- for local paths use a `file://` URL.
- `RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE_SHA256`: An optional sha256 value for the binary at the override url location.

Expand All @@ -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" |
Expand Down
6 changes: 4 additions & 2 deletions docs/flatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand All @@ -114,7 +115,7 @@ __WARNING__: This rule experimental and subject to change without warning.
Environment Variables:
- `REPIN`: Re-pin the lockfile if set (useful for repinning deps from multiple rulesets).
- `RULES_RUST_REPIN`: Re-pin the lockfile if set (useful for only repinning Rust deps).
- `RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE`: Override URL to use to download resolver binary
- `RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE`: Override URL to use to download resolver binary
- for local paths use a `file://` URL.
- `RULES_RUST_CRATE_UNIVERSE_RESOLVER_URL_OVERRIDE_SHA256`: An optional sha256 value for the binary at the override url location.

Expand All @@ -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" |
Expand Down