| 1 |
# This file will be copied into //third_party/externals/zlib via the new_local_repository |
| 2 |
# rule in WORKSPACE.bazel, so all files should be relative to that path. |
| 3 |
|
| 4 |
load("@rules_cc//cc:cc_library.bzl", "cc_library") |
| 5 |
|
| 6 |
# We define this here because the emscripten toolchain calls the cpu wasm, whereas the |
| 7 |
# bazelbuild/platforms call it wasm32. https://github.com/emscripten-core/emsdk/issues/919 |
| 8 |
config_setting( |
| 9 |
name = "cpu_wasm", |
| 10 |
values = { |
| 11 |
"cpu": "wasm", |
| 12 |
}, |
| 13 |
) |
| 14 |
|
| 15 |
constraint_value( |
| 16 |
name = "fuchsia", |
| 17 |
constraint_setting = "@platforms//os:os", |
| 18 |
) |
| 19 |
|
| 20 |
config_setting( |
| 21 |
name = "fuchsia_arm64", |
| 22 |
constraint_values = [ |
| 23 |
"@platforms//cpu:arm64", |
| 24 |
":fuchsia", |
| 25 |
], |
| 26 |
) |
| 27 |
|
| 28 |
config_setting( |
| 29 |
name = "linux_x64", |
| 30 |
constraint_values = [ |
| 31 |
"@platforms//cpu:x86_64", |
| 32 |
"@platforms//os:linux", |
| 33 |
], |
| 34 |
) |
| 35 |
|
| 36 |
config_setting( |
| 37 |
name = "linux_arm64", |
| 38 |
constraint_values = [ |
| 39 |
"@platforms//cpu:arm64", |
| 40 |
"@platforms//os:linux", |
| 41 |
], |
| 42 |
) |
| 43 |
|
| 44 |
config_setting( |
| 45 |
name = "mac_x64", |
| 46 |
constraint_values = [ |
| 47 |
"@platforms//cpu:x86_64", |
| 48 |
"@platforms//os:macos", |
| 49 |
], |
| 50 |
) |
| 51 |
|
| 52 |
config_setting( |
| 53 |
name = "mac_arm64", |
| 54 |
constraint_values = [ |
| 55 |
"@platforms//cpu:arm64", |
| 56 |
"@platforms//os:macos", |
| 57 |
], |
| 58 |
) |
| 59 |
|
| 60 |
config_setting( |
| 61 |
name = "windows_x64", |
| 62 |
constraint_values = [ |
| 63 |
"@platforms//cpu:x86_64", |
| 64 |
"@platforms//os:windows", |
| 65 |
], |
| 66 |
) |
| 67 |
|
| 68 |
ZLIB_SRCS = [ |
| 69 |
"adler32.c", |
| 70 |
"compress.c", |
| 71 |
"contrib/optimizations/insert_string.h", |
| 72 |
"cpu_features.c", |
| 73 |
"cpu_features.h", |
| 74 |
"crc32.h", |
| 75 |
"crc32.c", |
| 76 |
"deflate.c", |
| 77 |
"deflate.h", |
| 78 |
"gzclose.c", |
| 79 |
"gzguts.h", |
| 80 |
"gzlib.c", |
| 81 |
"gzread.c", |
| 82 |
"gzwrite.c", |
| 83 |
"infback.c", |
| 84 |
"inffast.c", |
| 85 |
"inffast.h", |
| 86 |
"inflate.h", |
| 87 |
"inftrees.c", |
| 88 |
"inftrees.h", |
| 89 |
"trees.c", |
| 90 |
"trees.h", |
| 91 |
"uncompr.c", |
| 92 |
"inffixed.h", |
| 93 |
"zutil.c", |
| 94 |
"zutil.h", |
| 95 |
] + select({ |
| 96 |
"@platforms//cpu:x86_64": [ |
| 97 |
"adler32_simd.h", |
| 98 |
"adler32_simd.c", |
| 99 |
"contrib/optimizations/chunkcopy.h", |
| 100 |
"contrib/optimizations/inffast_chunk.h", |
| 101 |
"contrib/optimizations/inffast_chunk.c", |
| 102 |
"contrib/optimizations/inflate.c", |
| 103 |
"crc32_simd.h", |
| 104 |
"crc32_simd.c", |
| 105 |
"crc_folding.c", |
| 106 |
], |
| 107 |
"@platforms//cpu:arm64": [ |
| 108 |
"adler32_simd.h", |
| 109 |
"adler32_simd.c", |
| 110 |
"contrib/optimizations/chunkcopy.h", |
| 111 |
"contrib/optimizations/inffast_chunk.h", |
| 112 |
"contrib/optimizations/inffast_chunk.c", |
| 113 |
"contrib/optimizations/inflate.c", |
| 114 |
"crc32_simd.h", |
| 115 |
"crc32_simd.c", |
| 116 |
], |
| 117 |
# No SIMD support in wasm for now |
| 118 |
":cpu_wasm": ["inflate.c"], |
| 119 |
# The default is to avoid using SIMD |
| 120 |
"//conditions:default": ["inflate.c"], |
| 121 |
}) |
| 122 |
|
| 123 |
ZLIB_DEFINES = ["ZLIB_IMPLEMENTATION"] + select({ |
| 124 |
"@platforms//cpu:x86_64": [ |
| 125 |
"ADLER32_SIMD_SSSE3", |
| 126 |
"CRC32_SIMD_SSE42_PCLMUL", |
| 127 |
"INFLATE_CHUNK_READ_64LE", |
| 128 |
"INFLATE_CHUNK_SIMD_SSE2", |
| 129 |
"DEFLATE_FILL_WINDOW_SSE2", |
| 130 |
], |
| 131 |
"@platforms//cpu:arm64": [ |
| 132 |
"ADLER32_SIMD_NEON", |
| 133 |
"INFLATE_CHUNK_SIMD_NEON", |
| 134 |
"INFLATE_CHUNK_READ_64LE", |
| 135 |
], |
| 136 |
":cpu_wasm": ["CPU_NO_SIMD"], |
| 137 |
"//conditions:default": ["CPU_NO_SIMD"], |
| 138 |
}) + select({ |
| 139 |
":fuchsia_arm64": [ |
| 140 |
"X86_NOT_WINDOWS", |
| 141 |
"ARMV8_OS_FUCHSIA", |
| 142 |
], |
| 143 |
":linux_x64": ["X86_NOT_WINDOWS"], |
| 144 |
":mac_x64": ["X86_NOT_WINDOWS"], |
| 145 |
":mac_arm64": [ |
| 146 |
"ARMV8_OS_MACOS", |
| 147 |
"CRC32_ARMV8_CRC32", |
| 148 |
], |
| 149 |
":windows_x64": ["X86_WINDOWS"], |
| 150 |
# TODO(kjlubick) other arm flavors |
| 151 |
"//conditions:default": ["X86_NOT_WINDOWS"], |
| 152 |
}) |
| 153 |
|
| 154 |
ZLIB_COPTS = [ |
| 155 |
"-Wno-unused-function", |
| 156 |
"-Wno-deprecated-non-prototype", |
| 157 |
# no-deprecated-non-prototype was added in Clang 14+, used in emscripten for CanvasKit, but |
| 158 |
# it is not in Clang 13, currently used for Skia. |
| 159 |
"-Wno-unknown-warning-option", |
| 160 |
] + select({ |
| 161 |
":linux_x64": [ |
| 162 |
"-mssse3", |
| 163 |
"-msse4.2", |
| 164 |
"-mpclmul", |
| 165 |
], |
| 166 |
":mac_x64": [ |
| 167 |
"-mpclmul", |
| 168 |
], |
| 169 |
":windows_x64": [ |
| 170 |
"-mssse3", |
| 171 |
"-msse4.2", |
| 172 |
"-mpclmul", |
| 173 |
], |
| 174 |
"@platforms//cpu:arm": ["-march=armv8-a+crc"], |
| 175 |
# If empty list isn't set for wasm, select picks linux_x64 |
| 176 |
":cpu_wasm": [], |
| 177 |
"//conditions:default": [], |
| 178 |
}) |
| 179 |
|
| 180 |
# TODO(kjlubick) this is not the most optimal build of zlib, but it's good enough for |
| 181 |
# our tests at the moment. We should re-evaluate how we are compiling in SIMD instructions. |
| 182 |
cc_library( |
| 183 |
name = "zlib", |
| 184 |
srcs = ZLIB_SRCS, |
| 185 |
hdrs = [ |
| 186 |
"chromeconf.h", |
| 187 |
"zconf.h", |
| 188 |
"zlib.h", |
| 189 |
], |
| 190 |
copts = ZLIB_COPTS, |
| 191 |
# Export the directory with hdrs so that `#include <zlib.h>` is allowed. |
| 192 |
includes = ["."], |
| 193 |
local_defines = ZLIB_DEFINES, |
| 194 |
visibility = ["//visibility:public"], |
| 195 |
) |