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