Skip to content

Commit 2d4163c

Browse files
committed
Fix rustfmt with remote exec
1 parent 48aa95d commit 2d4163c

4 files changed

Lines changed: 31 additions & 3 deletions

File tree

rs/experimental/toolchains/declare_rustfmt_toolchains.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def declare_rustfmt_toolchains(
3737
name = rustfmt_toolchain_name,
3838
rustfmt = "{}rustfmt_bin".format(rustfmt_repo_label),
3939
rustc = "{}rustc".format(rustc_repo_label),
40-
rustc_lib = "{}rustc_lib".format(rustc_repo_label),
40+
rustc_lib = "{}rustc_lib".format(rustfmt_repo_label),
4141
visibility = ["//visibility:public"],
4242
tags = ["rust_version={}".format(version)],
4343
)

rs/private/rustfmt_repository.bzl

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
load("@rules_rust//rust/private:repository_utils.bzl", "BUILD_for_rustfmt")
21
load("@rules_rust//rust/platform:triple.bzl", "triple")
2+
load("@rules_rust//rust/private:repository_utils.bzl", "BUILD_for_rustfmt")
33
load(":rust_repository_utils.bzl", "download_and_extract", "RUST_REPOSITORY_COMMON_ATTR")
44

5+
_RUSTFMT_LIB_FILEGROUP_TEMPLATE = """
6+
filegroup(
7+
name = "rustc_lib",
8+
srcs = ["lib", {upstream_rustc_lib}],
9+
visibility = ["//visibility:public"],
10+
)
11+
"""
12+
513
def _rustfmt_repository_impl(rctx):
614
exec_triple = triple(rctx.attr.triple)
715
download_and_extract(rctx, "rustfmt", "rustfmt-preview", exec_triple)
8-
rctx.file("BUILD.bazel", BUILD_for_rustfmt(exec_triple))
16+
17+
rctx.file(
18+
"BUILD.bazel",
19+
BUILD_for_rustfmt(exec_triple) + _RUSTFMT_LIB_FILEGROUP_TEMPLATE.format(
20+
upstream_rustc_lib = repr(str(rctx.attr.rustc_repo_build_file.same_package_label("rustc_lib"))),
21+
),
22+
)
923

1024
rustc_repo_root = rctx.path(rctx.attr.rustc_repo_build_file).dirname
1125
rctx.symlink(rustc_repo_root.get_child("lib"), "lib")

test/MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ local_path_override(
5151
path = "..",
5252
)
5353

54+
rules_rust = use_extension("@rules_rs//rs/experimental:rules_rust.bzl", "rules_rust")
55+
use_repo(rules_rust, "rules_rust")
56+
5457
toolchains = use_extension("@rules_rs//rs/experimental/toolchains:module_extension.bzl", "toolchains")
5558
toolchains.toolchain(
5659
edition = "2024",

test/workspace_path_dependency/BUILD.bazel

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
load("@rules_rs//rs:rust_binary.bzl", "rust_binary")
2+
load("@rules_rust//rust:defs.bzl", "rust_clippy", "rustfmt_test")
23

34
package(default_visibility = ["//visibility:public"])
45

@@ -8,3 +9,13 @@ rust_binary(
89
edition = "2024",
910
deps = ["@workspace_path_dependency//:itoa"],
1011
)
12+
13+
rustfmt_test(
14+
name = "workspace_path_demo_rustfmt_test",
15+
targets = [":workspace_path_demo"],
16+
)
17+
18+
rust_clippy(
19+
name = "workspace_path_demo_clippy_test",
20+
deps = [":workspace_path_demo"],
21+
)

0 commit comments

Comments
 (0)