diff --git a/utils/bazel/WORKSPACE b/utils/bazel/WORKSPACE --- a/utils/bazel/WORKSPACE +++ b/utils/bazel/WORKSPACE @@ -71,3 +71,13 @@ name = "vulkan_sdk", ) +maybe( + http_archive, + name = "llvm_zstd", + build_file = "@llvm-raw//utils/bazel/third_party_build:zstd.BUILD", + sha256 = "7c42d56fac126929a6a85dbc73ff1db2411d04f104fae9bdea51305663a83fd0", + strip_prefix = "zstd-1.5.2", + urls = [ + "https://github.com/facebook/zstd/releases/download/v1.5.2/zstd-1.5.2.tar.gz" + ], +) diff --git a/utils/bazel/llvm-project-overlay/lld/BUILD.bazel b/utils/bazel/llvm-project-overlay/lld/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/lld/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/lld/BUILD.bazel @@ -96,6 +96,7 @@ "//llvm:Passes", "//llvm:Support", "//llvm:TransformUtils", + "@llvm_zstd//:zstd", ], ) diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel --- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel @@ -278,6 +278,10 @@ # be an empty library unless zlib is enabled, in which case it will # both provide the necessary dependencies and configuration defines. "@llvm_zlib//:zlib", + # We unconditionally depend on the custom LLVM zstd wrapper. This will + # be an empty library unless zlib is enabled, in which case it will + # both provide the necessary dependencies and configuration defines. + "@llvm_zstd//:zstd", ], ) diff --git a/utils/bazel/third_party_build/zstd.BUILD b/utils/bazel/third_party_build/zstd.BUILD new file mode 100644 --- /dev/null +++ b/utils/bazel/third_party_build/zstd.BUILD @@ -0,0 +1,59 @@ +# This file is licensed under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +load("@bazel_skylib//rules:common_settings.bzl", "bool_flag") + +package( + default_visibility = ["//visibility:public"], + # BSD/MIT-like license (for zstd) + licenses = ["notice"], +) + +bool_flag( + name = "llvm_enable_zstd", + build_setting_default = True, +) + +config_setting( + name = "llvm_zstd_enabled", + flag_values = {":llvm_enable_zstd": "true"}, +) + +config_setting( + name = "llvm_zstd_disabled", + flag_values = {":llvm_enable_zstd": "false"}, +) + +cc_library( + name = "zstd", + srcs = select({ + ":llvm_zstd_disabled": [], + "//conditions:default": glob([ + "lib/common/*.c", + "lib/common/*.h", + "lib/compress/*.c", + "lib/compress/*.h", + "lib/decompress/*.c", + "lib/decompress/*.h", + "lib/decompress/*.S", + "lib/dictBuilder/*.c", + "lib/dictBuilder/*.h", + ]), + }), + hdrs = select({ + ":llvm_zstd_disabled": [], + "//conditions:default": [ + "lib/zstd.h", + "lib/zdict.h", + "lib/zstd_errors.h", + ], + }), + defines = select({ + ":llvm_zstd_disabled": [], + "//conditions:default": [ + "LLVM_ENABLE_ZSTD=1", + "ZSTD_MULTITHREAD", + ], + }), + includes = ["lib"], +)