|
1 |
| -# Copyright 2023 The XLS Authors |
| 1 | +# Copyright 2024 The XLS Authors |
2 | 2 | #
|
3 | 3 | # Licensed under the Apache License, Version 2.0 (the "License");
|
4 | 4 | # you may not use this file except in compliance with the License.
|
|
12 | 12 | # See the License for the specific language governing permissions and
|
13 | 13 | # limitations under the License.
|
14 | 14 |
|
15 |
| -package(default_visibility = ["//visibility:public"]) |
| 15 | +""" Builds zstd. |
| 16 | +""" |
16 | 17 |
|
17 |
| -licenses(["notice"]) |
| 18 | +load("@rules_cc//cc:defs.bzl", "cc_binary", "cc_library", "cc_test") |
18 | 19 |
|
19 |
| -# Builds everything together similarly to the zstd cmake file: |
20 |
| -# https://github.com/facebook/zstd/blob/dev/build/cmake/lib/CMakeLists.txt |
21 |
| -# but with legacy support and defines as in the zstd BUCK file: |
22 |
| -# https://github.com/facebook/zstd/blob/dev/lib/BUCK |
| 20 | +package(default_visibility = ["//visibility:public"]) |
23 | 21 |
|
24 |
| -cc_library( |
25 |
| - name = "zstd", |
| 22 | +filegroup( |
| 23 | + name = "common_sources", |
26 | 24 | srcs = glob([
|
27 |
| - "lib/common/*.h", |
28 | 25 | "lib/common/*.c",
|
29 |
| - "lib/compress/*.h", |
| 26 | + "lib/common/*.h", |
| 27 | + ]), |
| 28 | +) |
| 29 | + |
| 30 | +filegroup( |
| 31 | + name = "compress_sources", |
| 32 | + srcs = glob([ |
30 | 33 | "lib/compress/*.c",
|
31 |
| - "lib/decompress/*.h", |
| 34 | + "lib/compress/*.h", |
| 35 | + ]), |
| 36 | +) |
| 37 | + |
| 38 | +filegroup( |
| 39 | + name = "decompress_sources", |
| 40 | + srcs = glob([ |
32 | 41 | "lib/decompress/*.c",
|
33 |
| - "lib/decompress/*.S", |
34 |
| - "lib/deprecated/*.h", |
35 |
| - "lib/deprecated/*.c", |
36 |
| - "lib/dictBuilder/*.h", |
| 42 | + "lib/decompress/*.h", |
| 43 | + ]) + select({ |
| 44 | + "@platforms//os:windows": [], |
| 45 | + "//conditions:default": glob(["lib/decompress/*.S"]), |
| 46 | + }), |
| 47 | +) |
| 48 | + |
| 49 | +filegroup( |
| 50 | + name = "dictbuilder_sources", |
| 51 | + srcs = glob([ |
37 | 52 | "lib/dictBuilder/*.c",
|
38 |
| - "lib/legacy/*.h", |
39 |
| - "lib/legacy/*.c", |
| 53 | + "lib/dictBuilder/*.h", |
40 | 54 | ]),
|
| 55 | +) |
| 56 | + |
| 57 | +cc_library( |
| 58 | + name = "zstd", |
| 59 | + srcs = [ |
| 60 | + ":common_sources", |
| 61 | + ":compress_sources", |
| 62 | + ":decompress_sources", |
| 63 | + ":dictbuilder_sources", |
| 64 | + ], |
41 | 65 | hdrs = [
|
| 66 | + "lib/zdict.h", |
42 | 67 | "lib/zstd.h",
|
| 68 | + "lib/zstd_errors.h", |
43 | 69 | ],
|
44 |
| - strip_include_prefix = "lib", |
| 70 | + includes = ["lib"], |
| 71 | + linkopts = ["-pthread"], |
| 72 | + linkstatic = True, |
45 | 73 | local_defines = [
|
46 |
| - "ZSTD_LEGACY_SUPPORT=4", |
47 | 74 | "XXH_NAMESPACE=ZSTD_",
|
| 75 | + "ZSTD_MULTITHREAD", |
| 76 | + "ZSTD_BUILD_SHARED=OFF", |
| 77 | + "ZSTD_BUILD_STATIC=ON", |
| 78 | + ] + select({ |
| 79 | + "@platforms//os:windows": ["ZSTD_DISABLE_ASM"], |
| 80 | + "//conditions:default": [], |
| 81 | + }), |
| 82 | +) |
| 83 | + |
| 84 | +cc_binary( |
| 85 | + name = "zstd_cli", |
| 86 | + srcs = glob( |
| 87 | + include = [ |
| 88 | + "programs/*.c", |
| 89 | + "programs/*.h", |
| 90 | + ], |
| 91 | + exclude = [ |
| 92 | + "programs/datagen.c", |
| 93 | + "programs/datagen.h", |
| 94 | + "programs/platform.h", |
| 95 | + "programs/util.h", |
| 96 | + ], |
| 97 | + ), |
| 98 | + deps = [ |
| 99 | + ":datagen", |
| 100 | + ":util", |
| 101 | + ":zstd", |
| 102 | + ], |
| 103 | +) |
| 104 | + |
| 105 | +cc_library( |
| 106 | + name = "util", |
| 107 | + srcs = [ |
| 108 | + "programs/platform.h", |
| 109 | + "programs/util.c", |
| 110 | + ], |
| 111 | + hdrs = [ |
| 112 | + "lib/common/compiler.h", |
| 113 | + "lib/common/debug.h", |
| 114 | + "lib/common/mem.h", |
| 115 | + "lib/common/portability_macros.h", |
| 116 | + "lib/common/zstd_deps.h", |
| 117 | + "programs/util.h", |
| 118 | + ], |
| 119 | +) |
| 120 | + |
| 121 | +cc_library( |
| 122 | + name = "datagen", |
| 123 | + srcs = [ |
| 124 | + "programs/datagen.c", |
| 125 | + "programs/platform.h", |
| 126 | + ], |
| 127 | + hdrs = ["programs/datagen.h"], |
| 128 | + deps = [":util"], |
| 129 | +) |
| 130 | + |
| 131 | +cc_binary( |
| 132 | + name = "datagen_cli", |
| 133 | + srcs = [ |
| 134 | + "programs/lorem.c", |
| 135 | + "programs/lorem.h", |
| 136 | + "tests/datagencli.c", |
| 137 | + "tests/loremOut.c", |
| 138 | + "tests/loremOut.h", |
| 139 | + ], |
| 140 | + includes = [ |
| 141 | + "programs", |
| 142 | + "tests", |
| 143 | + ], |
| 144 | + deps = [":datagen"], |
| 145 | +) |
| 146 | + |
| 147 | +cc_test( |
| 148 | + name = "fullbench", |
| 149 | + srcs = [ |
| 150 | + "lib/decompress/zstd_decompress_internal.h", |
| 151 | + "programs/benchfn.c", |
| 152 | + "programs/benchfn.h", |
| 153 | + "programs/benchzstd.c", |
| 154 | + "programs/benchzstd.h", |
| 155 | + "programs/lorem.c", |
| 156 | + "programs/lorem.h", |
| 157 | + "programs/timefn.c", |
| 158 | + "programs/timefn.h", |
| 159 | + "tests/fullbench.c", |
| 160 | + "tests/loremOut.c", |
| 161 | + "tests/loremOut.h", |
| 162 | + ], |
| 163 | + copts = select({ |
| 164 | + "@platforms//os:windows": [], |
| 165 | + "//conditions:default": ["-Wno-deprecated-declarations"], |
| 166 | + }), |
| 167 | + includes = [ |
| 168 | + "lib/common", |
| 169 | + "programs", |
| 170 | + "tests", |
| 171 | + ], |
| 172 | + deps = [ |
| 173 | + ":datagen", |
| 174 | + ":zstd", |
48 | 175 | ],
|
49 |
| - visibility = ["//visibility:public"], |
50 | 176 | )
|
0 commit comments