load("//bazel:tensorstore.bzl", "tensorstore_cc_library", "tensorstore_cc_test")

package(default_visibility = ["//tensorstore:internal_packages"])

licenses(["notice"])

tensorstore_cc_library(
    name = "bytes",
    srcs = ["bytes.cc"],
    hdrs = ["bytes.h"],
    deps = [
        ":codec",
        "//tensorstore:array",
        "//tensorstore:contiguous_layout",
        "//tensorstore:data_type",
        "//tensorstore:index",
        "//tensorstore:rank",
        "//tensorstore/index_space:index_transform",
        "//tensorstore/internal:global_initializer",
        "//tensorstore/internal:integer_overflow",
        "//tensorstore/internal:intrusive_ptr",
        "//tensorstore/internal:unaligned_data_type_functions",
        "//tensorstore/internal/json_binding",
        "//tensorstore/internal/riegeli:array_endian_codec",
        "//tensorstore/util:endian",
        "//tensorstore/util:generic_stringify",
        "//tensorstore/util:result",
        "//tensorstore/util:span",
        "//tensorstore/util:status",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/strings:str_format",
        "@riegeli//riegeli/bytes:reader",
        "@riegeli//riegeli/bytes:writer",
    ],
    alwayslink = True,
)

tensorstore_cc_library(
    name = "transpose",
    srcs = ["transpose.cc"],
    hdrs = ["transpose.h"],
    deps = [
        ":codec",
        "//tensorstore:array",
        "//tensorstore:contiguous_layout",
        "//tensorstore:index",
        "//tensorstore:rank",
        "//tensorstore/driver:chunk",
        "//tensorstore/index_space:index_transform",
        "//tensorstore/internal:global_initializer",
        "//tensorstore/internal:intrusive_ptr",
        "//tensorstore/internal:storage_statistics",
        "//tensorstore/internal/json_binding",
        "//tensorstore/internal/json_binding:dimension_indexed",
        "//tensorstore/util:generic_stringify",
        "//tensorstore/util:result",
        "//tensorstore/util:span",
        "//tensorstore/util/execution:any_receiver",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/strings:str_format",
    ],
    alwayslink = True,
)

tensorstore_cc_library(
    name = "codec_chain_spec",
    srcs = ["codec_chain_spec.cc"],
    hdrs = ["codec_chain_spec.h"],
    deps = [
        ":bytes",
        ":codec",
        ":transpose",
        "//tensorstore:codec_spec",
        "//tensorstore:index",
        "//tensorstore:rank",
        "//tensorstore/driver/zarr3:name_configuration_json_binder",
        "//tensorstore/internal:intrusive_ptr",
        "//tensorstore/internal:unaligned_data_type_functions",
        "//tensorstore/internal/cache_key",
        "//tensorstore/internal/json_binding",
        "//tensorstore/internal/json_binding:bindable",
        "//tensorstore/serialization",
        "//tensorstore/serialization:json",
        "//tensorstore/util:result",
        "//tensorstore/util:span",
        "//tensorstore/util:status",
        "//tensorstore/util/garbage_collection",
        "@abseil-cpp//absl/container:fixed_array",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/strings:str_format",
        "@nlohmann_json//:json",
    ],
    alwayslink = True,
)

tensorstore_cc_library(
    name = "codec",
    srcs = [
        "codec.cc",
        "codec_spec.cc",
    ],
    hdrs = [
        "codec.h",
        "codec_spec.h",
        "registry.h",
    ],
    deps = [
        "//tensorstore:array",
        "//tensorstore:data_type",
        "//tensorstore:index",
        "//tensorstore:json_serialization_options_base",
        "//tensorstore:rank",
        "//tensorstore:strided_layout",
        "//tensorstore/driver:chunk",
        "//tensorstore/index_space:index_transform",
        "//tensorstore/internal:chunk_grid_specification",
        "//tensorstore/internal:intrusive_ptr",
        "//tensorstore/internal:json_registry",
        "//tensorstore/internal:lexicographical_grid_index_key",
        "//tensorstore/internal:storage_statistics",
        "//tensorstore/internal/cache",
        "//tensorstore/internal/json_binding:bindable",
        "//tensorstore/kvstore",
        "//tensorstore/util:executor",
        "//tensorstore/util:quote_string",
        "//tensorstore/util:result",
        "//tensorstore/util:span",
        "//tensorstore/util:status",
        "//tensorstore/util/execution:any_receiver",
        "@abseil-cpp//absl/base:no_destructor",
        "@abseil-cpp//absl/container:inlined_vector",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/strings:cord",
        "@nlohmann_json//:json",
        "@riegeli//riegeli/bytes:cord_reader",
        "@riegeli//riegeli/bytes:cord_writer",
        "@riegeli//riegeli/bytes:reader",
        "@riegeli//riegeli/bytes:writer",
    ],
)

