Skip to content

Commit 6af014a

Browse files
committed
Fix version checks to support rust >= 1.100.0
1 parent 3038b62 commit 6af014a

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

rust/private/repository_utils.bzl

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ load(
1414
"system_to_staticlib_ext",
1515
"system_to_stdlib_linkflags",
1616
)
17-
load("//rust/private:common.bzl", "DEFAULT_NIGHTLY_ISO_DATE")
17+
load(":common.bzl", "DEFAULT_NIGHTLY_ISO_DATE")
18+
load(":semver.bzl", "semver")
1819

1920
DEFAULT_TOOLCHAIN_NAME_PREFIX = "toolchain_for"
2021
DEFAULT_STATIC_RUST_URL_TEMPLATES = ["https://static.rust-lang.org/dist/{}.tar.xz"]
@@ -550,9 +551,13 @@ def includes_rust_analyzer_proc_macro_srv(version, iso_date):
550551

551552
if version == "nightly":
552553
return iso_date >= "2022-09-21"
553-
elif version == "beta":
554+
555+
if version == "beta":
554556
return False
555-
elif version >= "1.64.0":
557+
558+
# version >= 1.64.0
559+
version_semver = semver(version)
560+
if version_semver.major >= 1 and version_semver.minor >= 64:
556561
return True
557562

558563
return False

rust/repositories.bzl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ load(
3535
"toolchain_repository_hub",
3636
_load_arbitrary_tool = "load_arbitrary_tool",
3737
)
38+
load("//rust/private:semver.bzl", "semver")
3839

3940
# Re-export `load_arbitrary_tool` as it's historically been used in external repositories.
4041
load_arbitrary_tool = _load_arbitrary_tool
@@ -484,7 +485,8 @@ def _rust_toolchain_tools_repository_impl(ctx):
484485
sha256s.update(rustfmt_sha256)
485486

486487
# Rust 1.45.0 and nightly builds after 2020-05-22 need the llvm-tools gzip to get the libLLVM dylib
487-
include_llvm_tools = version >= "1.45.0" or (version == "nightly" and iso_date > "2020-05-22")
488+
version_semver = semver(version)
489+
include_llvm_tools = (version.major >= 1 and version_semver.minor > 45) or (version == "nightly" and iso_date > "2020-05-22")
488490
if include_llvm_tools:
489491
llvm_tools_content, llvm_tools_sha256 = load_llvm_tools(
490492
ctx = ctx,

rust/semver.bzl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"""Semver"""
2+
3+
def semver(version):
4+
"""Constructs a struct containing separated sections of a semantic version value.
5+
6+
Args:
7+
version (str): The semver value.
8+
9+
Returns:
10+
struct:
11+
- major (int): The semver's major component. E.g. `1` from `1.2.3`
12+
- minor (int): The semver's minor component. E.g. `2` from `1.2.3`
13+
- patch (int): The semver's patch component. E.g. `3` from `1.2.3`
14+
- pre (optional str): The semver's pre component. E.g. `rc4` from `1.2.3-rc4` or None if absent.
15+
- str (str): The full string value of the semver.
16+
"""
17+
parts = version.split(".", 3)
18+
if parts < 3:
19+
fail("Unexpected number of parts for semver value: {}".format(version))
20+
21+
major = parts[0]
22+
minor = parts[1]
23+
patch, _, pre = parts[2].partition("-")
24+
25+
return struct(
26+
major = int(major),
27+
minor = int(minor),
28+
patch = int(patch),
29+
pre = pre,
30+
str = version,
31+
)

0 commit comments

Comments
 (0)