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

Protobuf PHP Extension cannot be built on windows. "Cannot open include file: 'sys/time.h'" #17852

Open
gwharton opened this issue Aug 18, 2024 · 1 comment

Comments

@gwharton
Copy link

gwharton commented Aug 18, 2024

Microsoft Windows 11
Microsoft Visual Studio Community 2022
Protocol Buffers v27.3

Building the protobuf PHP extension on windows fails due to dependency on sys/time.h

c:\Users\GrahamWharton\php-sdk-binary-tools\php8.3.10\vs17\x64\php-src
$ "C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.41.34120\bin\HostX64\x64\nmake.exe" /I /nologo "php_protobuf.dll"
        "cl.exe" /I..\pecl\protobuf/third_party/utf8_range /D ZEND_COMPILE_DL_EXT=1 /D COMPILE_DL_PROTOBUF /D PROTOBUF_EXPORTS=1 /nologo /I . /I main /I Zend /I TSRM /I ext /D _WINDOWS /D WINDOWS=1 /D ZEND_WIN32=1 /D PHP_WIN32=1 /D WIN32 /D _MBCS /D _USE_MATH_DEFINES /FD /wd4996 /Qspectre /guard:cf /Zc:inline /Gw /Zc:__cplusplus /d2FuncCache1 /Zc:wchar_t /MP /Zi /LD /MD /Ox /D NDebug /D NDEBUG /GF /D ZEND_DEBUG=0 /I "C:\Users\GrahamWharton\php-sdk-binary-tools\php8.3.10\vs17\x64\deps\include" /D FD_SETSIZE=256 /DHAVE_ARGON2ID_HASH_RAW=1 /FoC:\Users\GrahamWharton\php-sdk-binary-tools\php8.3.10\vs17\x64\php-src\x64\Release\pecl\protobuf\third_party\utf8_range\ /FpC:\Users\GrahamWharton\php-sdk-binary-tools\php8.3.10\vs17\x64\php-src\x64\Release\pecl\protobuf\third_party\utf8_range\ /FRC:\Users\GrahamWharton\php-sdk-binary-tools\php8.3.10\vs17\x64\php-src\x64\Release\pecl\protobuf\third_party\utf8_range\ /FdC:\Users\GrahamWharton\php-sdk-binary-tools\php8.3.10\vs17\x64\php-src\x64\Release\pecl\protobuf\third_party\utf8_range\ /c ..\pecl\protobuf\third_party\utf8_range\lemire-avx2.c ..\pecl\protobuf\third_party\utf8_range\lemire-neon.c ..\pecl\protobuf\third_party\utf8_range\lemire-sse.c ..\pecl\protobuf\third_party\utf8_range\lookup.c ..\pecl\protobuf\third_party\utf8_range\main.c ..\pecl\protobuf\third_party\utf8_range\naive.c ..\pecl\protobuf\third_party\utf8_range\range-avx2.c ..\pecl\protobuf\third_party\utf8_range\range-neon.c ..\pecl\protobuf\third_party\utf8_range\range-sse.c ..\pecl\protobuf\third_party\utf8_range\range2-neon.c ..\pecl\protobuf\third_party\utf8_range\range2-sse.c ..\pecl\protobuf\third_party\utf8_range\utf8_range.c
lemire-avx2.c
lemire-neon.c
lemire-sse.c
lookup.c
main.c
naive.c
range-avx2.c
range-neon.c
range-sse.c
range2-neon.c
..\pecl\protobuf\third_party\utf8_range\main.c(7): fatal error C1083: Cannot open include file: 'sys/time.h': No such file or directory
range2-sse.c
utf8_range.c
..\pecl\protobuf\third_party\utf8_range\utf8_range.c(38): warning C4141: 'inline': used more than once
..\pecl\protobuf\third_party\utf8_range\utf8_range.c(45): warning C4141: 'inline': used more than once
..\pecl\protobuf\third_party\utf8_range\utf8_range.c(49): warning C4141: 'inline': used more than once
..\pecl\protobuf\third_party\utf8_range\utf8_range.c(178): warning C4141: 'inline': used more than once

