xref: /aosp_15_r20/external/bazelbuild-rules_rust/tools/upstream_wrapper/BUILD.bazel (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1*d4726bddSHONG Yifanload("//rust:defs.bzl", "rust_binary")
2*d4726bddSHONG Yifan
3*d4726bddSHONG Yifantools = {
4*d4726bddSHONG Yifan    "cargo": "//rust/toolchain:current_cargo_files",
5*d4726bddSHONG Yifan    "cargo_clippy": "//rust/toolchain:current_cargo_clippy_files",
6*d4726bddSHONG Yifan    "rustc": "//rust/toolchain:current_rustc_files",
7*d4726bddSHONG Yifan    "rustfmt": "//rust/toolchain:current_rustfmt_toolchain_for_target",
8*d4726bddSHONG Yifan}
9*d4726bddSHONG Yifan
10*d4726bddSHONG Yifanall_tools = [target for target in tools.values()]
11*d4726bddSHONG Yifan
12*d4726bddSHONG Yifan[
13*d4726bddSHONG Yifan    rust_binary(
14*d4726bddSHONG Yifan        name = tool_name,
15*d4726bddSHONG Yifan        srcs = [
16*d4726bddSHONG Yifan            "src/main.rs",
17*d4726bddSHONG Yifan        ],
18*d4726bddSHONG Yifan        # Cargo calls out to the other tools.
19*d4726bddSHONG Yifan        # Make sure that they are included in the runfiles.
20*d4726bddSHONG Yifan        data = all_tools if tool_name == "cargo" else [target],
21*d4726bddSHONG Yifan        edition = "2018",
22*d4726bddSHONG Yifan        rustc_env = {
23*d4726bddSHONG Yifan            "WRAPPED_TOOL_NAME": tool_name,
24*d4726bddSHONG Yifan            "WRAPPED_TOOL_TARGET": "$(rlocationpath {})".format(target),
25*d4726bddSHONG Yifan        },
26*d4726bddSHONG Yifan        toolchains = ["@rules_rust//rust/toolchain:current_rust_toolchain"],
27*d4726bddSHONG Yifan        visibility = ["//visibility:public"],
28*d4726bddSHONG Yifan        deps = [
29*d4726bddSHONG Yifan            "//tools/runfiles",
30*d4726bddSHONG Yifan        ],
31*d4726bddSHONG Yifan    )
32*d4726bddSHONG Yifan    for (tool_name, target) in tools.items()
33*d4726bddSHONG Yifan]
34