aboutsummaryrefslogtreecommitdiff
path: root/utils/bazel/third_party_build/zlib-ng.BUILD
blob: 055261acb0f693c7842e43aafb3ebc49e1fb36ea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# This file is licensed under the Apache License v2.0 with LLVM Exceptions.
# See https://llvm.org/LICENSE.txt for license information.
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
load("@bazel_skylib//rules:common_settings.bzl", "bool_flag")
load("@bazel_skylib//rules:expand_template.bzl", "expand_template")

package(
    default_visibility = ["//visibility:public"],
    # BSD/MIT-like license (for zlib)
    licenses = ["notice"],
)

bool_flag(
    name = "llvm_enable_zlib",
    build_setting_default = True,
)

config_setting(
    name = "llvm_zlib_enabled",
    flag_values = {":llvm_enable_zlib": "true"},
)

genrule(
    # The input template is identical to the CMake output.
    name = "zconf_gen",
    srcs = ["zconf.h.in"],
    outs = ["zconf.h"],
    cmd = "cp $(SRCS) $(OUTS)",
)

cc_library(
    name = "zlib",
    srcs = select({
        ":llvm_zlib_enabled": [
            "adler32.c",
            "adler32_p.h",
            "chunkset.c",
            "chunkset_tpl.h",
            "compare258.c",
            "compress.c",
            "crc32.c",
            "crc32_comb.c",
            "crc32_comb_tbl.h",
            "crc32_p.h",
            "crc32_tbl.h",
            "deflate.c",
            "deflate.h",
            "deflate_fast.c",
            "deflate_medium.c",
            "deflate_p.h",
            "deflate_quick.c",
            "deflate_slow.c",
            "fallback_builtins.h",
            "functable.c",
            "functable.h",
            "infback.c",
            "inffast.c",
            "inffast.h",
            "inffixed_tbl.h",
            "inflate.c",
            "inflate.h",
            "inflate_p.h",
            "inftrees.c",
            "inftrees.h",
            "insert_string.c",
            "insert_string_tpl.h",
            "match_tpl.h",
            "trees.c",
            "trees.h",
            "trees_emit.h",
            "trees_tbl.h",
            "uncompr.c",
            "zbuild.h",
            "zendian.h",
            "zutil.c",
            "zutil.h",
            "zutil_p.h",
        ],
        "//conditions:default": [],
    }),
    hdrs = select({
        ":llvm_zlib_enabled": [
            "zlib.h",
            ":zconf_gen",
        ],
        "//conditions:default": [],
    }),
    copts = [
        "-std=c11",
        "-DZLIB_COMPAT",
        "-DWITH_GZFILEOP",
        "-DWITH_OPTIM",
        "-DWITH_NEW_STRATEGIES",
        # For local builds you might want to add "-DWITH_NATIVE_INSTRUCTIONS"
        # here to improve performance. Native instructions aren't enabled in
        # the default config for reproducibility.
    ],
    defines = select({
        ":llvm_zlib_enabled": [
            "LLVM_ENABLE_ZLIB=1",
        ],
        "//conditions:default": [],
    }),
    # Clang includes zlib with angled instead of quoted includes, so we need
    # strip_include_prefix here.
    strip_include_prefix = ".",
    visibility = ["//visibility:public"],
)