@ -353,14 +353,14 @@ class CompilerBase extends \PhpAot\Core\Translator
// 如果 PATH 中没有,尝试从 LLVM_HOME 环境变量获取
// 如果 PATH 中没有,尝试从 LLVM_HOME 环境变量获取
$llvmHome = getenv('LLVM_HOME');
$llvmHome = getenv('LLVM_HOME');
if ($llvmHome & & is_dir($llvmHome)) {
if ($llvmHome & & is_dir($llvmHome)) {
$clangPath = rtrim($llvmHome, '\\ /') . '\x64\bin\clang++.exe';
$clangPath = rtrim($llvmHome, '\/') . '\x64\bin\clang++.exe';
if (file_exists($clangPath)) {
if (file_exists($clangPath)) {
// 验证是否可以执行
// 验证是否可以执行
exec('"' . $clangPath . '" --version 2>& 1', $output, $returnCode);
exec('"' . $clangPath . '" --version 2>& 1', $output, $returnCode);
if ($returnCode === 0) {
if ($returnCode === 0) {
// 将 Clang 路径添加到环境变量
// 将 Clang 路径添加到环境变量
$clangDir = dirname($clangPath);
$clangDir = dirname($clangPath);
putenv("PATH=$clangDir;" . getenv('PATH'));
putenv("PATH={ $clangDir} ;" . getenv('PATH'));
// 检查是否有 lld-link
// 检查是否有 lld-link
$this->checkLldLinker();
$this->checkLldLinker();
@ -391,13 +391,13 @@ class CompilerBase extends \PhpAot\Core\Translator
// 如果 PATH 中没有,尝试从 LLVM_HOME 获取
// 如果 PATH 中没有,尝试从 LLVM_HOME 获取
$llvmHome = getenv('LLVM_HOME');
$llvmHome = getenv('LLVM_HOME');
if ($llvmHome & & is_dir($llvmHome)) {
if ($llvmHome & & is_dir($llvmHome)) {
$lldLinkPath = rtrim($llvmHome, '\\ /') . '\x64\bin\lld-link.exe';
$lldLinkPath = rtrim($llvmHome, '\/') . '\x64\bin\lld-link.exe';
if (file_exists($lldLinkPath)) {
if (file_exists($lldLinkPath)) {
exec('"' . $lldLinkPath . '" --version 2>& 1', $output, $returnCode);
exec('"' . $lldLinkPath . '" --version 2>& 1', $output, $returnCode);
if ($returnCode === 0) {
if ($returnCode === 0) {
// 将 lld-link 路径添加到环境变量
// 将 lld-link 路径添加到环境变量
$lldDir = dirname($lldLinkPath);
$lldDir = dirname($lldLinkPath);
putenv("PATH=$lldDir;" . getenv('PATH'));
putenv("PATH={ $lldDir} ;" . getenv('PATH'));
$this->linker = 'lld-link';
$this->linker = 'lld-link';
$this->climate->info('Using lld-link linker from LLVM_HOME (faster than link.exe)');
$this->climate->info('Using lld-link linker from LLVM_HOME (faster than link.exe)');
return;
return;
@ -415,7 +415,7 @@ class CompilerBase extends \PhpAot\Core\Translator
// 优先使用环境变量 PHPX_HOME
// 优先使用环境变量 PHPX_HOME
$phpxDir = getenv('PHPX_HOME');
$phpxDir = getenv('PHPX_HOME');
if ($phpxDir & & is_dir($phpxDir)) {
if ($phpxDir & & is_dir($phpxDir)) {
return rtrim($phpxDir, '\\ /');
return rtrim($phpxDir, '\/');
}
}
// 默认路径
// 默认路径
@ -438,7 +438,7 @@ class CompilerBase extends \PhpAot\Core\Translator
// Windows 下尝试从环境变量获取 PHP 路径
// Windows 下尝试从环境变量获取 PHP 路径
$phpDir = getenv('PHP_HOME');
$phpDir = getenv('PHP_HOME');
if ($phpDir & & is_dir($phpDir)) {
if ($phpDir & & is_dir($phpDir)) {
return rtrim($phpDir, '\\ /');
return rtrim($phpDir, '\/');
}
}
// 尝试从 php.exe 路径推断(使用 where 命令)
// 尝试从 php.exe 路径推断(使用 where 命令)
@ -446,12 +446,12 @@ class CompilerBase extends \PhpAot\Core\Translator
if ($phpExe) {
if ($phpExe) {
$phpDir = dirname($phpExe);
$phpDir = dirname($phpExe);
if (is_dir($phpDir)) {
if (is_dir($phpDir)) {
return rtrim($phpDir, '\\ /');
return rtrim($phpDir, '\/');
}
}
}
}
// 默认路径
// 默认路径
return 'C:\\ php';
return 'C:\php';
} else {
} else {
// Unix/Linux/macOS 下使用 php-config 获取 PHP 路径
// Unix/Linux/macOS 下使用 php-config 获取 PHP 路径
$phpDir = shell_exec('php-config --prefix 2>/dev/null');
$phpDir = shell_exec('php-config --prefix 2>/dev/null');
@ -2292,18 +2292,15 @@ class CompilerBase extends \PhpAot\Core\Translator
protected function parseWindowsIncludes(): string
protected function parseWindowsIncludes(): string
{
{
$list = [
$list = [
$this->getPhpxDir() . '\\ include',
$this->getPhpxDir() . '\include',
$this->getBuildDir() . '\\ include',
$this->getBuildDir() . '\include',
$this->getPhpxDir() . '\\ src\ \misc',
$this->getPhpxDir() . '\src\misc',
];
];
// Windows 下 PHP 头文件必须从 SDK/include 读取
// Windows 下 PHP 头文件必须从 SDK/include 读取
$phpSdkInclude = $this->getPhpDir() . '\\ SDK\ \include';
$phpSdkInclude = $this->getPhpDir() . '\SDK\include';
if (!is_dir($phpSdkInclude)) {
if (!is_dir($phpSdkInclude)) {
throw new \RuntimeException(
throw new \RuntimeException("PHP SDK include directory not found: {$phpSdkInclude}\n" . 'Please ensure PHP is installed with SDK headers at the expected location.');
"PHP SDK include directory not found: {$phpSdkInclude}\n" .
"Please ensure PHP is installed with SDK headers at the expected location."
);
}
}
// 添加主包含目录
// 添加主包含目录
@ -2375,19 +2372,19 @@ class CompilerBase extends \PhpAot\Core\Translator
$list = [];
$list = [];
// Windows 下 PHP 库文件固定从 SDK/lib 读取
// Windows 下 PHP 库文件固定从 SDK/lib 读取
$phpLib = $this->getPhpDir() . '\\ SDK\ \lib';
$phpLib = $this->getPhpDir() . '\SDK\lib';
if (is_dir($phpLib)) {
if (is_dir($phpLib)) {
$list[] = $phpLib;
$list[] = $phpLib;
} else {
} else {
// 备选:尝试直接从 lib 目录
// 备选:尝试直接从 lib 目录
$phpLibAlt = $this->getPhpDir() . '\\ lib';
$phpLibAlt = $this->getPhpDir() . '\lib';
if (is_dir($phpLibAlt)) {
if (is_dir($phpLibAlt)) {
$list[] = $phpLibAlt;
$list[] = $phpLibAlt;
}
}
}
}
// phpx 库文件
// phpx 库文件
$phpxLib = $this->getPhpxDir() . '\\ lib';
$phpxLib = $this->getPhpxDir() . '\lib';
if (is_dir($phpxLib)) {
if (is_dir($phpxLib)) {
$list[] = $phpxLib;
$list[] = $phpxLib;
}
}
@ -2425,12 +2422,12 @@ class CompilerBase extends \PhpAot\Core\Translator
$list = [];
$list = [];
// 优先使用 .lib 导入库
// 优先使用 .lib 导入库
$phpxLib = $this->getPhpxDir() . '\\ lib\ \phpx.lib';
$phpxLib = $this->getPhpxDir() . '\lib\phpx.lib';
if (file_exists($phpxLib)) {
if (file_exists($phpxLib)) {
$list[] = '"' . $phpxLib . '"';
$list[] = '"' . $phpxLib . '"';
} else {
} else {
// 如果没有 .lib,尝试直接使用 DLL(需要生成导入库)
// 如果没有 .lib,尝试直接使用 DLL(需要生成导入库)
$phpxDll = $this->getPhpxDir() . '\\ lib\ \phpx.dll';
$phpxDll = $this->getPhpxDir() . '\lib\phpx.dll';
if (file_exists($phpxDll)) {
if (file_exists($phpxDll)) {
$this->climate->magenta('phpx.lib not found, using phpx.dll directly');
$this->climate->magenta('phpx.lib not found, using phpx.dll directly');
$this->climate->info('Note: You may need to generate phpx.lib from phpx.dll using lib /def:phpx.def');
$this->climate->info('Note: You may need to generate phpx.lib from phpx.dll using lib /def:phpx.def');
@ -2448,16 +2445,18 @@ class CompilerBase extends \PhpAot\Core\Translator
// 6. lib/php8.lib
// 6. lib/php8.lib
$phpDirs = [
$phpDirs = [
$this->getPhpDir() . '\\ SDK\ \lib', // 优先从 SDK/lib 查找
$this->getPhpDir() . '\SDK\lib', // 优先从 SDK/lib 查找
$this->getPhpDir() . '\\ lib', // 备选从 lib 查找
$this->getPhpDir() . '\lib', // 备选从 lib 查找
];
];
$found = false;
$found = false;
foreach ($phpDirs as $phpDir) {
foreach ($phpDirs as $phpDir) {
if (!is_dir($phpDir)) continue;
if (!is_dir($phpDir)) {
continue;
}
// 尝试 php8embed.lib (嵌入模式)
// 尝试 php8embed.lib (嵌入模式)
$phpEmbedLib = $phpDir . '\\ php8embed.lib';
$phpEmbedLib = $phpDir . '\php8embed.lib';
if (file_exists($phpEmbedLib)) {
if (file_exists($phpEmbedLib)) {
$list[] = '"' . $phpEmbedLib . '"';
$list[] = '"' . $phpEmbedLib . '"';
$found = true;
$found = true;
@ -2465,7 +2464,7 @@ class CompilerBase extends \PhpAot\Core\Translator
}
}
// 尝试 php8ts.lib
// 尝试 php8ts.lib
$phpTsLib = $phpDir . '\\ php8ts.lib';
$phpTsLib = $phpDir . '\php8ts.lib';
if (file_exists($phpTsLib)) {
if (file_exists($phpTsLib)) {
$list[] = '"' . $phpTsLib . '"';
$list[] = '"' . $phpTsLib . '"';
$found = true;
$found = true;
@ -2473,7 +2472,7 @@ class CompilerBase extends \PhpAot\Core\Translator
}
}
// 尝试 php8.lib
// 尝试 php8.lib
$phpLib = $phpDir . '\\ php8.lib';
$phpLib = $phpDir . '\php8.lib';
if (file_exists($phpLib)) {
if (file_exists($phpLib)) {
$list[] = '"' . $phpLib . '"';
$list[] = '"' . $phpLib . '"';
$found = true;
$found = true;
@ -2483,14 +2482,14 @@ class CompilerBase extends \PhpAot\Core\Translator
// 如果都没找到 .lib,尝试直接使用根目录的 DLL
// 如果都没找到 .lib,尝试直接使用根目录的 DLL
if (!$found) {
if (!$found) {
$phpDll = $this->getPhpDir() . '\\ php8.dll';
$phpDll = $this->getPhpDir() . '\php8.dll';
if (file_exists($phpDll)) {
if (file_exists($phpDll)) {
$this->climate->magenta('php8embed.lib not found, using php8.dll directly');
$this->climate->magenta('php8embed.lib not found, using php8.dll directly');
$this->climate->info('Note: This may require additional setup');
$this->climate->info('Note: This may require additional setup');
$list[] = '"' . $phpDll . '"';
$list[] = '"' . $phpDll . '"';
} else {
} else {
// 尝试 php8ts.dll
// 尝试 php8ts.dll
$phpTsDll = $this->getPhpDir() . '\\ php8ts.dll';
$phpTsDll = $this->getPhpDir() . '\php8ts.dll';
if (file_exists($phpTsDll)) {
if (file_exists($phpTsDll)) {
$this->climate->magenta('php8embed.lib not found, using php8ts.dll directly');
$this->climate->magenta('php8embed.lib not found, using php8ts.dll directly');
$this->climate->info('Note: This may require additional setup');
$this->climate->info('Note: This may require additional setup');
@ -2678,7 +2677,7 @@ class CompilerBase extends \PhpAot\Core\Translator
if (in_array($san, $validSanitizers)) {
if (in_array($san, $validSanitizers)) {
$enabledSanitizers[] = $san;
$enabledSanitizers[] = $san;
} else {
} else {
$this->climate->warning("Unsupported sanitizer: $san");
$this->climate->warning("Unsupported sanitizer: { $san} ");
}
}
}
}
@ -2786,7 +2785,7 @@ class CompilerBase extends \PhpAot\Core\Translator
if (in_array($san, $validSanitizers)) {
if (in_array($san, $validSanitizers)) {
$enabledSanitizers[] = $san;
$enabledSanitizers[] = $san;
} else {
} else {
$this->climate->warning("Unsupported sanitizer: $san");
$this->climate->warning("Unsupported sanitizer: { $san} ");
}
}
}
}