################################################################################
# Protocol Buffers Compiler - Rust code generator
################################################################################

load("@rules_cc//cc:defs.bzl", "cc_library")
load("//build_defs:cpp_opts.bzl", "COPTS")

cc_library(
    name = "rust",
    srcs = ["generator.cc"],
    hdrs = ["generator.h"],
    copts = COPTS,
    strip_include_prefix = "/src",
    visibility = [
        "//pkg:__pkg__",
        "//src/google/protobuf/compiler:__pkg__",
    ],
    deps = [
        ":context",
        ":crate_mapping",
        ":enum",
        ":message",
        ":naming",
        ":relative_path",
        "//src/google/protobuf",
        "//src/google/protobuf:port",
        "//src/google/protobuf/compiler:code_generator",
        "//src/google/protobuf/compiler/cpp:names",
        "//src/google/protobuf/io",
        "//src/google/protobuf/io:printer",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:btree",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:absl_check",
        "@com_google_absl//absl/memory",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:optional",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "crate_mapping",
    srcs = ["crate_mapping.cc"],
    hdrs = ["crate_mapping.h"],
    strip_include_prefix = "/src",
    deps = [
        ":context",
        "//src/google/protobuf",
        "//src/google/protobuf/testing:file",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
    ],
)

cc_test(
    name = "crate_mapping_unittest",
    srcs = ["crate_mapping_unittest.cc"],
    deps = [
        ":context",
        ":crate_mapping",
        "//src/google/protobuf/testing",
        "//src/google/protobuf/testing:file",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:string_view",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "message",
    srcs = ["message.cc"],
    hdrs = ["message.h"],
    copts = COPTS,
    strip_include_prefix = "/src",
    deps = [
        ":context",
        ":enum",
        ":naming",
        ":oneof",
        "//src/google/protobuf",
        "//src/google/protobuf/compiler/cpp:names",
        "//src/google/protobuf/compiler/cpp:names_internal",
        "//src/google/protobuf/compiler/rust/accessors",
        "//upb_generator:mangle",
        "@com_google_absl//absl/log:absl_check",
        "@com_google_absl//absl/log:absl_log",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/strings:str_format",
    ],
)

cc_library(
    name = "context",
    srcs = ["context.cc"],
    hdrs = ["context.h"],
    copts = COPTS,
    strip_include_prefix = "/src",
    visibility = [
        "//src/google/protobuf/compiler/rust:__subpackages__",
    ],
    deps = [
        "//src/google/protobuf",
        "//src/google/protobuf/compiler:code_generator",
        "//src/google/protobuf/io:printer",
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/log:absl_check",
        "@com_google_absl//absl/log:absl_log",
        "@com_google_absl//absl/status",
        "@com_google_absl//absl/status:statusor",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_library(
    name = "enum",
    srcs = ["enum.cc"],
    hdrs = ["enum.h"],
    copts = COPTS,
    strip_include_prefix = "/src",
    deps = [
        ":context",
        ":naming",
        "//src/google/protobuf",
        "//src/google/protobuf/compiler/cpp:names",
        "@com_google_absl//absl/container:flat_hash_map",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:absl_check",
        "@com_google_absl//absl/strings",
        "@com_google_absl//absl/types:span",
    ],
)

cc_test(
    name = "enum_test",
    srcs = ["enum_test.cc"],
    deps = [
        ":enum",
        "@com_google_absl//absl/strings",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "naming",
    srcs = [
        "naming.cc",
        "rust_keywords.cc",
    ],
    hdrs = [
        "naming.h",
        "rust_keywords.h",
    ],
    copts = COPTS,
    strip_include_prefix = "/src",
    visibility = [
        "//src/google/protobuf/compiler/rust:__subpackages__",
    ],
    deps = [
        ":context",
        ":rust_field_type",
        "//src/google/protobuf",
        "//src/google/protobuf:port",
        "//src/google/protobuf/compiler:code_generator",
        "//src/google/protobuf/compiler/cpp:names_internal",
        "@com_google_absl//absl/container:flat_hash_set",
        "@com_google_absl//absl/log:absl_check",
        "@com_google_absl//absl/log:absl_log",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "oneof",
    srcs = ["oneof.cc"],
    hdrs = ["oneof.h"],
    copts = COPTS,
    strip_include_prefix = "/src",
    deps = [
        ":context",
        ":naming",
        ":rust_field_type",
        "//src/google/protobuf",
        "//src/google/protobuf/compiler/cpp:names",
        "//src/google/protobuf/compiler/cpp:names_internal",
        "//src/google/protobuf/compiler/rust/accessors",
        "@com_google_absl//absl/log:absl_log",
        "@com_google_absl//absl/strings",
    ],
)

cc_library(
    name = "relative_path",
    srcs = ["relative_path.cc"],
    hdrs = ["relative_path.h"],
    strip_include_prefix = "/src",
    deps = [
        "@com_google_absl//absl/algorithm:container",
        "@com_google_absl//absl/log:absl_check",
        "@com_google_absl//absl/strings",
    ],
)

cc_test(
    name = "relative_path_test",
    srcs = ["relative_path_test.cc"],
    deps = [
        ":relative_path",
        "@com_google_googletest//:gtest",
        "@com_google_googletest//:gtest_main",
    ],
)

cc_library(
    name = "rust_field_type",
    srcs = ["rust_field_type.cc"],
    hdrs = ["rust_field_type.h"],
    strip_include_prefix = "/src",
    visibility = [
        "//src/google/protobuf/compiler/rust:__subpackages__",
    ],
    deps = [
        "//src/google/protobuf",
        "@com_google_absl//absl/log:absl_log",
    ],
)
