# Description:
# BLAKE3 is a very fast cryptographic hash function, see README.md for details.
#

load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")

package(default_visibility = ["//visibility:public"])

licenses(["unencumbered"])  # Creative Commons CC0

exports_files(["LICENSE"])

config_setting(
    name = "x86_64_windows",
    constraint_values = [
        "@platforms//cpu:x86_64",
        "@platforms//os:windows",
    ],
)

cc_library(
    name = "blake3",
    srcs = [
        "c/blake3.c",
        "c/blake3_dispatch.c",
        "c/blake3_portable.c",
    ] + select({
        ":x86_64_windows": [
            "c/blake3_avx2_x86-64_windows_msvc.asm",
            "c/blake3_avx512_x86-64_windows_msvc.asm",
            "c/blake3_sse2_x86-64_windows_msvc.asm",
            "c/blake3_sse41_x86-64_windows_msvc.asm",
        ],
        "@platforms//cpu:arm64": [
            "c/blake3_neon.c",
        ],
        "@platforms//cpu:x86_64": [
            "c/blake3_avx2_x86-64_unix.S",
            "c/blake3_avx512_x86-64_unix.S",
            "c/blake3_sse2_x86-64_unix.S",
            "c/blake3_sse41_x86-64_unix.S",
        ],
    }),
    hdrs = [
        "c/blake3.h",
        "c/blake3_impl.h",
    ],
    includes = ["c"],
)

cc_binary(
    name = "example",
    srcs = ["c/example.c"],
    deps = [":blake3"],
)
