Skip to content

PHPC-2236: Allow compression libraries to be configured at build time #1438

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 89 additions & 50 deletions scripts/autotools/libmongoc/CheckCompression.m4
Original file line number Diff line number Diff line change
@@ -1,72 +1,111 @@
PHP_ARG_WITH([mongodb-snappy],
[whether to enable Snappy for compression],
[AS_HELP_STRING([--with-mongodb-snappy=@<:@auto/yes/no@:>@],
[MongoDB: Enable Snappy for compression [default=auto]])],
[auto],
[no])

PHP_ARG_WITH([mongodb-zlib],
[whether to enable zlib for compression],
[AS_HELP_STRING([--with-mongodb-zlib=@<:@auto/yes/system/bundled/no@:>@],
[MongoDB: Enable zlib for compression [default=auto]])],
[auto],
[no])

PHP_ARG_WITH([mongodb-zstd],
[whether to enable zstd for compression],
[AS_HELP_STRING([--with-mongodb-zstd=@<:@auto/yes/no@:>@],
[MongoDB: Enable zstd for compression [default=auto]])],
[auto],
[no])

found_snappy="no"
found_zlib="no"
bundled_zlib="no"
found_zstd="no"

PKG_CHECK_MODULES([PHP_MONGODB_SNAPPY],[snappy],[
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_SNAPPY_CFLAGS"
PHP_EVAL_LIBLINE([$PHP_MONGODB_SNAPPY_LIBS],[MONGODB_SHARED_LIBADD])
found_snappy="yes"
],[
PHP_CHECK_LIBRARY([snappy],
[snappy_uncompress],
[have_snappy_lib="yes"],
[have_snappy_lib="no"])

AC_CHECK_HEADER([snappy-c.h],
[have_snappy_headers=yes],
[have_snappy_headers=no])

if test "$have_snappy_lib" = "yes" -a "$have_snappy_headers" = "yes"; then
PHP_ADD_LIBRARY([snappy],,[MONGODB_SHARED_LIBADD])
AS_IF([test "$PHP_MONGODB_SNAPPY" = "auto" -o "$PHP_MONGODB_SNAPPY" = "yes"],[
PKG_CHECK_MODULES([PHP_MONGODB_SNAPPY],[snappy],[
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_SNAPPY_CFLAGS"
PHP_EVAL_LIBLINE([$PHP_MONGODB_SNAPPY_LIBS],[MONGODB_SHARED_LIBADD])
found_snappy="yes"
],[
PHP_CHECK_LIBRARY([snappy],
[snappy_uncompress],
[have_snappy_lib="yes"],
[have_snappy_lib="no"])

AC_CHECK_HEADER([snappy-c.h],
[have_snappy_headers=yes],
[have_snappy_headers=no])

if test "$have_snappy_lib" = "yes" -a "$have_snappy_headers" = "yes"; then
PHP_ADD_LIBRARY([snappy],,[MONGODB_SHARED_LIBADD])
found_snappy="yes"
fi
])

if test "$PHP_MONGODB_SNAPPY" = "yes" -a "$found_snappy" = "no"; then
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have system libraries for all three compression libraries. Rather than remove them, I tested this by flipping this (and related conditionals) to "$found_snappy" = "yes" and checking for an error when the system library was picked up.

I also tested "system" and "bundled" interactions for zlib.

When system libraries are found, you'll see the following configure output:

checking for PHP_MONGODB_SNAPPY... yes
checking for PHP_MONGODB_ZLIB... yes
checking for PHP_MONGODB_ZSTD... yes

...

MONGODB_SHARED_LIBADD                            : -lsnappy -lz -lzstd

Using bundled zlib doesn't result in any configure output, so to test that you'll want to check the definitions in the generated mongoc-config.h output file (e.g. MONGOC_ENABLE_COMPRESSION_X).

Compiling the driver and checking phpinfo() output also works.

AC_MSG_ERROR([Snappy libraries and development headers could not be found])
fi
])

PKG_CHECK_MODULES([PHP_MONGODB_ZLIB],[zlib],[
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_ZLIB_CFLAGS"
PHP_EVAL_LIBLINE([$PHP_MONGODB_ZLIB_LIBS],[MONGODB_SHARED_LIBADD])
found_zlib="yes"
],[
PHP_CHECK_LIBRARY([zlib],
[compress2],
[have_zlib_lib="yes"],
[have_zlib_lib="no"])

AC_CHECK_HEADER([zlib.h],
[have_zlib_headers=yes],
[have_zlib_headers=no])

if test "$have_zlib_lib" = "yes" -a "$have_zlib_headers" = "yes"; then
PHP_ADD_LIBRARY([z],,[MONGODB_SHARED_LIBADD])
AS_IF([test "$PHP_MONGODB_ZLIB" = "auto" -o "$PHP_MONGODB_ZLIB" = "yes" -o "$PHP_MONGODB_ZLIB" = "system"],[
PKG_CHECK_MODULES([PHP_MONGODB_ZLIB],[zlib],[
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_ZLIB_CFLAGS"
PHP_EVAL_LIBLINE([$PHP_MONGODB_ZLIB_LIBS],[MONGODB_SHARED_LIBADD])
found_zlib="yes"
],[
PHP_CHECK_LIBRARY([zlib],
[compress2],
[have_zlib_lib="yes"],
[have_zlib_lib="no"])

AC_CHECK_HEADER([zlib.h],
[have_zlib_headers=yes],
[have_zlib_headers=no])

if test "$have_zlib_lib" = "yes" -a "$have_zlib_headers" = "yes"; then
PHP_ADD_LIBRARY([z],,[MONGODB_SHARED_LIBADD])
found_zlib="yes"
fi
])

if test "$PHP_MONGODB_ZLIB" = "system" -a "$found_zlib" = "no"; then
AC_MSG_ERROR([zlib libraries and development headers could not be found])
fi
])

dnl If zlib was not found, use libmongoc's bundled version
AS_IF([test "$found_zlib" != "yes"],[
dnl Use libmongoc's bundled zlib if necessary
AS_IF([test "$found_zlib" = "no" -a \( "$PHP_MONGODB_ZLIB" = "auto" -o "$PHP_MONGODB_ZLIB" = "yes" -o "$PHP_MONGODB_ZLIB" = "bundled" \)],[
AC_CHECK_HEADER([unistd.h],[PHP_MONGODB_ZLIB_CFLAGS="$PHP_MONGODB_ZLIB_CFLAGS -DHAVE_UNISTD_H"])
AC_CHECK_HEADER([stdarg.h],[PHP_MONGODB_ZLIB_CFLAGS="$PHP_MONGODB_ZLIB_CFLAGS -DHAVE_STDARG_H"])
bundled_zlib="yes"
])

PKG_CHECK_MODULES([PHP_MONGODB_ZSTD],[libzstd],[
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_ZSTD_CFLAGS"
PHP_EVAL_LIBLINE([$PHP_MONGODB_ZSTD_LIBS],[MONGODB_SHARED_LIBADD])
found_zstd="yes"
],[
PHP_CHECK_LIBRARY([zstd],
[ZSTD_compress],
[have_zstd_lib="yes"],
[have_zstd_lib="no"])

AC_CHECK_HEADER([zstd.h],
[have_zstd_headers=yes],
[have_zstd_headers=no])

if test "$have_zstd_lib" = "yes" -a "$have_zstd_headers" = "yes"; then
PHP_ADD_LIBRARY([zstd],,[MONGODB_SHARED_LIBADD])
AS_IF([test "$PHP_MONGODB_ZSTD" = "auto" -o "$PHP_MONGODB_ZSTD" = "yes"],[
PKG_CHECK_MODULES([PHP_MONGODB_ZSTD],[libzstd],[
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_ZSTD_CFLAGS"
PHP_EVAL_LIBLINE([$PHP_MONGODB_ZSTD_LIBS],[MONGODB_SHARED_LIBADD])
found_zstd="yes"
],[
PHP_CHECK_LIBRARY([zstd],
[ZSTD_compress],
[have_zstd_lib="yes"],
[have_zstd_lib="no"])

AC_CHECK_HEADER([zstd.h],
[have_zstd_headers=yes],
[have_zstd_headers=no])

if test "$have_zstd_lib" = "yes" -a "$have_zstd_headers" = "yes"; then
PHP_ADD_LIBRARY([zstd],,[MONGODB_SHARED_LIBADD])
found_zstd="yes"
fi
])

if test "$PHP_MONGODB_ZSTD" = "yes" -a "$found_zstd" = "no"; then
AC_MSG_ERROR([zstd libraries and development headers could not be found])
fi
])

Expand Down