Skip to content

Feat/pgo v3#1138

Open
henderkes wants to merge 56 commits into
v3from
feat/pgo-v3
Open

Feat/pgo v3#1138
henderkes wants to merge 56 commits into
v3from
feat/pgo-v3

Conversation

@henderkes
Copy link
Copy Markdown
Collaborator

What does this PR do?

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.

@henderkes henderkes marked this pull request as ready for review May 11, 2026 14:49
@henderkes henderkes requested a review from crazywhalecc May 11, 2026 14:49
@crazywhalecc crazywhalecc added the need-test This PR has not been tested yet, cannot merge now label May 12, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 12, 2026

StaticPHP Test Bot

Detected: Extensions: fastchart, fastjson | Libraries: bzip2, fastlz, icu, imagemagick, jbig, krb5, libaom, libheif, liblz4, ncurses, openssl, postgresql, qdbm, unixodbc, watcher | Targets: llvm-compiler-rt, llvm-tools, php
Active labels: none
Config: Linux x86_64 + Windows x86_64 + macOS arm64 | PHP 8.5 NTS

@henderkes
Copy link
Copy Markdown
Collaborator Author

(I tested with static-php/packages v3 branch, php 8.5 zig on rpm. Tests with Alpine and gcc are still to finish in a few hours when ci runs.)

@henderkes
Copy link
Copy Markdown
Collaborator Author

Wair, why is curl a target like php and not a package/library? We don't compile the exe right?

@crazywhalecc
Copy link
Copy Markdown
Owner

Wair, why is curl a target like php and not a package/library? We don't compile the exe right?

We could compile curl.exe, which shows that StaticPHP is not only suitable for building static PHP, but also for other projects. Just like we already support building pkg-config and re2c. Making them targets simply makes reasonable.

target is superset of library.

@henderkes
Copy link
Copy Markdown
Collaborator Author

Wair, why is curl a target like php and not a package/library? We don't compile the exe right?

We could compile curl.exe, which shows that StaticPHP is not only suitable for building static PHP, but also for other projects. Just like we already support building pkg-config and re2c. Making them targets simply makes reasonable.

target is superset of library.

Okay, added curl.exe on Windows too. Also figured out the root cause of the BUILD_CC patch minilua crash (zigs undefined behaviour sanitizer tripping up, if you run CC="clang -fsanitize=undefined" it will also fail) which coincidentally also fixed a possible edge case bug. BUILD_CC is also used for gen_ir so by using a different vm type it could have theoretically clashed.

@henderkes
Copy link
Copy Markdown
Collaborator Author

Oh, there's even an issue running the binaries despite no undefined sanitizer that I can't reproduce locally or in docker. Very weird.

@henderkes
Copy link
Copy Markdown
Collaborator Author

henderkes commented May 19, 2026

It's working as intended now, but compiling llvm binutils is really taking quite some time. We should host a prebuilt package for that and use that regardless of whether the user prefers prebuilts or not, there's no reason to rebuild this. It's static (always compiled with -musl) per arch-os.

I tried downloading llvm tarball instead, but GitHub gives me such a bad connection here in SEA that the wait time is too ridiculous.

@crazywhalecc
Copy link
Copy Markdown
Owner

We should host a prebuilt package for that and use that regardless of whether the user prefers prebuilts or not

Just add a workflow in static-php/hosted repo like icu-static-windows one.

@crazywhalecc
Copy link
Copy Markdown
Owner

crazywhalecc commented May 20, 2026

I tried downloading llvm tarball instead, but GitHub gives me such a bad connection here in SEA that the wait time is too ridiculous.

😞 Singapore VPN has the best speed accessing GitHub for me.

Comment on lines +1 to +15
<?php

declare(strict_types=1);

namespace StaticPHP\Doctor\Item;

use StaticPHP\Attribute\Doctor\CheckItem;
use StaticPHP\Attribute\Doctor\FixItem;
use StaticPHP\Attribute\Doctor\OptionalCheck;
use StaticPHP\DI\ApplicationContext;
use StaticPHP\Doctor\CheckResult;
use StaticPHP\Package\PackageInstaller;

#[OptionalCheck([self::class, 'optionalCheck'])]
class GoXcaddyCheck
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Is there any reason that we must check go-xcaddy in doctor check?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

not strictly necessary, but it makes things like pre building images by just running doctor a bit easier. you can remove it if you want

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Oh, I did forget to consider the base image in v3. But for FrankenPHP, I think it's easy to just run bin/spc install-pkg go-xcaddy after the doctor command.

