Skip to content

Commit 684a262

Browse files
committed
Make clippy and rustfmt repos self-contained
1 parent 691ab7b commit 684a262

7 files changed

Lines changed: 15 additions & 71 deletions

File tree

rs/private/BUILD.bazel

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ bzl_library(
136136
srcs = ["clippy_repository.bzl"],
137137
visibility = ["//rs:__subpackages__"],
138138
deps = [
139-
":symlink_utils",
139+
"//rs/private:rust_repository_utils",
140140
"@rules_rust//rust/platform:bzl_lib",
141141
"@rules_rust//rust/private:bzl_lib",
142142
],
@@ -147,7 +147,6 @@ bzl_library(
147147
srcs = ["rustfmt_repository.bzl"],
148148
visibility = ["//rs:__subpackages__"],
149149
deps = [
150-
":symlink_utils",
151150
"//rs/private:rust_repository_utils",
152151
"@rules_rust//rust/platform:bzl_lib",
153152
"@rules_rust//rust/private:bzl_lib",
@@ -218,16 +217,6 @@ bzl_library(
218217
],
219218
)
220219

221-
bzl_library(
222-
name = "symlink_utils",
223-
srcs = ["symlink_utils.bzl"],
224-
visibility = ["//rs:__subpackages__"],
225-
deps = [
226-
"@bazel_features//:features",
227-
"@bazel_lib//lib:paths",
228-
],
229-
)
230-
231220
bzl_library(
232221
name = "cargo_lints",
233222
srcs = ["cargo_lints.bzl"],

rs/private/clippy_repository.bzl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
load("@rules_rust//rust/platform:triple.bzl", "triple")
22
load("@rules_rust//rust/private:repository_utils.bzl", "BUILD_for_clippy")
33
load(":rust_repository_utils.bzl", "RUST_REPOSITORY_COMMON_ATTR", "download_and_extract")
4-
load(":symlink_utils.bzl", "relative_symlink")
54

65
def _clippy_repository_impl(rctx):
76
exec_triple = triple(rctx.attr.triple)
87
download_and_extract(rctx, "clippy", "clippy-preview", exec_triple)
9-
rctx.file("BUILD.bazel", BUILD_for_clippy(exec_triple))
10-
11-
rustc_repo_root = rctx.path(rctx.attr.rustc_repo_build_file).dirname
12-
relative_symlink(rctx, rustc_repo_root.get_child("lib"), "lib")
8+
download_and_extract(rctx, "rustc", "rustc", exec_triple, sha256 = rctx.attr.rustc_sha256)
9+
rctx.file("BUILD.bazel", BUILD_for_clippy(exec_triple, include_rustc_lib = True))
1310

1411
return rctx.repo_metadata(reproducible = True)
1512

1613
clippy_repository = repository_rule(
1714
implementation = _clippy_repository_impl,
1815
attrs = {
19-
"rustc_repo_build_file": attr.label(allow_single_file = True, mandatory = True),
16+
"rustc_sha256": attr.string(mandatory = True),
2017
} | RUST_REPOSITORY_COMMON_ATTR,
2118
)

rs/private/rust_repository_utils.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ load("@bazel_tools//tools/build_defs/repo:utils.bzl", "get_auth")
22
load(
33
"@rules_rust//rust/private:repository_utils.bzl",
44
"DEFAULT_STATIC_RUST_URL_TEMPLATES",
5-
"produce_tool_suburl",
65
"produce_tool_path",
6+
"produce_tool_suburl",
77
)
88

9-
def download_and_extract(rctx, tool, dir, triple):
9+
def download_and_extract(rctx, tool, dir, triple, sha256 = None):
1010
tool_suburl = produce_tool_suburl(tool, triple, rctx.attr.version, rctx.attr.iso_date)
1111
urls = [url.format(tool_suburl) for url in rctx.attr.urls]
1212

1313
tool_path = produce_tool_path(tool, rctx.attr.version, triple)
1414

1515
rctx.download_and_extract(
1616
urls,
17-
sha256 = rctx.attr.sha256,
17+
sha256 = sha256 or rctx.attr.sha256,
1818
auth = get_auth(rctx, urls),
1919
strip_prefix = "{}/{}".format(tool_path, dir),
2020
)

rs/private/rustfmt_repository.bzl

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
11
load("@rules_rust//rust/platform:triple.bzl", "triple")
22
load("@rules_rust//rust/private:repository_utils.bzl", "BUILD_for_rustfmt")
33
load(":rust_repository_utils.bzl", "RUST_REPOSITORY_COMMON_ATTR", "download_and_extract")
4-
load(":symlink_utils.bzl", "relative_symlink")
5-
6-
_RUSTFMT_LIB_FILEGROUP_TEMPLATE = """
7-
filegroup(
8-
name = "rustc_lib",
9-
srcs = ["lib", {upstream_rustc_lib}],
10-
visibility = ["//visibility:public"],
11-
)
12-
"""
134

145
def _rustfmt_repository_impl(rctx):
156
exec_triple = triple(rctx.attr.triple)
167
download_and_extract(rctx, "rustfmt", "rustfmt-preview", exec_triple)
17-
18-
rctx.file(
19-
"BUILD.bazel",
20-
BUILD_for_rustfmt(exec_triple) + _RUSTFMT_LIB_FILEGROUP_TEMPLATE.format(
21-
upstream_rustc_lib = repr(str(rctx.attr.rustc_repo_build_file.same_package_label("rustc_lib"))),
22-
),
23-
)
24-
25-
rustc_repo_root = rctx.path(rctx.attr.rustc_repo_build_file).dirname
26-
relative_symlink(rctx, rustc_repo_root.get_child("lib"), "lib")
8+
download_and_extract(rctx, "rustc", "rustc", exec_triple, sha256 = rctx.attr.rustc_sha256)
9+
rctx.file("BUILD.bazel", BUILD_for_rustfmt(exec_triple, include_rustc_lib = True))
2710

2811
return rctx.repo_metadata(reproducible = True)
2912

3013
rustfmt_repository = repository_rule(
3114
implementation = _rustfmt_repository_impl,
3215
attrs = {
33-
"rustc_repo_build_file": attr.label(allow_single_file = True, mandatory = True),
16+
"rustc_sha256": attr.string(mandatory = True),
3417
} | RUST_REPOSITORY_COMMON_ATTR,
3518
)

rs/private/symlink_utils.bzl

Lines changed: 0 additions & 25 deletions
This file was deleted.

rs/rules_rust.bzl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ def _rules_rust_impl(mctx):
3131

3232
http_archive(
3333
name = "rules_rust",
34-
integrity = "sha256-kp7kh5YHlHGkpJxw5TreSVcggyXfL4C22T034BvH9fs=",
35-
strip_prefix = "rules_rust-77bc22e052b911bff07cb4463817779b3d11695e",
36-
url = "https://github.com/hermeticbuild/rules_rust/archive/77bc22e052b911bff07cb4463817779b3d11695e.tar.gz",
34+
integrity = "sha256-aROt7MxNPUOELpgM4BZEQpptsoT6t2qjFpAzyZRF0LE=",
35+
strip_prefix = "rules_rust-1c00622c3ba0269a6d5306772fe2e9aff4bf89a0",
36+
url = "https://github.com/hermeticbuild/rules_rust/archive/1c00622c3ba0269a6d5306772fe2e9aff4bf89a0.tar.gz",
3737
patches = patches,
3838
patch_strip = strip,
3939
)

rs/toolchains/module_extension.bzl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ def _toolchains_impl(mctx):
239239
version = base_version,
240240
iso_date = iso_date,
241241
sha256 = _sha_for("clippy", base_version, iso_date, exec_triple),
242-
rustc_repo_build_file = "@rustc_{}_{}//:BUILD.bazel".format(triple_suffix, version_key),
242+
rustc_sha256 = _sha_for("rustc", base_version, iso_date, exec_triple),
243243
)
244244

245245
if version in versions:
@@ -266,7 +266,7 @@ def _toolchains_impl(mctx):
266266
version = base_version,
267267
iso_date = iso_date,
268268
sha256 = _sha_for("rustfmt", base_version, iso_date, exec_triple),
269-
rustc_repo_build_file = "@rustc_{}_{}//:BUILD.bazel".format(triple_suffix, version_key),
269+
rustc_sha256 = _sha_for("rustc", base_version, iso_date, exec_triple),
270270
)
271271

272272
for version in rust_analyzer_versions:

0 commit comments

Comments
 (0)