bazel: `@remote_java_tools` fail to build on macOS 13.3 with Xcode 14.3

Description of the bug:

Building @remote_java_tools from source on macOS 13.3 with Xcode 14.3 fails with:

external/remote_java_tools/java_tools/zlib/gzlib.c:254:9: error: call to undeclared function 'lseek'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        LSEEK(state->fd, 0, SEEK_END);  /* so gzoffset() is correct */
        ^
external/remote_java_tools/java_tools/zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
#  define LSEEK lseek
                ^
external/remote_java_tools/java_tools/zlib/gzlib.c:254:9: note: did you mean 'fseek'?
external/remote_java_tools/java_tools/zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
#  define LSEEK lseek
                ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/stdio.h:162:6: note: 'fseek' declared here
int      fseek(FILE *, long, int);
         ^
external/remote_java_tools/java_tools/zlib/gzlib.c:260:24: error: call to undeclared function 'lseek'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        state->start = LSEEK(state->fd, 0, SEEK_CUR);
                       ^
external/remote_java_tools/java_tools/zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
#  define LSEEK lseek
                ^
external/remote_java_tools/java_tools/zlib/gzlib.c:361:9: error: call to undeclared function 'lseek'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
        ^
external/remote_java_tools/java_tools/zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
#  define LSEEK lseek
                ^
external/remote_java_tools/java_tools/zlib/gzlib.c:402:15: error: call to undeclared function 'lseek'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        ret = LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
              ^
external/remote_java_tools/java_tools/zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
#  define LSEEK lseek
                ^
external/remote_java_tools/java_tools/zlib/gzlib.c:498:14: error: call to undeclared function 'lseek'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    offset = LSEEK(state->fd, 0, SEEK_CUR);
             ^
external/remote_java_tools/java_tools/zlib/gzlib.c:14:17: note: expanded from macro 'LSEEK'
#  define LSEEK lseek
                ^
5 errors generated.

What’s the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Try to build a Java target on macOS 13.3 with Xcode 14.3 using a non-prebuilt Java toolchain such as:

load("@bazel_tools//tools/jdk:default_java_toolchain.bzl", "NONPREBUILT_TOOLCHAIN_CONFIGURATION", "default_java_toolchain")
default_java_toolchain(
    name = "java_non_prebuilt",
    configuration = NONPREBUILT_TOOLCHAIN_CONFIGURATION,
)

Which operating system are you running Bazel on?

macOS

What is the output of bazel info release?

6.1.1

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What’s the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

This does appear to be an unfixed portability issue in zlib.

Other repos apply patches to resolve this: https://github.com/Blosc/c-blosc/pull/353/commits/ac72c2cf8248c6fdfb8b1ed97e1da95f8714870f

Any other information, logs, or outputs that you want to share?

