diff --git a/utils/bazel/WORKSPACE b/utils/bazel/WORKSPACE --- a/utils/bazel/WORKSPACE +++ b/utils/bazel/WORKSPACE @@ -121,3 +121,14 @@ remote = "https://git.code.sf.net/p/perfmon2/libpfm4", tag = "v4.12.1", ) + +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 @@ -108,6 +108,7 @@ "//llvm:TargetParser", "//llvm:TransformUtils", "//llvm:config", + "@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 @@ -283,6 +283,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 zstd 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,54 @@ +# 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"}, +) + +cc_library( + name = "zstd", + srcs = select({ + ":llvm_zstd_enabled": 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", + ]), + "//conditions:default": [], + }), + hdrs = select({ + ":llvm_zstd_enabled": [ + "lib/zstd.h", + "lib/zdict.h", + "lib/zstd_errors.h", + ], + "//conditions:default": [], + }), + defines = select({ + ":llvm_zstd_enabled": [ + "LLVM_ENABLE_ZSTD=1", + "ZSTD_MULTITHREAD", + ], + "//conditions:default": [], + }), + strip_include_prefix = "lib", +)