Enhance Unix Makefile patch to disable auto-vectorization for zig-cc to prevent minilua segfault

This commit is contained in:
crazywhalecc
2026-05-10 15:17:51 +08:00
parent 21c868463a
commit 02d8f51bb2

View File

@@ -20,6 +20,7 @@ use StaticPHP\Package\PhpExtensionPackage;
use StaticPHP\Package\TargetPackage;
use StaticPHP\Runtime\SystemTarget;
use StaticPHP\Toolchain\Interface\ToolchainInterface;
use StaticPHP\Toolchain\ZigToolchain;
use StaticPHP\Util\DirDiff;
use StaticPHP\Util\FileSystem;
use StaticPHP\Util\GlobalEnvManager;
@@ -167,7 +168,8 @@ trait unix
#[BeforeStage('php', [self::class, 'makeForUnix'], 'php')]
#[PatchDescription('Patch Makefile to fix //lib path for Linux builds')]
public function tryPatchMakefileUnix(): void
#[PatchDescription('Patch BUILD_CC to disable auto-vectorization when zig-cc is used (prevents minilua segfault)')]
public function tryPatchMakefileUnix(ToolchainInterface $toolchain): void
{
if (SystemTarget::getTargetOS() !== 'Linux') {
return;
@@ -175,6 +177,12 @@ trait unix
// replace //lib with /lib in Makefile
shell()->cd(SOURCE_PATH . '/php-src')->exec('sed -i "s|//lib|/lib|g" Makefile');
// try to fix minilua with zig-cc, disable vectorize for some edge cases
if ($toolchain instanceof ZigToolchain) {
$makefile = "{$this->getSourceDir()}/Makefile";
FileSystem::replaceFileRegex($makefile, '/^(BUILD_CC\s*=\s*zig-cc)\s*$/m', '$1 -fno-vectorize -fno-slp-vectorize');
}
}
#[BeforeStage('php', [self::class, 'makeForUnix'], 'php')]