load("@bazel_skylib//rules:common_settings.bzl", "string_flag")
load("@rules_cc//cc:cc_library.bzl", "cc_library")

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

string_flag(
    name = "driver",
    build_setting_default = "iproute2",
)

config_setting(
    name = "netlink",
    flag_values = {
        ":driver": "netlink",
    },
)

config_setting(
    name = "iproute2",
    flag_values = {
        ":driver": "iproute2",
    },
)

cc_library(
    name = "alloc_utils",
    srcs = [
        "alloc_utils.cpp",
    ],
    hdrs = [
        "alloc_utils.h",
    ],
    copts = ["-std=c++20"],
    deps = select({
        ":netlink": [":alloc_netlink"],
        "//conditions:default": [":alloc_iproute2"],
    }) + [
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/common/libs/utils:files",
        "//cuttlefish/common/libs/utils:network",
        "//cuttlefish/common/libs/utils:subprocess",
        "//cuttlefish/host/commands/cvd/utils:common",
        "//cuttlefish/host/libs/config:logging",
        "//cuttlefish/result",
        "@abseil-cpp//absl/base:no_destructor",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/strings:str_format",
    ],
)

cc_library(
    name = "alloc_iproute2",
    srcs = [
        "alloc_iproute2.cpp",
    ],
    hdrs = [
        "alloc_driver.h",
    ],
    copts = ["-std=c++20"],
    deps = [
        "//cuttlefish/common/libs/utils:subprocess",
        "//cuttlefish/result",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/strings:str_format",
    ],
)

cc_library(
    name = "alloc_netlink",
    srcs = [
        "alloc_netlink.cpp",
    ],
    hdrs = [
        "alloc_driver.h",
    ],
    copts = ["-std=c++20"],
    deps = [
        "//allocd/net:netlink",
        "//cuttlefish/common/libs/fs",
        "//cuttlefish/common/libs/utils:subprocess",
        "//cuttlefish/result",
        "//libbase",
        "@abseil-cpp//absl/log",
        "@abseil-cpp//absl/log:check",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/strings:str_format",
    ],
)
