blob: 687375d7b3612970c2d843dd64c715dfd2e1bd43 [file] [log] [blame]
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_cc//cc:defs.bzl", "cc_library")
_ZLIB_HEADERS = [
"crc32.h",
"deflate.h",
"gzguts.h",
"inffast.h",
"inffixed.h",
"inflate.h",
"inftrees.h",
"trees.h",
"zconf.h",
"zlib.h",
"zutil.h",
]
# In order to limit the damage from the `includes` propagation
# via `:zlib`, copy the public headers to a subdirectory and
# expose those.
_ZLIB_HEADER_PREFIX = "zlib/include"
_ZLIB_PREFIXED_HEADERS = ["{}/{}".format(_ZLIB_HEADER_PREFIX, hdr) for hdr in _ZLIB_HEADERS]
[
copy_file(
name = "{}.copy".format(hdr),
src = hdr,
out = "{}/{}".format(_ZLIB_HEADER_PREFIX, hdr),
)
for hdr in _ZLIB_HEADERS
]
_COMMON_COPTS = [
"-Wno-deprecated-non-prototype",
"-Wno-unused-variable",
"-Wno-implicit-function-declaration",
]
cc_library(
name = "zlib",
srcs = [
"adler32.c",
"compress.c",
"crc32.c",
"deflate.c",
"gzclose.c",
"gzlib.c",
"gzread.c",
"gzwrite.c",
"infback.c",
"inffast.c",
"inflate.c",
"inftrees.c",
"trees.c",
"uncompr.c",
"zutil.c",
# Include the un-prefixed headers in srcs to work
# around the fact that zlib isn't consistent in its
# choice of <> or "" delimiter when including itself.
] + _ZLIB_HEADERS,
hdrs = _ZLIB_PREFIXED_HEADERS,
copts = select({
"@platforms//os:linux": [
# Required for opt builds to avoid
# `libzlib.a(crc32.o): requires unsupported dynamic reloc 11; recompile with -fPIC`
"-fPIC",
# Silence all warnings
"-w",
] + _COMMON_COPTS,
"@platforms//os:windows": [],
"//conditions:default": _COMMON_COPTS,
}),
includes = ["zlib/include/"],
visibility = ["//visibility:public"],
)