Skip to content

Fix grpc build - #1055

Merged
crazywhalecc merged 4 commits into
mainfrom
fix/grpc-build
Mar 10, 2026
Merged

crazywhalecc merged 4 commits into
mainfrom
fix/grpc-build

Conversation

@crazywhalecc

Copy link
Copy Markdown
Owner

What does this PR do?

Closes #1054

Checklist before merging

If your PR involves the changes mentioned below and completed the action, please tick the corresponding option.
If a modification is not involved, please skip it directly.

  • If you modified *.php or *.json, run them locally to ensure your changes are valid:
    • composer cs-fix
    • composer analyse
    • composer test
    • bin/spc dev:sort-config
  • If it's an extension or dependency update, please ensure the following:
    • Add your test combination to src/globals/test-extensions.php.
    • If adding new or fixing bugs, add commit message containing extension test or test extensions to trigger full test suite.

@crazywhalecc

crazywhalecc commented Mar 9, 2026 •

Copy link
Copy Markdown
Owner Author

Using ext-grpc to compile all grpc dependencies looks not good for our build procedure.

First of all, it's too slow for building static php binary every time. Building separately could reduce a lot of time when debugging and publishing. And another potential issue is building openssl, libcares and zlib twice. And also, although we can make a patch for boringssl and openssl built by grpc source to solve the CI error above, it often leads to misleading errors when building in-tree ext-grpc with all dependencies.

@henderkes

henderkes commented Mar 9, 2026 •

Copy link
Copy Markdown
Collaborator

I know, but the extension is just shit. There's nothing we can do about it, short of completely replacing the extension build logic. We built the library standalone before, but the extension build doesn't use prebuilt libraries, it builds every time no matter what.

@crazywhalecc
crazywhalecc requested a review from henderkes March 10, 2026 07:05
Comment on lines +31 to +58
$config_m4 = <<<'M4'
PHP_ARG_ENABLE(grpc, [whether to enable grpc support], [AS_HELP_STRING([--enable-grpc], [Enable grpc support])])

if test "$PHP_GRPC" != "no"; then
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/include)
PHP_ADD_INCLUDE(PHP_EXT_SRCDIR()/src/php/ext/grpc)
GRPC_LIBDIR=@@build_lib_path@@
PHP_ADD_LIBPATH($GRPC_LIBDIR)
PHP_ADD_LIBRARY(grpc,,GRPC_SHARED_LIBADD)
LIBS="-lpthread $LIBS"
PHP_ADD_LIBRARY(pthread)

case $host in
*darwin*)
PHP_ADD_LIBRARY(c++,1,GRPC_SHARED_LIBADD)
;;
*)
PHP_ADD_LIBRARY(stdc++,1,GRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY(rt,,GRPC_SHARED_LIBADD)
PHP_ADD_LIBRARY(rt)
;;
esac

PHP_NEW_EXTENSION(grpc, @grpc_c_files@, $ext_shared, , -DGRPC_POSIX_FORK_ALLOW_PTHREAD_ATFORK=1)
PHP_SUBST(GRPC_SHARED_LIBADD)
PHP_INSTALL_HEADERS([ext/grpc], [php_grpc.h])
fi
M4;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Very ugly, but the best we can do at this point. We will need to keep it in sync with version changes, though.

@crazywhalecc crazywhalecc Mar 10, 2026 •

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Yes, and for now, unless it changes the interface, we can tolerate it adding new files. It's ugly, but much simpler than patching the original files.

Comment on lines 17 to 18
// '8.2',
// '8.3',

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

did you test for 8.3 too? 8.2 can be ignored.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

I even tested it locally on version 8.0, and this m4 basically has maximum compatibility.

@crazywhalecc
crazywhalecc merged commit 281b958 into main Mar 10, 2026
17 checks passed
@crazywhalecc
crazywhalecc deleted the fix/grpc-build branch March 10, 2026 11:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ext-grpc build failed on macOS and Linux

2 participants