Skip to content

Commit adb1957

Browse files
krasimirggcopybara-github
authored andcommitted
Adapt for rules_rust 0.66.0.
bazelbuild/rules_rust#3634, which updates the deps and proc_macro_deps of rustc_compile_action and collect_deps to list. PiperOrigin-RevId: 822050008
1 parent 412d0a2 commit adb1957

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

rust/bazel/aspects.bzl

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain")
44
load("@rules_cc//cc/common:cc_common.bzl", "cc_common")
55
load("@rules_cc//cc/common:cc_info.bzl", "CcInfo")
6+
load("@rules_rust//:version.bzl", RUST_VERSION = "VERSION")
67

78
# buildifier: disable=bzl-visibility
89
load("@rules_rust//rust/private:providers.bzl", "CrateInfo", "DepInfo", "DepVariantInfo")
@@ -33,6 +34,14 @@ RustProtoInfo = provider(
3334
},
3435
)
3536

37+
def _version_parts(version):
38+
major, minor = version.split(".")[0:2]
39+
return (int(major), int(minor))
40+
41+
def _rust_version_ge(version):
42+
"""Checks if the rust version as at least the given major.minor version."""
43+
return _version_parts(RUST_VERSION) >= _version_parts(version)
44+
3645
def label_to_crate_name(ctx, label, toolchain):
3746
return label.name.replace("-", "_")
3847

@@ -243,6 +252,13 @@ def _compile_rust(ctx, attr, src, extra_srcs, deps, runtime):
243252
lib = ctx.actions.declare_file(lib_name)
244253
rmeta = ctx.actions.declare_file(rmeta_name)
245254

255+
if _rust_version_ge("0.66"):
256+
deps = deps
257+
proc_macro_deps = []
258+
else:
259+
deps = depset(deps)
260+
proc_macro_deps = depset()
261+
246262
# TODO: Use higher level rules_rust API once available.
247263
providers = rustc_compile_action(
248264
ctx = ctx,
@@ -253,8 +269,8 @@ def _compile_rust(ctx, attr, src, extra_srcs, deps, runtime):
253269
type = "rlib",
254270
root = src,
255271
srcs = depset([src] + extra_srcs),
256-
deps = depset(deps),
257-
proc_macro_deps = depset([]),
272+
deps = deps,
273+
proc_macro_deps = proc_macro_deps,
258274
# Make "protobuf" into an alias for the runtime. This allows the
259275
# generated code to use a consistent name, even though the actual
260276
# name of the runtime crate varies depending on the protobuf kernel

0 commit comments

Comments
 (0)