tensorstore_cc_library(
    name = "crc32c",
    srcs = ["crc32c.cc"],
    hdrs = ["crc32c.h"],
    deps = [
        ":codec",
        "//tensorstore/internal:global_initializer",
        "//tensorstore/internal:integer_overflow",
        "//tensorstore/internal:intrusive_ptr",
        "//tensorstore/internal/json_binding",
        "//tensorstore/internal/riegeli:digest_suffixed_reader",
        "//tensorstore/internal/riegeli:digest_suffixed_writer",
        "//tensorstore/util:result",
        "@abseil-cpp//absl/status",
        "@riegeli//riegeli/bytes:reader",
        "@riegeli//riegeli/bytes:writer",
        "@riegeli//riegeli/digests:crc32c_digester",
    ],
    alwayslink = True,
)

tensorstore_cc_test(
    name = "bytes_test",
    size = "small",
    srcs = ["bytes_test.cc"],
    deps = [
        ":codec",
        ":codec_chain_spec",
        ":codec_test_util",
        "//tensorstore:data_type",
        "//tensorstore/internal/testing:json_gtest",
        "//tensorstore/util:status_testutil",
        "@abseil-cpp//absl/status",
        "@googletest//:gtest_main",
        "@nlohmann_json//:json",
    ],
)

tensorstore_cc_test(
    name = "transpose_test",
    size = "small",
    srcs = ["transpose_test.cc"],
    deps = [
        ":codec",
        ":codec_chain_spec",
        ":codec_test_util",
        ":transpose",
        "//tensorstore:data_type",
        "//tensorstore/internal/testing:json_gtest",
        "//tensorstore/util:status_testutil",
        "@abseil-cpp//absl/status",
        "@googletest//:gtest_main",
    ],
)

tensorstore_cc_library(
    name = "gzip",
    srcs = ["gzip.cc"],
    hdrs = ["gzip.h"],
    deps = [
        ":codec",
        "//tensorstore/internal:global_initializer",
        "//tensorstore/internal:intrusive_ptr",
        "//tensorstore/internal/json_binding",
        "//tensorstore/util:result",
        "//tensorstore/util:status",
        "@abseil-cpp//absl/status",
        "@riegeli//riegeli/bytes:reader",
        "@riegeli//riegeli/bytes:writer",
        "@riegeli//riegeli/zlib:zlib_reader",
        "@riegeli//riegeli/zlib:zlib_writer",
    ],
    alwayslink = True,
)

tensorstore_cc_test(
    name = "gzip_test",
    size = "small",
    srcs = ["gzip_test.cc"],
    deps = [
        ":bytes",
        ":codec_test_util",
        ":gzip",
        "@googletest//:gtest_main",
    ],
)

tensorstore_cc_library(
    name = "sharding_indexed",
    srcs = ["sharding_indexed.cc"],
    hdrs = ["sharding_indexed.h"],
    deps = [
        ":bytes",
        ":codec",
        ":codec_chain_spec",
        ":crc32c",
        "//tensorstore:array",
        "//tensorstore:box",
        "//tensorstore:contiguous_layout",
        "//tensorstore:data_type",
        "//tensorstore:index",
        "//tensorstore:index_interval",
        "//tensorstore:rank",
        "//tensorstore/internal:async_write_array",
        "//tensorstore/internal:chunk_grid_specification",
        "//tensorstore/internal:global_initializer",
        "//tensorstore/internal:intrusive_ptr",
        "//tensorstore/internal:lexicographical_grid_index_key",
        "//tensorstore/internal/cache",
        "//tensorstore/internal/json_binding",
        "//tensorstore/kvstore",
        "//tensorstore/kvstore/zarr3_sharding_indexed",
        "//tensorstore/kvstore/zarr3_sharding_indexed:key",
        "//tensorstore/kvstore/zarr3_sharding_indexed:shard_format",
        "//tensorstore/util:executor",
        "//tensorstore/util:generic_stringify",
        "//tensorstore/util:result",
        "//tensorstore/util:span",
        "//tensorstore/util:status",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/strings:str_format",
        "@riegeli//riegeli/bytes:reader",
        "@riegeli//riegeli/bytes:writer",
    ],
    alwayslink = True,
)

