[MONGOCRYPT-390] Build errors compiling PHP driver with bundled libmongocrypt 1.3.1 on Windows Created: 02/Mar/22  Updated: 28/Oct/23  Resolved: 09/Mar/22

Status: Closed
Project: Libmongocrypt
Component/s: None
Affects Version/s: 1.3.1
Fix Version/s: 1.3.2

Type: Bug Priority: Unknown
Reporter: Jeremy Mikola Assignee: Colby Pike
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to MONGOCRYPT-391 Add 32 bit Windows builds to Evergreen Closed
is related to PHPC-2031 Upgrade libmongoc to 1.21.1 and libmo... Closed

 Description   

I observed several build errors (see: AppVeyor task log) compiling PHPC with bundled libmongocrypt 1.3.1. An abridged log is below:

C:\projects\mongodb\src\libmongocrypt\src\mlib/thread.h(81): error C2440: 'function': cannot convert from 'BOOL (__cdecl *)(INIT_ONCE *,void *,void *)' to 'PINIT_ONCE_FN' (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt-util.c)
C:\projects\mongodb\src\libmongocrypt\src\mlib/thread.h(81): warning C4024: 'InitOnceExecuteOnce': different types for formal and actual parameter 2 (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt-util.c)
C:\projects\mongodb\src\libmongocrypt\src\mlib/thread.h(81): error C2440: 'function': cannot convert from 'BOOL (__cdecl *)(INIT_ONCE *,void *,void *)' to 'PINIT_ONCE_FN' (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt.c)
C:\projects\mongodb\src\libmongocrypt\src\mlib/thread.h(81): warning C4024: 'InitOnceExecuteOnce': different types for formal and actual parameter 2 (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt.c)
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared\ws2def.h(103): warning C4005: 'AF_IPX': macro redefinition (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt.c)
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um\winsock.h(457): note: see previous definition of 'AF_IPX' (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt.c)
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared\ws2def.h(147): warning C4005: 'AF_MAX': macro redefinition (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt.c)
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um\winsock.h(476): note: see previous definition of 'AF_MAX' (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt.c)
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared\ws2def.h(187): warning C4005: 'SO_DONTLINGER': macro redefinition (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt.c)
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um\winsock.h(399): note: see previous definition of 'SO_DONTLINGER' (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt.c)
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared\ws2def.h(240): error C2011: 'sockaddr': 'struct' type redefinition (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt.c)
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\um\winsock.h(482): note: see declaration of 'sockaddr' (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt.c)
C:\Program Files (x86)\Windows Kits\10\include\10.0.22000.0\shared\ws2def.h(442): error C2059: syntax error: 'constant' (compiling source file C:\projects\mongodb\src\libmongocrypt\src\mongocrypt.c)

The errors in mlib/thread.h stand out, but there are also many errors/warnings due to redefined macros and symbols. It's not clear to me if the issue is caused by our build environment or libmongocrypt directly, but I'll note that previous builds of libmongocrypt 1.3.0 had no issues (see: task log). The current errors appear throughout our CI matrix, which includes VS16 (PHP 8.0+) and VS15 (PHP 7.x).



 Comments   
Comment by Githook User [ 18/Mar/22 ]

Author:

{'name': 'vector-of-bool', 'email': 'vectorofbool@gmail.com', 'username': 'vector-of-bool'}

Message: No global WIN32_LEAN_AND_MEAN required. [Fix MONGOCRYPT-390] (#258)
Branch: r1.3
https://github.com/mongodb/libmongocrypt/commit/64e75583ce71094315e3a0ba0785ff394656c360

Comment by Colby Pike [ 09/Mar/22 ]

Fixed in https://github.com/mongodb/libmongocrypt/pull/256 and https://github.com/mongodb/libmongocrypt/pull/258

Comment by Githook User [ 04/Mar/22 ]

Author:

{'name': 'vector-of-bool', 'email': 'vectorofbool@gmail.com', 'username': 'vector-of-bool'}

Message: No global WIN32_LEAN_AND_MEAN required. [Fix MONGOCRYPT-390] (#258)
Branch: master
https://github.com/mongodb/libmongocrypt/commit/fb853ed4b3d1fc911f9533adba3ee6490e209000

Comment by Jeremy Mikola [ 04/Mar/22 ]

and PHPC can sort out the other errors by defining WIN32_LEAN_AND_MEAN during compilation of bundled libmongocrypt sources.

It turns out this wasn't feasible to address in PHPC, as defining WIN32_LEAN_AND_MEAN globally introduced other issues.

Subsequent PR: https://github.com/mongodb/libmongocrypt/pull/258

Comment by Jeremy Mikola [ 03/Mar/22 ]

PR: https://github.com/mongodb/libmongocrypt/pull/256

Sharing some context from Slack:

On Windows it now also requires WIN32_LEAN_AND_MEAN to be defined for each source as well. That will fix the majority of the errors in the linked build failure. The error with PINIT_ONCE_FN only emerges on 32-bit builds, so it wasn't caught before merging.

The PR above will address the PINIT_ONCE_FN issue, and PHPC can sort out the other errors by defining WIN32_LEAN_AND_MEAN during compilation of bundled libmongocrypt sources.

Generated at Thu Feb 08 09:08:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.