@@ -836,7 +836,10 @@ def collect_inputs(
836836
837837def _will_emit_object_file (emit ):
838838 for e in emit :
839- if e == "obj" or e .startswith ("obj=" ):
839+ if type (e ) in ["tuple" , "list" ] and len (e ) == 2 :
840+ if e [0 ] == "obj" :
841+ return True
842+ elif type (e ) == "string" and (e == "obj" or e .startswith ("obj=" )):
840843 return True
841844 return False
842845
@@ -1175,6 +1178,10 @@ def construct_arguments(
11751178 for kind in emit :
11761179 if kind == "link" and crate_info .type == "bin" and crate_info .output != None :
11771180 rustc_flags .add (crate_info .output , format = "--emit=link=%s" )
1181+ elif type (kind ) in ["tuple" , "list" ] and len (kind ) == 2 :
1182+ # 'kind' is a (string, File) tuple/list. Passing the File object directly to
1183+ # Args.add allows Bazel to perform path mapping on the path.
1184+ rustc_flags .add (kind [1 ], format = "--emit=" + kind [0 ] + "=%s" )
11781185 else :
11791186 emit_without_paths .append (kind )
11801187
@@ -1565,6 +1572,23 @@ def rustc_compile_action(
15651572 if experimental_use_cc_common_link :
15661573 emit = ["obj" ]
15671574
1575+ # Declares the outputs of the rustc compile action.
1576+ # By default this is the binary output; if cc_common.link is used, this is
1577+ # the main `.o` file (`output_o` below).
1578+ outputs = [crate_info .output ]
1579+
1580+ # The `.o` output file, only used for linking via cc_common.link.
1581+ # When output_hash is set (e.g. for rust_test targets), include it in the
1582+ # filename to avoid collisions with other targets sharing the same crate name.
1583+ output_o = None
1584+ if "obj" in emit :
1585+ obj_ext = ".o"
1586+ obj_basename = crate_info .name + ("-%s" % output_hash if output_hash else "" )
1587+ output_o = ctx .actions .declare_file (obj_basename + obj_ext , sibling = crate_info .output )
1588+ outputs = [output_o ]
1589+ emit .remove ("obj" )
1590+ emit .append (("obj" , output_o ))
1591+
15681592 # Determine whether to pass `--require-explicit-unstable-features true` to the process wrapper:
15691593 require_explicit_unstable_features = False
15701594 if hasattr (ctx .attr , "require_explicit_unstable_features" ):
@@ -1639,21 +1663,6 @@ def rustc_compile_action(
16391663 else :
16401664 formatted_version = ""
16411665
1642- # Declares the outputs of the rustc compile action.
1643- # By default this is the binary output; if cc_common.link is used, this is
1644- # the main `.o` file (`output_o` below).
1645- outputs = [crate_info .output ]
1646-
1647- # The `.o` output file, only used for linking via cc_common.link.
1648- # When output_hash is set (e.g. for rust_test targets), include it in the
1649- # filename to avoid collisions with other targets sharing the same crate name.
1650- output_o = None
1651- if experimental_use_cc_common_link :
1652- obj_ext = ".o"
1653- obj_basename = crate_info .name + ("-%s" % output_hash if output_hash else "" )
1654- output_o = ctx .actions .declare_file (obj_basename + obj_ext , sibling = crate_info .output )
1655- outputs = [output_o ]
1656-
16571666 # For a cdylib that might be added as a dependency to a cc_* target on Windows, it is important to include the
16581667 # interface library that rustc generates in the output files.
16591668 interface_library = None
0 commit comments