Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Dec 21, 2022
1 parent b766eac commit 5a05402
Showing 1 changed file with 43 additions and 9 deletions.
52 changes: 43 additions & 9 deletions rust/repositories.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def rust_register_toolchains(
extra_target_triples = ["wasm32-unknown-unknown", "wasm32-wasi"],
urls = DEFAULT_STATIC_RUST_URL_TEMPLATES,
version = None,
versions = _RUST_TOOLCHAIN_VERSIONS):
versions = []):
"""Emits a default set of toolchains for Linux, MacOS, and Freebsd
Skip this macro and call the `rust_repository_set` macros directly if you need a compiler for \
Expand All @@ -139,23 +139,35 @@ def rust_register_toolchains(
include_rustc_srcs (bool, optional): Whether to download rustc's src code. This is required in order to use rust-analyzer support.
See [rust_toolchain_repository.include_rustc_srcs](#rust_toolchain_repository-include_rustc_srcs). for more details
allocator_library (str, optional): Target that provides allocator functions when rust_library targets are embedded in a cc_binary.
iso_date (str, optional): The date of the nightly or beta release (ignored if the version is a specific version).
iso_date (str, optional): **Deprecated**: Use `versions` instead.
register_toolchains (bool): If true, repositories will be generated to produce and register `rust_toolchain` targets.
rustfmt_version (str, optional): The version of rustfmt. Either "nightly", "beta", or an exact version. Defaults to `version` if not specified.
rustfmt_version (str, optional): The version of rustfmt.
rust_analyzer_version (str, optional): The version of Rustc to pair with rust-analyzer.
sha256s (str, optional): A dict associating tool subdirectories to sha256 hashes.
extra_target_triples (list, optional): Additional rust-style targets that rust toolchains should support.
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).
version (str, optional): The version of Rust. Either "nightly", "beta", or an exact version. Defaults to a modern version.
version (str, optional): **Deprecated**: Use `versions` instead.
versions (list, optional): A list of toolchain versions to download. This paramter only accepts one versions
per channel. E.g. `["1.65.0", "nightly/2022-11-02", "beta/2020-12-30"]`.
"""
if version:
# buildifier: disable=print
print("`rust_register.toolchains.version` is deprecated. Please use `versions` instead: https://bazelbuild.github.io/rules_rust/flatten.html#rust_register_toolchains-versions")

if iso_date:
# buildifier: disable=print
print("`rust_register.toolchains.iso_date` is deprecated. Please use `versions` instead: https://bazelbuild.github.io/rules_rust/flatten.html#rust_register_toolchains-versions")

if rustfmt_version in ("nightly", "beta"):
# buildifier: disable=print
print("`rust_register.toolchains.rustfmt_version` now requires iso date to be included in the string. E.g. `nightly/2022-12-15`. This version will be assumed until this value is updated")
rustfmt_version = "{}/{}".format(rustfmt_version, DEFAULT_NIGHTLY_ISO_DATE)

if not versions:
fail("No versions of Rust were requested. Please update `rust_register_toolchains.versions`")
if version:
versions = [version]
else:
versions = _RUST_TOOLCHAIN_VERSIONS

if dev_components:
has_nightly = False
Expand Down Expand Up @@ -189,8 +201,9 @@ def rust_register_toolchains(
))

rustfmt_iso_date = None
rustfmt_version_or_channel = rustfmt_version
if rustfmt_version.startswith(("beta", "nightly")):
rustfmt_version, _, rustfmt_iso_date = rustfmt_version.partition("/")
rustfmt_version_or_channel, _, rustfmt_iso_date = rustfmt_version.partition("/")

for exec_triple, name in DEFAULT_TOOLCHAIN_TRIPLES.items():
maybe(
Expand All @@ -204,6 +217,7 @@ def rust_register_toolchains(
allocator_library = allocator_library,
iso_date = iso_date,
register_toolchain = register_toolchains,
rustfmt_version = rustfmt_version,
sha256s = sha256s,
urls = urls,
version = version,
Expand All @@ -215,7 +229,7 @@ def rust_register_toolchains(
maybe(
rustfmt_toolchain_repository,
name = rustfmt_repo_name,
version = rustfmt_version,
version = rustfmt_version_or_channel,
urls = urls,
sha256s = sha256s,
iso_date = rustfmt_iso_date,
Expand Down Expand Up @@ -260,11 +274,22 @@ def _rust_toolchain_tools_repository_impl(ctx):
]

if ctx.attr.rustfmt_version:
rustfmt_version = ctx.attr.rustfmt_version
rustfmt_iso_date = None
if rustfmt_version in ("nightly", "beta"):
if ctx.attr.iso_date:
rustfmt_iso_date = ctx.attr.iso_date
else:
fail("`rustfmt_version` does not include an iso_date. The following reposiotry should either set `iso_date` or update `rustfmt_version` to include an iso_date suffix: {}".format(
ctx.name,
))
elif rustfmt_version.startswith(("nightly", "beta")):
rustfmt_version, _, rustfmt_iso_date = rustfmt_version.partition("/")
build_components.append(load_rustfmt(
ctx = ctx,
target_triple = ctx.attr.exec_triple,
version = ctx.attr.rustfmt_version,
iso_date = ctx.attr.iso_date,
version = rustfmt_version,
iso_date = rustfmt_iso_date,
))

# Rust 1.45.0 and nightly builds after 2020-05-22 need the llvm-tools gzip to get the libLLVM dylib
Expand Down Expand Up @@ -459,6 +484,11 @@ def rust_toolchain_repository(
str: The name of the registerable toolchain created by this rule.
"""

if rustfmt_version in ("nightly", "beta"):
# buildifier: disable=print
print("`rust_toolchain_repository.rustfmt_version` now requires iso date to be included in the string. E.g. `nightly/2022-12-15`. This version will be assumed until this value is updated")
rustfmt_version = "{}/{}".format(rustfmt_version, DEFAULT_NIGHTLY_ISO_DATE)

if exec_compatible_with == None:
exec_compatible_with = triple_to_constraint_set(exec_triple)

Expand Down Expand Up @@ -800,6 +830,10 @@ def rust_repository_set(
name,
))

if version:
# buildifier: disable=print
print("`rust_repository_set.version` is deprecated. Instead use `rust_repository_set.versions`")

if version and not versions:
versions = [version]

Expand Down

0 comments on commit 5a05402

Please sign in to comment.