[CDRIVER-2666] Call bundled zLib's CMake script to avoid warnings Created: 25/May/18  Updated: 31/Mar/22

Status: Backlog
Project: C Driver
Component/s: Build, libmongoc
Affects Version/s: 1.10.0
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Jeremy Mikola Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to PHPC-1197 Check for unistd.h when compiling bun... Closed
is related to CDRIVER-2511 Disable warnings for zlib in CMake Closed

 Description   

Updated description: We currently ignore the bundled zLib code's CMakeLists.txt, and instead just include the zLib code into our project without any of zLib's config checks. This results in some compiler warnings: we skip the step in zLib's CMake script that would set Z_HAVE_UNISTD_H, and therefore zLib's source doesn't include unistd.h, therefore we get warnings about implicit declarations. We have worked around the issue by suppressed warnings when compiling bundled zLib. Instead, our CMake script should call zLib's, this may have other (good?) consequences besides defining Z_HAVE_UNISTD_H . It should allow zLib's source to compile without warnings, and then we can remove our workaround that suppresses warnings when compiling bundled zLib.

Original report from Jeremy: "Implicit declaration warnings when building bundled zlib"

I noticed the following build warnings when compiling libmongoc with zlib support:

/home/jmikola/workspace/mongodb/phpc/src/libmongoc/src/zlib-1.2.11/gzlib.c: In function ‘gz_open’:
/home/jmikola/workspace/mongodb/phpc/src/libmongoc/src/zlib-1.2.11/gzlib.c:14:17: warning: implicit declaration of function ‘lseek’; did you mean ‘fseek’? [-Wimplicit-function-declaration]
 #  define LSEEK lseek
                 ^
/home/jmikola/workspace/mongodb/phpc/src/libmongoc/src/zlib-1.2.11/gzlib.c:252:9: note: in expansion of macro ‘LSEEK’
         LSEEK(state->fd, 0, SEEK_END);  /* so gzoffset() is correct */
         ^~~~~
/home/jmikola/workspace/mongodb/phpc/src/libmongoc/src/zlib-1.2.11/gzread.c: In function ‘gz_load’:
/home/jmikola/workspace/mongodb/phpc/src/libmongoc/src/zlib-1.2.11/gzread.c:36:15: warning: implicit declaration of function ‘read’; did you mean ‘fread’? [-Wimplicit-function-declaration]
         ret = read(state->fd, buf + *have, get);
               ^~~~
               fread
/home/jmikola/workspace/mongodb/phpc/src/libmongoc/src/zlib-1.2.11/gzread.c: In function ‘gzclose_r’:
/home/jmikola/workspace/mongodb/phpc/src/libmongoc/src/zlib-1.2.11/gzread.c:652:11: warning: implicit declaration of function ‘close’; did you mean ‘pclose’? [-Wimplicit-function-declaration]
     ret = close(state->fd);
           ^~~~~
           pclose
/home/jmikola/workspace/mongodb/phpc/src/libmongoc/src/zlib-1.2.11/gzwrite.c: In function ‘gz_comp’:
/home/jmikola/workspace/mongodb/phpc/src/libmongoc/src/zlib-1.2.11/gzwrite.c:90:20: warning: implicit declaration of function ‘write’; did you mean ‘fwrite’? [-Wimplicit-function-declaration]
             writ = write(state->fd, strm->next_in, put);
                    ^~~~~
                    fwrite
/home/jmikola/workspace/mongodb/phpc/src/libmongoc/src/zlib-1.2.11/gzwrite.c: In function ‘gzclose_w’:
/home/jmikola/workspace/mongodb/phpc/src/libmongoc/src/zlib-1.2.11/gzwrite.c:662:9: warning: implicit declaration of function ‘close’; did you mean ‘pclose’? [-Wimplicit-function-declaration]
     if (close(state->fd) == -1)
         ^~~~~
         pclose

I expect patching the vendored sources with #include <unistd.h> would resolve this. Alternatively, this might have been fixed upstream. This is certainly not unique to libmongoc (see: opencv/opencv_contrib#721).

Lastly, I'm not sure why we only recently noticed this in PHPC builds, but I expect it's due to our recent Autotools migration. We may be passing developer CFLAGS for libmongoc sources now.



 Comments   
Comment by A. Jesse Jiryu Davis [ 10/Oct/18 ]

Thanks Henrik. Patches welcome if you feel up to it.

Comment by Henrik Edin [ 10/Oct/18 ]

We also encountered this when building mongoc for iOS. Because we don't allow warnings in that build we had to disable ZLIB. If it could be fixed it would be great.

Comment by Jeremy Mikola [ 04/Jun/18 ]

That works so far and only produces warnings

Are you referring to the same build warnings I saw above? If so, I think it may be worth fixing. It was trivial to add a check for unistd.h in PHPC-1197.

I was under the impression that it's much easier to trigger a bundled library's configuration from CMake, so I might suggest doing that as a proper fix long term.

Comment by A. Jesse Jiryu Davis [ 31/May/18 ]

Jeremy feel free to reopen if this is really a C Driver bug.

Comment by A. Jesse Jiryu Davis [ 30/May/18 ]

Interesting. We are not invoking zlib's CMake configuration, we just copy zconf.h.in to zconf.h. That means Z_HAVE_UNISTD_H is not defined and unistd.h is not included. That works so far and only produces warnings, so I'm going to leave it as-is, but in a perfect world we might have done differently.

Comment by Jeremy Mikola [ 30/May/18 ]

I don't believe this is a problem upstream, as zLib does check for unistd.h. If you are recursively invoking its CMake configuration, I expect this isn't a problem for libmongoc. Feel free to close this if so.

Comment by A. Jesse Jiryu Davis [ 27/May/18 ]

The old Autotools scripts disabled warnings for the vendored zLib sources:

https://github.com/mongodb/mongo-c-driver/blob/r1.9/src/mongoc/Makefile.am#L326

PHPC should do the same, unless zLib itself has fixed the issue upstream. Could you check if they have please?

 

Generated at Wed Feb 07 21:15:57 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.