load("//bazel:yr.bzl", "COPTS", "cc_strip")

exports_files(["WORKSPACE"])

# Config setting for Linux platform
config_setting(
    name = "is_linux",
    constraint_values = ["@platforms//os:linux"],
)

# Config setting for macOS platform
config_setting(
    name = "is_macos",
    constraint_values = ["@platforms//os:macos"],
)

# Config setting for disabling Gloo
config_setting(
    name = "disable_gloo",
    values = {"define": "ENABLE_GLOO=false"},
)

# Config setting for disabling DataSystem
config_setting(
    name = "disable_datasystem",
    values = {"define": "ENABLE_DATASYSTEM=false"},
)

config_setting(
    name = "disable_observability",
    values = {"define": "ENABLE_OBSERVABILITY=false"},
)

cc_library(
    name = "runtime_lib",
    srcs = glob([
        "src/libruntime/*.cpp",
        "src/libruntime/objectstore/*.cpp",
        "src/libruntime/objectstore/*.h",
        "src/libruntime/statestore/*.cpp",
        "src/libruntime/statestore/*.h",
        "src/libruntime/streamstore/*.cpp",
        "src/libruntime/streamstore/*.h",
        "src/libruntime/heterostore/*.h",
        "src/libruntime/heterostore/*.cpp",
        "src/libruntime/utils/*.cpp",
        "src/libruntime/utils/*.h",
        "src/libruntime/utils/crypto/*.cpp",
        "src/libruntime/utils/crypto/*.h",
        "src/libruntime/invokeadaptor/*.h",
        "src/libruntime/invokeadaptor/*.cpp",
        "src/scene/*.cpp",
        "src/scene/*.h",
        "src/libruntime/fsclient/*.cpp",
        "src/libruntime/fsclient/*.h",
        "src/libruntime/fsclient/grpc/*.cpp",
        "src/libruntime/fsclient/grpc/*.h",
        "src/libruntime/gwclient/*.cpp",
        "src/libruntime/gwclient/*.h",
        "src/libruntime/gwclient/http/*.h",
        "src/libruntime/gwclient/http/*.cpp",
        "src/libruntime/gwclient/transport/*.h",
        "src/libruntime/gwclient/transport/*.cpp",
        "src/libruntime/connect/*.h",
        "src/libruntime/connect/*.cpp",
        "src/libruntime/clientsmanager/*.h",
        "src/libruntime/clientsmanager/*.cpp",
        "src/libruntime/groupmanager/*.h",
        "src/libruntime/groupmanager/*.cpp",
        "src/dto/*.cpp",
        "src/libruntime/stacktrace/*.h",
        "src/libruntime/stacktrace/*.cpp",
        "src/libruntime/metricsadaptor/*.h",
        "src/libruntime/metricsadaptor/*.cpp",
        "src/libruntime/generator/*.h",
        "src/libruntime/generator/*.cpp",
        "src/libruntime/driverlog/*.h",
        "src/libruntime/driverlog/*.cpp",
        "src/libruntime/fmclient/*.cpp",
        "src/libruntime/fmclient/*.h",
        "src/libruntime/rgroupmanager/*.cpp",
        "src/libruntime/rgroupmanager/*.h",
        "src/libruntime/traceadaptor/*.cpp",
        "src/libruntime/traceadaptor/*.h",
        "src/libruntime/traceadaptor/exporter/*.cpp",
        "src/libruntime/traceadaptor/exporter/*.h",
    ]) + glob(
        ["src/libruntime/*.h"],
        exclude = [
            "src/libruntime/libruntime.h",
            "src/libruntime/libruntime_manager.h",
            "src/libruntime/err_type.h",
        ],
    ),
    hdrs = [
        "src/libruntime/err_type.h",
        "src/libruntime/libruntime.h",
        "src/libruntime/libruntime_manager.h",
    ] + glob([
        "src/dto/*.h",
    ]),
    copts = COPTS + select({
        "//:disable_datasystem": [],
        "//conditions:default": ["-DENABLE_DATASYSTEM"],
    }) + select({
        "//:disable_observability": [],
        "//conditions:default": ["-DENABLE_OBSERVABILITY"],
    }),
    linkopts = [],
    deps = [
        "//src/libruntime/fsclient/protobuf:posix_cc_grpc",
        "//src/proto:libruntime_cc_proto",
        "//src/proto:socket_cc_proto",
        "//src/utility:yr_utils",
        "@boost",
        "@boringssl//:ssl",
        "@com_github_grpc_grpc//:grpc++",
        "@msgpack",
        "@nlohmann_json",
        "@securec",
        "@com_googlesource_code_re2//:re2",
        "@opentelemetry_cpp//api",
        "@opentelemetry_cpp//exporters/otlp:otlp_grpc_exporter",
        "@opentelemetry_cpp//exporters/ostream:ostream_log_record_exporter",
        "@opentelemetry_cpp//sdk/src/trace",
        "@opentelemetry_cpp//sdk/src/resource",
    ] + select({
        "//:disable_datasystem": [],
        "//conditions:default": [
            "@datasystem_sdk//:lib_datasystem_sdk",
        ],
    }) + select({
        "//:disable_observability": [],
        "//conditions:default": [
            "//src/utility/metrics:metrics",
        ],
    }) + [
        "@boost_libs//:boost_libs",
    ],
    linkstatic = True,
    visibility = ["//visibility:public"],
    alwayslink = True,
)

