@@ -533,6 +533,12 @@ def _generate_sysroot(
533533def _experimental_use_cc_common_link (ctx ):
534534 return ctx .attr .experimental_use_cc_common_link [BuildSettingInfo ].value
535535
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+
536542def _rust_toolchain_impl (ctx ):
537543 """The rust_toolchain implementation
538544
@@ -587,25 +593,9 @@ def _rust_toolchain_impl(ctx):
587593 llvm_tools = ctx .attr .llvm_tools ,
588594 )
589595
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 )
609599
610600 linking_context = cc_common .create_linking_context (
611601 linker_inputs = depset ([
@@ -738,7 +728,7 @@ def _rust_toolchain_impl(ctx):
738728 stdlib_linkflags = stdlib_linkflags_cc_info ,
739729 extra_rustc_flags = expanded_extra_rustc_flags ,
740730 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 ,
742732 per_crate_rustc_flags = ctx .attr .per_crate_rustc_flags ,
743733 sysroot = sysroot_path ,
744734 sysroot_short_path = sysroot_short_path ,
@@ -851,7 +841,7 @@ rust_toolchain = rule(
851841 doc = "Label to a boolean build setting that controls whether cc_common.link is used to link rust binaries." ,
852842 ),
853843 "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. " ,
855845 ),
856846 "extra_rustc_flags" : attr .string_list (
857847 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