load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository", "new_git_repository")
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

http_archive(
  name = "com_google_absl",
  urls = ["https://github.com/abseil/abseil-cpp/archive/a59b4daa07a14326d2ceb28cc6d0e079feea3338.zip"],
  strip_prefix = "abseil-cpp-a59b4daa07a14326d2ceb28cc6d0e079feea3338",
  sha256 = "5bb0b7cd556e68ddedb0d9f13fcb79ac13e7a880f3728559836f62a699c75a79",
)

http_archive(
    name = "gtest",
    url = "https://github.com/google/googletest/archive/refs/tags/release-1.12.1.zip",
    sha256 = "24564e3b712d3eb30ac9a85d92f7d720f60cc0173730ac166f27dda7fed76cb2",
    strip_prefix = "googletest-release-1.12.1",
)

new_git_repository(
    name = "concurrentqueue",
    remote = "https://github.com/cameron314/concurrentqueue.git",
    commit = "79cec4c3bf1ca23ea4a03adfcd3c2c3659684dd2",
    shallow_since = "1580387311 -0500",
    build_file_content = """

cc_library(
    name = "concurrentqueue",
    hdrs = ["concurrentqueue.h", "blockingconcurrentqueue.h", "lightweightsemaphore.h"],
    visibility = ["//visibility:public"],
)
""",
)

http_archive(
    name = "readerwriterqueue",
    url = "https://github.com/cameron314/readerwriterqueue/archive/refs/tags/v1.0.6.tar.gz",
    strip_prefix = "readerwriterqueue-1.0.6",
    sha256 = "fc68f55bbd49a8b646462695e1777fb8f2c0b4f342d5e6574135211312ba56c1",
    build_file_content = """

cc_library(
    name = "readerwriterqueue",
    hdrs = ["readerwritercircularbuffer.h", "readerwriterqueue.h", "atomicops.h"],
    visibility = ["//visibility:public"],
)
""",
)

pybind11_bazel_version = "5a8209f6ddcc848272e27a36a5fc2b79e7438374"

http_archive(
  name = "pybind11_bazel",
  strip_prefix = "pybind11_bazel-" + pybind11_bazel_version,
  urls = ["https://github.com/Lalaland/pybind11_bazel/archive/" + pybind11_bazel_version + ".tar.gz"],
  sha256 = "cc9bd704ec128049f6b0c7a64313a690a3f53dac2f040e9d00d87cf33d45d9c1",
)

pybind11_version = 'fab1eebe2c4c52e0abac249f3d058787bc83b5ec'

# We still require the pybind library.
http_archive(
  name = "pybind11",
  build_file = "@pybind11_bazel//:pybind11.BUILD",
  strip_prefix = "pybind11-" + pybind11_version,
  urls = ["https://github.com/pybind/pybind11/archive/" + pybind11_version + ".tar.gz"],
)

load("@pybind11_bazel//:python_configure.bzl", "python_configure")
python_configure(name = "local_config_python")

http_archive(
    name = "streamvbyte",
    url = "https://github.com/lemire/streamvbyte/archive/refs/tags/v0.5.1.zip",
    strip_prefix = "streamvbyte-0.5.1",
    build_file_content = """
cc_library (
    name = "streamvbyte",
    hdrs = glob(["include/*"]) + glob(["src/*"]),
    srcs = [
        "src/streamvbyte_decode.c",
        "src/streamvbyte_encode.c",
        "src/streamvbytedelta_decode.c",
        "src/streamvbytedelta_encode.c",
        "src/streamvbyte_0124_encode.c",
        "src/streamvbyte_0124_decode.c",
        "src/streamvbyte_zigzag.c"
    ],
    visibility = ["//visibility:public"],
    includes = ["include"],
    copts = ["-std=c99"],
)
""",
    sha256 = "7d5899e0a8908db423dca82259388a291c642cc335d5c6ef6a6beb08be39b0ef",
)

http_archive(
    name = "dlpack",
    url = "https://github.com/dmlc/dlpack/archive/refs/tags/v0.7.zip",
    strip_prefix = "dlpack-0.7",
    build_file_content = """
cc_library (
    name = "dlpack",
    hdrs = ["include/dlpack.h"],
    visibility = ["//visibility:public"],
    includes = ["include"],
)
""",
)

http_archive(
    name = "json",
    url = "https://github.com/nlohmann/json/archive/refs/tags/v3.11.2.zip",
    strip_prefix = "json-3.11.2",
     build_file_content = """
cc_library (
    name = "json",
    hdrs = glob(["include/nlohmann/**"]),
     visibility = ["//visibility:public"],
     includes = ["include"],
 )
 """,
 sha256 = "95651d7d1fcf2e5c3163c3d37df6d6b3e9e5027299e6bd050d157322ceda9ac9",
)

