Skip to content

Commit

Permalink
Updated zlib BUILD file to support darwin-arm64 (#1931)
Browse files Browse the repository at this point in the history
  • Loading branch information
UebelAndre committed Apr 24, 2023
1 parent a863132 commit fa304ae
Showing 1 changed file with 57 additions and 15 deletions.
72 changes: 57 additions & 15 deletions crate_universe/3rdparty/BUILD.zlib.bazel
Original file line number Diff line number Diff line change
@@ -1,25 +1,67 @@
load("@bazel_skylib//rules:copy_file.bzl", "copy_file")
load("@rules_cc//cc:defs.bzl", "cc_library")

_ZLIB_HEADERS = [
"crc32.h",
"deflate.h",
"gzguts.h",
"inffast.h",
"inffixed.h",
"inflate.h",
"inftrees.h",
"trees.h",
"zconf.h",
"zlib.h",
"zutil.h",
]

# In order to limit the damage from the `includes` propagation
# via `:zlib`, copy the public headers to a subdirectory and
# expose those.
_ZLIB_HEADER_PREFIX = "zlib/include"

_ZLIB_PREFIXED_HEADERS = ["{}/{}".format(_ZLIB_HEADER_PREFIX, hdr) for hdr in _ZLIB_HEADERS]

[
copy_file(
name = "{}.copy".format(hdr),
src = hdr,
out = "{}/{}".format(_ZLIB_HEADER_PREFIX, hdr),
)
for hdr in _ZLIB_HEADERS
]

cc_library(
name = "zlib",
srcs = glob(["*.c"]),
hdrs = glob(["*.h"]),
# Use -Dverbose=-1 to turn off zlib's trace logging.
# https://github.com/bazelbuild/bazel/issues/3280
srcs = [
"adler32.c",
"compress.c",
"crc32.c",
"deflate.c",
"gzclose.c",
"gzlib.c",
"gzread.c",
"gzwrite.c",
"infback.c",
"inffast.c",
"inflate.c",
"inftrees.c",
"trees.c",
"uncompr.c",
"zutil.c",
# Include the un-prefixed headers in srcs to work
# around the fact that zlib isn't consistent in its
# choice of <> or "" delimiter when including itself.
] + _ZLIB_HEADERS,
hdrs = _ZLIB_PREFIXED_HEADERS,
copts = select({
"@platforms//os:linux": [
"-w",
"-Dverbose=-1",
# Required for opt builds to avoid
# `libzlib.a(crc32.o): requires unsupported dynamic reloc 11; recompile with -fPIC`
"-fPIC",
],
"@platforms//os:windows": [],
"//conditions:default": [
"-w",
"-Dverbose=-1",
"-Wno-deprecated-non-prototype",
"-Wno-unused-variable",
"-Wno-implicit-function-declaration",
],
}),
includes = ["."],
linkstatic = True,
includes = ["zlib/include/"],
visibility = ["//visibility:public"],
)

0 comments on commit fa304ae

Please sign in to comment.