@@ -31,6 +31,32 @@ def _assert_no_deprecated_attributes(ctx):
31
31
"instead. If you used `cargo raze`, please use version 0.3.3 or later." ,
32
32
]))
33
33
34
+ def _assert_correct_dep_mapping (ctx ):
35
+ """Forces a failure if proc_macro_deps and deps are mixed inappropriately
36
+
37
+ Args:
38
+ ctx (ctx): The current rule's context object
39
+ """
40
+ for dep in ctx .attr .deps :
41
+ if rust_common .crate_info in dep :
42
+ if dep [rust_common .crate_info ].type == "proc-macro" :
43
+ fail (
44
+ "{} listed {} in its deps, but it is a proc-macro. It should instead be in the bazel property proc_macro_deps." .format (
45
+ ctx .label ,
46
+ dep .label ,
47
+ ),
48
+ )
49
+ for dep in ctx .attr .proc_macro_deps :
50
+ type = dep [rust_common .crate_info ].type
51
+ if type != "proc-macro" :
52
+ fail (
53
+ "{} listed {} in its proc_macro_deps, but it is not proc-macro, it is a {}. It should probably instead be listed in deps." .format (
54
+ ctx .label ,
55
+ dep .label ,
56
+ type ,
57
+ ),
58
+ )
59
+
34
60
def _determine_lib_name (name , crate_type , toolchain , lib_hash = "" ):
35
61
"""See https://github.com/bazelbuild/rules_rust/issues/405
36
62
@@ -203,6 +229,7 @@ def _rust_library_common(ctx, crate_type):
203
229
# Find lib.rs
204
230
crate_root = crate_root_src (ctx .attr , ctx .files .srcs , "lib" )
205
231
_assert_no_deprecated_attributes (ctx )
232
+ _assert_correct_dep_mapping (ctx )
206
233
207
234
toolchain = find_toolchain (ctx )
208
235
@@ -249,6 +276,7 @@ def _rust_binary_impl(ctx):
249
276
"""
250
277
toolchain = find_toolchain (ctx )
251
278
crate_name = name_to_crate_name (ctx .label .name )
279
+ _assert_correct_dep_mapping (ctx )
252
280
253
281
output = ctx .actions .declare_file (ctx .label .name + toolchain .binary_ext )
254
282
@@ -363,6 +391,7 @@ def _rust_test_common(ctx, toolchain, output):
363
391
list: The list of providers. See `rustc_compile_action`
364
392
"""
365
393
_assert_no_deprecated_attributes (ctx )
394
+ _assert_correct_dep_mapping (ctx )
366
395
367
396
crate_name = name_to_crate_name (ctx .label .name )
368
397
crate_type = "bin"
0 commit comments