This seems to be an issue with the extensions config.<m4/w32> files.

Here the Linux module config compiles only third_party/utf8_range/utf8_range.c from the utf8_range library

PHP_ARG_ENABLE(protobuf, whether to enable Protobuf extension, [ --enable-protobuf Enable Protobuf extension])
if test "$PHP_PROTOBUF" != "no"; then
PHP_NEW_EXTENSION(
protobuf,
arena.c array.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c third_party/utf8_range/utf8_range.c,
$ext_shared, , -std=gnu99 -I@ext_srcdir@/third_party/utf8_range)
PHP_ADD_BUILD_DIR($ext_builddir/third_party/utf8_range)
fi

Whereas the windows module config appears to compile /third_party/utf8_range/*.c

ARG_ENABLE("protobuf", "whether to enable Protobuf extension", "no");
if (PHP_PROTOBUF != "no") {
var PHP_PROTOBUF_SRC_ARRAY = glob(configure_module_dirname + "/third_party/utf8_range/*.c");
var PHP_PROTOBUF_SOURCES=" ";
for (var i=0; i<PHP_PROTOBUF_SRC_ARRAY.length; ++i) {
var basename = FSO.GetFileName(PHP_PROTOBUF_SRC_ARRAY[i]);
PHP_PROTOBUF_SOURCES = PHP_PROTOBUF_SOURCES + " " + basename;
}
ADD_SOURCES(configure_module_dirname + "/third_party/utf8_range", PHP_PROTOBUF_SOURCES, "PROTOBUF");
ADD_FLAG("CFLAGS_PROTOBUF", "/I" + configure_module_dirname + "/third_party/utf8_range");
EXTENSION("protobuf", "arena.c array.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c");
}

changing the file https://github.com/protocolbuffers/protobuf/blob/025909cb539359c8001cf69707229587d430adff/php/ext/google/protobuf/config.w32 to

ARG_ENABLE("protobuf", "whether to enable Protobuf extension", "no");

if (PHP_PROTOBUF != "no") {
  ADD_SOURCES(configure_module_dirname + "/third_party/utf8_range", "utf8_range.c", "PROTOBUF");
  ADD_FLAG("CFLAGS_PROTOBUF", "/I" + configure_module_dirname + "/third_party/utf8_range");
  EXTENSION("protobuf", "arena.c array.c convert.c def.c map.c message.c names.c php-upb.c protobuf.c");
}

Resolves this issue and allows the php Extension to build under windows.

@gwharton gwharton changed the title Protobufs use of <sys/time.h> prevents building of protobuf php extension on Windows Protobuf PHP Extension cannot be built on windows. <sys/time.h> prevents building of protobuf php extension on Windows Aug 19, 2024
@gwharton gwharton changed the title Protobuf PHP Extension cannot be built on windows. <sys/time.h> prevents building of protobuf php extension on Windows Protobuf PHP Extension cannot be built on windows. The build fails with file not found <sys/time.h> Aug 19, 2024
@gwharton gwharton changed the title Protobuf PHP Extension cannot be built on windows. The build fails with file not found <sys/time.h> Protobuf PHP Extension cannot be built on windows. "Cannot open include file: 'sys/time.h'" Aug 19, 2024
gwharton referenced this issue Aug 20, 2024
This PR adds a config.w32 for the PHP extension and includes it in the tgz for PECL.
I used this to build php_protobuf.dll for PHP 8.2.7.
See phalcon/cphalcon#16318 (comment) for the request to build the extension and the result.

Please review and merge.

Closes #13097

COPYBARA_INTEGRATE_REVIEW=#13097 from Jan-E:php-windows 4259af1
PiperOrigin-RevId: 542050878
@zhangskz
Copy link
Member

Thanks for raising this -- please feel free to send us a PR with the proposed fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants