load("//cuttlefish/bazel:rules.bzl", "cf_cc_binary", "cf_cc_library")

package(
    default_visibility = ["//:android_cuttlefish"],
)

cf_cc_library(
    name = "credentialed_unix_server",
    srcs = ["credentialed_unix_server.cpp"],
    hdrs = ["credentialed_unix_server.h"],
    deps = [
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@sandboxed_api//sandboxed_api/util:fileops",
    ],
)

cf_cc_library(
    name = "logs",
    srcs = ["logs.cpp"],
    hdrs = ["logs.h"],
    deps = [
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/log:log_entry",
        "@abseil-cpp//absl/log:log_sink",
        "@abseil-cpp//absl/log:log_sink_registry",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
    ],
)

cf_cc_library(
    name = "pidfd",
    srcs = ["pidfd.cpp"],
    hdrs = ["pidfd.h"],
    deps = [
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/strings:str_format",
        "@abseil-cpp//absl/types:span",
        "@sandboxed_api//sandboxed_api/util:fileops",
    ],
)

cf_cc_library(
    name = "policies_header",
    hdrs = ["policies.h"],
    deps = [
        "@abseil-cpp//absl/status",
        "@sandboxed_api//sandboxed_api/sandbox2",
    ],
)

cf_cc_library(
    name = "policies",
    srcs = ["policies.cpp"],
    hdrs = ["policies.h"],
    deps = [
        "//cuttlefish/host/commands/process_sandboxer:proxy_common",
        "//cuttlefish/host/commands/process_sandboxer/policies:adb_connector",
        "//cuttlefish/host/commands/process_sandboxer/policies:assemble_cvd",
        "//cuttlefish/host/commands/process_sandboxer/policies:avbtool",
        "//cuttlefish/host/commands/process_sandboxer/policies:baseline",
        "//cuttlefish/host/commands/process_sandboxer/policies:casimir",
        "//cuttlefish/host/commands/process_sandboxer/policies:casimir_control_server",
        "//cuttlefish/host/commands/process_sandboxer/policies:cf_vhost_user_input",
        "//cuttlefish/host/commands/process_sandboxer/policies:control_env_proxy_server",
        "//cuttlefish/host/commands/process_sandboxer/policies:cvd_internal_start",
        "//cuttlefish/host/commands/process_sandboxer/policies:echo_server",
        "//cuttlefish/host/commands/process_sandboxer/policies:gnss_grpc_proxy",
        "//cuttlefish/host/commands/process_sandboxer/policies:kernel_log_monitor",
        "//cuttlefish/host/commands/process_sandboxer/policies:log_tee",
        "//cuttlefish/host/commands/process_sandboxer/policies:logcat_receiver",
        "//cuttlefish/host/commands/process_sandboxer/policies:metrics",
        "//cuttlefish/host/commands/process_sandboxer/policies:mkenvimage_slim",
        "//cuttlefish/host/commands/process_sandboxer/policies:modem_simulator",
        "//cuttlefish/host/commands/process_sandboxer/policies:netsimd",
        "//cuttlefish/host/commands/process_sandboxer/policies:newfs_msdos",
        "//cuttlefish/host/commands/process_sandboxer/policies:no_policy",
        "//cuttlefish/host/commands/process_sandboxer/policies:openwrt_control_server",
        "//cuttlefish/host/commands/process_sandboxer/policies:operator_proxy",
        "//cuttlefish/host/commands/process_sandboxer/policies:process_restarter",
        "//cuttlefish/host/commands/process_sandboxer/policies:run_cvd",
        "//cuttlefish/host/commands/process_sandboxer/policies:screen_recording_server",
        "//cuttlefish/host/commands/process_sandboxer/policies:secure_env",
        "//cuttlefish/host/commands/process_sandboxer/policies:simg2img",
        "//cuttlefish/host/commands/process_sandboxer/policies:socket_vsock_proxy",
        "//cuttlefish/host/commands/process_sandboxer/policies:tcp_connector",
        "//cuttlefish/host/commands/process_sandboxer/policies:tombstone_receiver",
        "//cuttlefish/host/commands/process_sandboxer/policies:vhost_device_vsock",
        "//cuttlefish/host/commands/process_sandboxer/policies:webrtc",
        "//cuttlefish/host/commands/process_sandboxer/policies:webrtc_operator",
        "//cuttlefish/host/commands/process_sandboxer/policies:wmediumd",
        "//cuttlefish/host/commands/process_sandboxer/policies:wmediumd_gen_config",
        "@abseil-cpp//absl/container:flat_hash_map",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/status",
        "@sandboxed_api//sandboxed_api/sandbox2",
        "@sandboxed_api//sandboxed_api/util:file_base",
        "@sandboxed_api//sandboxed_api/util:fileops",
    ],
)

