Skip to content

Commit 4cecd21

Browse files
committed
deps: migrate zstd to BCR-compatible native Bazel build for bzlmod
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 6963766 commit 4cecd21

File tree

12 files changed

+180
-110
lines changed

12 files changed

+180
-110
lines changed

bazel/external/zstd.BUILD

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
""" Builds zstd.
2+
"""
3+
4+
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test")
5+
6+
package(default_visibility = ["//visibility:public"])
7+
8+
filegroup(
9+
name = "common_sources",
10+
srcs = glob([
11+
"lib/common/*.c",
12+
"lib/common/*.h",
13+
]),
14+
)
15+
16+
filegroup(
17+
name = "compress_sources",
18+
srcs = glob([
19+
"lib/compress/*.c",
20+
"lib/compress/*.h",
21+
]),
22+
)
23+
24+
filegroup(
25+
name = "decompress_sources",
26+
srcs = glob([
27+
"lib/decompress/*.c",
28+
"lib/decompress/*.h",
29+
]) + select({
30+
"@platforms//os:windows": [],
31+
"//conditions:default": glob(["lib/decompress/*.S"]),
32+
}),
33+
)
34+
35+
filegroup(
36+
name = "dictbuilder_sources",
37+
srcs = glob([
38+
"lib/dictBuilder/*.c",
39+
"lib/dictBuilder/*.h",
40+
]),
41+
)
42+
43+
cc_library(
44+
name = "zstd",
45+
srcs = [
46+
":common_sources",
47+
":compress_sources",
48+
":decompress_sources",
49+
":dictbuilder_sources",
50+
],
51+
hdrs = [
52+
"lib/zdict.h",
53+
"lib/zstd.h",
54+
"lib/zstd_errors.h",
55+
],
56+
includes = ["lib"],
57+
linkopts = ["-pthread"],
58+
linkstatic = True,
59+
local_defines = [
60+
"XXH_NAMESPACE=ZSTD_",
61+
"ZSTD_MULTITHREAD",
62+
"ZSTD_BUILD_SHARED=OFF",
63+
"ZSTD_BUILD_STATIC=ON",
64+
] + select({
65+
"@platforms//os:windows": ["ZSTD_DISABLE_ASM"],
66+
"//conditions:default": [],
67+
}),
68+
)
69+
70+
cc_binary(
71+
name = "zstd_cli",
72+
srcs = glob(
73+
include = [
74+
"programs/*.c",
75+
"programs/*.h",
76+
],
77+
exclude = [
78+
"programs/datagen.c",
79+
"programs/datagen.h",
80+
"programs/platform.h",
81+
"programs/util.h",
82+
],
83+
),
84+
deps = [
85+
":datagen",
86+
":util",
87+
":zstd",
88+
],
89+
)
90+
91+
cc_library(
92+
name = "util",
93+
srcs = [
94+
"programs/platform.h",
95+
"programs/util.c",
96+
],
97+
hdrs = [
98+
"lib/common/compiler.h",
99+
"lib/common/debug.h",
100+
"lib/common/mem.h",
101+
"lib/common/portability_macros.h",
102+
"lib/common/zstd_deps.h",
103+
"programs/util.h",
104+
],
105+
)
106+
107+
cc_library(
108+
name = "datagen",
109+
srcs = [
110+
"programs/datagen.c",
111+
"programs/platform.h",
112+
],
113+
hdrs = ["programs/datagen.h"],
114+
deps = [":util"],
115+
)
116+
117+
cc_binary(
118+
name = "datagen_cli",
119+
srcs = [
120+
"programs/lorem.c",
121+
"programs/lorem.h",
122+
"tests/datagencli.c",
123+
"tests/loremOut.c",
124+
"tests/loremOut.h",
125+
],
126+
includes = [
127+
"programs",
128+
"tests",
129+
],
130+
deps = [":datagen"],
131+
)
132+
133+
cc_test(
134+
name = "fullbench",
135+
srcs = [
136+
"lib/decompress/zstd_decompress_internal.h",
137+
"programs/benchfn.c",
138+
"programs/benchfn.h",
139+
"programs/benchzstd.c",
140+
"programs/benchzstd.h",
141+
"programs/lorem.c",
142+
"programs/lorem.h",
143+
"programs/timefn.c",
144+
"programs/timefn.h",
145+
"tests/fullbench.c",
146+
"tests/loremOut.c",
147+
"tests/loremOut.h",
148+
],
149+
copts = select({
150+
"@platforms//os:windows": [],
151+
"//conditions:default": ["-Wno-deprecated-declarations"],
152+
}),
153+
includes = [
154+
"lib/common",
155+
"programs",
156+
"tests",
157+
],
158+
deps = [
159+
":datagen",
160+
":zstd",
161+
],
162+
)

