3939 "generate_output_diagnostics" ,
4040 "get_edition" ,
4141 "get_import_macro_deps" ,
42+ "partition_deps" ,
4243 "transform_deps" ,
4344 "transform_sources" ,
4445)
@@ -53,31 +54,6 @@ def _assert_no_deprecated_attributes(_ctx):
5354 """
5455 pass
5556
56- def _assert_correct_dep_mapping (ctx ):
57- """Forces a failure if proc_macro_deps and deps are mixed inappropriately
58-
59- Args:
60- ctx (ctx): The current rule's context object
61- """
62- for dep in ctx .attr .deps :
63- if rust_common .crate_info in dep :
64- if dep [rust_common .crate_info ].type == "proc-macro" :
65- fail (
66- "{} listed {} in its deps, but it is a proc-macro. It should instead be in the bazel property proc_macro_deps." .format (
67- ctx .label ,
68- dep .label ,
69- ),
70- )
71- for dep in ctx .attr .proc_macro_deps :
72- type = dep [rust_common .crate_info ].type
73- if type != "proc-macro" :
74- fail (
75- "{} listed {} in its proc_macro_deps, but it is not proc-macro, it is a {}. It should probably instead be listed in deps." .format (
76- ctx .label ,
77- dep .label ,
78- type ,
79- ),
80- )
8157
8258def _rust_library_impl (ctx ):
8359 """The implementation of the `rust_library` rule.
@@ -148,7 +124,7 @@ def _rust_library_common(ctx, crate_type):
148124 list: A list of providers. See `rustc_compile_action`
149125 """
150126 _assert_no_deprecated_attributes (ctx )
151- _assert_correct_dep_mapping (ctx )
127+ deps , proc_macro_deps = partition_deps (ctx )
152128
153129 toolchain = find_toolchain (ctx )
154130
@@ -195,8 +171,8 @@ def _rust_library_common(ctx, crate_type):
195171 not ctx .attr .disable_pipelining
196172 )
197173
198- deps = transform_deps (ctx . attr . deps )
199- proc_macro_deps = transform_deps (ctx . attr . proc_macro_deps + get_import_macro_deps (ctx ))
174+ deps = transform_deps (deps )
175+ proc_macro_deps = transform_deps (proc_macro_deps + get_import_macro_deps (ctx ))
200176
201177 return rustc_compile_action (
202178 ctx = ctx ,
@@ -238,16 +214,16 @@ def _rust_binary_impl(ctx):
238214 """
239215 toolchain = find_toolchain (ctx )
240216 crate_name = compute_crate_name (ctx .workspace_name , ctx .label , toolchain , ctx .attr .crate_name )
241- _assert_correct_dep_mapping (ctx )
217+ deps , proc_macro_deps = partition_deps (ctx )
242218
243219 if ctx .attr .binary_name :
244220 output_filename = ctx .attr .binary_name
245221 else :
246222 output_filename = ctx .label .name
247223 output = ctx .actions .declare_file (output_filename + toolchain .binary_ext )
248224
249- deps = transform_deps (ctx . attr . deps )
250- proc_macro_deps = transform_deps (ctx . attr . proc_macro_deps + get_import_macro_deps (ctx ))
225+ deps = transform_deps (deps )
226+ proc_macro_deps = transform_deps (proc_macro_deps + get_import_macro_deps (ctx ))
251227
252228 crate_root = getattr (ctx .file , "crate_root" , None )
253229 if not crate_root :
@@ -327,13 +303,13 @@ def _rust_test_impl(ctx):
327303 list: The list of providers. See `rustc_compile_action`
328304 """
329305 _assert_no_deprecated_attributes (ctx )
330- _assert_correct_dep_mapping (ctx )
306+ deps , proc_macro_deps = partition_deps (ctx )
331307
332308 toolchain = find_toolchain (ctx )
333309
334310 crate_type = "bin"
335- deps = transform_deps (ctx . attr . deps )
336- proc_macro_deps = transform_deps (ctx . attr . proc_macro_deps + get_import_macro_deps (ctx ))
311+ deps = transform_deps (deps )
312+ proc_macro_deps = transform_deps (proc_macro_deps + get_import_macro_deps (ctx ))
337313
338314 if ctx .attr .crate and ctx .attr .srcs :
339315 fail ("rust_test.crate and rust_test.srcs are mutually exclusive. Update {} to use only one of these attributes" .format (
@@ -1072,6 +1048,21 @@ rust_shared_library = rule(
10721048 """ ),
10731049)
10741050
1051+ def _exec_transition_impl (_settings , attr ):
1052+ return {
1053+ "//command_line_option:is exec configuration" : not attr .internal_doctest_transition_override ,
1054+ "//command_line_option:stamp" : False ,
1055+ }
1056+
1057+ _exec_transition = transition (
1058+ inputs = [],
1059+ outputs = [
1060+ "//command_line_option:is exec configuration" ,
1061+ "//command_line_option:stamp" ,
1062+ ],
1063+ implementation = _exec_transition_impl ,
1064+ )
1065+
10751066def _proc_macro_dep_transition_impl (settings , _attr ):
10761067 if settings ["//rust/private:is_proc_macro_dep_enabled" ]:
10771068 return {"//rust/private:is_proc_macro_dep" : True }
@@ -1105,7 +1096,11 @@ rust_proc_macro = rule(
11051096 """ ),
11061097 cfg = _proc_macro_dep_transition ,
11071098 ),
1099+ internal_doctest_transition_override = attr .bool (
1100+ doc = "Used for internal testing; do not set" ,
1101+ ),
11081102 ),
1103+ cfg = _exec_transition ,
11091104 fragments = ["cpp" ],
11101105 toolchains = [
11111106 str (Label ("//rust:toolchain_type" )),
0 commit comments