@@ -515,27 +515,6 @@ def get_linker_and_args(ctx, crate_type, cc_toolchain, feature_configuration, rp
515
515
516
516
return ld , link_args , link_env
517
517
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
-
539
518
def _symlink_for_ambiguous_lib (actions , toolchain , crate_info , lib ):
540
519
"""Constructs a disambiguating symlink for a library dependency.
541
520
@@ -727,7 +706,7 @@ def collect_inputs(
727
706
- (list[File]): Linkstamp outputs
728
707
- (dict[String, File]): Ambiguous libs, see `_disambiguate_libs`.
729
708
"""
730
- linker_script = getattr (file , "linker_script" ) if hasattr ( file , "linker_script" ) else None
709
+ linker_script = getattr (file , "linker_script" , None )
731
710
732
711
# TODO: As of writing this comment Bazel used Java CcToolchainInfo.
733
712
# However there is ongoing work to rewrite provider in Starlark.
@@ -765,29 +744,31 @@ def collect_inputs(
765
744
if _depend_on_metadata (crate_info , force_depend_on_objects ):
766
745
transitive_crate_outputs = dep_info .transitive_metadata_outputs
767
746
768
- build_info_inputs = []
747
+ nolinkstamp_compile_direct_inputs = []
769
748
if build_info :
770
749
if build_info .rustc_env :
771
- build_info_inputs .append (build_info .rustc_env )
750
+ nolinkstamp_compile_direct_inputs .append (build_info .rustc_env )
772
751
if build_info .flags :
773
- build_info_inputs .append (build_info .flags )
752
+ nolinkstamp_compile_direct_inputs .append (build_info .flags )
774
753
775
754
# The old default behavior was to include data files at compile time.
776
755
# This flag controls whether to include data files in compile_data.
777
- data_included_in_inputs = []
778
756
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 )
780
764
781
765
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 ,
786
768
transitive = [
787
769
linker_depset ,
788
770
crate_info .srcs ,
789
771
transitive_crate_outputs ,
790
- depset (additional_transitive_inputs ),
791
772
crate_info .compile_data ,
792
773
dep_info .transitive_proc_macro_data ,
793
774
toolchain .all_files ,
@@ -847,12 +828,16 @@ def collect_inputs(
847
828
# `crate_info.rustc_env_files` is not populated.
848
829
build_env_files = crate_info .rustc_env_files if crate_info .rustc_env_files else getattr (files , "rustc_env_files" , [])
849
830
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 )
851
833
compile_inputs = depset (build_env_files + lint_files , transitive = [build_script_compile_inputs , compile_inputs ])
852
834
return compile_inputs , out_dir , build_env_files , build_flags_files , linkstamp_outs , ambiguous_libs
853
835
854
836
def _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
856
841
857
842
def _remove_codegen_units (flag ):
858
843
return None if flag .startswith ("-Ccodegen-units" ) else flag
@@ -1920,23 +1905,26 @@ def add_edition_flags(args, crate):
1920
1905
if crate .edition != "2015" :
1921
1906
args .add (crate .edition , format = "--edition=%s" )
1922
1907
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.
1925
1913
1926
1914
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 .
1928
1916
dep_info (DepInfo): The Depinfo provider form the target Crate's set of inputs.
1929
1917
include_link_flags (bool, optional): Whether to include flags like `-l` that instruct the linker to search for a library.
1930
1918
1931
1919
Returns:
1932
- tuple: A tuple of the following items:
1920
+ tuple: A tuple: A tuple of the following items:
1933
1921
- (depset[File]): A list of all build info `OUT_DIR` File objects
1934
1922
- (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.
1937
1925
"""
1938
- input_files = []
1939
- input_depsets = []
1926
+ direct_inputs = []
1927
+ transitive_inputs = [dep_info . link_search_path_files , dep_info . transitive_data ]
1940
1928
1941
1929
# Arguments to the commandline line wrapper that are going to be used
1942
1930
# to create the final command line
@@ -1948,25 +1936,25 @@ def _create_extra_input_args(build_info, dep_info, include_link_flags = True):
1948
1936
if build_info :
1949
1937
if build_info .out_dir :
1950
1938
out_dir = build_info .out_dir .path
1951
- input_files .append (build_info .out_dir )
1939
+ direct_inputs .append (build_info .out_dir )
1952
1940
build_env_file = build_info .rustc_env
1953
1941
if build_info .flags :
1954
1942
build_flags_files .append (build_info .flags )
1955
1943
if build_info .linker_flags and include_link_flags :
1956
1944
build_flags_files .append (build_info .linker_flags )
1957
- input_files .append (build_info .linker_flags )
1945
+ direct_inputs .append (build_info .linker_flags )
1958
1946
1959
- input_depsets .append (build_info .compile_data )
1947
+ transitive_inputs .append (build_info .compile_data )
1960
1948
1961
1949
# We include transitive dep build_infos because cargo build scripts may generate files which get linked into the final binary.
1962
1950
# This should probably only actually be exposed to actions which link.
1963
1951
for dep_build_info in dep_info .transitive_build_infos .to_list ():
1964
1952
if dep_build_info .out_dir :
1965
- input_files .append (dep_build_info .out_dir )
1953
+ direct_inputs .append (dep_build_info .out_dir )
1966
1954
1967
1955
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 ,
1970
1958
)
1971
1959
1972
1960
return (
0 commit comments