new_git_repository(
    name = "picosha2",
    commit = "b699e6c900be6e00152db5a3d123c1db42ea13d0",
    remote = "https://github.com/okdshin/PicoSHA2.git",
    build_file_content = """
cc_library (
    name = "picosha2",
    hdrs = ['picosha2.h'],
    visibility = ["//visibility:public"],
)
""",
shallow_since = "1531968639 +0900"
)

http_archive(
    name = "rules_foreign_cc",
    sha256 = "2a4d07cd64b0719b39a7c12218a3e507672b82a97b98c6a89d38565894cf7c51",
    strip_prefix = "rules_foreign_cc-0.9.0",
    url = "https://github.com/bazelbuild/rules_foreign_cc/archive/refs/tags/0.9.0.tar.gz",
)

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")
rules_foreign_cc_dependencies()


# Group the sources of the library so that CMake rule have access to it
all_content = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""

zstd_content = """
cc_library(
    name = "everything",
    srcs = [
        "lib/common/zstd_deps.h",
        "lib/common/error_private.h",
        "lib/common/bits.h",
        "lib/common/zstd_internal.h",
        "lib/common/pool.h",
        "lib/common/bitstream.h",
        "lib/common/compiler.h",
        "lib/common/cpu.h",
        "lib/common/debug.c",
        "lib/common/debug.h",
        "lib/common/entropy_common.c",
        "lib/common/error_private.c",
        "lib/common/fse_decompress.c",
        "lib/common/fse.h",
        "lib/common/huf.h",
        "lib/common/mem.h",
        "lib/common/pool.c",
        "lib/common/portability_macros.h",
        "lib/common/threading.c",
        "lib/common/threading.h",
        "lib/common/xxhash.c",
        "lib/common/xxhash.h",
        "lib/common/zstd_common.c",
        "lib/common/zstd_trace.h",
        "lib/compress/clevels.h",
        "lib/compress/fse_compress.c",
        "lib/compress/hist.c",
        "lib/compress/hist.h",
        "lib/compress/huf_compress.c",
        "lib/compress/zstd_compress_internal.h",
        "lib/compress/zstd_compress_literals.c",
        "lib/compress/zstd_compress_literals.h",
        "lib/compress/zstd_compress_sequences.c",
        "lib/compress/zstd_compress_sequences.h",
        "lib/compress/zstd_compress_superblock.c",
        "lib/compress/zstd_compress_superblock.h",
        "lib/compress/zstd_compress.c",
        "lib/compress/zstd_cwksp.h",
        "lib/compress/zstd_double_fast.c",
        "lib/compress/zstd_double_fast.h",
        "lib/compress/zstd_fast.c",
        "lib/compress/zstd_fast.h",
        "lib/compress/zstd_lazy.c",
        "lib/compress/zstd_lazy.h",
        "lib/compress/zstd_ldm_geartab.h",
        "lib/compress/zstd_ldm.c",
        "lib/compress/zstd_ldm.h",
        "lib/compress/zstd_opt.c",
        "lib/compress/zstd_opt.h",
        "lib/compress/zstdmt_compress.c",
        "lib/compress/zstdmt_compress.h",
        "lib/decompress/huf_decompress.c",
        "lib/decompress/zstd_ddict.c",
        "lib/decompress/zstd_ddict.h",
        "lib/decompress/zstd_decompress_block.c",
        "lib/decompress/zstd_decompress_block.h",
        "lib/decompress/zstd_decompress_internal.h",
        "lib/decompress/zstd_decompress.c",
        "lib/deprecated/zbuff_common.c",
        "lib/deprecated/zbuff_compress.c",
        "lib/deprecated/zbuff_decompress.c",
        "lib/deprecated/zbuff.h",
        "lib/dictBuilder/cover.c",
        "lib/dictBuilder/cover.h",
        "lib/dictBuilder/divsufsort.c",
        "lib/dictBuilder/divsufsort.h",
        "lib/dictBuilder/fastcover.c",
        "lib/dictBuilder/zdict.c",
        "lib/legacy/zstd_legacy.h",
        "lib/legacy/zstd_v01.c",
        "lib/legacy/zstd_v01.h",
        "lib/legacy/zstd_v02.c",
        "lib/legacy/zstd_v02.h",
        "lib/legacy/zstd_v03.c",
        "lib/legacy/zstd_v03.h",
        "lib/legacy/zstd_v04.c",
        "lib/legacy/zstd_v04.h",
        "lib/legacy/zstd_v05.c",
        "lib/legacy/zstd_v05.h",
        "lib/legacy/zstd_v06.c",
        "lib/legacy/zstd_v06.h",
        "lib/legacy/zstd_v07.c",
        "lib/legacy/zstd_v07.h",
        "lib/zstd_errors.h",
        "lib/zstd.h",
        # TODO: Use a select statement to only include for relevant
        # architectures.
        "lib/decompress/huf_decompress_amd64.S",
    ],
    hdrs = [
        "lib/zdict.h",
        "lib/zstd.h",
    ],
    copts = [
        "-DXXH_NAMESPACE=ZSTD_",
        "-DZSTD_GZCOMPRESS",
        "-DZSTD_GZDECOMPRESS",
        "-DZSTD_LEGACY_SUPPORT=4",
        "-DZSTD_LZ4COMPRESS",
        "-DZSTD_LZ4DECOMPRES",
        "-DZSTD_LZMACOMPRESS",
        "-DZSTD_LZMADECOMPRES",
        "-DZSTD_MULTITHREAD",
    ],
    strip_include_prefix = "lib/",
    visibility = [
        "//visibility:public",
    ],
)
"""