tensorstore_cc_test(
    name = "sharding_indexed_test",
    size = "small",
    srcs = ["sharding_indexed_test.cc"],
    deps = [
        ":bytes",
        ":codec",
        ":codec_chain_spec",
        ":codec_test_util",
        ":gzip",
        ":sharding_indexed",
        "//tensorstore:array",
        "//tensorstore:data_type",
        "//tensorstore/internal/testing:json_gtest",
        "//tensorstore/util:status_testutil",
        "@abseil-cpp//absl/status",
        "@googletest//:gtest_main",
    ],
)

tensorstore_cc_library(
    name = "blosc",
    srcs = ["blosc.cc"],
    hdrs = ["blosc.h"],
    deps = [
        ":codec",
        "//tensorstore/internal:global_initializer",
        "//tensorstore/internal:intrusive_ptr",
        "//tensorstore/internal/compression:blosc",
        "//tensorstore/internal/json_binding",
        "//tensorstore/util:quote_string",
        "//tensorstore/util:result",
        "//tensorstore/util:status",
        "@abseil-cpp//absl/status",
        "@abseil-cpp//absl/strings",
        "@abseil-cpp//absl/strings:str_format",
        "@org_blosc_cblosc//:blosc",
        "@riegeli//riegeli/bytes:reader",
        "@riegeli//riegeli/bytes:writer",
    ],
    alwayslink = True,
)

tensorstore_cc_test(
    name = "blosc_test",
    size = "small",
    srcs = ["blosc_test.cc"],
    deps = [
        ":blosc",
        ":bytes",
        ":codec_chain_spec",
        ":codec_test_util",
        "//tensorstore:data_type",
        "//tensorstore/internal/testing:json_gtest",
        "//tensorstore/util:status_testutil",
        "@abseil-cpp//absl/status",
        "@googletest//:gtest_main",
    ],
)

tensorstore_cc_library(
    name = "all_codecs",
    deps = [
        ":blosc",
        ":bytes",
        ":crc32c",
        ":gzip",
        ":sharding_indexed",
        ":transpose",
        ":zstd",
    ],
)

tensorstore_cc_library(
    name = "codec_test_util",
    testonly = True,
    srcs = ["codec_test_util.cc"],
    hdrs = ["codec_test_util.h"],
    deps = [
        ":codec",
        ":codec_chain_spec",
        "//tensorstore:array",
        "//tensorstore:array_testutil",
        "//tensorstore:contiguous_layout",
        "//tensorstore:data_type",
        "//tensorstore:index",
        "//tensorstore/internal:data_type_random_generator",
        "//tensorstore/internal/testing:json_gtest",
        "//tensorstore/util:endian",
        "//tensorstore/util:result",
        "//tensorstore/util:span",
        "//tensorstore/util:status",
        "//tensorstore/util:status_testutil",
        "@abseil-cpp//absl/random",
        "@googletest//:gtest",
        "@nlohmann_json//:json",
    ],
)

tensorstore_cc_library(
    name = "zstd",
    srcs = ["zstd_codec.cc"],
    hdrs = ["zstd_codec.h"],
    deps = [
        ":codec",
        "//tensorstore/internal:global_initializer",
        "//tensorstore/internal:intrusive_ptr",
        "//tensorstore/internal/json_binding",
        "//tensorstore/internal/json_binding:bindable",
        "//tensorstore/util:result",
        "//tensorstore/util:status",
        "@abseil-cpp//absl/status",
        "@riegeli//riegeli/bytes:reader",
        "@riegeli//riegeli/bytes:writer",
        "@riegeli//riegeli/zstd:zstd_reader",
        "@riegeli//riegeli/zstd:zstd_writer",
    ],
    alwayslink = True,
)

tensorstore_cc_test(
    name = "zstd_test",
    size = "small",
    srcs = ["zstd_test.cc"],
    deps = [
        ":bytes",
        ":codec_test_util",
        ":zstd",
        "//tensorstore/util:status_testutil",
        "@abseil-cpp//absl/status",
        "@googletest//:gtest_main",
    ],
)

tensorstore_cc_test(
    name = "codec_chain_spec_test",
    srcs = ["codec_chain_spec_test.cc"],
    deps = [
        ":codec_chain_spec",
        ":codec_test_util",
        ":gzip",
        ":sharding_indexed",
        "//tensorstore:codec_spec",
        "//tensorstore/internal/testing:json_gtest",
        "//tensorstore/util:status_testutil",
        "@abseil-cpp//absl/status",
        "@googletest//:gtest_main",
        "@nlohmann_json//:json",
    ],
)
