diff --git a/utils/bazel/MODULE.bazel b/utils/bazel/MODULE.bazel index 1a8327c33d246..cf760ba24cb4c 100644 --- a/utils/bazel/MODULE.bazel +++ b/utils/bazel/MODULE.bazel @@ -15,6 +15,7 @@ bazel_dep(name = "rules_cc", version = "0.2.11") bazel_dep(name = "rules_foreign_cc", version = "0.15.1") bazel_dep(name = "rules_python", version = "1.6.3") bazel_dep(name = "rules_shell", version = "0.6.1") +bazel_dep(name = "zstd", version = "1.5.7", repo_name = "llvm_zstd") llvm_repos_extension = use_extension(":extensions.bzl", "llvm_repos_extension") use_repo( @@ -22,7 +23,6 @@ use_repo( "gmp", "llvm-raw", "llvm_zlib", - "llvm_zstd", "mpc", "mpfr", "nanobind", 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..8a03266da6327 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..bf780b5f3c0bf --- /dev/null +++ b/utils/bazel/llvm-project-overlay/third-party/BUILD.bazel @@ -0,0 +1,34 @@ +# 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(":cc_library_wrapper.bzl", "cc_library_wrapper") + +package(default_visibility = ["//visibility:public"]) + +bool_flag( + name = "llvm_enable_zstd", + build_setting_default = True, +) + +config_setting( + name = "llvm_zstd_enabled", + flag_values = {":llvm_enable_zstd": "true"}, +) + +cc_library_wrapper( + name = "zstd", + defines = select({ + ":llvm_zstd_enabled": [ + "LLVM_ENABLE_ZSTD=1", + "ZSTD_MULTITHREAD", + ], + "//conditions:default": [], + }), + deps = select({ + ":llvm_zstd_enabled": [ + "@llvm_zstd//:zstd", + ], + "//conditions:default": [], + }), +) diff --git a/utils/bazel/llvm-project-overlay/third-party/cc_library_wrapper.bzl b/utils/bazel/llvm-project-overlay/third-party/cc_library_wrapper.bzl new file mode 100644 index 0000000000000..b484a611571e3 --- /dev/null +++ b/utils/bazel/llvm-project-overlay/third-party/cc_library_wrapper.bzl @@ -0,0 +1,50 @@ +# 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 + +"""Re-export a cc_library with added LLVM specific settings. + +This re-exports the dependent libraries in a way that satisfies layering_check + +cc_library_wrapper( + name = "library_wrapper", + deps = [ + "@example//:library", + ], + defines = [ + "LLVM_ENABLE_EXAMPLE=1", + ], +) +""" + +load("@rules_cc//cc/common:cc_common.bzl", "cc_common") +load("@rules_cc//cc/common:cc_info.bzl", "CcInfo") + +visibility("private") + +def _cc_library_wrapper_impl(ctx): + all_cc_infos = [dep[CcInfo] for dep in ctx.attr.deps] + if ctx.attr.defines: + all_cc_infos.append(CcInfo( + compilation_context = cc_common.create_compilation_context( + defines = depset(ctx.attr.defines), + ), + )) + + return cc_common.merge_cc_infos(direct_cc_infos = all_cc_infos) + +cc_library_wrapper = rule( + implementation = _cc_library_wrapper_impl, + attrs = { + "deps": attr.label_list( + doc = "Dependencies to cc_library targets to re-export.", + providers = [CcInfo], + ), + "defines": attr.string_list( + doc = "Additional preprocessor definitions to add to all dependent targets.", + default = [], + ), + }, + doc = "Re-export a cc_library with added LLVM specific settings.", + provides = [CcInfo], +) diff --git a/utils/bazel/third_party_build/zstd.BUILD b/utils/bazel/third_party_build/zstd.BUILD index 7d022d4226de1..89da165225ad7 100644 --- a/utils/bazel/third_party_build/zstd.BUILD +++ b/utils/bazel/third_party_build/zstd.BUILD @@ -1,7 +1,7 @@ # 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:cc_library.bzl", "cc_library") package( default_visibility = ["//visibility:public"], @@ -9,20 +9,10 @@ package( 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([ + "@llvm-project//third-party:llvm_zstd_enabled": glob([ "lib/common/*.c", "lib/common/*.h", "lib/compress/*.c", @@ -36,7 +26,7 @@ cc_library( "//conditions:default": [], }), hdrs = select({ - ":llvm_zstd_enabled": [ + "@llvm-project//third-party:llvm_zstd_enabled": [ "lib/zdict.h", "lib/zstd.h", "lib/zstd_errors.h", @@ -44,7 +34,7 @@ cc_library( "//conditions:default": [], }), defines = select({ - ":llvm_zstd_enabled": [ + "@llvm-project//third-party:llvm_zstd_enabled": [ "LLVM_ENABLE_ZSTD=1", "ZSTD_MULTITHREAD", ],