Skip to content

Commit c3de37e

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

File tree

17 files changed

+506
-122
lines changed

17 files changed

+506
-122
lines changed

MODULE.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ module(
33
version = "1.37.0-dev",
44
)
55

6+
bazel_dep(name = "aspect_bazel_lib", version = "2.21.2")
67
bazel_dep(name = "envoy_api", version = "1.37.0-dev")
78
bazel_dep(name = "envoy_build_config", version = "1.37.0-dev")
89
bazel_dep(name = "envoy_mobile", version = "1.37.0-dev")
10+
bazel_dep(name = "rules_python", version = "1.6.3")
11+
bazel_dep(name = "rules_shell", version = "0.6.1")
12+
bazel_dep(name = "zstd", version = "1.5.7")
913

1014
local_path_override(
1115
module_name = "envoy_api",

MODULE.bazel.lock

Lines changed: 315 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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
@@ -551,42 +551,6 @@ envoy_cmake(
551551
}),
552552
)
553553

554-
envoy_cmake(
555-
name = "zstd",
556-
build_args = select({
557-
"//bazel/foreign_cc:parallel_builds_enabled": ["-j"],
558-
"//bazel:engflow_rbe_x86_64": ["-j"],
559-
"//bazel:engflow_rbe_aarch64": ["-j"],
560-
"//conditions:default": ["-j1"],
561-
}),
562-
build_data = ["@com_github_facebook_zstd//:all"],
563-
cache_entries = {
564-
"CMAKE_BUILD_TYPE": "Release",
565-
"CMAKE_INSTALL_LIBDIR": "lib",
566-
"ZSTD_BUILD_SHARED": "off",
567-
"ZSTD_BUILD_STATIC": "on",
568-
},
569-
exec_properties = select({
570-
"//bazel:engflow_rbe_x86_64": {
571-
"Pool": "linux_x64_large",
572-
},
573-
"//bazel:engflow_rbe_aarch64": {
574-
"Pool": "linux_arm64_small",
575-
},
576-
"//conditions:default": {},
577-
}),
578-
generate_args = [
579-
"-G",
580-
"Ninja",
581-
],
582-
lib_source = "@com_github_facebook_zstd//:all",
583-
out_static_libs = select({
584-
"//bazel:windows_x86_64": ["zstd_static.lib"],
585-
"//conditions:default": ["libzstd.a"],
586-
}),
587-
working_directory = "build/cmake",
588-
)
589-
590554
envoy_cmake(
591555
name = "maxmind",
592556
build_args = select({

bazel/repositories.bzl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def envoy_dependencies(skip_targets = []):
205205
_com_github_zlib_ng_zlib_ng()
206206
_org_boost()
207207
_org_brotli()
208-
_com_github_facebook_zstd()
208+
_zstd()
209209
_re2()
210210
_proxy_wasm_cpp_sdk()
211211
_proxy_wasm_cpp_host()
@@ -503,10 +503,10 @@ def _org_brotli():
503503
name = "org_brotli",
504504
)
505505

506-
def _com_github_facebook_zstd():
506+
def _zstd():
507507
external_http_archive(
508-
name = "com_github_facebook_zstd",
509-
build_file_content = BUILD_ALL_CONTENT,
508+
name = "zstd",
509+
build_file = "@envoy//bazel/external:zstd.BUILD",
510510
)
511511

512512
def _com_google_cel_cpp():

bazel/repository_locations.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -798,7 +798,7 @@ REPOSITORY_LOCATIONS_SPEC = dict(
798798
license = "MIT",
799799
license_url = "https://github.com/google/brotli/blob/v{version}/LICENSE",
800800
),
801-
com_github_facebook_zstd = dict(
801+
zstd = dict(
802802
project_name = "zstd",
803803
project_desc = "zstd compression library",
804804
project_url = "https://facebook.github.io/zstd",

ci/do_ci.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,12 @@ case $CI_TARGET in
542542
fi
543543

544544
bazel run "${BAZEL_BUILD_OPTIONS[@]}" \
545-
//tools/zstd \
545+
@zstd//:zstd_cli \
546546
-- --stdout \
547547
-d "$ENVOY_RELEASE_TARBALL" \
548548
| tar xfO - envoy > distribution/custom/envoy
549549
bazel run "${BAZEL_BUILD_OPTIONS[@]}" \
550-
//tools/zstd \
550+
@zstd//:zstd_cli \
551551
-- --stdout \
552552
-d "$ENVOY_RELEASE_TARBALL" \
553553
| tar xfO - envoy-contrib > distribution/custom/envoy-contrib

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

Lines changed: 5 additions & 3 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/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/zstd/lib",
2224
},
2325
}),
2426
includes = [],
@@ -34,8 +36,8 @@ make(
3436
"install",
3537
],
3638
deps = [
37-
"//bazel/foreign_cc:zstd",
3839
"//contrib/qat:qatlib",
40+
"@zstd",
3941
],
4042
)
4143

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 = "@zstd//:zstd_cli",
4040
compressor_args = "-T0",
4141
extension = "tar.zst",
4242
)

source/common/compression/zstd/common/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ envoy_cc_library(
1313
srcs = ["base.cc"],
1414
hdrs = ["base.h"],
1515
deps = [
16-
"//bazel/foreign_cc:zstd",
1716
"//source/common/buffer:buffer_lib",
17+
"@zstd",
1818
],
1919
)

0 commit comments

Comments
 (0)