Skip to content
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

Compilation error under cygwin #1381

Closed
matyhtf opened this issue Nov 12, 2022 · 4 comments
Closed

Compilation error under cygwin #1381

matyhtf opened this issue Nov 12, 2022 · 4 comments
Labels
tracked-in-jira Ticket filed in Mongo's Jira system waiting-for-user

Comments

@matyhtf
Copy link

matyhtf commented Nov 12, 2022

Bug Report

Compilation error under cygwin

Environment

  • php 8.1.12
  • ext-mongodb 1.14.2
  • cygwin 3.3.6
  • uname -a CYGWIN_NT-10.0-19042 pc-08 3.3.6-341.x86_64 2022-09-05 11:15 UTC x86_64 Cygwin

Cygwin Packages

wget tar libtool bison gcc-g++ autoconf automake openssl libpcre2-devel libssl-devel libcurl-devel libxml2-devel libxslt-devel libgmp-devel ImageMagick libpng-devel libjpeg-devel libfreetype-devel libwebp-devel libsqlite3-devel zlib-devel libbz2-devel libzip-devel libicu-devel libonig-devel libcares-devel libsodium-devel libyaml-devel libMagick-devel 

Test Script

git clone https://github.com/php/php-src.git
cd php-src
git checkout PHP-8.1.12
cd ext
pecl download mongodb-1.14.2
tar xvf mongodb-1.14.2.tgz
mv mongodb-1.14.2 mongodb
cd ..

Configure

./buildconf --force
./configure --prefix=/usr --disable-all \
    --disable-fiber-asm \
    --disable-opcache \
    --without-pcre-jit \
    --with-openssl --enable-openssl \
    --with-curl \
    --with-iconv \
    --enable-intl \
    --with-bz2 \
    --enable-bcmath \
    --enable-filter \
    --enable-session \
    --enable-tokenizer \
    --enable-mbstring \
    --enable-ctype \
    --with-zlib \
    --with-zip \
    --enable-posix \
    --enable-sockets \
    --enable-pdo \
    --with-sqlite3 \
    --enable-phar \
    --enable-pcntl \
    --enable-mysqlnd \
    --with-mysqli \
    --enable-fileinfo \
    --with-pdo_mysql \
    --with-pdo-sqlite \
    --enable-soap \
    --with-xsl \
    --with-gmp \
    --enable-exif \
    --with-sodium \
    --enable-xml --enable-simplexml --enable-xmlreader --enable-xmlwriter --enable-dom --with-libxml \
    --enable-gd --with-jpeg  --with-freetype \
    --enable-mongodb

Build

make -j 8

/cygdrive/d/workspace/php-src/ext/mongodb/src/libmongocrypt/kms-message/src/kms_crypto.h:45:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
   45 | kms_crypto_init ();
      | ^~~~~~~~~~~~~~~
/cygdrive/d/workspace/php-src/ext/mongodb/src/libmongocrypt/kms-message/src/kms_crypto.h:48:1: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
   48 | kms_crypto_cleanup ();
      | ^~~~~~~~~~~~~~~~~~
/cygdrive/d/workspace/php-src/ext/mongodb/src/libmongocrypt/src/os_posix/os_dll.c:130:2: error: #error "Don't know how to do mcr_dll_path() on this platform"
  130 | #error "Don't know how to do mcr_dll_path() on this platform"
      |  ^~~~~

Expected and Actual Behavior

successfully compiled

Debug Log

@jmikola
Copy link
Member

jmikola commented Nov 14, 2022

Regarding the -Wstrict-prototypes warnings: I created PHPC-2166 and MONGOCRYPT-496 to fix that in the driver and libmongocrypt, respectively. It looks like this was recently addressed for libmongoc in CDRIVER-4484 so there was nothing to do there.

Regarding the build error in os_dll.c, that appears to be caused by libmongoc depending on _WIN32, which Cygwin intentionally does not define. See also:

Using the Linux implementation of mcr_dll_path() in this file seems unlikely to work as dlinfo() is not available on Cygwin. I'm not familiar with Windows' APIs, but this ML thread explains why it's not relevant.

I think the correct fix here would be to amend the _WIN32 check both here and in the related ../os_win/os_dll.c file to also consider __CYGWIN__ (per https://sourceforge.net/p/predef/wiki/OperatingSystems/). This would ensure that the Windows-specific implementations of the mcr_dll functions get compiled and used. I've opened MONGOCRYPT-497 to track this.

If you don't actually needed libmongocrypt, you can specify --with-mongodb-client-side-encryption=no as a configure argument to disable its compilation until we can address this upstream.

@jmikola jmikola added the tracked-in-jira Ticket filed in Mongo's Jira system label Nov 14, 2022
@matyhtf
Copy link
Author

matyhtf commented Nov 15, 2022

Thanks. After specifying the --with-mongodb-client-side-encryption=no argument, it can be successfully compiled, but a new error occurs when linking.

/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: warning: --export-dynamic is not supported for PE+ targets, did you mean --export-all-symbols?
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: ext/mongodb/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.o: in function `_mongoc_get_rr_search':
/cygdrive/d/workspace/php-src/ext/mongodb/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:499: undefined reference to `__ns_initparse'
/usr/lib/gcc/x86_64-pc-cygwin/11/../../../../x86_64-pc-cygwin/bin/ld: /cygdrive/d/workspace/php-src/ext/mongodb/src/libmongoc/src/libmongoc/src/mongoc/mongoc-client.c:511: undefined reference to `__ns_parserr'
collect2: error: ld returned 1 exit status
make: *** [Makefile:291: bin/php] Error 1

@jmikola
Copy link
Member

jmikola commented Nov 15, 2022

That last error matches what was originally reported in #848 (older issue from 2018). Based on https://bugs.bitlbee.org/ticket/1098, it looks like these APIs aren't available under Cygwin at all. I expect the fix for this issue would require a similar patch for libmongoc; however, libmongoc does not support or test on Cygwin (it's only mentioned in passing in the install docs). The closest environment in their CI matrix appears to be MinGW.

As for the PHP driver, our Windows builds are only tested with the standard PHP SDK, which uses Visual Studio and the config.w32 build script (not Autotools). Since neither our build scripts nor libmongoc support Cygwin, I'm not confident that fixing the above issue would fully resolve this. There are likely other incompatibilities lurking that would need to be resolved as well -- something to keep in mind if you want to venture down the rabbit hole and contribute patches.

Is there any reason you can't use Visual Studio and the PHP SDK to compile the driver and/or just use a DLL? I realize those were unavailable for the past few months after PECL stopped building them, but we recently started attaching DLLs for various Windows environments to our GitHub releases as a work around.

@matyhtf
Copy link
Author

matyhtf commented Feb 10, 2023

@jmikola
Thanks, we use pcntl, posix and other extensions that only support the linux/unix platform, and cygwin is required to run in the windows OS. Hope to support the cygwin platform in the future.

Best regards.

@matyhtf matyhtf closed this as completed Feb 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tracked-in-jira Ticket filed in Mongo's Jira system waiting-for-user
Projects
None yet
Development

No branches or pull requests

2 participants