@@ -834,7 +834,10 @@ def collect_inputs(
834834
835835def _will_emit_object_file (emit ):
836836 for e in emit :
837- if e == "obj" or e .startswith ("obj=" ):
837+ if type (e ) in ["tuple" , "list" ] and len (e ) == 2 :
838+ if e [0 ] == "obj" :
839+ return True
840+ elif type (e ) == "string" and (e == "obj" or e .startswith ("obj=" )):
838841 return True
839842 return False
840843
@@ -1173,6 +1176,10 @@ def construct_arguments(
11731176 for kind in emit :
11741177 if kind == "link" and crate_info .type == "bin" and crate_info .output != None :
11751178 rustc_flags .add (crate_info .output , format = "--emit=link=%s" )
1179+ elif type (kind ) in ["tuple" , "list" ] and len (kind ) == 2 :
1180+ # 'kind' is a (string, File) tuple/list. Passing the File object directly to
1181+ # Args.add allows Bazel to perform path mapping on the path.
1182+ rustc_flags .add (kind [1 ], format = "--emit=" + kind [0 ] + "=%s" )
11761183 else :
11771184 emit_without_paths .append (kind )
11781185
@@ -1563,6 +1570,23 @@ def rustc_compile_action(
15631570 if experimental_use_cc_common_link :
15641571 emit = ["obj" ]
15651572
1573+ # Declares the outputs of the rustc compile action.
1574+ # By default this is the binary output; if cc_common.link is used, this is
1575+ # the main `.o` file (`output_o` below).
1576+ outputs = [crate_info .output ]
1577+
1578+ # The `.o` output file, only used for linking via cc_common.link.
1579+ # When output_hash is set (e.g. for rust_test targets), include it in the
1580+ # filename to avoid collisions with other targets sharing the same crate name.
1581+ output_o = None
1582+ if "obj" in emit :
1583+ obj_ext = ".o"
1584+ obj_basename = crate_info .name + ("-%s" % output_hash if output_hash else "" )
1585+ output_o = ctx .actions .declare_file (obj_basename + obj_ext , sibling = crate_info .output )
1586+ outputs = [output_o ]
1587+ emit .remove ("obj" )
1588+ emit .append (("obj" , output_o ))
1589+
15661590 # Determine whether to pass `--require-explicit-unstable-features true` to the process wrapper:
15671591 require_explicit_unstable_features = False
15681592 if hasattr (ctx .attr , "require_explicit_unstable_features" ):
@@ -1637,21 +1661,6 @@ def rustc_compile_action(
16371661 else :
16381662 formatted_version = ""
16391663
1640- # Declares the outputs of the rustc compile action.
1641- # By default this is the binary output; if cc_common.link is used, this is
1642- # the main `.o` file (`output_o` below).
1643- outputs = [crate_info .output ]
1644-
1645- # The `.o` output file, only used for linking via cc_common.link.
1646- # When output_hash is set (e.g. for rust_test targets), include it in the
1647- # filename to avoid collisions with other targets sharing the same crate name.
1648- output_o = None
1649- if experimental_use_cc_common_link :
1650- obj_ext = ".o"
1651- obj_basename = crate_info .name + ("-%s" % output_hash if output_hash else "" )
1652- output_o = ctx .actions .declare_file (obj_basename + obj_ext , sibling = crate_info .output )
1653- outputs = [output_o ]
1654-
16551664 # For a cdylib that might be added as a dependency to a cc_* target on Windows, it is important to include the
16561665 # interface library that rustc generates in the output files.
16571666 interface_library = None
0 commit comments