Skip to content

Commit f6a8f00

Browse files
authored
PHPC-2274 and PHPC-2308: Endian detection for KMS sources (#1479)
* PHPC-2274: Apply libmongocrypt defs to PHP_MONGODB_LIBMONGOCRYPT_CFLAGS This ensures PHP_MONGODB_LIBMONGOCRYPT_CFLAGS is used instead of PHP_MONGODB_BUNDLED_CFLAGS for libmongocrypt-specific checks. A libmongoc-specific copy of Endian.m4 has been created to use when building without libmongocrypt, since the endianness check is still required by libmongoc's bundled KMS sources. * PHPC-2308: Handle unknown and universal cases for AC_C_BIGENDIAN
1 parent 0805c8a commit f6a8f00

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

config.m4

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,9 @@ if test "$PHP_MONGODB" != "no"; then
328328
dnl CheckCompression.m4 will modify this when using bundled zlib
329329
PHP_MONGODB_ZLIB_CFLAGS=""
330330

331+
dnl Endian.m4 will modify this when using bundled libmongocrypt
332+
PHP_MONGODB_LIBMONGOCRYPT_CFLAGS=""
333+
331334
dnl M4 doesn't know if we're building statically or as a shared module, so
332335
dnl attempt to include both paths while ignoring errors. If neither path
333336
dnl exists, report an error during configure (this is later than M4 parsing
@@ -364,6 +367,7 @@ if test "$PHP_MONGODB" != "no"; then
364367
_include([scripts/autotools/libmongoc/CheckSasl.m4])
365368
_include([scripts/autotools/libmongoc/CheckSSL.m4])
366369
_include([scripts/autotools/libmongoc/CheckUtf8Proc.m4])
370+
_include([scripts/autotools/libmongoc/Endian.m4])
367371
_include([scripts/autotools/libmongoc/FindDependencies.m4])
368372
_include([scripts/autotools/libmongoc/Versions.m4])
369373
_include([scripts/autotools/libmongoc/WeakSymbols.m4])
@@ -482,7 +486,7 @@ if test "$PHP_MONGODB" != "no"; then
482486
fi
483487

484488
if test "$PHP_MONGODB_CLIENT_SIDE_ENCRYPTION" = "yes"; then
485-
PHP_MONGODB_LIBMONGOCRYPT_CFLAGS="-DKMS_MSG_STATIC -DMLIB_USER"
489+
PHP_MONGODB_LIBMONGOCRYPT_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_LIBMONGOCRYPT_CFLAGS -DKMS_MSG_STATIC -DMLIB_USER"
486490

487491
dnl Since libmongocrypt adds kms-message, we can enable AWS auth in this case
488492
AC_SUBST(MONGOC_ENABLE_MONGODB_AWS_AUTH, 1)
@@ -505,7 +509,6 @@ if test "$PHP_MONGODB" != "no"; then
505509
dnl Generated with: find src/libmongocrypt/kms-message/src -maxdepth 1 -name '*.c' -print0 | cut -sz -d / -f 5- | sort -dz | tr '\000' ' '
506510
PHP_MONGODB_MONGOCRYPT_KMS_MESSAGE_SOURCES="hexlify.c kms_azure_request.c kms_b64.c kms_caller_identity_request.c kms_crypto_apple.c kms_crypto_libcrypto.c kms_crypto_none.c kms_crypto_windows.c kms_decrypt_request.c kms_encrypt_request.c kms_gcp_request.c kms_kmip_reader_writer.c kms_kmip_request.c kms_kmip_response.c kms_kmip_response_parser.c kms_kv_list.c kms_message.c kms_port.c kms_request.c kms_request_opt.c kms_request_str.c kms_response.c kms_response_parser.c sort.c"
507511

508-
PHP_MONGODB_LIBMONGOCRYPT_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS $PHP_MONGODB_LIBMONGOCRYPT_CFLAGS"
509512
PHP_MONGODB_ADD_SOURCES([src/libmongocrypt/src/], $PHP_MONGODB_MONGOCRYPT_SOURCES, $PHP_MONGODB_LIBMONGOCRYPT_CFLAGS)
510513
PHP_MONGODB_ADD_SOURCES([src/libmongocrypt/src/crypto/], $PHP_MONGODB_MONGOCRYPT_CRYPTO_SOURCES, $PHP_MONGODB_LIBMONGOCRYPT_CFLAGS)
511514
PHP_MONGODB_ADD_SOURCES([src/libmongocrypt/src/os_posix/], $PHP_MONGODB_MONGOCRYPT_OS_POSIX_SOURCES, $PHP_MONGODB_LIBMONGOCRYPT_CFLAGS)

scripts/autotools/libbson/Endian.m4

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
AC_C_BIGENDIAN
2-
AC_SUBST(BSON_BYTE_ORDER, 1234)
3-
if test "x$ac_cv_c_bigendian" = "xyes"; then
4-
AC_SUBST(BSON_BYTE_ORDER, 4321)
5-
fi
1+
AC_C_BIGENDIAN(
2+
[AC_SUBST(BSON_BYTE_ORDER, 4321)],
3+
[AC_SUBST(BSON_BYTE_ORDER, 1234)],
4+
[AC_MSG_ERROR([unknown endianness])],
5+
[AC_MSG_ERROR([universal endianness is not supported])]
6+
)

scripts/autotools/libmongoc/Endian.m4

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
AC_C_BIGENDIAN(
2+
[PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS -DKMS_MESSAGE_BIG_ENDIAN=1"],
3+
[PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS -DKMS_MESSAGE_LITTLE_ENDIAN=1"],
4+
[AC_MSG_ERROR([unknown endianness])],
5+
[AC_MSG_ERROR([universal endianness is not supported])]
6+
)
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
AC_C_BIGENDIAN
2-
if test "x$ac_cv_c_bigendian" = "xyes"; then
3-
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS -DKMS_MESSAGE_BIG_ENDIAN=1 -DMONGOCRYPT_BIG_ENDIAN=1"
4-
else
5-
PHP_MONGODB_BUNDLED_CFLAGS="$PHP_MONGODB_BUNDLED_CFLAGS -DKMS_MESSAGE_LITTLE_ENDIAN=1 -DMONGOCRYPT_LITTLE_ENDIAN=1"
6-
fi
1+
AC_C_BIGENDIAN(
2+
[PHP_MONGODB_LIBMONGOCRYPT_CFLAGS="$PHP_MONGODB_LIBMONGOCRYPT_CFLAGS -DKMS_MESSAGE_BIG_ENDIAN=1 -DMONGOCRYPT_BIG_ENDIAN=1"],
3+
[PHP_MONGODB_LIBMONGOCRYPT_CFLAGS="$PHP_MONGODB_LIBMONGOCRYPT_CFLAGS -DKMS_MESSAGE_LITTLE_ENDIAN=1 -DMONGOCRYPT_LITTLE_ENDIAN=1"],
4+
[AC_MSG_ERROR([unknown endianness])],
5+
[AC_MSG_ERROR([universal endianness is not supported])]
6+
)

0 commit comments

Comments
 (0)