load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:java.bzl", "java_import_external")
load("//bazel:python.bzl", "python_repository")
load("//bazel:tensorflow.bzl", "tensorflow_repository")
load("//bazel:tensorflow_hdrs.bzl", "tensorflow_hdrs_repository")
load("//bazel:libtorch.bzl", "libtorch_repository")

# Use an internal LLVM toolchain instead of the system one
http_archive(
    name = "com_grail_bazel_toolchain",
    patches = ["@//bazel:toolchain.patch"],
    sha256 = "dd6b7b877fe7e4f927c9c44b6ea4fbc94dd4c3c0ffe8f5deac28a33b3c78c866",
    strip_prefix = "bazel-toolchain-8570c4ccb39f750452b0b5607c9f54a093214f26",
    url = "https://github.com/grailbio/bazel-toolchain/archive/8570c4ccb39f750452b0b5607c9f54a093214f26.tar.gz",
)

load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain")

# This is a manylinux2014 compatible sysroot
http_archive(
    name = "manylinux2014_sysroot",
    build_file_content = """
filegroup(
  name = "sysroot",
  srcs = glob(["*/**"]),
  visibility = ["//visibility:public"],
)
""",
    sha256 = "2c5aa261bb7a124e2363b6f42f93e6188c44f2aa8871496adef61a653ccd0575",
    urls = ["https://github.com/VivekPanyam/manylinux-sysroot/releases/download/0.0.1/manylinux2014_sysroot.tar.gz"],
)

llvm_toolchain(
    name = "llvm_toolchain",
    llvm_version = "9.0.0",
    sysroot = {
        "linux": "@manylinux2014_sysroot//:sysroot",
    },
)

libtorch_repository(
    name = "libtorch_repo",
    build_file_template = "@//deps:BUILD.libtorch",
)

tensorflow_repository(
    name = "tensorflow_repo",
    build_file = "@//deps:BUILD.tensorflow",
)

tensorflow_hdrs_repository(
    name = "tensorflow_hdrs_repo",
    build_file_template = "@//deps:BUILD.tensorflow_hdrs",
)

http_archive(
    name = "libjsoncpp_repo",
    build_file = "@//deps:BUILD.libjsoncpp",
    sha256 = "c49deac9e0933bcb7044f08516861a2d560988540b23de2ac1ad443b219afdb6",
    strip_prefix = "jsoncpp-1.8.4",
    url = "https://github.com/open-source-parsers/jsoncpp/archive/1.8.4.tar.gz",
)

http_archive(
    name = "boost_repo",
    build_file = "@//deps:BUILD.boost",
    sha256 = "3b1db0b67079266c40b98329d85916e910bbadfc3db3e860c049056788d4d5cd",
    strip_prefix = "boost_1_68_0",
    type = "zip",
    urls = [
        "https://dl.bintray.com/boostorg/release/1.68.0/source/boost_1_68_0.zip",
        "https://sourceforge.net/projects/boost/files/boost/1.68.0/boost_1_68_0.zip",
    ],
)

http_archive(
    name = "pybind11_repo",
    build_file = "@//deps:BUILD.pybind11",
    sha256 = "1859f121837f6c41b0c6223d617b85a63f2f72132bae3135a2aa290582d61520",
    strip_prefix = "pybind11-2.5.0",
    type = "zip",
    url = "https://github.com/pybind/pybind11/archive/v2.5.0.zip",
)

python_repository(
    name = "python_repo",
    build_file_template = "@//deps:BUILD.python",
)

http_archive(
    name = "gtest",
    build_file = "@//deps:BUILD.gtest",
    patches = ["@//bazel:gtest.patch"],
    sha256 = "ae0b47c4d3e61446bdeb74f4ce098efda1c27d289b04afba6c29d2970e58c5b9",
    strip_prefix = "googletest-e6e2d3b7614ff4e6017d8968bd4c3f579133666e",
    url = "https://github.com/google/googletest/archive/e6e2d3b7614ff4e6017d8968bd4c3f579133666e.tar.gz",
)

http_archive(
    name = "benchmark",
    build_file = "@//deps:BUILD.benchmark",
    sha256 = "2d22dd3758afee43842bb504af1a8385cccb3ee1f164824e4837c1c1b04d92a0",
    strip_prefix = "benchmark-1.5.0",
    url = "https://github.com/google/benchmark/archive/v1.5.0.zip",
)

http_archive(
    name = "eigen3_repo",
    build_file = "@//deps:BUILD.eigen3",
    sha256 = "3b025b3f82f2b95eb66fced90521b798c169b00fb755ee7f48194cf2d6be2faf",
    strip_prefix = "eigen-git-mirror-3.2.10",
    url = "https://github.com/eigenteam/eigen-git-mirror/archive/3.2.10.zip",
)

