[llvm] [bazel] Use zstd from the BCR (PR #169146)

Keith Smiley via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 21 21:32:45 PST 2025


https://github.com/keith created https://github.com/llvm/llvm-project/pull/169146

This way if the downstream consuming project uses zstd we make sure
they are dedup'd.


>From a49686cb129113924c36a8c79e4193b8a3d533c7 Mon Sep 17 00:00:00 2001
From: Keith Smiley <keithbsmiley at gmail.com>
Date: Fri, 21 Nov 2025 21:29:35 -0800
Subject: [PATCH] [bazel] Use zstd from the BCR

This way if the downstream consuming project uses zstd we make sure
they are dedup'd.
---
 utils/bazel/MODULE.bazel                      |  3 +-
 utils/bazel/MODULE.bazel.lock                 | 17 ++----
 utils/bazel/extensions.bzl                    | 10 ----
 .../llvm-project-overlay/lld/BUILD.bazel      |  2 +-
 .../llvm-project-overlay/llvm/BUILD.bazel     |  2 +-
 .../third-party/BUILD.bazel                   | 40 ++++++++++++++
 utils/bazel/third_party_build/zstd.BUILD      | 54 -------------------
 7 files changed, 48 insertions(+), 80 deletions(-)
 create mode 100644 utils/bazel/llvm-project-overlay/third-party/BUILD.bazel
 delete mode 100644 utils/bazel/third_party_build/zstd.BUILD

diff --git a/utils/bazel/MODULE.bazel b/utils/bazel/MODULE.bazel
index 1a8327c33d246..bd398deda7a9e 100644
--- a/utils/bazel/MODULE.bazel
+++ b/utils/bazel/MODULE.bazel
@@ -22,7 +22,6 @@ use_repo(
     "gmp",
     "llvm-raw",
     "llvm_zlib",
-    "llvm_zstd",
     "mpc",
     "mpfr",
     "nanobind",
@@ -34,6 +33,8 @@ use_repo(
     "vulkan_sdk",
 )
 
+bazel_dep(name = "zstd", version = "1.5.7", repo_name = "llvm_zstd")
+
 llvm_configure = use_repo_rule("@llvm-raw//utils/bazel:configure.bzl", "llvm_configure")
 
 llvm_configure(name = "llvm-project")
diff --git a/utils/bazel/MODULE.bazel.lock b/utils/bazel/MODULE.bazel.lock
index 3b196231c6723..c923f3aaea68d 100644
--- a/utils/bazel/MODULE.bazel.lock
+++ b/utils/bazel/MODULE.bazel.lock
@@ -224,13 +224,15 @@
     "https://bcr.bazel.build/modules/zlib/1.2.12/MODULE.bazel": "3b1a8834ada2a883674be8cbd36ede1b6ec481477ada359cd2d3ddc562340b27",
     "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/MODULE.bazel": "eec517b5bbe5492629466e11dae908d043364302283de25581e3eb944326c4ca",
     "https://bcr.bazel.build/modules/zlib/1.3.1.bcr.5/source.json": "22bc55c47af97246cfc093d0acf683a7869377de362b5d1c552c2c2e16b7a806",
-    "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198"
+    "https://bcr.bazel.build/modules/zlib/1.3.1/MODULE.bazel": "751c9940dcfe869f5f7274e1295422a34623555916eb98c174c1e945594bf198",
+    "https://bcr.bazel.build/modules/zstd/1.5.7/MODULE.bazel": "f5780cdbd6f4c5bb985a20f839844316fe48fb5e463056f372dbc37cfabdf450",
+    "https://bcr.bazel.build/modules/zstd/1.5.7/source.json": "f72c48184b6528ffc908a5a2bcbf3070c6684f3db03da2182c8ca999ae5f5cfd"
   },
   "selectedYankedVersions": {},
   "moduleExtensions": {
     "//:extensions.bzl%llvm_repos_extension": {
       "general": {
-        "bzlTransitiveDigest": "ojj7cD2YU2vcH58jVPVj2juUYn5SvdSNj1pmWb8Xo/k=",
+        "bzlTransitiveDigest": "05R8ZuqDbhn1LOyXHQzta+x0dI9dEY6RIu21atUo+Kw=",
         "usagesDigest": "X0yUkkWyxQ2Y5oZVDkRSE/K4YkDWo1IjhHsL+1weKyU=",
         "recordedFileInputs": {},
         "recordedDirentsInputs": {},
@@ -314,17 +316,6 @@
               "build_file": "@@+llvm_repos_extension+llvm-raw//utils/bazel/third_party_build:pfm.BUILD"
             }
           },
-          "llvm_zstd": {
-            "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
-            "attributes": {
-              "build_file": "@@+llvm_repos_extension+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"
-              ]
-            }
-          },
           "pybind11": {
             "repoRuleId": "@@bazel_tools//tools/build_defs/repo:http.bzl%http_archive",
             "attributes": {
diff --git a/utils/bazel/extensions.bzl b/utils/bazel/extensions.bzl
index bb5ce1955f916..e57046530aa89 100644
--- a/utils/bazel/extensions.bzl
+++ b/utils/bazel/extensions.bzl
@@ -79,16 +79,6 @@ def _llvm_repos_extension_impl(module_ctx):
         build_file = "@llvm-raw//utils/bazel/third_party_build:pfm.BUILD",
     )
 
-    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",
-        ],
-    )
-
     http_archive(
         name = "pybind11",
         url = "https://github.com/pybind/pybind11/archive/v2.10.3.zip",
diff --git a/utils/bazel/llvm-project-overlay/lld/BUILD.bazel b/utils/bazel/llvm-project-overlay/lld/BUILD.bazel
index 162c4f955d150..b903aef10692b 100644
--- a/utils/bazel/llvm-project-overlay/lld/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/lld/BUILD.bazel
@@ -105,8 +105,8 @@ cc_library(
         "//llvm:TargetParser",
         "//llvm:TransformUtils",
         "//llvm:config",
+        "//third_party:zstd",
         "@llvm_zlib//:zlib",
-        "@llvm_zstd//:zstd",
     ],
 )
 