bazel/foreign_cc/BUILD

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -540,42 +540,6 @@ envoy_cmake(
540540
}),
541541
)
542542

543-
envoy_cmake(
544-
name = "zstd",
545-
build_args = select({
546-
"//bazel/foreign_cc:parallel_builds_enabled": ["-j"],
547-
"//bazel:engflow_rbe_x86_64": ["-j"],
548-
"//bazel:engflow_rbe_aarch64": ["-j"],
549-
"//conditions:default": ["-j1"],
550-
}),
551-
build_data = ["@com_github_facebook_zstd//:all"],
552-
cache_entries = {
553-
"CMAKE_BUILD_TYPE": "Release",
554-
"CMAKE_INSTALL_LIBDIR": "lib",
555-
"ZSTD_BUILD_SHARED": "off",
556-
"ZSTD_BUILD_STATIC": "on",
557-
},
558-
exec_properties = select({
559-
"//bazel:engflow_rbe_x86_64": {
560-
"Pool": "linux_x64_large",
561-
},
562-
"//bazel:engflow_rbe_aarch64": {
563-
"Pool": "linux_arm64_small",
564-
},
565-
"//conditions:default": {},
566-
}),
567-
generate_args = [
568-
"-G",
569-
"Ninja",
570-
],
571-
lib_source = "@com_github_facebook_zstd//:all",
572-
out_static_libs = select({
573-
"//bazel:windows_x86_64": ["zstd_static.lib"],
574-
"//conditions:default": ["libzstd.a"],
575-
}),
576-
working_directory = "build/cmake",
577-
)
578-
579543
envoy_cmake(
580544
name = "maxmind",
581545
build_args = select({

bazel/repositories.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ def _org_brotli():
506506
def _com_github_facebook_zstd():
507507
external_http_archive(
508508
name = "com_github_facebook_zstd",
509-
build_file_content = BUILD_ALL_CONTENT,
509+
build_file = "@envoy//bazel/external:zstd.BUILD",
510510
)
511511

512512
def _com_google_cel_cpp():

ci/do_ci.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -539,12 +539,12 @@ case $CI_TARGET in
539539
fi
540540

541541
bazel run "${BAZEL_BUILD_OPTIONS[@]}" \
542-
//tools/zstd \
542+
@com_github_facebook_zstd//:zstd_cli \
543543
-- --stdout \
544544
-d "$ENVOY_RELEASE_TARBALL" \
545545
| tar xfO - envoy > distribution/custom/envoy
546546
bazel run "${BAZEL_BUILD_OPTIONS[@]}" \
547-
//tools/zstd \
547+
@com_github_facebook_zstd//:zstd_cli \
548548
-- --stdout \
549549
-d "$ENVOY_RELEASE_TARBALL" \
550550
| tar xfO - envoy-contrib > distribution/custom/envoy-contrib

contrib/qat/compression/qatzstd/compressor/source/BUILD

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ make(
1515
build_data = ["@com_github_qat_zstd//:all"],
1616
env = select({
1717
"//bazel:clang_build": {
18-
"CFLAGS": "-Wno-error=unused-parameter -Wno-error=unused-command-line-argument -I$$EXT_BUILD_DEPS/qatlib/include -I$$EXT_BUILD_DEPS/zstd/include",
18+
"CFLAGS": "-Wno-error=unused-parameter -Wno-error=unused-command-line-argument -I$$EXT_BUILD_DEPS/qatlib/include",
19+
"ZSTDLIB": "$$EXT_BUILD_ROOT/external/com_github_facebook_zstd/lib",
1920
},
2021
"//conditions:default": {
21-
"CFLAGS": "-I$$EXT_BUILD_DEPS/qatlib/include -I$$EXT_BUILD_DEPS/zstd/include",
22+
"CFLAGS": "-I$$EXT_BUILD_DEPS/qatlib/include",
23+
"ZSTDLIB": "$$EXT_BUILD_ROOT/external/com_github_facebook_zstd/lib",
2224
},
2325
}),
2426
includes = [],

distribution/binary/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ pkg_tar(
3636
srcs = [
3737
":release_files",
3838
],
39-
compressor = "//tools/zstd",
39+
compressor = "@com_github_facebook_zstd//:zstd_cli",
4040
compressor_args = "-T0",
4141
extension = "tar.zst",
4242
)

test/run_envoy_bazel_coverage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ unpack_coverage_report() {
9797
mkdir -p "${COVERAGE_DIR}"
9898
rm -f bazel-out/_coverage/_coverage_report.tar.zst
9999
mv bazel-out/_coverage/_coverage_report.dat bazel-out/_coverage/_coverage_report.tar.zst
100-
bazel run "${BAZEL_BUILD_OPTIONS[@]}" --nobuild_tests_only @envoy//tools/zstd -- -d -c "${PWD}/bazel-out/_coverage/_coverage_report.tar.zst" \
100+
bazel run "${BAZEL_BUILD_OPTIONS[@]}" --nobuild_tests_only @com_github_facebook_zstd//:zstd_cli -- -d -c "${PWD}/bazel-out/_coverage/_coverage_report.tar.zst" \
101101
| tar -xf - -C "${COVERAGE_DIR}"
102102
COVERAGE_JSON="${COVERAGE_DIR}/coverage.json"
103103
}

tools/coverage/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ sh_binary(
7676
":templates/base.html",
7777
":templates/index.html",
7878
":templates/macros.html",
79-
"//tools/zstd",
79+
"@com_github_facebook_zstd//:zstd_cli",
8080
"@jq_toolchains//:resolved_toolchain",
8181
],
8282
toolchains = ["@jq_toolchains//:resolved_toolchain"],

tools/coverage/report_generator.sh.template

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ done
2222
find_file() {
2323
# kinda wierd to use PYTHON_RUNFILES but that is what is available in the
2424
# bazel generator customization
25-
find "${PYTHON_RUNFILES}" -type f -o -type l -name "${1}" -path "*/tools/coverage/**/*" | head -1
25+
find "${PYTHON_RUNFILES}" \( -type f -o -type l \) -name "${1}" -path "*/tools/**/*" | head -1
2626
}
2727

2828
GRCOV="$(find_file grcov_bin)"
2929
GRCOV_CONFIG="$(find_file grcov_config.json)"
3030
COVERAGE_CONFIG="$(find_file "*coverage_config.json")"
3131
JQ_BIN="$(find_file jq)"
32-
ZSTD_BIN="$(find_file zstd)"
32+
ZSTD_BIN="$(find_file zstd_cli)"
3333
TEMPLATES_DIR="$(dirname "$(find_file base.html)")"
3434
JQ_FILTER="$(find_file "filter.jq")"
3535
INFO_FILES=()

tools/tarball/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ licenses(["notice"]) # Apache 2
44

55
unpacker(
66
name = "unpack",
7-
zstd = "//tools/zstd",
7+
zstd = "@com_github_facebook_zstd//:zstd_cli",
88
)

0 commit comments

Comments
 (0)