http_archive(
    name = "mklml_repo_darwin",
    build_file = "@//deps:BUILD.mklml",
    sha256 = "2fbb71a0365d42a39ea7906568d69b1db3bfc9914fee75eedb06c5f32bf5fa68",
    strip_prefix = "mklml_mac_2019.0.5.20190502",
    url = "https://github.com/intel/mkl-dnn/releases/download/v0.19/mklml_mac_2019.0.5.20190502.tgz",
)

http_archive(
    name = "minizip_repo",
    build_file = "@//deps:BUILD.minizip",
    sha256 = "518e5b0f4e5529f2f939c4234f0101478142ca9b03e8afb2e17ae48742b008bc",
    strip_prefix = "minizip-ng-3.0.6",
    url = "https://github.com/zlib-ng/minizip-ng/archive/refs/tags/3.0.6.zip",
)

http_archive(
    name = "zlib_repo",
    build_file = "@//deps:BUILD.zlib",
    sha256 = "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff",
    strip_prefix = "zlib-1.2.11",
    url = "https://github.com/madler/zlib/archive/refs/tags/v1.2.11.tar.gz",
)

http_archive(
    name = "filesystem_repo",
    build_file = "@//deps:BUILD.filesystem",
    sha256 = "29b482791dc35a3099e5e27263cb75bf6d1e332e9b4ed6489cca82c0781818b5",
    strip_prefix = "filesystem-1.2.6",
    url = "https://github.com/gulrak/filesystem/archive/v1.2.6.zip",
)

http_archive(
    name = "picosha2_repo",
    build_file = "@//deps:BUILD.picosha2",
    sha256 = "d9b23652e4838eb84db96d9090cf143a8809c27d09207e74de90f2340f8a37e1",
    strip_prefix = "PicoSHA2-b699e6c900be6e00152db5a3d123c1db42ea13d0",
    url = "https://github.com/okdshin/PicoSHA2/archive/b699e6c900be6e00152db5a3d123c1db42ea13d0.zip",
)

http_archive(
    name = "spdlog_repo",
    build_file = "@//deps:BUILD.spdlog",
    sha256 = "56b90f0bd5b126cf1b623eeb19bf4369516fa68f036bbc22d9729d2da511fb5a",
    strip_prefix = "spdlog-1.4.2",
    url = "https://github.com/gabime/spdlog/archive/v1.4.2.zip",
)

http_archive(
    name = "fmt_repo",
    build_file = "@//deps:BUILD.fmt",
    sha256 = "2ba1469c1f7677e70cb32bcd7dd0907e6952e16a161f07e05c7ffa388643b607",
    strip_prefix = "fmt-5.3.0",
    url = "https://github.com/fmtlib/fmt/archive/5.3.0.zip",
)

http_archive(
    name = "semver_repo",
    build_file = "@//deps:BUILD.semver",
    patch_args = ["-p1"],
    patches = ["@//bazel:semver.patch"],
    sha256 = "3cb8b507c3389f8d8b80304360afc0ba8b3dbbe9504332d9b8f5d6793fb221e8",
    strip_prefix = "cpp-semver-ff341259099465283bc3dc60fb5ede16776e1607",
    url = "https://github.com/easz/cpp-semver/archive/ff341259099465283bc3dc60fb5ede16776e1607.zip",
)

http_archive(
    name = "pfr_repo",
    build_file = "@//deps:BUILD.pfr",
    sha256 = "92e0ffa3be49ffb21486e8e929dde599455fc1818054254bac832bcbc2c5491b",
    strip_prefix = "magic_get-1.0.0",
    url = "https://github.com/apolukhin/magic_get/archive/1.0.0.zip",
)

java_import_external(
    name = "junit",
    jar_sha256 = "59721f0805e223d84b90677887d9ff567dc534d7c502ca903c0c2b17f05c116a",
    jar_urls = [
        "https://repo1.maven.org/maven2/junit/junit/4.12/junit-4.12.jar",
        "https://maven.ibiblio.org/maven2/junit/junit/4.12/junit-4.12.jar",
    ],
    testonly_ = True,
    deps = ["@org_hamcrest_core"],
)

java_import_external(
    name = "org_hamcrest_core",
    jar_sha256 = "66fdef91e9739348df7a096aa384a5685f4e875584cce89386a7a47251c4d8e9",
    jar_urls = [
        "https://repo1.maven.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar",
        "https://maven.ibiblio.org/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar",
    ],
    testonly_ = True,
)
