@@ -515,27 +515,6 @@ def get_linker_and_args(ctx, crate_type, cc_toolchain, feature_configuration, rp
515515
516516 return ld , link_args , link_env
517517
518- def _process_build_scripts (
519- build_info ,
520- dep_info ,
521- include_link_flags = True ):
522- """Gathers the outputs from a target's `cargo_build_script` action.
523-
524- Args:
525- build_info (BuildInfo): The target Build's dependency info.
526- dep_info (DepInfo): The Depinfo provider form the target Crate's set of inputs.
527- include_link_flags (bool, optional): Whether to include flags like `-l` that instruct the linker to search for a library.
528-
529- Returns:
530- tuple: A tuple: A tuple of the following items:
531- - (depset[File]): A list of all build info `OUT_DIR` File objects
532- - (str): The `OUT_DIR` of the current build info
533- - (File): An optional path to a generated environment file from a `cargo_build_script` target
534- - (depset[File]): All direct and transitive build flags from the current build info.
535- """
536- extra_inputs , out_dir , build_env_file , build_flags_files = _create_extra_input_args (build_info , dep_info , include_link_flags = include_link_flags )
537- return extra_inputs , out_dir , build_env_file , build_flags_files
538-
539518def _symlink_for_ambiguous_lib (actions , toolchain , crate_info , lib ):
540519 """Constructs a disambiguating symlink for a library dependency.
541520
@@ -727,7 +706,7 @@ def collect_inputs(
727706 - (list[File]): Linkstamp outputs
728707 - (dict[String, File]): Ambiguous libs, see `_disambiguate_libs`.
729708 """
730- linker_script = getattr (file , "linker_script" ) if hasattr ( file , "linker_script" ) else None
709+ linker_script = getattr (file , "linker_script" , None )
731710
732711 # TODO: As of writing this comment Bazel used Java CcToolchainInfo.
733712 # However there is ongoing work to rewrite provider in Starlark.
@@ -765,29 +744,31 @@ def collect_inputs(
765744 if _depend_on_metadata (crate_info , force_depend_on_objects ):
766745 transitive_crate_outputs = dep_info .transitive_metadata_outputs
767746
768- build_info_inputs = []
747+ nolinkstamp_compile_direct_inputs = []
769748 if build_info :
770749 if build_info .rustc_env :
771- build_info_inputs .append (build_info .rustc_env )
750+ nolinkstamp_compile_direct_inputs .append (build_info .rustc_env )
772751 if build_info .flags :
773- build_info_inputs .append (build_info .flags )
752+ nolinkstamp_compile_direct_inputs .append (build_info .flags )
774753
775754 # The old default behavior was to include data files at compile time.
776755 # This flag controls whether to include data files in compile_data.
777- data_included_in_inputs = []
778756 if not toolchain ._incompatible_do_not_include_data_in_compile_data :
779- data_included_in_inputs = getattr (files , "data" , [])
757+ nolinkstamp_compile_direct_inputs += files .data
758+
759+ if toolchain .target_json :
760+ nolinkstamp_compile_direct_inputs .append (toolchain .target_json )
761+
762+ if linker_script :
763+ nolinkstamp_compile_direct_inputs .append (linker_script )
780764
781765 nolinkstamp_compile_inputs = depset (
782- data_included_in_inputs +
783- build_info_inputs +
784- ([toolchain .target_json ] if toolchain .target_json else []) +
785- ([] if linker_script == None else [linker_script ]),
766+ nolinkstamp_compile_direct_inputs +
767+ additional_transitive_inputs ,
786768 transitive = [
787769 linker_depset ,
788770 crate_info .srcs ,
789771 transitive_crate_outputs ,
790- depset (additional_transitive_inputs ),
791772 crate_info .compile_data ,
792773 dep_info .transitive_proc_macro_data ,
793774 toolchain .all_files ,
@@ -847,12 +828,16 @@ def collect_inputs(
847828 # `crate_info.rustc_env_files` is not populated.
848829 build_env_files = crate_info .rustc_env_files if crate_info .rustc_env_files else getattr (files , "rustc_env_files" , [])
849830 if build_env_file :
850- build_env_files = [f for f in build_env_files ] + [build_env_file ]
831+ build_env_files = list (build_env_files )
832+ build_env_files .append (build_env_file )
851833 compile_inputs = depset (build_env_files + lint_files , transitive = [build_script_compile_inputs , compile_inputs ])
852834 return compile_inputs , out_dir , build_env_files , build_flags_files , linkstamp_outs , ambiguous_libs
853835
854836def _will_emit_object_file (emit ):
855- return any ([e == "obj" or e .startswith ("obj=" ) for e in emit ])
837+ for e in emit :
838+ if e == "obj" or e .startswith ("obj=" ):
839+ return True
840+ return False
856841
857842def _remove_codegen_units (flag ):
858843 return None if flag .startswith ("-Ccodegen-units" ) else flag
@@ -1920,23 +1905,26 @@ def add_edition_flags(args, crate):
19201905 if crate .edition != "2015" :
19211906 args .add (crate .edition , format = "--edition=%s" )
19221907
1923- def _create_extra_input_args (build_info , dep_info , include_link_flags = True ):
1924- """Gather additional input arguments from transitive dependencies
1908+ def _process_build_scripts (
1909+ build_info ,
1910+ dep_info ,
1911+ include_link_flags = True ):
1912+ """Gathers the outputs from a target's `cargo_build_script` action.
19251913
19261914 Args:
1927- build_info (BuildInfo): The BuildInfo provider from the target Crate 's set of inputs .
1915+ build_info (BuildInfo): The target Build 's dependency info .
19281916 dep_info (DepInfo): The Depinfo provider form the target Crate's set of inputs.
19291917 include_link_flags (bool, optional): Whether to include flags like `-l` that instruct the linker to search for a library.
19301918
19311919 Returns:
1932- tuple: A tuple of the following items:
1920+ tuple: A tuple: A tuple of the following items:
19331921 - (depset[File]): A list of all build info `OUT_DIR` File objects
19341922 - (str): The `OUT_DIR` of the current build info
1935- - (File): An optional generated environment file from a `cargo_build_script` target
1936- - (depset[File]): All direct and transitive build flag files from the current build info to be passed to rustc .
1923+ - (File): An optional path to a generated environment file from a `cargo_build_script` target
1924+ - (depset[File]): All direct and transitive build flags from the current build info.
19371925 """
1938- input_files = []
1939- input_depsets = []
1926+ direct_inputs = []
1927+ transitive_inputs = [dep_info . link_search_path_files , dep_info . transitive_data ]
19401928
19411929 # Arguments to the commandline line wrapper that are going to be used
19421930 # to create the final command line
@@ -1948,25 +1936,25 @@ def _create_extra_input_args(build_info, dep_info, include_link_flags = True):
19481936 if build_info :
19491937 if build_info .out_dir :
19501938 out_dir = build_info .out_dir .path
1951- input_files .append (build_info .out_dir )
1939+ direct_inputs .append (build_info .out_dir )
19521940 build_env_file = build_info .rustc_env
19531941 if build_info .flags :
19541942 build_flags_files .append (build_info .flags )
19551943 if build_info .linker_flags and include_link_flags :
19561944 build_flags_files .append (build_info .linker_flags )
1957- input_files .append (build_info .linker_flags )
1945+ direct_inputs .append (build_info .linker_flags )
19581946
1959- input_depsets .append (build_info .compile_data )
1947+ transitive_inputs .append (build_info .compile_data )
19601948
19611949 # We include transitive dep build_infos because cargo build scripts may generate files which get linked into the final binary.
19621950 # This should probably only actually be exposed to actions which link.
19631951 for dep_build_info in dep_info .transitive_build_infos .to_list ():
19641952 if dep_build_info .out_dir :
1965- input_files .append (dep_build_info .out_dir )
1953+ direct_inputs .append (dep_build_info .out_dir )
19661954
19671955 out_dir_compile_inputs = depset (
1968- input_files ,
1969- transitive = [ dep_info . link_search_path_files , dep_info . transitive_data ] + input_depsets ,
1956+ direct_inputs ,
1957+ transitive = transitive_inputs ,
19701958 )
19711959
19721960 return (
0 commit comments