xref: /llvm-project/utils/bazel/third_party_build/zlib-ng.BUILD (revision 2fcfc9754a16805b81e541dc8222a8b5cf17a121)
1# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2# See https://llvm.org/LICENSE.txt for license information.
3# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
5load("@bazel_skylib//rules:expand_template.bzl", "expand_template")
6
7package(
8    default_visibility = ["//visibility:public"],
9    # BSD/MIT-like license (for zlib)
10    licenses = ["notice"],
11)
12
13bool_flag(
14    name = "llvm_enable_zlib",
15    build_setting_default = True,
16)
17
18config_setting(
19    name = "llvm_zlib_enabled",
20    flag_values = {":llvm_enable_zlib": "true"},
21)
22
23genrule(
24    # The input template is identical to the CMake output.
25    name = "zconf_gen",
26    srcs = ["zconf.h.in"],
27    outs = ["zconf.h"],
28    cmd = "cp $(SRCS) $(OUTS)",
29)
30
31cc_library(
32    name = "zlib",
33    srcs = select({
34        ":llvm_zlib_enabled": [
35            "adler32.c",
36            "adler32_p.h",
37            "chunkset.c",
38            "chunkset_tpl.h",
39            "compare258.c",
40            "compress.c",
41            "crc32.c",
42            "crc32_comb.c",
43            "crc32_comb_tbl.h",
44            "crc32_p.h",
45            "crc32_tbl.h",
46            "deflate.c",
47            "deflate.h",
48            "deflate_fast.c",
49            "deflate_medium.c",
50            "deflate_p.h",
51            "deflate_quick.c",
52            "deflate_slow.c",
53            "fallback_builtins.h",
54            "functable.c",
55            "functable.h",
56            "infback.c",
57            "inffast.c",
58            "inffast.h",
59            "inffixed_tbl.h",
60            "inflate.c",
61            "inflate.h",
62            "inflate_p.h",
63            "inftrees.c",
64            "inftrees.h",
65            "insert_string.c",
66            "insert_string_tpl.h",
67            "match_tpl.h",
68            "trees.c",
69            "trees.h",
70            "trees_emit.h",
71            "trees_tbl.h",
72            "uncompr.c",
73            "zbuild.h",
74            "zendian.h",
75            "zutil.c",
76            "zutil.h",
77            "zutil_p.h",
78        ],
79        "//conditions:default": [],
80    }),
81    hdrs = select({
82        ":llvm_zlib_enabled": [
83            "zlib.h",
84            ":zconf_gen",
85        ],
86        "//conditions:default": [],
87    }),
88    copts = [
89        "-std=c11",
90        "-DZLIB_COMPAT",
91        "-DWITH_GZFILEOP",
92        "-DWITH_OPTIM",
93        "-DWITH_NEW_STRATEGIES",
94        # For local builds you might want to add "-DWITH_NATIVE_INSTRUCTIONS"
95        # here to improve performance. Native instructions aren't enabled in
96        # the default config for reproducibility.
97    ],
98    defines = select({
99        ":llvm_zlib_enabled": [
100            "LLVM_ENABLE_ZLIB=1",
101        ],
102        "//conditions:default": [],
103    }),
104    # Clang includes zlib with angled instead of quoted includes, so we need
105    # strip_include_prefix here.
106    strip_include_prefix = ".",
107    visibility = ["//visibility:public"],
108)
109