Skip to content

Commit faf7eec

Browse files
committed
Declare Z_HAVE_UNISTD_H on non-windows platforms for zlib
This avoids an error when compiling zlib with ISO C99 conforming compilers: ``` external/zlib.hs/gzwrite.c:78:20: error: call to undeclared function 'write'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] writ = write(state->fd, strm->next_in, put); ^ external/zlib.hs/gzwrite.c:78:20: note: did you mean 'fwrite'? /nix/store/51c1k4sj0irwgyvkgbyhqi0ggilyh3j2-Libsystem-1238.60.2/include/stdio.h:254:9: note: 'fwrite' declared here size_t fwrite(const void * __restrict __ptr, size_t __size, size_t __nitems, FILE * __restrict __stream) __DARWIN_ALIAS(fwrite); ^ external/zlib.hs/gzwrite.c:108:24: error: call to undeclared function 'write'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] writ = write(state->fd, state->x.next, put); ^ external/zlib.hs/gzwrite.c:627:9: error: call to undeclared function 'close'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration] if (close(state->fd) == -1) ^ 3 errors generated. ```
1 parent 145730a commit faf7eec

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

examples/non_module_deps.bzl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ cc_library(
2121
includes = ["."],
2222
visibility = ["//visibility:public"],
2323
)
24-
cc_library(name = "z", srcs = glob(["*.c"]), hdrs = glob(["*.h"]))
24+
cc_library(
25+
name = "z",
26+
srcs = glob(["*.c"]),
27+
hdrs = glob(["*.h"]),
28+
copts = select({
29+
"@bazel_tools//src/conditions:windows": [],
30+
# Needed to avoid "call to undeclared function" errors [-Wimplicit-function-declaration]
31+
"//conditions:default": ["-DZ_HAVE_UNISTD_H"],
32+
}),
33+
)
2534
""",
2635
sha256 = "b5b06d60ce49c8ba700e0ba517fa07de80b5d4628a037f4be8ad16955be7a7c0",
2736
strip_prefix = "zlib-1.3",

rules_haskell_tests/non_module_deps.bzl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,11 @@ cc_library(
8989
name = "z",
9090
srcs = glob(["*.c"]),
9191
hdrs = glob(["*.h"]),
92-
# Needed because XCode 12.0 Clang errors by default.
93-
# See https://developer.apple.com/documentation/xcode-release-notes/xcode-12-release-notes.
94-
copts = ["-Wno-error=implicit-function-declaration"],
92+
copts = select({
93+
"@bazel_tools//src/conditions:windows": [],
94+
# Needed to avoid "call to undeclared function" errors [-Wimplicit-function-declaration]
95+
"//conditions:default": ["-DZ_HAVE_UNISTD_H"],
96+
}),
9597
# Cabal packages depending on dynamic C libraries fail on MacOS
9698
# due to `-rpath` flags being forwarded indiscriminately.
9799
# See https://github.com/tweag/rules_haskell/issues/1317

0 commit comments

Comments
 (0)