diff --git a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
index f67e4ea29b51f..b59e6ea973f14 100644
--- a/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
@@ -331,7 +331,7 @@ cc_library(
         # 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",
+        "//third-party:zstd",
     ],
 )
 
diff --git a/utils/bazel/llvm-project-overlay/third-party/BUILD.bazel b/utils/bazel/llvm-project-overlay/third-party/BUILD.bazel
new file mode 100644
index 0000000000000..cf7a91fca160f
--- /dev/null
+++ b/utils/bazel/llvm-project-overlay/third-party/BUILD.bazel
@@ -0,0 +1,40 @@
+# 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")
+load("@rules_cc//cc:defs.bzl", "cc_library")
+
+cc_library(name = "empty_lib")
+
+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_wrapper",
+    defines = select({
+        ":llvm_zstd_enabled": [
+            "LLVM_ENABLE_ZSTD=1",
+            "ZSTD_MULTITHREAD",
+        ],
+        "//conditions:default": [],
+    }),
+    deps = [
+        "@llvm_zstd//:zstd",
+    ],
+)
+
+alias(
+    name = "zstd",
+    actual = select({
+        ":llvm_zstd_enabled": ":zstd_wrapper",
+        "//conditions:default": ":empty_lib",
+    }),
+    visibility = ["//visibility:public"],
+)
diff --git a/utils/bazel/third_party_build/zstd.BUILD b/utils/bazel/third_party_build/zstd.BUILD
deleted file mode 100644
index 7d022d4226de1..0000000000000
--- a/utils/bazel/third_party_build/zstd.BUILD
+++ /dev/null
@@ -1,54 +0,0 @@
-# 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/zdict.h",
-            "lib/zstd.h",
-            "lib/zstd_errors.h",
-        ],
-        "//conditions:default": [],
-    }),
-    defines = select({
-        ":llvm_zstd_enabled": [
-            "LLVM_ENABLE_ZSTD=1",
-            "ZSTD_MULTITHREAD",
-        ],
-        "//conditions:default": [],
-    }),
-    strip_include_prefix = "lib",
-)



More information about the llvm-commits mailing list