@@ -90,12 +90,24 @@ filegroup(
9090)
9191"""
9292
93- def BUILD_for_compiler (target_triple , include_linker = False ):
93+ _build_file_for_objcopy_template = """\
94+ filegroup(
95+ name = "rust-objcopy",
96+ srcs = glob(
97+ ["lib/rustlib/{target_triple}/bin/rust-objcopy{binary_ext}"],
98+ allow_empty = True,
99+ ),
100+ visibility = ["//visibility:public"],
101+ )
102+ """
103+
104+ def BUILD_for_compiler (target_triple , include_linker = False , include_objcopy = False ):
94105 """Emits a BUILD file the compiler archive.
95106
96107 Args:
97108 target_triple (str): The triple of the target platform
98109 include_linker (bool): Whether to generate targets for linkers.
110+ include_objcopy (bool): Whether to generate targets for rust-objcopy.
99111
100112 Returns:
101113 str: The contents of a BUILD file
@@ -117,6 +129,14 @@ def BUILD_for_compiler(target_triple, include_linker = False):
117129 ),
118130 )
119131
132+ if include_objcopy :
133+ content .append (
134+ _build_file_for_objcopy_template .format (
135+ binary_ext = system_to_binary_ext (target_triple .system ),
136+ target_triple = target_triple .str ,
137+ ),
138+ )
139+
120140 return "\n " .join (content )
121141
122142_build_file_for_cargo_template = """\
@@ -324,6 +344,7 @@ rust_toolchain(
324344 rustc = "//:rustc",
325345 linker = {linker_label},
326346 linker_type = {linker_type},
347+ rust_objcopy = {rust_objcopy_label},
327348 rustfmt = {rustfmt_label},
328349 cargo = "//:cargo",
329350 clippy_driver = "//:clippy_driver_bin",
@@ -361,6 +382,7 @@ def BUILD_for_rust_toolchain(
361382 include_rustfmt ,
362383 include_llvm_tools ,
363384 include_linker ,
385+ include_objcopy = False ,
364386 stdlib_linkflags = None ,
365387 extra_rustc_flags = None ,
366388 extra_exec_rustc_flags = None ,
@@ -381,6 +403,7 @@ def BUILD_for_rust_toolchain(
381403 include_rustfmt (bool): Whether rustfmt is present in the toolchain.
382404 include_llvm_tools (bool): Whether llvm-tools are present in the toolchain.
383405 include_linker (bool): Whether a linker is available in the toolchain.
406+ include_objcopy (bool): Whether rust-objcopy is available in the toolchain.
384407 stdlib_linkflags (list, optional): Overridden flags needed for linking to rust
385408 stdlib, akin to BAZEL_LINKLIBS. Defaults to
386409 None.
@@ -418,6 +441,10 @@ def BUILD_for_rust_toolchain(
418441 linker_label = "//:rust-lld"
419442 linker_type = "direct"
420443
444+ rust_objcopy_label = None
445+ if include_objcopy :
446+ rust_objcopy_label = "//:rust-objcopy"
447+
421448 return _build_file_for_rust_toolchain_template .format (
422449 toolchain_name = name ,
423450 binary_ext = system_to_binary_ext (target_triple .system ),
@@ -435,6 +462,7 @@ def BUILD_for_rust_toolchain(
435462 llvm_lib_label = repr (llvm_lib_label ),
436463 linker_label = repr (linker_label ),
437464 linker_type = repr (linker_type ),
465+ rust_objcopy_label = repr (rust_objcopy_label ),
438466 extra_rustc_flags = extra_rustc_flags ,
439467 extra_exec_rustc_flags = extra_exec_rustc_flags ,
440468 opt_level = opt_level ,
@@ -519,7 +547,7 @@ def load_rustfmt(ctx, target_triple, version, iso_date):
519547
520548 return BUILD_for_rustfmt (target_triple ), sha256
521549
522- def load_rust_compiler (ctx , iso_date , target_triple , version , include_linker = False ):
550+ def load_rust_compiler (ctx , iso_date , target_triple , version , include_linker = False , include_objcopy = False ):
523551 """Loads a rust compiler and yields corresponding BUILD for it
524552
525553 Args:
@@ -528,6 +556,7 @@ def load_rust_compiler(ctx, iso_date, target_triple, version, include_linker = F
528556 target_triple (struct): The Rust-style target that this compiler runs on.
529557 version (str): The version of the tool among \" nightly\" , \" beta\" , or an exact version.
530558 include_linker (bool): Whether to include linker targets in the output BUILD contents.
559+ include_objcopy (bool): Whether to include rust-objcopy targets in the output BUILD contents.
531560
532561 Returns:
533562 Tuple[str, Dict[str, str]]: The BUILD file contents for this compiler and compiler library
@@ -543,7 +572,7 @@ def load_rust_compiler(ctx, iso_date, target_triple, version, include_linker = F
543572 version = version ,
544573 )
545574
546- return BUILD_for_compiler (target_triple , include_linker ), sha256
575+ return BUILD_for_compiler (target_triple , include_linker , include_objcopy ), sha256
547576
548577def load_clippy (ctx , iso_date , target_triple , version ):
549578 """Loads Clippy and yields corresponding BUILD for it
0 commit comments