1load("@bazel_skylib//rules:copy_file.bzl", "copy_file") 2load("@rules_cc//cc:defs.bzl", "cc_library") 3 4_ZLIB_HEADERS = [ 5 "crc32.h", 6 "deflate.h", 7 "gzguts.h", 8 "inffast.h", 9 "inffixed.h", 10 "inflate.h", 11 "inftrees.h", 12 "trees.h", 13 "zconf.h", 14 "zlib.h", 15 "zutil.h", 16] 17 18# In order to limit the damage from the `includes` propagation 19# via `:zlib`, copy the public headers to a subdirectory and 20# expose those. 21_ZLIB_HEADER_PREFIX = "zlib/include" 22 23_ZLIB_PREFIXED_HEADERS = ["{}/{}".format(_ZLIB_HEADER_PREFIX, hdr) for hdr in _ZLIB_HEADERS] 24 25[ 26 copy_file( 27 name = "{}.copy".format(hdr), 28 src = hdr, 29 out = "{}/{}".format(_ZLIB_HEADER_PREFIX, hdr), 30 ) 31 for hdr in _ZLIB_HEADERS 32] 33 34_COMMON_COPTS = [ 35 "-Wno-deprecated-non-prototype", 36 "-Wno-unused-variable", 37 "-Wno-implicit-function-declaration", 38] 39 40cc_library( 41 name = "zlib", 42 srcs = [ 43 "adler32.c", 44 "compress.c", 45 "crc32.c", 46 "deflate.c", 47 "gzclose.c", 48 "gzlib.c", 49 "gzread.c", 50 "gzwrite.c", 51 "infback.c", 52 "inffast.c", 53 "inflate.c", 54 "inftrees.c", 55 "trees.c", 56 "uncompr.c", 57 "zutil.c", 58 # Include the un-prefixed headers in srcs to work 59 # around the fact that zlib isn't consistent in its 60 # choice of <> or "" delimiter when including itself. 61 ] + _ZLIB_HEADERS, 62 hdrs = _ZLIB_PREFIXED_HEADERS, 63 copts = select({ 64 "@platforms//os:linux": [ 65 # Required for opt builds to avoid 66 # `libzlib.a(crc32.o): requires unsupported dynamic reloc 11; recompile with -fPIC` 67 "-fPIC", 68 # Silence all warnings 69 "-w", 70 ] + _COMMON_COPTS, 71 "@platforms//os:windows": [], 72 "//conditions:default": _COMMON_COPTS, 73 }), 74 includes = ["zlib/include/"], 75 visibility = ["//visibility:public"], 76) 77