Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion utils/bazel/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ 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(
llvm_repos_extension,
"gmp",
"llvm-raw",
"llvm_zlib",
"llvm_zstd",
"mpc",
"mpfr",
"nanobind",
Expand Down
17 changes: 4 additions & 13 deletions utils/bazel/MODULE.bazel.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions utils/bazel/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion utils/bazel/llvm-project-overlay/lld/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ cc_library(
"//llvm:TargetParser",
"//llvm:TransformUtils",
"//llvm:config",
"//third-party:zstd",
"@llvm_zlib//:zlib",
"@llvm_zstd//:zstd",
],
)

Expand Down
2 changes: 1 addition & 1 deletion utils/bazel/llvm-project-overlay/llvm/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

Expand Down
34 changes: 34 additions & 0 deletions utils/bazel/llvm-project-overlay/third-party/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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": [],
}),
)
Original file line number Diff line number Diff line change
@@ -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],
)
18 changes: 4 additions & 14 deletions utils/bazel/third_party_build/zstd.BUILD
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
# 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"],
# 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([
"@llvm-project//third-party:llvm_zstd_enabled": glob([
"lib/common/*.c",
"lib/common/*.h",
"lib/compress/*.c",
Expand All @@ -36,15 +26,15 @@ 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",
],
"//conditions:default": [],
}),
defines = select({
":llvm_zstd_enabled": [
"@llvm-project//third-party:llvm_zstd_enabled": [
"LLVM_ENABLE_ZSTD=1",
"ZSTD_MULTITHREAD",
],
Expand Down
Loading