Skip to content

Commit 6edb34b

Browse files
authored
Zlib fix for updated MacOS (#755)
1 parent 487d4d3 commit 6edb34b

File tree

5 files changed

+80
-0
lines changed

5 files changed

+80
-0
lines changed

.bazelrc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,15 @@ build --java_runtime_version=11
1717
build --remote_cache=https://storage.googleapis.com/zipline-bazel-cache
1818
test --test_output=errors
1919
test --test_timeout=1200
20+
21+
# Enable platform-specific configuration
22+
build --enable_platform_specific_config
23+
24+
# macOS-specific flags
25+
build:macos --copt=-Wno-macro-redefined
26+
build:macos --copt=-Wno-deprecated-non-prototype
27+
build:macos --host_copt=-Wno-macro-redefined
28+
build:macos --host_copt=-Wno-deprecated-non-prototype
29+
30+
# CI-specific flags
31+
build:linux --copt=-Wno-deprecated-function

WORKSPACE

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,18 @@ workspace(name = "chronon")
22

33
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
44

5+
http_archive(
6+
name = "zlib",
7+
sha256 = "c3e5e9fdd5004dcb542feda5ee4f0ff0744628baf8ed2dd5d66f8ca1197cb1a1",
8+
strip_prefix = "zlib-1.2.11",
9+
urls = [
10+
"https://mirror.bazel.build/zlib.net/zlib-1.2.11.tar.gz",
11+
"https://zlib.net/zlib-1.2.11.tar.gz",
12+
],
13+
build_file = "//third_party:zlib.BUILD",
14+
)
15+
16+
517
# Load scala version from the config
618
load("//:scala_config.bzl", "scala_version")
719

third_party/BUILD.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
exports_files([
4+
"zlib.BUILD",
5+
])
6+
7+
config_setting(
8+
name = "macos",
9+
constraint_values = ["@platforms//os:macos"],
10+
)
11+
12+
cc_library(
13+
name = "macos_zlib_fix",
14+
srcs = ["macos_zlib_fix.cc"],
15+
visibility = ["//visibility:public"],
16+
)

third_party/macos_zlib_fix.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifdef __APPLE__
2+
/* This provides a redefinition-safe fdopen on macOS as zlib is incompatible without it */
3+
#include <stdio.h>
4+
5+
FILE* my_fdopen_wrapper(int fd, const char* mode) {
6+
return fdopen(fd, mode);
7+
}
8+
#endif

third_party/zlib.BUILD

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package(default_visibility = ["//visibility:public"])
2+
3+
# Import config_setting for macOS
4+
config_setting(
5+
name = "macos",
6+
constraint_values = ["@platforms//os:macos"],
7+
)
8+
9+
# Define zlib with conditional compilation flags
10+
cc_library(
11+
name = "zlib",
12+
srcs = glob(["*.c"], exclude = ["example.c", "minigzip.c"]),
13+
hdrs = glob(["*.h"]),
14+
includes = ["."],
15+
defines = select({
16+
":macos": [
17+
"HAVE_UNISTD_H",
18+
"NO_FSEEKO",
19+
"HAVE_STDARG_H",
20+
"_DARWIN_C_SOURCE",
21+
"fdopen=my_fdopen_wrapper", # Redefine fdopen to avoid conflicts
22+
],
23+
"//conditions:default": [],
24+
}),
25+
copts = select({
26+
":macos": [
27+
"-Wno-macro-redefined",
28+
"-Wno-deprecated-non-prototype",
29+
],
30+
"//conditions:default": [],
31+
}),
32+
)

0 commit comments

Comments
 (0)