xref: /aosp_15_r20/external/bazelbuild-rules_rust/util/process_wrapper/BUILD.bazel (revision d4726bddaa87cc4778e7472feed243fa4b6c267f)
1*d4726bddSHONG Yifanload("@bazel_skylib//lib:selects.bzl", "selects")
2*d4726bddSHONG Yifanload("//rust:defs.bzl", "rust_test")
3*d4726bddSHONG Yifan
4*d4726bddSHONG Yifan# buildifier: disable=bzl-visibility
5*d4726bddSHONG Yifanload("//rust/private:rust.bzl", "rust_binary_without_process_wrapper")
6*d4726bddSHONG Yifanload("//util/process_wrapper/private:bootstrap_process_wrapper.bzl", "bootstrap_process_wrapper")
7*d4726bddSHONG Yifan
8*d4726bddSHONG Yifanconfig_setting(
9*d4726bddSHONG Yifan    name = "compilation_mode_opt",
10*d4726bddSHONG Yifan    values = {"compilation_mode": "opt"},
11*d4726bddSHONG Yifan)
12*d4726bddSHONG Yifan
13*d4726bddSHONG Yifanselects.config_setting_group(
14*d4726bddSHONG Yifan    name = "opt_linux",
15*d4726bddSHONG Yifan    match_all = [
16*d4726bddSHONG Yifan        ":compilation_mode_opt",
17*d4726bddSHONG Yifan        "@platforms//os:linux",
18*d4726bddSHONG Yifan    ],
19*d4726bddSHONG Yifan    visibility = ["@rules_rust_tinyjson//:__pkg__"],
20*d4726bddSHONG Yifan)
21*d4726bddSHONG Yifan
22*d4726bddSHONG Yifanselects.config_setting_group(
23*d4726bddSHONG Yifan    name = "opt_macos",
24*d4726bddSHONG Yifan    match_all = [
25*d4726bddSHONG Yifan        ":compilation_mode_opt",
26*d4726bddSHONG Yifan        "@platforms//os:macos",
27*d4726bddSHONG Yifan    ],
28*d4726bddSHONG Yifan    visibility = ["@rules_rust_tinyjson//:__pkg__"],
29*d4726bddSHONG Yifan)
30*d4726bddSHONG Yifan
31*d4726bddSHONG Yifanrust_binary_without_process_wrapper(
32*d4726bddSHONG Yifan    name = "process_wrapper",
33*d4726bddSHONG Yifan    srcs = glob(["*.rs"]),
34*d4726bddSHONG Yifan    edition = "2018",
35*d4726bddSHONG Yifan    # To ensure the process wrapper is produced deterministically
36*d4726bddSHONG Yifan    # debug info, which is known to sometimes have host specific
37*d4726bddSHONG Yifan    # paths embedded in this section, is stripped out.
38*d4726bddSHONG Yifan    rustc_flags = select({
39*d4726bddSHONG Yifan        ":opt_linux": ["-Cstrip=debuginfo"],
40*d4726bddSHONG Yifan        ":opt_macos": ["-Cstrip=debuginfo"],
41*d4726bddSHONG Yifan        "//conditions:default": [],
42*d4726bddSHONG Yifan    }),
43*d4726bddSHONG Yifan    visibility = ["//visibility:public"],
44*d4726bddSHONG Yifan    deps = [
45*d4726bddSHONG Yifan        "@rules_rust_tinyjson//:tinyjson",
46*d4726bddSHONG Yifan    ],
47*d4726bddSHONG Yifan)
48*d4726bddSHONG Yifan
49*d4726bddSHONG Yifanrust_test(
50*d4726bddSHONG Yifan    name = "process_wrapper_test",
51*d4726bddSHONG Yifan    crate = ":process_wrapper",
52*d4726bddSHONG Yifan    edition = "2018",
53*d4726bddSHONG Yifan)
54*d4726bddSHONG Yifan
55*d4726bddSHONG Yifanbootstrap_process_wrapper(
56*d4726bddSHONG Yifan    name = "bootstrap_process_wrapper",
57*d4726bddSHONG Yifan    is_windows = select({
58*d4726bddSHONG Yifan        "@platforms//os:windows": True,
59*d4726bddSHONG Yifan        "//conditions:default": False,
60*d4726bddSHONG Yifan    }),
61*d4726bddSHONG Yifan    visibility = ["//visibility:public"],
62*d4726bddSHONG Yifan)
63