cf_cc_library(
    name = "poll_callback",
    srcs = ["poll_callback.cpp"],
    hdrs = ["poll_callback.h"],
    deps = [
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/status",
    ],
)

cf_cc_binary(
    name = "process_sandboxer",
    srcs = ["main.cpp"],
    deps = [
        "//cuttlefish/host/commands/process_sandboxer:logs",
        "//cuttlefish/host/commands/process_sandboxer:pidfd",
        "//cuttlefish/host/commands/process_sandboxer:policies",
        "//cuttlefish/host/commands/process_sandboxer:sandbox_manager",
        "//cuttlefish/host/libs/log_names",
        "@abseil-cpp//absl/base:log_severity",
        "@abseil-cpp//absl/flags:flag",
        "@abseil-cpp//absl/flags:parse",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/log:globals",
        "@abseil-cpp//absl/log:initialize",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@sandboxed_api//sandboxed_api/util:file_base",
        "@sandboxed_api//sandboxed_api/util:fileops",
    ],
)

cf_cc_library(
    name = "proxy_common",
    srcs = ["proxy_common.cpp"],
    hdrs = ["proxy_common.h"],
    deps = [
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
    ],
)

cf_cc_library(
    name = "sandbox_manager",
    srcs = ["sandbox_manager.cpp"],
    hdrs = ["sandbox_manager.h"],
    deps = [
        "//cuttlefish/host/commands/process_sandboxer:credentialed_unix_server",
        "//cuttlefish/host/commands/process_sandboxer:pidfd",
        "//cuttlefish/host/commands/process_sandboxer:policies",
        "//cuttlefish/host/commands/process_sandboxer:poll_callback",
        "//cuttlefish/host/commands/process_sandboxer:proxy_common",
        "//cuttlefish/host/commands/process_sandboxer:signal_fd",
        "@abseil-cpp//absl/functional:bind_front",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/log:vlog_is_on",
        "@abseil-cpp//absl/memory",
        "@abseil-cpp//absl/random",
        "@abseil-cpp//absl/random:bit_gen_ref",
        "@abseil-cpp//absl/random:distributions",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/strings:str_format",
        "@abseil-cpp//absl/time",
        "@abseil-cpp//absl/types:span",
        "@sandboxed_api//sandboxed_api/sandbox2",
        "@sandboxed_api//sandboxed_api/util:file_base",
        "@sandboxed_api//sandboxed_api/util:fileops",
    ],
)

cf_cc_binary(
    name = "sandboxer_proxy",
    srcs = ["sandboxer_proxy.cpp"],
    deps = [
        "//cuttlefish/host/commands/process_sandboxer:proxy_common",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
    ],
)

cf_cc_library(
    name = "signal_fd",
    srcs = ["signal_fd.cpp"],
    hdrs = ["signal_fd.h"],
    deps = [
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/status:statusor",
        "@abseil-cpp//absl/strings",
        "@sandboxed_api//sandboxed_api/util:fileops",
    ],
)
