fix(build): select opcode decoder from build PHP CLI version

master
韩天峰 3 weeks ago
parent cb548e5a2a
commit 5bfe58c0f8
  1. 22
      src/Translator.php

@ -2218,19 +2218,15 @@ CODE;
$sourceFiles[] = $this->getPhpxDir() . '/src/misc/typephp_main.cc'; $sourceFiles[] = $this->getPhpxDir() . '/src/misc/typephp_main.cc';
if ($this->bundledFiles !== [] || $this->embeddedOpcodeFiles !== []) { if ($this->bundledFiles !== [] || $this->embeddedOpcodeFiles !== []) {
$sourceFiles[] = $this->getPhpxDir() . '/src/misc/typephp_opcode_table.cc'; $sourceFiles[] = $this->getPhpxDir() . '/src/misc/typephp_opcode_table.cc';
$versionHeader = $this->isWindows() // Select the decoder for the PHP CLI that generated the blobs.
? $this->getPhpDir() . '/SDK/include/main/php_version.h' // Distribution PHP headers need not live under the PHP prefix.
: $this->getPhpDir() . '/include/php/main/php_version.h'; $this->getOpcodeBuildExtensionArgs();
$versionText = is_file($versionHeader) ? file_get_contents($versionHeader) : ''; if (!preg_match('/^8\.(4|5)\./', $this->opcodeBuildPhpVersion, $versionMatch)) {
if (!preg_match('/#define PHP_VERSION_ID\s+(\d+)/', $versionText, $versionMatch)) { throw new \RuntimeException(
throw new \RuntimeException("Cannot determine the target PHP version from {$versionHeader}"); "Unsupported opcode decoder PHP version: {$this->opcodeBuildPhpVersion}",
} );
$targetPhpVersion = (int) $versionMatch[1]; }
$decoder = match (true) { $decoder = 'opcode_unserialize_8' . $versionMatch[1] . '.c';
$targetPhpVersion >= 80400 && $targetPhpVersion < 80500 => 'opcode_unserialize_84.c',
$targetPhpVersion >= 80500 && $targetPhpVersion < 80600 => 'opcode_unserialize_85.c',
default => throw new \RuntimeException("Unsupported opcode decoder PHP version: {$targetPhpVersion}"),
};
$sourceFiles[] = $this->getPhpxDir() . '/thirdparty/opcache/' . $decoder; $sourceFiles[] = $this->getPhpxDir() . '/thirdparty/opcache/' . $decoder;
} }
} }

Loading…
Cancel
Save