cc_library(
    name = "runtime_lib_hdrs",
    srcs = glob(
        [
            "src/libruntime/objectstore/*.h",
            "src/libruntime/statestore/*.h",
            "src/libruntime/streamstore/*.h",
            "src/libruntime/heterostore/*.h",
            "src/libruntime/utils/*.h",
            "src/libruntime/utils/crypto/*.h",
            "src/libruntime/invokeadaptor/*.h",
            "src/libruntime/fsclient/*.h",
            "src/libruntime/fsclient/grpc/*.h",
            "src/libruntime/gwclient/*.h",
            "src/libruntime/gwclient/http/*.h",
            "src/libruntime/gwclient/transport/*.h",
            "src/libruntime/connect/*.h",
            "src/libruntime/clientsmanager/*.h",
            "src/libruntime/groupmanager/*.h",
            "src/libruntime/stacktrace/*.h",
            "src/libruntime/metricsadaptor/*.h",
            "src/libruntime/generator/*.h",
            "src/libruntime/fmclient/*.h",
            "src/libruntime/driverlog/*.h",
            "src/libruntime/rgroupmanager/*.h",
            "src/libruntime/*.h",
            "src/scene/*.h",
        ],
        exclude = [
            "src/libruntime/libruntime.h",
            "src/libruntime/libruntime_manager.h",
            "src/libruntime/err_type.h",
        ],
    ),
    hdrs = [
        "src/libruntime/err_type.h",
        "src/libruntime/libruntime.h",
        "src/libruntime/libruntime_manager.h",
    ] + glob([
        "src/dto/*.h",
    ]),
    visibility = ["//visibility:public"],
    copts = select({
        "//:disable_observability": [],
        "//conditions:default": ["-DENABLE_OBSERVABILITY"],
    }),
    deps = [
        "//src/libruntime/fsclient/protobuf:posix_cc_grpc_hdrs",
        "//src/proto:libruntime_cc_proto_hdrs",
        "//src/proto:socket_cc_proto_hdrs",
        "//src/utility:yr_utils_hdrs",
        "@com_github_grpc_grpc//:grpc++",
        "@securec",
    ] + select({
        "//:disable_datasystem": [],
        "//conditions:default": [
            "@datasystem_sdk//:lib_datasystem_sdk",
        ],
    }) + select({
        "//:disable_observability": [],
        "//conditions:default": [
            "//src/utility/metrics:metrics",
        ],
    }),
)