| 1 |
# Copied from https://github.com/bazelbuild/bazel-central-registry/tree/main/modules/zlib/1.3.1.bcr.4/patches |
| 2 |
# Adapted from https://github.com/protocolbuffers/protobuf/blob/master/third_party/zlib.BUILD |
| 3 |
|
| 4 |
# Copyright 2008 Google Inc. All rights reserved. |
| 5 |
# |
| 6 |
# Redistribution and use in source and binary forms, with or without |
| 7 |
# modification, are permitted provided that the following conditions are |
| 8 |
# met: |
| 9 |
# |
| 10 |
# * Redistributions of source code must retain the above copyright |
| 11 |
# notice, this list of conditions and the following disclaimer. |
| 12 |
# * Redistributions in binary form must reproduce the above |
| 13 |
# copyright notice, this list of conditions and the following disclaimer |
| 14 |
# in the documentation and/or other materials provided with the |
| 15 |
# distribution. |
| 16 |
# * Neither the name of Google Inc. nor the names of its |
| 17 |
# contributors may be used to endorse or promote products derived from |
| 18 |
# this software without specific prior written permission. |
| 19 |
# |
| 20 |
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 |
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 |
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 |
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 |
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 |
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 |
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 |
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 |
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 |
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 |
# |
| 32 |
# Code generated by the Protocol Buffer compiler is owned by the owner |
| 33 |
# of the input file used when generating it. This code is not |
| 34 |
# standalone and requires a support library to be linked with it. This |
| 35 |
# support library is itself covered by the above license. |
| 36 |
|
| 37 |
load("@rules_cc//cc:defs.bzl", "cc_library") |
| 38 |
load("@rules_license//rules:license.bzl", "license") |
| 39 |
|
| 40 |
package( |
| 41 |
default_applicable_licenses = [":license"], |
| 42 |
) |
| 43 |
|
| 44 |
license( |
| 45 |
name = "license", |
| 46 |
license_kinds = ["@rules_license//licenses/spdx:Zlib"], |
| 47 |
license_text = "LICENSE", |
| 48 |
) |
| 49 |
|
| 50 |
exports_files([ |
| 51 |
"LICENSE", |
| 52 |
]) |
| 53 |
|
| 54 |
_ZLIB_HEADERS = [ |
| 55 |
"crc32.h", |
| 56 |
"deflate.h", |
| 57 |
"gzguts.h", |
| 58 |
"inffast.h", |
| 59 |
"inffixed.h", |
| 60 |
"inflate.h", |
| 61 |
"inftrees.h", |
| 62 |
"trees.h", |
| 63 |
"zconf.h", |
| 64 |
"zlib.h", |
| 65 |
"zutil.h", |
| 66 |
] |
| 67 |
|
| 68 |
_ZLIB_PREFIXED_HEADERS = ["zlib/include/" + hdr for hdr in _ZLIB_HEADERS] |
| 69 |
|
| 70 |
# In order to limit the damage from the `includes` propagation |
| 71 |
# via `:zlib`, copy the public headers to a subdirectory and |
| 72 |
# expose those. |
| 73 |
genrule( |
| 74 |
name = "copy_public_headers", |
| 75 |
srcs = _ZLIB_HEADERS, |
| 76 |
outs = _ZLIB_PREFIXED_HEADERS, |
| 77 |
cmd_bash = "cp $(SRCS) $(@D)/zlib/include/", |
| 78 |
cmd_bat = " && ".join( |
| 79 |
["@copy /Y \"$(location %s)\" \"$(@D)\\zlib\\include\\\" >NUL" % |
| 80 |
s for s in _ZLIB_HEADERS], |
| 81 |
), |
| 82 |
) |
| 83 |
|
| 84 |
config_setting( |
| 85 |
name = "mingw_gcc_compiler", |
| 86 |
flag_values = { |
| 87 |
"@bazel_tools//tools/cpp:compiler": "mingw-gcc", |
| 88 |
}, |
| 89 |
visibility = [":__subpackages__"], |
| 90 |
) |
| 91 |
|
| 92 |
cc_library( |
| 93 |
name = "z", |
| 94 |
srcs = [ |
| 95 |
"adler32.c", |
| 96 |
"compress.c", |
| 97 |
"crc32.c", |
| 98 |
"deflate.c", |
| 99 |
"gzclose.c", |
| 100 |
"gzlib.c", |
| 101 |
"gzread.c", |
| 102 |
"gzwrite.c", |
| 103 |
"infback.c", |
| 104 |
"inffast.c", |
| 105 |
"inflate.c", |
| 106 |
"inftrees.c", |
| 107 |
"trees.c", |
| 108 |
"uncompr.c", |
| 109 |
"zutil.c", |
| 110 |
# Include the un-prefixed headers in srcs to work |
| 111 |
# around the fact that zlib isn't consistent in its |
| 112 |
# choice of <> or "" delimiter when including itself. |
| 113 |
] + _ZLIB_HEADERS, |
| 114 |
hdrs = _ZLIB_PREFIXED_HEADERS, |
| 115 |
copts = select({ |
| 116 |
":mingw_gcc_compiler": [ |
| 117 |
"-fpermissive", |
| 118 |
], |
| 119 |
"@platforms//os:windows": [], |
| 120 |
"//conditions:default": [ |
| 121 |
"-Wno-deprecated-non-prototype", |
| 122 |
"-Wno-unused-variable", |
| 123 |
"-Wno-implicit-function-declaration", |
| 124 |
], |
| 125 |
}), |
| 126 |
includes = ["zlib/include/"], |
| 127 |
visibility = ["//visibility:public"], |
| 128 |
) |
| 129 |
|
| 130 |
alias( |
| 131 |
name = "zlib", |
| 132 |
actual = ":z", |
| 133 |
visibility = ["//visibility:public"], |
| 134 |
) |