@@ -448,7 +448,8 @@ def construct_arguments(
448
448
out_dir ,
449
449
build_env_files ,
450
450
build_flags_files ,
451
- emit = ["dep-info" , "link" ]):
451
+ emit = ["dep-info" , "link" ],
452
+ force_all_deps_direct = False ):
452
453
"""Builds an Args object containing common rustc flags
453
454
454
455
Args:
@@ -468,6 +469,8 @@ def construct_arguments(
468
469
build_env_files (list): Files containing rustc environment variables, for instance from `cargo_build_script` actions.
469
470
build_flags_files (list): The output files of a `cargo_build_script` actions containing rustc build flags
470
471
emit (list): Values for the --emit flag to rustc.
472
+ force_all_deps_direct (bool, optional): Whether to pass the transitive rlibs with --extern
473
+ to the commandline as opposed to -L.
471
474
472
475
Returns:
473
476
tuple: A tuple of the following items
@@ -598,7 +601,7 @@ def construct_arguments(
598
601
_add_native_link_flags (rustc_flags , dep_info , linkstamp_outs , crate_info .type , toolchain , cc_toolchain , feature_configuration )
599
602
600
603
# These always need to be added, even if not linking this crate.
601
- add_crate_link_flags (rustc_flags , dep_info )
604
+ add_crate_link_flags (rustc_flags , dep_info , force_all_deps_direct )
602
605
603
606
needs_extern_proc_macro_flag = "proc-macro" in [crate_info .type , crate_info .wrapped_crate_type ] and \
604
607
crate_info .edition != "2015"
@@ -647,7 +650,8 @@ def rustc_compile_action(
647
650
crate_info ,
648
651
output_hash = None ,
649
652
rust_flags = [],
650
- environ = {}):
653
+ environ = {},
654
+ force_all_deps_direct = False ):
651
655
"""Create and run a rustc compile action based on the current rule's attributes
652
656
653
657
Args:
@@ -658,6 +662,8 @@ def rustc_compile_action(
658
662
output_hash (str, optional): The hashed path of the crate root. Defaults to None.
659
663
rust_flags (list, optional): Additional flags to pass to rustc. Defaults to [].
660
664
environ (dict, optional): A set of makefile expandable environment variables for the action
665
+ force_all_deps_direct (bool, optional): Whether to pass the transitive rlibs with --extern
666
+ to the commandline as opposed to -L.
661
667
662
668
Returns:
663
669
list: A list of the following providers:
@@ -710,6 +716,7 @@ def rustc_compile_action(
710
716
out_dir = out_dir ,
711
717
build_env_files = build_env_files ,
712
718
build_flags_files = build_flags_files ,
719
+ force_all_deps_direct = force_all_deps_direct ,
713
720
)
714
721
715
722
if hasattr (attr , "version" ) and attr .version != "0.0.0" :
@@ -962,33 +969,55 @@ def _get_dir_names(files):
962
969
dirs [f .dirname ] = None
963
970
return dirs .keys ()
964
971
965
- def add_crate_link_flags (args , dep_info ):
972
+ def add_crate_link_flags (args , dep_info , force_all_deps_direct = False ):
966
973
"""Adds link flags to an Args object reference
967
974
968
975
Args:
969
976
args (Args): An arguments object reference
970
977
dep_info (DepInfo): The current target's dependency info
978
+ force_all_deps_direct (bool, optional): Whether to pass the transitive rlibs with --extern
979
+ to the commandline as opposed to -L.
971
980
"""
972
981
973
- # nb. Crates are linked via --extern regardless of their crate_type
974
- args .add_all (dep_info .direct_crates , map_each = _crate_to_link_flag )
982
+ if force_all_deps_direct :
983
+ args .add_all (
984
+ depset (
985
+ transitive = [
986
+ dep_info .direct_crates ,
987
+ dep_info .transitive_crates ,
988
+ ],
989
+ ),
990
+ uniquify = True ,
991
+ map_each = _crate_to_link_flag ,
992
+ )
993
+ else :
994
+ # nb. Direct crates are linked via --extern regardless of their crate_type
995
+ args .add_all (dep_info .direct_crates , map_each = _crate_to_link_flag )
975
996
args .add_all (
976
997
dep_info .transitive_crates ,
977
998
map_each = _get_crate_dirname ,
978
999
uniquify = True ,
979
1000
format_each = "-Ldependency=%s" ,
980
1001
)
981
1002
982
- def _crate_to_link_flag (crate_info ):
1003
+ def _crate_to_link_flag (crate ):
983
1004
"""A helper macro used by `add_crate_link_flags` for adding crate link flags to a Arg object
984
1005
985
1006
Args:
986
- crate_info (CrateInfo): A CrateInfo provider from the current rule
1007
+ crate (CrateInfo|AliasableDepInfo ): A CrateInfo or an AliasableDepInfo provider
987
1008
988
1009
Returns:
989
- list: Link flags for the current crate info
1010
+ list: Link flags for the given provider
990
1011
"""
991
- return ["--extern={}={}" .format (crate_info .name , crate_info .dep .output .path )]
1012
+
1013
+ # This is AliasableDepInfo, we should use the alias as a crate name
1014
+ if hasattr (crate , "dep" ):
1015
+ name = crate .name
1016
+ crate_info = crate .dep
1017
+ else :
1018
+ name = crate .name
1019
+ crate_info = crate
1020
+ return ["--extern={}={}" .format (name , crate_info .output .path )]
992
1021
993
1022
def _get_crate_dirname (crate ):
994
1023
"""A helper macro used by `add_crate_link_flags` for getting the directory name of the current crate's output path
0 commit comments