http_archive(
    name = "zstd",
    url = "https://github.com/facebook/zstd/releases/download/v1.5.4/zstd-1.5.4.tar.gz",
    strip_prefix="zstd-1.5.4",
    build_file_content = zstd_content,
)

_RULES_BOOST_COMMIT = "ce6bd1a54c9527ffee7d0a87e97a2bdd50162ac2"

http_archive(
    name = "com_github_nelhage_rules_boost",
    strip_prefix = "rules_boost-%s" % _RULES_BOOST_COMMIT,
    sha256 = "781c5413ce5d5ae8e0f90e524dc712e0ccc329bf4d5dc5850d883e64db8eff9b",
    urls = [
        "https://github.com/nelhage/rules_boost/archive/%s.tar.gz" % _RULES_BOOST_COMMIT,
    ],
)

load("@com_github_nelhage_rules_boost//:boost/boost.bzl", "boost_deps")
boost_deps()

http_archive(
    name = "com_github_storypku_bazel_iwyu",
    strip_prefix = "bazel_iwyu-0.0.5",
    sha256 = "b4596e4f11e61c1ead77065dca8755fccff51e98a903b79ff61562c93ae7138d",
    urls = [
        "https://github.com/storypku/bazel_iwyu/archive/0.0.5.tar.gz",
    ],
)

load("@com_github_storypku_bazel_iwyu//bazel:dependencies.bzl", "bazel_iwyu_dependencies")
bazel_iwyu_dependencies()

git_repository(
       name = "bazel_clang_tidy",
       commit = "068891fa0720b9ce24ee9649ace0a5ce4f93e417",
       remote = "https://github.com/Lalaland/bazel_clang_tidy.git",
       shallow_since = "1665975942 +0000",
)

http_archive(
    name = "rules_cuda",
    strip_prefix = "rules_cuda-f5dda407d98443b3ec17bba209b92c697e2fe3a6",
    urls = ["https://github.com/bazel-contrib/rules_cuda/archive/f5dda407d98443b3ec17bba209b92c697e2fe3a6.zip"],
)

load("@rules_cuda//cuda:repositories.bzl", "register_detected_cuda_toolchains", "rules_cuda_dependencies")
rules_cuda_dependencies()
register_detected_cuda_toolchains()

dlpack_build = """filegroup(name = "all", srcs = glob(["**"]), visibility = ["//visibility:public"])"""

http_archive(
    name = "eigen",
    sha256 = "0215c6593c4ee9f1f7f28238c4e8995584ebf3b556e9dbf933d84feb98d5b9ef",
    strip_prefix = "eigen-3.3.8",
    urls = [
        "https://gitlab.com/libeigen/eigen/-/archive/3.3.8/eigen-3.3.8.tar.bz2",
    ],
    build_file_content =
"""
cc_library(
    name = 'eigen',
    srcs = [],
    includes = ['.'],
    hdrs = glob(['Eigen/**', 'unsupported/**']),
    visibility = ['//visibility:public'],
)
"""
)

http_archive(
    name = "cpp-base64",
    strip_prefix = "cpp-base64-2.rc.08",
    urls = [
        "https://github.com/ReneNyffenegger/cpp-base64/archive/refs/tags/V2.rc.08.zip",
    ],
    sha256 = "5e5366919938b834ca95fec4c2a80ad0c002872175d43226c933d25e40572883",
    build_file_content =
"""
cc_library(
    name = 'cpp-base64',
    srcs = ['base64.cpp'],
    includes = ['.'],
    hdrs = ['base64.h'],
    visibility = ['//visibility:public'],
)
"""
)
