crazywhalecc / static-php-cli

Build standalone PHP binary on Linux, macOS, FreeBSD, Windows, with PHP project together, with popular extensions included.
https://static-php.dev
MIT License
1.33k stars 233 forks source link

Latest PHP versions can not be patched #527

Closed mpociot closed 2 months ago

mpociot commented 2 months ago

When trying to build the latest PHP versions, the Micro patches can not be applied.

[09:36:36] [ERRO] Uncaught SPC\exception\FileSystemException: Cannot extract source micro: Command run failed with code[1]: cd /Users/runner/work/static-php-builder/static-php-builder/source/php-src && cat sapi/micro/patches/static_opcache_83.patch sapi/micro/patches/static_extensions_win32_83.patch sapi/micro/patches/cli_checks_83.patch sapi/micro/patches/disable_huge_page_80.patch sapi/micro/patches/vcruntime140_80.patch sapi/micro/patches/win32_82.patch sapi/micro/patches/zend_stream.patch sapi/micro/patches/macos_iconv.patch | patch -p1  at /Users/runner/work/static-php-builder/static-php-builder/src/SPC/store/FileSystem.php(205)
[09:36:36] [ERRO] #0 /Users/runner/work/static-php-builder/static-php-builder/src/SPC/store/SourceManager.php(65): SPC\store\FileSystem::extractSource()

I assume something changed between 8.3.10/8.3.11 and 8.2.22/8.2.23

mpociot commented 2 months ago

Yup, so this patch is failing:

ext/opcache/config.m4

This line got changes in 8.3.11 https://github.com/php/php-src/compare/php-8.3.10...php-8.3.11#diff-fba8aed1e512099e6635bd4d9ffd939e0489105bc6b2c68d0bfe1abb0ee1007cR322

And the patch is looking for this line:

https://github.com/dixyes/phpmicro/blob/master/patches/static_opcache_83.patch#L62-L63

mpociot commented 2 months ago

@crazywhalecc What's the best way to fix this? Is there a fork of phpmicro being used? I have a working patch file but I'm not sure where to send a PR for this.

mpociot commented 2 months ago

Update: even though it compiles successfully with the updated patch file, the sanity check fails:

[11:48:48] [DEBU] [EXEC] /Users/marcelpociot/Code/static-php-builder/buildroot/bin/php --ri "Zend Opcache"
[11:48:48] [DEBU] Executed at: /Users/marcelpociot/Code/static-php-builder/src/SPC/builder/Extension.php:175

   SPC\exception\RuntimeException

  extension opcache failed compile check: php-cli returned 1

To reproduce:

./bin/spc download --with-php=8.3 --all --custom-url=micro:https://github.com/beyondcode/phpmicro/archive/refs/heads/master.zip
export SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS="-g -Os" && ./bin/spc build intl,pdo_sqlite,sqlite3,curl,openssl,tokenizer,bcmath,bz2,calendar,dba,ftp,iconv,mysqli,mbstring,mbregex,xml,simplexml,ctype,dom,pdo,filter,session,zlib,fileinfo,pdo_mysql,posix,sockets,shmop,sodium,sysvmsg,sysvsem,sysvshm,gd,zip,gmp,xmlwriter,phar,exif,xmlreader,readline,pcntl,soap,ffi,password-argon2,pgsql,pdo_pgsql,xsl,ldap,igbinary,zstd,opcache --debug --build-cli  --build-fpm --with-libs=nghttp2,liblz4  --debug --no-strip

When running ./buildroot/bin/php -i | grep opcache after a "successful" build, all I see is the --enable-opcache configure command argument. Opcache itself is not compiled/enabled.

crazywhalecc commented 2 months ago

Now the phpmicro repository in static-php is consistent with the upstream repository (easysoft/phpmicro). If this issue is caused by phpmicro, you can make PR at easysoft/phpmicro. I'll also ~remind~ask the phpmicro author later, as he may not check emails often.

mpociot commented 2 months ago

@crazywhalecc Thanks! Yeah so it's definitely the patch that needs to be updated. But even with a good patch, the opcache extension is now missing. I don't know enough about how micro works internalls to fix this I'm afraid. Or if this might be related to changes that need to be done in this repo.

mpociot commented 2 months ago

I opened a PR for phpmicro and added some tasks as I'm not really sure how micro and static-php work together/where things need to be fixed.

mpociot commented 2 months ago

Just to add some additional context, as someone suggested that the issue might be related to JIT. I tried to disable JIT but the opcache extension is still not properly registered.

The easiest way to reproduce this is:

./bin/spc build opcache --debug --disable-opcache-jit --build-cli --debug

Or with jit (as I used it before):

./bin/spc build opcache --debug --build-cli --debug

It does get passed to the make command correctly though, as I can see checking whether to enable Zend OPcache support... yes in the output.

I'd really appreciate any help in order to be able to update to the latest PHP version.

simonhamp commented 2 months ago

I know @mpociot is keen to get the latest PHP versions here, but as this problem is more widely breaking all fresh builds, it would be nice if it was possible to explicitly set the exact version of PHP we want to build, e.g. 8.3.10, which would at least allow us to continue building with a known release that worked...

crazywhalecc commented 2 months ago

@simonhamp @mpociot I understand. I'll temporarily fix this to avoid build errors caused by this patch file while we wait for @dixyes to fix the patch.

mpociot commented 2 months ago

@simonhamp You can already use --custom-url when downloading spx dependencies to specify an older PHP version

simonhamp commented 2 months ago

@mpociot i tried that, but i must be missing something about its syntax because every time i cleaned the downloads/source and then re-ran with a URL to an older release, it always fetched the latest version and the build step kept failing

crazywhalecc commented 2 months ago

@simonhamp I added x.y.z specific version download for --with-php option in #532 . You can switch php version using bin/spc switch-php-version 8.2.22 --debug command. Or you can directly download fresh new php-src using bin/spc download --for-extensions=xxx --with-php=8.2.22 --ignore-cache-sources=php-src.

simonhamp commented 2 months ago

🙏🏼 I will try this out shortly

simonhamp commented 2 months ago

@crazywhalecc this has worked for me to fixate on older versions for which these patches were working, nice job 👍🏼

crazywhalecc commented 2 months ago

This issue has been fixed via #536 .