@@ -526,6 +526,34 @@ def _stamp_attribute(default_value):
526
526
values = [1 , 0 , - 1 ],
527
527
)
528
528
529
+ def _crate_scope_transition_impl (settings , attr ):
530
+ if hasattr (attr , "_change_crate_scope" ):
531
+ return {"//rust/private:crate_scope" : attr ._change_crate_scope }
532
+ if settings ["//rust/private:crate_scope" ] == "proc_macro" :
533
+ # the whole transitive closure of a proc_macro should be the proc_macro scope,
534
+ # except that it is reset by either the _change_crate_scope attr above or the
535
+ # _crate_scope_reset_transition below.
536
+ return {"//rust/private:crate_scope" : "proc_macro" }
537
+ return {"//rust/private:crate_scope" : "regular" }
538
+
539
+ _crate_scope_transition_inputs = ["//rust/private:crate_scope" ]
540
+ _crate_scope_transition_outputs = ["//rust/private:crate_scope" ]
541
+
542
+ _crate_scope_transition = transition (
543
+ implementation = _crate_scope_transition_impl ,
544
+ inputs = _crate_scope_transition_inputs ,
545
+ outputs = _crate_scope_transition_outputs ,
546
+ )
547
+
548
+ def _crate_scope_reset_transition_impl (_settings , _attr ):
549
+ return {"//rust/private:crate_scope" : "none" }
550
+
551
+ _crate_scope_reset_transition = transition (
552
+ implementation = _crate_scope_reset_transition_impl ,
553
+ inputs = [],
554
+ outputs = _crate_scope_transition_outputs ,
555
+ )
556
+
529
557
# Internal attributes core to Rustc actions.
530
558
RUSTC_ATTRS = {
531
559
"_error_format" : attr .label (
@@ -591,6 +619,7 @@ _common_attrs = {
591
619
macro.
592
620
""" ),
593
621
allow_files = True ,
622
+ cfg = _crate_scope_reset_transition ,
594
623
),
595
624
"crate_features" : attr .string_list (
596
625
doc = dedent ("""\
@@ -617,6 +646,7 @@ _common_attrs = {
617
646
or the single file in `srcs` if `srcs` contains only one file.
618
647
""" ),
619
648
allow_single_file = [".rs" ],
649
+ cfg = _crate_scope_reset_transition ,
620
650
),
621
651
"data" : attr .label_list (
622
652
doc = dedent ("""\
@@ -627,6 +657,7 @@ _common_attrs = {
627
657
in the runfiles.
628
658
""" ),
629
659
allow_files = True ,
660
+ cfg = _crate_scope_reset_transition ,
630
661
),
631
662
"deps" : attr .label_list (
632
663
doc = dedent ("""\
@@ -723,6 +754,9 @@ _common_attrs = {
723
754
doc = "A setting used to determine whether or not the `--stamp` flag is enabled" ,
724
755
default = Label ("//rust/private:stamp" ),
725
756
),
757
+ "_allowlist_function_transition" : attr .label (
758
+ default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
759
+ ),
726
760
} | RUSTC_ATTRS
727
761
728
762
_coverage_attrs = {
@@ -828,6 +862,7 @@ rust_library = rule(
828
862
),
829
863
},
830
864
fragments = ["cpp" ],
865
+ cfg = _crate_scope_transition ,
831
866
toolchains = [
832
867
str (Label ("//rust:toolchain_type" )),
833
868
"@bazel_tools//tools/cpp:toolchain_type" ,
@@ -901,16 +936,16 @@ rust_library = rule(
901
936
def _rust_static_library_transition_impl (settings , attr ):
902
937
return {
903
938
"//command_line_option:platforms" : str (attr .platform ) if attr .platform else settings ["//command_line_option:platforms" ],
904
- }
939
+ } | _crate_scope_transition_impl ( settings , attr )
905
940
906
941
_rust_static_library_transition = transition (
907
942
implementation = _rust_static_library_transition_impl ,
908
943
inputs = [
909
944
"//command_line_option:platforms" ,
910
- ],
945
+ ] + _crate_scope_transition_inputs ,
911
946
outputs = [
912
947
"//command_line_option:platforms" ,
913
- ],
948
+ ] + _crate_scope_transition_outputs ,
914
949
)
915
950
916
951
rust_static_library = rule (
@@ -920,9 +955,6 @@ rust_static_library = rule(
920
955
doc = "Optional platform to transition the static library to." ,
921
956
default = None ,
922
957
),
923
- "_allowlist_function_transition" : attr .label (
924
- default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
925
- ),
926
958
},
927
959
fragments = ["cpp" ],
928
960
cfg = _rust_static_library_transition ,
@@ -950,16 +982,16 @@ rust_static_library = rule(
950
982
def _rust_shared_library_transition_impl (settings , attr ):
951
983
return {
952
984
"//command_line_option:platforms" : str (attr .platform ) if attr .platform else settings ["//command_line_option:platforms" ],
953
- }
985
+ } | _crate_scope_transition_impl ( settings , attr )
954
986
955
987
_rust_shared_library_transition = transition (
956
988
implementation = _rust_shared_library_transition_impl ,
957
989
inputs = [
958
990
"//command_line_option:platforms" ,
959
- ],
991
+ ] + _crate_scope_transition_inputs ,
960
992
outputs = [
961
993
"//command_line_option:platforms" ,
962
- ],
994
+ ] + _crate_scope_transition_outputs ,
963
995
)
964
996
965
997
rust_shared_library = rule (
@@ -969,9 +1001,6 @@ rust_shared_library = rule(
969
1001
doc = "Optional platform to transition the shared library to." ,
970
1002
default = None ,
971
1003
),
972
- "_allowlist_function_transition" : attr .label (
973
- default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
974
- ),
975
1004
"_use_grep_includes" : attr .bool (default = True ),
976
1005
},
977
1006
fragments = ["cpp" ],
@@ -1018,9 +1047,7 @@ rust_proc_macro = rule(
1018
1047
# https://docs.bazel.build/versions/main/skylark/config.html#user-defined-transitions.
1019
1048
attrs = dict (
1020
1049
_common_attrs .items (),
1021
- _allowlist_function_transition = attr .label (
1022
- default = Label ("//tools/allowlists/function_transition_allowlist" ),
1023
- ),
1050
+ _change_crate_scope = attr .string (default = "proc_macro" ),
1024
1051
deps = attr .label_list (
1025
1052
doc = dedent ("""\
1026
1053
List of other libraries to be linked to this library target.
@@ -1032,6 +1059,7 @@ rust_proc_macro = rule(
1032
1059
),
1033
1060
),
1034
1061
fragments = ["cpp" ],
1062
+ cfg = _crate_scope_transition ,
1035
1063
toolchains = [
1036
1064
str (Label ("//rust:toolchain_type" )),
1037
1065
"@bazel_tools//tools/cpp:toolchain_type" ,
@@ -1074,6 +1102,7 @@ _rust_binary_attrs = {
1074
1102
Link script to forward into linker via rustc options.
1075
1103
""" ),
1076
1104
allow_single_file = True ,
1105
+ cfg = _crate_scope_reset_transition ,
1077
1106
),
1078
1107
"out_binary" : attr .bool (
1079
1108
doc = (
@@ -1090,16 +1119,16 @@ _rust_binary_attrs = {
1090
1119
def _rust_binary_transition_impl (settings , attr ):
1091
1120
return {
1092
1121
"//command_line_option:platforms" : str (attr .platform ) if attr .platform else settings ["//command_line_option:platforms" ],
1093
- }
1122
+ } | _crate_scope_transition_impl ( settings , attr )
1094
1123
1095
1124
_rust_binary_transition = transition (
1096
1125
implementation = _rust_binary_transition_impl ,
1097
1126
inputs = [
1098
1127
"//command_line_option:platforms" ,
1099
- ],
1128
+ ] + _crate_scope_transition_inputs ,
1100
1129
outputs = [
1101
1130
"//command_line_option:platforms" ,
1102
- ],
1131
+ ] + _crate_scope_transition_outputs ,
1103
1132
)
1104
1133
1105
1134
rust_binary = rule (
@@ -1110,9 +1139,6 @@ rust_binary = rule(
1110
1139
doc = "Optional platform to transition the binary to." ,
1111
1140
default = None ,
1112
1141
),
1113
- "_allowlist_function_transition" : attr .label (
1114
- default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
1115
- ),
1116
1142
},
1117
1143
executable = True ,
1118
1144
fragments = ["cpp" ],
@@ -1252,9 +1278,7 @@ rust_binary_without_process_wrapper = rule(
1252
1278
doc = "Optional platform to transition the binary to." ,
1253
1279
default = None ,
1254
1280
),
1255
- "_allowlist_function_transition" : attr .label (
1256
- default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
1257
- ),
1281
+ "_change_crate_scope" : attr .string (default = "regular" ),
1258
1282
}),
1259
1283
executable = True ,
1260
1284
fragments = ["cpp" ],
@@ -1268,8 +1292,11 @@ rust_binary_without_process_wrapper = rule(
1268
1292
rust_library_without_process_wrapper = rule (
1269
1293
implementation = _rust_library_impl ,
1270
1294
provides = COMMON_PROVIDERS ,
1271
- attrs = dict (_common_attrs_for_binary_without_process_wrapper (_common_attrs ).items ()),
1295
+ attrs = _common_attrs_for_binary_without_process_wrapper (_common_attrs | {
1296
+ "_change_crate_scope" : attr .string (default = "regular" ),
1297
+ }),
1272
1298
fragments = ["cpp" ],
1299
+ cfg = _crate_scope_transition ,
1273
1300
toolchains = [
1274
1301
str (Label ("//rust:toolchain_type" )),
1275
1302
"@bazel_tools//tools/cpp:toolchain_type" ,
@@ -1279,16 +1306,16 @@ rust_library_without_process_wrapper = rule(
1279
1306
def _rust_test_transition_impl (settings , attr ):
1280
1307
return {
1281
1308
"//command_line_option:platforms" : str (attr .platform ) if attr .platform else settings ["//command_line_option:platforms" ],
1282
- }
1309
+ } | _crate_scope_transition_impl ( settings , attr )
1283
1310
1284
1311
_rust_test_transition = transition (
1285
1312
implementation = _rust_test_transition_impl ,
1286
1313
inputs = [
1287
1314
"//command_line_option:platforms" ,
1288
- ],
1315
+ ] + _crate_scope_transition_inputs ,
1289
1316
outputs = [
1290
1317
"//command_line_option:platforms" ,
1291
- ],
1318
+ ] + _crate_scope_transition_outputs ,
1292
1319
)
1293
1320
1294
1321
rust_test = rule (
@@ -1299,9 +1326,6 @@ rust_test = rule(
1299
1326
doc = "Optional platform to transition the test to." ,
1300
1327
default = None ,
1301
1328
),
1302
- "_allowlist_function_transition" : attr .label (
1303
- default = "@bazel_tools//tools/allowlists/function_transition_allowlist" ,
1304
- ),
1305
1329
},
1306
1330
executable = True ,
1307
1331
fragments = ["cpp" ],
0 commit comments