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