aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore12
-rw-r--r--BUILD.bazel134
-rw-r--r--MODULE.bazel9
3 files changed, 155 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
index e867428..a06fb10 100644
--- a/.gitignore
+++ b/.gitignore
@@ -35,3 +35,15 @@ contrib/vstudio/vc143/arm64
35contrib/nuget/bin 35contrib/nuget/bin
36contrib/nuget/obj 36contrib/nuget/obj
37*.included 37*.included
38
39# Bazel directories
40/bazel-*
41/bazel-bin
42/bazel-genfiles
43/bazel-out
44/bazel-testlogs
45user.bazelrc
46
47# MODULE.bazel.lock is ignored for now as per this recommendation:
48# https://github.com/bazelbuild/bazel/issues/20369
49MODULE.bazel.lock
diff --git a/BUILD.bazel b/BUILD.bazel
new file mode 100644
index 0000000..9a294f2
--- /dev/null
+++ b/BUILD.bazel
@@ -0,0 +1,134 @@
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
37load("@rules_cc//cc:defs.bzl", "cc_library")
38load("@rules_license//rules:license.bzl", "license")
39
40package(
41 default_applicable_licenses = [":license"],
42)
43
44license(
45 name = "license",
46 license_kinds = ["@rules_license//licenses/spdx:Zlib"],
47 license_text = "LICENSE",
48)
49
50exports_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.
73genrule(
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
84config_setting(
85 name = "mingw_gcc_compiler",
86 flag_values = {
87 "@bazel_tools//tools/cpp:compiler": "mingw-gcc",
88 },
89 visibility = [":__subpackages__"],
90)
91
92cc_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
130alias(
131 name = "zlib",
132 actual = ":z",
133 visibility = ["//visibility:public"],
134)
diff --git a/MODULE.bazel b/MODULE.bazel
new file mode 100644
index 0000000..cb4c13e
--- /dev/null
+++ b/MODULE.bazel
@@ -0,0 +1,9 @@
1module(
2 name = "zlib",
3 version = "0.0.0",
4 compatibility_level = 1,
5)
6
7bazel_dep(name = "platforms", version = "0.0.10")
8bazel_dep(name = "rules_cc", version = "0.0.16")
9bazel_dep(name = "rules_license", version = "1.0.0")