*/
public function stripBinary(string $binary_path): void
{
$strip = ApplicationContext::tryGet(ToolchainInterface::class) instanceof ZigToolchain
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Why tryGet here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

for some reason the DI library you're using returns "true" for ->has even if the class is in fact not autowirable

return null;
}

private function reconcilePhpSrcVersion(): void
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This solution seems too wild, and I don't think it is appropriate here.

Comment on lines +737 to +746
if ($source_downloaded && $artifact->getName() === 'php-src' && ($requested = $this->getOption('with-php'))) {
$info = ApplicationContext::get(ArtifactCache::class)->getSourceInfo('php-src');
$cv = $info['version'] ?? null;
$ct = $info['cache_type'] ?? null;
$matches = $requested === 'git' ? $ct === 'git' : ($cv !== null && $ct !== 'git' && ($cv === $requested || str_starts_with($cv, $requested . '.')));
if (!$matches) {
$source_downloaded = false;
}
}

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

you want to try to switch PHP versions simply by changing --with-php?

Copy link
Copy Markdown
Collaborator Author

@henderkes henderkes May 22, 2026

Choose a reason for hiding this comment

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

Yes, --dl-with-php switches the php version in the build command, or spc download --with-php=.. switches the php version too. We shouldn't use the old version in source/php-src when the user explicitly switched it.

Even better would be to have different trees for different php versions (php-src-8.2, ... , php-src-8.5), that would simplify the switch more, but it's a larger refactor.

Edit: v2 already did this with the source dir stale logic. In v3 it kept rebuilding the old php versions even after switching.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Ah, I think I need to look into that. I previously designed a separate command to achieve this bin/spc switch-php-version. I have not considered using --with-php to switch it directly.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Anyway hardcoding looks strange in ArtifactDownloader and PackageInstaller, and I'll take a look at how to fix it later.

Copy link
Copy Markdown
Collaborator Author

@henderkes henderkes May 22, 2026

Choose a reason for hiding this comment

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

Ah, could you also add llvm-tools to static-php/hosted? We only need a x86-64 and an aarch64 version for linux (any maybe macOS in the future, pending m5 mini availability next month). They are linked statically (musl target, like all packages) and only update when zig version updates.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Of course, but let's take them one by one first 🤯 There's so much to do before releasing the first alpha version.

@henderkes
Copy link
Copy Markdown
Collaborator Author

wtf I have no idea what failed in the tests and why. it passes locally and looking for php-config there makes no sense, neither of the new extensions does it

@luthermonson
Copy link
Copy Markdown
Contributor

luthermonson commented May 22, 2026

had claude pull everything and this is what it thinks the problem is with CI

Why it broke now (not a PR regression)

  The earlier runs on this same PR (02:27, 06:11 today) passed. Then it broke at 08:43.

  - 06:11 green run used mongodb-2.3.2.tgz
  - 08:43 failed run used mongodb-2.3.3.tgz
  - mongodb 2.3.3 was released today at 07:07:49Z — right between those two runs
  - spc's ext-mongodb.yml uses type: ghrel + match: mongodb.+\.tgz, which always pulls the latest mongodb release. So CI silently picked up the new
  version.

I'll get a PR up with the fix and we'll see if it's right

luthermonson and others added 6 commits May 22, 2026 10:03
mongo-php-driver 2.3.3 added a config.m4 check that falls back to
php-config when PHP_VERSION_ID is unset in the shell env. In-tree
PHP source builds have no php-config, so configure fails with:

    checking PHP version... configure: error: php-config not found

Set PHP_VERSION_ID from main/php_version.h before configureForUnix
so the lookup short-circuits.
… (bleeds libpq polyfills into php configure, poisoning e.g. have_strlcat results)
@henderkes
Copy link
Copy Markdown
Collaborator Author

(current CI failures are because I didn't forward the temporary fixes for fastchart and clickhouse extensions, iliaa will probably release versions with my fixes upstreamed in a few days)

@crazywhalecc
Copy link
Copy Markdown
Owner

I'd like to merge some easily split parts of this branch into v3 first, so that the branch doesn't become too large and make reviews troublesome.

@henderkes
Copy link
Copy Markdown
Collaborator Author

Yes, I'm getting to a point where building static-php/packages based on this branch is possible. The majority of changes here are really just behaviour fixes that can be applied independently.

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

Labels

need-test This PR has not been tested yet, cannot merge now

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants