@@ -899,8 +899,8 @@ def construct_arguments(
899899 rustc_flags .set_param_file_format ("multiline" )
900900 rustc_flags .use_param_file ("@%s" , use_always = False )
901901 rustc_flags .add (crate_info .root )
902- rustc_flags .add ("--crate-name=" + crate_info . name )
903- rustc_flags .add ("--crate-type=" + crate_info . type )
902+ rustc_flags .add (crate_info . name , format = "--crate-name=%s" )
903+ rustc_flags .add (crate_info . type , format = "--crate-type=%s" )
904904
905905 error_format = "human"
906906 if hasattr (attr , "_error_format" ):
@@ -921,15 +921,15 @@ def construct_arguments(
921921 # If the os is not windows, we can get colorized output.
922922 json .append ("diagnostic-rendered-ansi" )
923923
924- rustc_flags .add ( "--json=" + "," . join ( json ) )
924+ rustc_flags .add_joined ( json , format_joined = "--json=%s" , join_with = "," )
925925
926926 error_format = "json"
927927
928928 if build_metadata :
929929 # Configure process_wrapper to terminate rustc when metadata are emitted
930930 process_wrapper_flags .add ("--rustc-quit-on-rmeta" , "true" )
931931
932- rustc_flags .add ("--error-format=" + error_format )
932+ rustc_flags .add (error_format , format = "--error-format=%s" )
933933
934934 # Mangle symbols to disambiguate crates with the same name. This could
935935 # happen only for non-final artifacts where we compute an output_hash,
@@ -939,37 +939,33 @@ def construct_arguments(
939939 # Bazel, such as rust_binary, rust_static_library and rust_shared_library,
940940 # where output_hash is None we don't need to add these flags.
941941 if output_hash :
942- extra_filename = "-" + output_hash
943- rustc_flags .add ("--codegen=metadata=" + extra_filename )
944- rustc_flags .add ("--codegen=extra-filename=" + extra_filename )
942+ rustc_flags .add (output_hash , format = "--codegen=metadata=-%s" )
943+ rustc_flags .add (output_hash , format = "--codegen=extra-filename=-%s" )
945944
946945 if output_dir :
947- rustc_flags .add ("--out-dir=" + output_dir )
946+ rustc_flags .add (output_dir , format = "--out-dir=%s" )
948947
949948 compilation_mode = get_compilation_mode_opts (ctx , toolchain )
950- rustc_flags .add ("--codegen=opt-level=" + compilation_mode . opt_level )
951- rustc_flags .add ("--codegen=debuginfo=" + compilation_mode . debug_info )
949+ rustc_flags .add (compilation_mode . opt_level , format = "--codegen=opt-level=%s" )
950+ rustc_flags .add (compilation_mode . debug_info , format = "--codegen=debuginfo=%s" )
952951
953952 # For determinism to help with build distribution and such
954953 if remap_path_prefix != None :
955954 rustc_flags .add ("--remap-path-prefix=${{pwd}}={}" .format (remap_path_prefix ))
956955
957956 if emit :
958- rustc_flags .add ( "--emit=" + "," . join ( emit_with_paths ) )
957+ rustc_flags .add_joined ( emit_with_paths , format_joined = "--emit=%s" , join_with = "," )
959958 if error_format != "json" :
960959 # Color is not compatible with json output.
961960 rustc_flags .add ("--color=always" )
962- rustc_flags .add ("--target=" + toolchain . target_flag_value )
961+ rustc_flags .add (toolchain . target_flag_value , format = "--target=%s" )
963962 if hasattr (attr , "crate_features" ):
964963 rustc_flags .add_all (getattr (attr , "crate_features" ), before_each = "--cfg" , format_each = 'feature="%s"' )
965964 if linker_script :
966- rustc_flags .add (linker_script . path , format = "--codegen=link-arg=-T%s" )
965+ rustc_flags .add (linker_script , format = "--codegen=link-arg=-T%s" )
967966
968- # Gets the paths to the folders containing the standard library (or libcore)
969- rust_std_paths = toolchain .rust_std_paths .to_list ()
970-
971- # Tell Rustc where to find the standard library
972- rustc_flags .add_all (rust_std_paths , before_each = "-L" , format_each = "%s" )
967+ # Tell Rustc where to find the standard library (or libcore)
968+ rustc_flags .add_all (toolchain .rust_std_paths , before_each = "-L" , format_each = "%s" )
973969 rustc_flags .add_all (rust_flags )
974970
975971 # Gather data path from crate_info since it is inherited from real crate for rust_doc and rust_test
@@ -995,12 +991,12 @@ def construct_arguments(
995991 use_pic = _should_use_pic (cc_toolchain , feature_configuration , crate_info .type , compilation_mode )
996992 rpaths = _compute_rpaths (toolchain , output_dir , dep_info , use_pic )
997993 else :
998- rpaths = depset ([] )
994+ rpaths = depset ()
999995
1000996 ld , link_args , link_env = get_linker_and_args (ctx , attr , crate_info .type , cc_toolchain , feature_configuration , rpaths , rustdoc )
1001997
1002998 env .update (link_env )
1003- rustc_flags .add ("--codegen=linker=" + ld )
999+ rustc_flags .add (ld , format = "--codegen=linker=%s" )
10041000 rustc_flags .add_joined ("--codegen" , link_args , join_with = " " , format_joined = "link-args=%s" )
10051001
10061002 _add_native_link_flags (rustc_flags , dep_info , linkstamp_outs , ambiguous_libs , crate_info .type , toolchain , cc_toolchain , feature_configuration , compilation_mode )
@@ -1067,7 +1063,7 @@ def construct_arguments(
10671063 rustc_flags .add_all (ctx .attr ._extra_exec_rustc_flag [ExtraExecRustcFlagsInfo ].extra_exec_rustc_flags )
10681064
10691065 if _is_no_std (ctx , toolchain , crate_info ):
1070- rustc_flags .add_all ([ '--cfg=feature="no_std"' ] )
1066+ rustc_flags .add ( '--cfg=feature="no_std"' )
10711067
10721068 # Create a struct which keeps the arguments separate so each may be tuned or
10731069 # replaced where necessary
@@ -1590,7 +1586,7 @@ def add_edition_flags(args, crate):
15901586 crate (CrateInfo): A CrateInfo provider
15911587 """
15921588 if crate .edition != "2015" :
1593- args .add ("--edition={}" . format ( crate . edition ) )
1589+ args .add (crate . edition , format = "--edition=%s" )
15941590
15951591def _create_extra_input_args (build_info , dep_info ):
15961592 """Gather additional input arguments from transitive dependencies
@@ -1928,12 +1924,11 @@ def _add_native_link_flags(args, dep_info, linkstamp_outs, ambiguous_libs, crate
19281924 # If there are ambiguous libs, the disambiguation symlinks to them are
19291925 # all created in the same directory. Add it to the library search path.
19301926 ambiguous_libs_dirname = ambiguous_libs .values ()[0 ].dirname
1931- args .add ("-Lnative={}" . format ( ambiguous_libs_dirname ) )
1927+ args .add (ambiguous_libs_dirname , format = "-Lnative=%s" )
19321928
19331929 args .add_all (args_and_pic_and_ambiguous_libs , map_each = make_link_flags )
19341930
1935- for linkstamp_out in linkstamp_outs :
1936- args .add_all (["-C" , "link-arg=%s" % linkstamp_out .path ])
1931+ args .add_all (linkstamp_outs , before_each = "-C" , format_each = "link-args=%s" )
19371932
19381933 if crate_type in ["dylib" , "cdylib" ]:
19391934 # For shared libraries we want to link C++ runtime library dynamically
0 commit comments