load("@rules_rust//rust:defs.bzl", "rust_binary", "rust_library", "rust_proc_macro", "rust_test")
load("@crates//:defs.bzl", "aliases", "all_crate_deps")
load("//bazel:rust_cargo_tests.bzl", "rust_cargo_integration_tests")

rust_library(
    name = "tidal_server",
    srcs = glob(["src/**/*.rs", "src/*.rs"], allow_empty = True),
    crate_root = "src/lib.rs",
    crate_name = "tidal_server",
    edition = "2024",
    compile_data = glob(["**/*"], exclude = ["**/*.rs", "**/*.bazel", "BUILD", "WORKSPACE"], allow_empty = True),
    aliases = aliases(),
    deps = all_crate_deps(normal = True) + [
        "//tidal:tidaldb_test_support",
        "//tidal-net:tidal_net",
    ],
    proc_macro_deps = all_crate_deps(proc_macro = True),
    visibility = ["//visibility:public"],
)

rust_test(
    name = "tidal_server_test",
    crate = ":tidal_server",
    compile_data = glob(["**/*"], exclude = ["**/*.rs", "**/*.bazel", "BUILD", "WORKSPACE"], allow_empty = True),
    data = glob(["**/*"], exclude = ["**/*.rs", "**/*.bazel", "BUILD", "WORKSPACE"], allow_empty = True),
    aliases = aliases(normal_dev = True, proc_macro_dev = True),
    deps = all_crate_deps(normal = True, normal_dev = True),
    proc_macro_deps = all_crate_deps(proc_macro = True, proc_macro_dev = True),
)

rust_binary(
    name = "tidal-server",
    srcs = glob(["src/**/*.rs", "src/*.rs"], allow_empty = True),
    crate_root = "src/main.rs",
    edition = "2024",
    compile_data = glob(["**/*"], exclude = ["**/*.rs", "**/*.bazel", "BUILD", "WORKSPACE"], allow_empty = True),
    aliases = aliases(),
    deps = all_crate_deps(normal = True) + [
        "//tidal:tidaldb_test_support",
        "//tidal-net:tidal_net",
        ":tidal_server",
    ],
    proc_macro_deps = all_crate_deps(proc_macro = True),
    visibility = ["//visibility:public"],
)

rust_cargo_integration_tests(
    name_prefix = "tidal_server",
    tests = glob(["tests/*.rs"]),
    srcs = glob(["tests/**/*.rs"]),
    compile_data = glob(["**/*"], exclude = ["**/*.rs", "**/*.bazel", "BUILD", "WORKSPACE"], allow_empty = True),
    data = glob(["**/*"], exclude = ["**/*.rs", "**/*.bazel", "BUILD", "WORKSPACE"], allow_empty = True) + [
        ":tidal-server",
    ],
    aliases = aliases(normal_dev = True, proc_macro_dev = True),
    deps = all_crate_deps(normal = True, normal_dev = True) + [
        "//tidal:tidaldb_test_support",
        "//tidal-net:tidal_net",
        ":tidal_server",
    ],
    proc_macro_deps = all_crate_deps(proc_macro = True, proc_macro_dev = True),
)
