# Native Bazel BUILD file for zlib-ng. # Based on envoyproxy/toolshed bazel-registry/modules/zlib-ng BUILD file, # which is derived from LLVM's zlib-ng.BUILD. load("@bazel_skylib//rules:copy_file.bzl", "copy_file") load("@bazel_skylib//rules:expand_template.bzl", "expand_template") load("@rules_cc//cc:cc_library.bzl", "cc_library") copy_file( # The input template is identical to the CMake output. name = "zconf_gen", src = "zconf.h.in", out = "zconf.h", allow_symlink = True, ) expand_template( name = "zlib_gen", out = "zlib.h", substitutions = {"@ZLIB_SYMBOL_PREFIX@": ""}, template = "zlib.h.in", ) copy_file( # Use the empty name mangling header for ZLIB_COMPAT mode (no symbol prefix). name = "zlib_name_mangling_gen", src = "zlib_name_mangling.h.empty", out = "zlib_name_mangling.h", allow_symlink = True, ) expand_template( name = "gzread_gen", out = "gzread_mangle.h", substitutions = {"@ZLIB_SYMBOL_PREFIX@": ""}, template = "gzread_mangle.h.in", ) cc_library( name = "zlib-ng", srcs = [ "adler32.c", "adler32_p.h", "arch_functions.h", "chunkset_tpl.h", "compare256_rle.h", "compress.c", "cpu_features.c", "cpu_features.h", "crc32.c", "crc32.h", "crc32_braid_comb.c", "crc32_braid_comb_p.h", "crc32_braid_p.h", "crc32_braid_tbl.h", "deflate.c", "deflate.h", "deflate_fast.c", "deflate_huff.c", "deflate_medium.c", "deflate_p.h", "deflate_quick.c", "deflate_rle.c", "deflate_slow.c", "deflate_stored.c", "fallback_builtins.h", "functable.c", "functable.h", "gzguts.h", "gzlib.c", "gzread.c", "gzwrite.c", "infback.c", "inffast_tpl.h", "inffixed_tbl.h", "inflate.c", "inflate.h", "inflate_p.h", "inftrees.c", "inftrees.h", "insert_string.c", "insert_string_roll.c", "insert_string_tpl.h", "match_tpl.h", "trees.c", "trees.h", "trees_emit.h", "trees_tbl.h", "uncompr.c", "zbuild.h", "zendian.h", "zmemory.h", "zutil.c", "zutil.h", "zutil_p.h", # Generic architecture files - required for arch/generic/generic_functions.h. "arch/generic/adler32_c.c", "arch/generic/adler32_fold_c.c", "arch/generic/chunkset_c.c", "arch/generic/compare256_c.c", "arch/generic/crc32_braid_c.c", "arch/generic/crc32_chorba_c.c", "arch/generic/crc32_fold_c.c", "arch/generic/slide_hash_c.c", "arch/generic/chunk_128bit_perm_idx_lut.h", "arch/generic/chunk_256bit_perm_idx_lut.h", "arch/generic/chunk_permute_table.h", "arch/generic/compare256_p.h", "arch/generic/generic_functions.h", # Generated files. ":gzread_gen", ":zconf_gen", ":zlib_name_mangling_gen", ], hdrs = [ ":zlib_gen", ], copts = select({ "@platforms//os:windows": [ "/wd4127", # conditional expression is constant "/wd4131", # old-style declarator "/wd4244", # possible loss of data "/wd4245", # signed/unsigned mismatch "/wd4267", # conversion from size_t "/wd4996", # deprecated functions ], "@platforms//os:macos": [ "-std=c11", "-Wno-deprecated-non-prototype", "-Wno-unused-variable", "-Wno-implicit-function-declaration", ], "//conditions:default": [ "-std=c11", "-Wno-deprecated-non-prototype", "-Wno-unused-variable", "-Wno-implicit-function-declaration", ], }), features = ["-parse_headers"], # Needed for arch/generic includes and strip_include_prefix for zlib.h. includes = ["."], local_defines = [ "ZLIB_COMPAT", "WITH_GZFILEOP", "WITH_OPTIM", "WITH_NEW_STRATEGIES", # Enable all generic C fallbacks for the function table. # This ensures the functable is properly initialized on all platforms. "WITH_ALL_FALLBACKS", ] + select({ "@platforms//os:windows": ["_CRT_NONSTDC_NO_WARNINGS"], "//conditions:default": [], }), strip_include_prefix = ".", visibility = ["//visibility:public"], ) # Alias for compatibility with references expecting `:zlib`. alias( name = "zlib", actual = ":zlib-ng", visibility = ["//visibility:public"], )