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

Added a build setting for toolchain channels #1671

Merged
merged 6 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from 4 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
19 changes: 12 additions & 7 deletions cargo/cargo_bootstrap.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,11 @@ def _cargo_bootstrap_repository_impl(repository_ctx):
_detect_changes(repository_ctx)

if repository_ctx.attr.version in ("beta", "nightly"):
version_str = "{}-{}".format(repository_ctx.attr.version, repository_ctx.attr.iso_date)
channel = repository_ctx.attr.version
version = repository_ctx.attr.iso_date
else:
version_str = repository_ctx.attr.version
channel = "stable"
version = repository_ctx.attr.version

host_triple = get_host_triple(repository_ctx)
cargo_template = repository_ctx.attr.rust_toolchain_cargo_template
Expand All @@ -190,7 +192,8 @@ def _cargo_bootstrap_repository_impl(repository_ctx):
cargo_template = cargo_template,
rustc_template = rustc_template,
host_triple = host_triple,
version = version_str,
channel = channel,
version = version,
)

binary_name = repository_ctx.attr.binary or repository_ctx.name
Expand Down Expand Up @@ -264,17 +267,19 @@ cargo_bootstrap_repository = repository_rule(
doc = (
"The template to use for finding the host `cargo` binary. `{version}` (eg. '1.53.0'), " +
"`{triple}` (eg. 'x86_64-unknown-linux-gnu'), `{arch}` (eg. 'aarch64'), `{vendor}` (eg. 'unknown'), " +
"`{system}` (eg. 'darwin'), and `{tool}` (eg. 'rustc.exe') will be replaced in the string if present."
"`{system}` (eg. 'darwin'), `{channel}` (eg. 'stable'), and `{tool}` (eg. 'rustc.exe') will be " +
"replaced in the string if present."
),
default = "@rust_{system}_{arch}__{triple}_tools//:bin/{tool}",
default = "@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}",
),
"rust_toolchain_rustc_template": attr.string(
doc = (
"The template to use for finding the host `rustc` binary. `{version}` (eg. '1.53.0'), " +
"`{triple}` (eg. 'x86_64-unknown-linux-gnu'), `{arch}` (eg. 'aarch64'), `{vendor}` (eg. 'unknown'), " +
"`{system}` (eg. 'darwin'), and `{tool}` (eg. 'rustc.exe') will be replaced in the string if present."
"`{system}` (eg. 'darwin'), `{channel}` (eg. 'stable'), and `{tool}` (eg. 'rustc.exe') will be " +
"replaced in the string if present."
),
default = "@rust_{system}_{arch}__{triple}_tools//:bin/{tool}",
default = "@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}",
),
"srcs": attr.label_list(
doc = "Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made",
Expand Down
12 changes: 10 additions & 2 deletions cargo/private/cargo_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def _resolve_repository_template(
template,
abi = None,
arch = None,
channel = None,
system = None,
tool = None,
triple = None,
Expand All @@ -17,6 +18,7 @@ def _resolve_repository_template(
template (str): The template to use for rendering
abi (str, optional): The host ABI
arch (str, optional): The host CPU architecture
channel (str, optional): The toolchain channel. Eg. `stable`, `nightly`.
system (str, optional): The host system name
tool (str, optional): The tool to expect in the particular repository.
Eg. `cargo`, `rustc`, `stdlib`.
Expand Down Expand Up @@ -47,16 +49,20 @@ def _resolve_repository_template(
if version:
template = template.replace("{version}", version)

if channel:
template = template.replace("{channel}", channel)

return template

def get_rust_tools(cargo_template, rustc_template, host_triple, version):
def get_rust_tools(cargo_template, rustc_template, host_triple, channel, version):
"""Retrieve `cargo` and `rustc` labels based on the host triple.

Args:
cargo_template (str): A template used to identify the label of the host `cargo` binary.
rustc_template (str): A template used to identify the label of the host `rustc` binary.
host_triple (struct): The host's triple. See `@rules_rust//rust/platform:triple.bzl`.
version (str): The version of Cargo+Rustc to use.
channel (str): The Rust toolchain channel.
version (str): The version (or iso date in case of beta or nightly channels) of Cargo+Rustc to use.

Returns:
struct: A struct containing the labels of expected tools
Expand All @@ -66,6 +72,7 @@ def get_rust_tools(cargo_template, rustc_template, host_triple, version):
cargo_label = Label(_resolve_repository_template(
template = cargo_template,
version = version,
channel = channel,
triple = host_triple.str,
arch = host_triple.arch,
vendor = host_triple.vendor,
Expand All @@ -77,6 +84,7 @@ def get_rust_tools(cargo_template, rustc_template, host_triple, version):
rustc_label = Label(_resolve_repository_template(
template = rustc_template,
version = version,
channel = channel,
triple = host_triple.str,
arch = host_triple.arch,
vendor = host_triple.vendor,
Expand Down
9 changes: 8 additions & 1 deletion crate_universe/private/common_utils.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,18 @@ def get_rust_tools(repository_ctx, host_triple):
cargo_config = repository_ctx.path(repository_ctx.attr.cargo_config)
repository_ctx.symlink(cargo_config, cargo_home_config)

if repository_ctx.attr.rust_version.startswith(("beta", "nightly")):
channel, _, version = repository_ctx.attr.rust_version.partition("/")
krasimirgg marked this conversation as resolved.
Show resolved Hide resolved
else:
channel = "stable"
version = repository_ctx.attr.rust_version

return _rust_get_rust_tools(
cargo_template = repository_ctx.attr.rust_toolchain_cargo_template,
rustc_template = repository_ctx.attr.rust_toolchain_rustc_template,
host_triple = host_triple,
version = repository_ctx.attr.rust_version,
channel = channel,
version = version,
)

def _cargo_home_path(repository_ctx):
Expand Down
14 changes: 7 additions & 7 deletions crate_universe/private/crates_repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -264,22 +264,22 @@ that is called behind the scenes to update dependencies.
doc = (
"The template to use for finding the host `cargo` binary. `{version}` (eg. '1.53.0'), " +
"`{triple}` (eg. 'x86_64-unknown-linux-gnu'), `{arch}` (eg. 'aarch64'), `{vendor}` (eg. 'unknown'), " +
"`{system}` (eg. 'darwin'), `{cfg}` (eg. 'exec'), and `{tool}` (eg. 'rustc.exe') will be replaced in " +
"the string if present."
"`{system}` (eg. 'darwin'), `{cfg}` (eg. 'exec'), `{channel}` (eg. 'stable'), and `{tool}` (eg. " +
"'rustc.exe') will be replaced in the string if present."
),
default = "@rust_{system}_{arch}__{triple}_tools//:bin/{tool}",
default = "@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}",
),
"rust_toolchain_rustc_template": attr.string(
doc = (
"The template to use for finding the host `rustc` binary. `{version}` (eg. '1.53.0'), " +
"`{triple}` (eg. 'x86_64-unknown-linux-gnu'), `{arch}` (eg. 'aarch64'), `{vendor}` (eg. 'unknown'), " +
"`{system}` (eg. 'darwin'), `{cfg}` (eg. 'exec'), and `{tool}` (eg. 'cargo.exe') will be replaced in " +
"the string if present."
"`{system}` (eg. 'darwin'), `{cfg}` (eg. 'exec'), `{channel}` (eg. 'stable'), and `{tool}` (eg. " +
"'cargo.exe') will be replaced in the string if present."
),
default = "@rust_{system}_{arch}__{triple}_tools//:bin/{tool}",
default = "@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}",
),
"rust_version": attr.string(
doc = "The version of Rust the currently registered toolchain is using. Eg. `1.56.0`, or `nightly-2021-09-08`",
doc = "The version of Rust the currently registered toolchain is using. Eg. `1.56.0`, or `nightly/2021-09-08`",
default = rust_common.default_version,
),
"splicing_config": attr.string(
Expand Down
4 changes: 2 additions & 2 deletions docs/cargo.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ A rule for bootstrapping a Rust binary using [Cargo](https://doc.rust-lang.org/c
| <a id="cargo_bootstrap_repository-env_label"></a>env_label | A mapping of platform triple to a set of environment variables. This attribute differs from <code>env</code> in that all variables passed here must be fully qualified labels of files. See [cargo_env](#cargo_env) for usage details. Additionally, the platform triple <code>*</code> applies to all platforms. | <a href="https://bazel.build/rules/lib/dict">Dictionary: String -> String</a> | optional | <code>{}</code> |
| <a id="cargo_bootstrap_repository-iso_date"></a>iso_date | The iso_date of cargo binary the resolver should use. Note: This can only be set if <code>version</code> is <code>beta</code> or <code>nightly</code> | String | optional | <code>""</code> |
| <a id="cargo_bootstrap_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="cargo_bootstrap_repository-rust_toolchain_cargo_template"></a>rust_toolchain_cargo_template | The template to use for finding the host <code>cargo</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present. | String | optional | <code>"@rust_{system}_{arch}__{triple}_tools//:bin/{tool}"</code> |
| <a id="cargo_bootstrap_repository-rust_toolchain_rustc_template"></a>rust_toolchain_rustc_template | The template to use for finding the host <code>rustc</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present. | String | optional | <code>"@rust_{system}_{arch}__{triple}_tools//:bin/{tool}"</code> |
| <a id="cargo_bootstrap_repository-rust_toolchain_cargo_template"></a>rust_toolchain_cargo_template | The template to use for finding the host <code>cargo</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present. | String | optional | <code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code> |
| <a id="cargo_bootstrap_repository-rust_toolchain_rustc_template"></a>rust_toolchain_rustc_template | The template to use for finding the host <code>rustc</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present. | String | optional | <code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code> |
| <a id="cargo_bootstrap_repository-srcs"></a>srcs | Souce files of the crate to build. Passing source files here can be used to trigger rebuilds when changes are made | <a href="https://bazel.build/concepts/labels">List of labels</a> | optional | <code>[]</code> |
| <a id="cargo_bootstrap_repository-timeout"></a>timeout | Maximum duration of the Cargo build command in seconds | Integer | optional | <code>600</code> |
| <a id="cargo_bootstrap_repository-version"></a>version | The version of cargo the resolver should use | String | optional | <code>"1.65.0"</code> |
Expand Down
6 changes: 3 additions & 3 deletions docs/crate_universe.md
Original file line number Diff line number Diff line change
Expand Up @@ -290,9 +290,9 @@ that is called behind the scenes to update dependencies.
| <a id="crates_repository-quiet"></a>quiet | If stdout and stderr should not be printed to the terminal. | Boolean | optional | <code>True</code> |
| <a id="crates_repository-render_config"></a>render_config | The configuration flags to use for rendering. Use <code>//crate_universe:defs.bzl\%render_config</code> to generate the value for this field. If unset, the defaults defined there will be used. | String | optional | <code>""</code> |
| <a id="crates_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="crates_repository-rust_toolchain_cargo_template"></a>rust_toolchain_cargo_template | The template to use for finding the host <code>cargo</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{cfg}</code> (eg. 'exec'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present. | String | optional | <code>"@rust_{system}_{arch}__{triple}_tools//:bin/{tool}"</code> |
| <a id="crates_repository-rust_toolchain_rustc_template"></a>rust_toolchain_rustc_template | The template to use for finding the host <code>rustc</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{cfg}</code> (eg. 'exec'), and <code>{tool}</code> (eg. 'cargo.exe') will be replaced in the string if present. | String | optional | <code>"@rust_{system}_{arch}__{triple}_tools//:bin/{tool}"</code> |
| <a id="crates_repository-rust_version"></a>rust_version | The version of Rust the currently registered toolchain is using. Eg. <code>1.56.0</code>, or <code>nightly-2021-09-08</code> | String | optional | <code>"1.65.0"</code> |
| <a id="crates_repository-rust_toolchain_cargo_template"></a>rust_toolchain_cargo_template | The template to use for finding the host <code>cargo</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{cfg}</code> (eg. 'exec'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'rustc.exe') will be replaced in the string if present. | String | optional | <code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code> |
| <a id="crates_repository-rust_toolchain_rustc_template"></a>rust_toolchain_rustc_template | The template to use for finding the host <code>rustc</code> binary. <code>{version}</code> (eg. '1.53.0'), <code>{triple}</code> (eg. 'x86_64-unknown-linux-gnu'), <code>{arch}</code> (eg. 'aarch64'), <code>{vendor}</code> (eg. 'unknown'), <code>{system}</code> (eg. 'darwin'), <code>{cfg}</code> (eg. 'exec'), <code>{channel}</code> (eg. 'stable'), and <code>{tool}</code> (eg. 'cargo.exe') will be replaced in the string if present. | String | optional | <code>"@rust_{system}_{arch}__{triple}__{channel}_tools//:bin/{tool}"</code> |
| <a id="crates_repository-rust_version"></a>rust_version | The version of Rust the currently registered toolchain is using. Eg. <code>1.56.0</code>, or <code>nightly/2021-09-08</code> | String | optional | <code>"1.65.0"</code> |
| <a id="crates_repository-splicing_config"></a>splicing_config | The configuration flags to use for splicing Cargo maniests. Use <code>//crate_universe:defs.bzl\%rsplicing_config</code> to generate the value for this field. If unset, the defaults defined there will be used. | String | optional | <code>""</code> |
| <a id="crates_repository-supported_platform_triples"></a>supported_platform_triples | A set of all platform triples to consider when generating dependencies. | List of strings | optional | <code>["i686-apple-darwin", "i686-pc-windows-msvc", "i686-unknown-linux-gnu", "x86_64-apple-darwin", "x86_64-pc-windows-msvc", "x86_64-unknown-linux-gnu", "aarch64-apple-darwin", "aarch64-apple-ios", "aarch64-apple-ios-sim", "aarch64-pc-windows-msvc", "aarch64-linux-android", "aarch64-unknown-linux-gnu", "arm-unknown-linux-gnueabi", "armv7-unknown-linux-gnueabi", "armv7-linux-androideabi", "i686-linux-android", "i686-unknown-freebsd", "powerpc-unknown-linux-gnu", "s390x-unknown-linux-gnu", "wasm32-unknown-unknown", "wasm32-wasi", "x86_64-apple-ios", "x86_64-linux-android", "x86_64-unknown-freebsd", "riscv32imc-unknown-none-elf", "riscv64gc-unknown-none-elf"]</code> |

Expand Down
Loading