This can be worked around with --host_conlyopt=-std=c90 (see https://github.com/bazelbuild/bazel/issues/17956#issuecomment-1494853070 for less intrusive workarounds).

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Comments: 33 (21 by maintainers)

Commits related to this issue

Most upvoted comments

for anyone else who lands here, fixes are either adding -std=c90 to the zlib BUILD file copts, or adding build --per_file_copt='external/zlib[~/].*\.c@-std=c90' --host_per_file_copt='external/zlib[~/].*\.c@-std=c90' to their .bazelrc

the blanket --host_conlyopt=-std=c90 flag can break a lot of other common/important things, like the go compiler

edit: changed regex to work with bzlmod as well

@bazel-io fork 4.2.4

I guess that should be fine? Can you give some instruction here on how to do that?

The instructions are published with every java_tools release, eg: https://github.com/bazelbuild/java_tools/releases/tag/java_v12.0

@keertk @kshyanashree Would it be possible for you to make a regular release for java_tools? I’m going to be OOO soon and might not be able to finish the process.

For fixing remote_java_tools itself, we’ll need a separate java_tools release. /cc @hvadehra can you do that?

Is version 6.1.2rc1 supposed to fix this issue? Doesn’t seem to be doing the trick for me. Still getting the same problem.

➜   bazel version
Bazelisk version: development
Build label: 6.1.2rc1
Build target: bazel-out/darwin_arm64-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Tue Apr 11 23:08:27 2023 (1681254507)
Build timestamp: 1681254507
Build timestamp as int: 1681254507
➜   pkgutil --pkg-info=com.apple.pkg.CLTools_Executables | grep version // XCode version
version: 14.3.0.0.1.1679647830
➜   sw_vers // macOS version
ProductName:            macOS
ProductVersion:         13.3.1
BuildVersion:           22E261

And I still get

external/remote_java_tools/java_tools/zlib/gzlib.c:254:9: error: call to undeclared function 'lseek'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        LSEEK(state->fd, 0, SEEK_END);  /* so gzoffset() is correct */

@bazel-io fork 6.1.2

@bazel-io fork 6.2.0

@bazel-io fork 5.4.1

@fmeum Oh, that makes sense, how confident are we that Blosc/c-blosc@ac72c2c is the correct fix, it’s weird I don’t see any upstream issue or PR mentioning this problem.

@brentleyjones Yes, looks like the same error.

I got this building bazel with Xcode 14.3, but from macOS 13.1, not sure if related:

ERROR: /Users/brentley/Developer/bazel/third_party/zlib/BUILD:39:19: Compiling third_party/zlib/gzlib.c [for tool] failed: (Exit 1): wrapped_clang failed: error executing command (from target //third_party/zlib:zlib_checked_in) external/local_config_cc/wrapped_clang ‘-D_FORTIFY_SOURCE=1’ -fstack-protector -fcolor-diagnostics -Wall -Wthread-safety -Wself-assign -fno-omit-frame-pointer -g0 -O2 -DNDEBUG ‘-DNS_BLOCK_ASSERTIONS=1’ ... (remaining 34 arguments skipped)

Use --sandbox_debug to see verbose messages from the sandbox and retain the sandbox build root for debugging
third_party/zlib/gzlib.c:254:9: error: call to undeclared function ‘lseek’; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        LSEEK(state->fd, 0, SEEK_END);  /* so gzoffset() is correct */
        ^
third_party/zlib/gzlib.c:14:17: note: expanded from macro ‘LSEEK’
#  define LSEEK lseek
                ^
third_party/zlib/gzlib.c:254:9: note: did you mean ‘fseek’?
third_party/zlib/gzlib.c:14:17: note: expanded from macro ‘LSEEK’
#  define LSEEK lseek
                ^
/Applications/Xcode-14.3.0-RC2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/stdio.h:162:6: note: ‘fseek’ declared here
int      fseek(FILE *, long, int);
         ^
third_party/zlib/gzlib.c:260:24: error: call to undeclared function ‘lseek’; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        state->start = LSEEK(state->fd, 0, SEEK_CUR);
                       ^
third_party/zlib/gzlib.c:14:17: note: expanded from macro ‘LSEEK’
#  define LSEEK lseek
                ^
third_party/zlib/gzlib.c:361:9: error: call to undeclared function ‘lseek’; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    if (LSEEK(state->fd, state->start, SEEK_SET) == -1)
        ^
third_party/zlib/gzlib.c:14:17: note: expanded from macro ‘LSEEK’
#  define LSEEK lseek
                ^
third_party/zlib/gzlib.c:402:15: error: call to undeclared function ‘lseek’; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
        ret = LSEEK(state->fd, offset - (z_off64_t)state->x.have, SEEK_CUR);
              ^
third_party/zlib/gzlib.c:14:17: note: expanded from macro ‘LSEEK’
#  define LSEEK lseek
                ^
third_party/zlib/gzlib.c:498:14: error: call to undeclared function ‘lseek’; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
    offset = LSEEK(state->fd, 0, SEEK_CUR);
             ^
third_party/zlib/gzlib.c:14:17: note: expanded from macro ‘LSEEK’
#  define LSEEK lseek
                ^
5 errors generated.

@hvadehra Would applying a patch such as https://github.com/Blosc/c-blosc/commit/ac72c2cf8248c6fdfb8b1ed97e1da95f8714870f to third_party/zlib be an acceptable solution?