xref: /aosp_15_r20/external/protobuf/third_party/zlib.BUILD (revision 1b3f573f81763fcece89efc2b6a5209149e44ab8)
1load("@rules_cc//cc:defs.bzl", "cc_library")
2
3licenses(["notice"])  # BSD/MIT-like license (for zlib)
4
5exports_files(["zlib.BUILD"])
6
7_ZLIB_HEADERS = [
8    "crc32.h",
9    "deflate.h",
10    "gzguts.h",
11    "inffast.h",
12    "inffixed.h",
13    "inflate.h",
14    "inftrees.h",
15    "trees.h",
16    "zconf.h",
17    "zlib.h",
18    "zutil.h",
19]
20
21_ZLIB_PREFIXED_HEADERS = ["zlib/include/" + hdr for hdr in _ZLIB_HEADERS]
22
23# In order to limit the damage from the `includes` propagation
24# via `:zlib`, copy the public headers to a subdirectory and
25# expose those.
26genrule(
27    name = "copy_public_headers",
28    srcs = _ZLIB_HEADERS,
29    outs = _ZLIB_PREFIXED_HEADERS,
30    cmd_bash = "cp $(SRCS) $(@D)/zlib/include/",
31    cmd_bat = " && ".join(
32        ["@copy /Y $(location %s) $(@D)\\zlib\\include\\  >NUL" %
33         s for s in _ZLIB_HEADERS],
34    ),
35)
36
37cc_library(
38    name = "zlib",
39    srcs = [
40        "adler32.c",
41        "compress.c",
42        "crc32.c",
43        "deflate.c",
44        "gzclose.c",
45        "gzlib.c",
46        "gzread.c",
47        "gzwrite.c",
48        "infback.c",
49        "inffast.c",
50        "inflate.c",
51        "inftrees.c",
52        "trees.c",
53        "uncompr.c",
54        "zutil.c",
55        # Include the un-prefixed headers in srcs to work
56        # around the fact that zlib isn't consistent in its
57        # choice of <> or "" delimiter when including itself.
58    ] + _ZLIB_HEADERS,
59    hdrs = _ZLIB_PREFIXED_HEADERS,
60    copts = select({
61        "@bazel_tools//src/conditions:windows": [],
62        "//conditions:default": [
63            "-Wno-unused-variable",
64            "-Wno-implicit-function-declaration",
65        ],
66    }),
67    includes = ["zlib/include/"],
68    visibility = ["//visibility:public"],
69)
70