Skip to content

Commit 718ffb7

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

File tree

7 files changed

+120
-99
lines changed

7 files changed

+120
-99
lines changed

bazel/external/zstd.BUILD

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
filegroup(
6+
name = "common_sources",
7+
srcs = glob([
8+
"lib/common/*.c",
9+
"lib/common/*.h",
10+
]),
11+
)
12+
13+
filegroup(
14+
name = "compress_sources",
15+
srcs = glob([
16+
"lib/compress/*.c",
17+
"lib/compress/*.h",
18+
]),
19+
)
20+
21+
filegroup(
22+
name = "decompress_sources",
23+
srcs = glob([
24+
"lib/decompress/*.c",
25+
"lib/decompress/*.h",
26+
]) + select({
27+
"@platforms//os:windows": [],
28+
"//conditions:default": glob(["lib/decompress/*.S"]),
29+
}),
30+
)
31+
32+
filegroup(
33+
name = "dictbuilder_sources",
34+
srcs = glob([
35+
"lib/dictBuilder/*.c",
36+
"lib/dictBuilder/*.h",
37+
]),
38+
)
39+
40+
cc_library(
41+
name = "zstd",
42+
srcs = [
43+
":common_sources",
44+
":compress_sources",
45+
":decompress_sources",
46+
":dictbuilder_sources",
47+
],
48+
hdrs = [
49+
"lib/zdict.h",
50+
"lib/zstd.h",
51+
"lib/zstd_errors.h",
52+
],
53+
includes = ["lib"],
54+
linkopts = ["-pthread"],
55+
linkstatic = True,
56+
local_defines = [
57+
"XXH_NAMESPACE=ZSTD_",
58+
"ZSTD_MULTITHREAD",
59+
"ZSTD_BUILD_SHARED=OFF",
60+
"ZSTD_BUILD_STATIC=ON",
61+
] + select({
62+
"@platforms//os:windows": ["ZSTD_DISABLE_ASM"],
63+
"//conditions:default": [],
64+
}),
65+
)
66+
67+
cc_library(
68+
name = "util",
69+
srcs = [
70+
"programs/platform.h",
71+
"programs/util.c",
72+
],
73+
hdrs = [
74+
"lib/common/compiler.h",
75+
"lib/common/debug.h",
76+
"lib/common/mem.h",
77+
"lib/common/portability_macros.h",
78+
"lib/common/zstd_deps.h",
79+
"programs/util.h",
80+
],
81+
)
82+
83+
cc_library(
84+
name = "datagen",
85+
srcs = [
86+
"programs/datagen.c",
87+
"programs/platform.h",
88+
],
89+
hdrs = ["programs/datagen.h"],
90+
deps = [":util"],
91+
)
92+
93+
cc_binary(
94+
name = "zstd_cli",
95+
srcs = glob(
96+
include = [
97+
"programs/*.c",
98+
"programs/*.h",
99+
],
100+
exclude = [
101+
"programs/datagen.c",
102+
"programs/datagen.h",
103+
"programs/platform.h",
104+
"programs/util.h",
105+
],
106+
),
107+
deps = [
108+
":datagen",
109+
":util",
110+
":zstd",
111+
],
112+
)

bazel/foreign_cc/BUILD

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -540,40 +540,10 @@ envoy_cmake(
540540
}),
541541
)
542542

543-
envoy_cmake(
543+
alias(
544544
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",
545+
actual = "@com_github_facebook_zstd//:zstd",
546+
visibility = ["//visibility:public"],
577547
)
578548

579549
envoy_cmake(

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():

source/common/compression/zstd/common/base.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
#include "envoy/buffer/buffer.h"
66

7-
#include "zstd.h"
7+
#include "lib/zstd.h"
88

99
namespace Envoy {
1010
namespace Compression {

source/extensions/compression/zstd/common/dictionary_manager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "source/common/config/datasource.h"
99

10-
#include "zstd.h"
10+
#include "lib/zstd.h"
1111

1212
namespace Envoy {
1313
namespace Extensions {

tools/zstd/BUILD

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
load(":zstd.bzl", "zstd")
2-
31
licenses(["notice"]) # Apache 2
42

5-
zstd(
3+
alias(
64
name = "zstd",
7-
target = "//bazel/foreign_cc:zstd",
5+
actual = "@com_github_facebook_zstd//:zstd_cli",
86
visibility = ["//visibility:public"],
97
)

tools/zstd/zstd.bzl

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)