@@ -533,6 +533,12 @@ def _generate_sysroot(
533
533
def _experimental_use_cc_common_link (ctx ):
534
534
return ctx .attr .experimental_use_cc_common_link [BuildSettingInfo ].value
535
535
536
+ def _expand_flags (ctx , flags , targets ):
537
+ expanded_flags = []
538
+ for flag in flags :
539
+ expanded_flags .append (dedup_expand_location (ctx , flag , targets ))
540
+ return expanded_flags
541
+
536
542
def _rust_toolchain_impl (ctx ):
537
543
"""The rust_toolchain implementation
538
544
@@ -587,25 +593,9 @@ def _rust_toolchain_impl(ctx):
587
593
llvm_tools = ctx .attr .llvm_tools ,
588
594
)
589
595
590
- expanded_stdlib_linkflags = []
591
- for flag in ctx .attr .stdlib_linkflags :
592
- expanded_stdlib_linkflags .append (
593
- dedup_expand_location (
594
- ctx ,
595
- flag ,
596
- targets = rust_std [rust_common .stdlib_info ].srcs ,
597
- ),
598
- )
599
-
600
- expanded_extra_rustc_flags = []
601
- for flag in ctx .attr .extra_rustc_flags :
602
- expanded_extra_rustc_flags .append (
603
- dedup_expand_location (
604
- ctx ,
605
- flag ,
606
- targets = rust_std [rust_common .stdlib_info ].srcs ,
607
- ),
608
- )
596
+ expanded_stdlib_linkflags = _expand_flags (ctx , ctx .attr .stdlib_linkflags , rust_std [rust_common .stdlib_info ].srcs )
597
+ expanded_extra_rustc_flags = _expand_flags (ctx , ctx .attr .extra_rustc_flags , rust_std [rust_common .stdlib_info ].srcs )
598
+ expanded_extra_exec_rustc_flags = _expand_flags (ctx , ctx .attr .extra_exec_rustc_flags , rust_std [rust_common .stdlib_info ].srcs )
609
599
610
600
linking_context = cc_common .create_linking_context (
611
601
linker_inputs = depset ([
@@ -738,7 +728,7 @@ def _rust_toolchain_impl(ctx):
738
728
stdlib_linkflags = stdlib_linkflags_cc_info ,
739
729
extra_rustc_flags = expanded_extra_rustc_flags ,
740
730
extra_rustc_flags_for_crate_types = ctx .attr .extra_rustc_flags_for_crate_types ,
741
- extra_exec_rustc_flags = ctx . attr . extra_exec_rustc_flags ,
731
+ extra_exec_rustc_flags = expanded_extra_exec_rustc_flags ,
742
732
per_crate_rustc_flags = ctx .attr .per_crate_rustc_flags ,
743
733
sysroot = sysroot_path ,
744
734
sysroot_short_path = sysroot_short_path ,
@@ -851,7 +841,7 @@ rust_toolchain = rule(
851
841
doc = "Label to a boolean build setting that controls whether cc_common.link is used to link rust binaries." ,
852
842
),
853
843
"extra_exec_rustc_flags" : attr .string_list (
854
- doc = "Extra flags to pass to rustc in exec configuration" ,
844
+ doc = "Extra flags to pass to rustc in exec configuration. Subject to location expansion with respect to the srcs of the `rust_std` attribute. " ,
855
845
),
856
846
"extra_rustc_flags" : attr .string_list (
857
847
doc = "Extra flags to pass to rustc in non-exec configuration. Subject to location expansion with respect to the srcs of the `rust_std` attribute." ,
0 commit comments