From efed2a73979ecd268930bf9805b5e422f22301fa Mon Sep 17 00:00:00 2001 From: Tianfeng Han Date: Thu, 30 Jul 2026 20:59:10 +0800 Subject: [PATCH] Fix windows [2] --- phpunit/src/Platform/PlatformTest.php | 27 +++++++++++++++++++++++++++ src/Build/SourcePipelineTrait.php | 13 +++++++++++-- src/Platform/Windows.php | 8 ++++---- 3 files changed, 42 insertions(+), 6 deletions(-) diff --git a/phpunit/src/Platform/PlatformTest.php b/phpunit/src/Platform/PlatformTest.php index e887eca3..76ee9688 100644 --- a/phpunit/src/Platform/PlatformTest.php +++ b/phpunit/src/Platform/PlatformTest.php @@ -65,6 +65,33 @@ class PlatformTest extends TestCase $this->assertStringContainsString('"php8ts.lib"', $flags); } + public function testWindowsMissingPhpxLibrariesAreFatalDiagnostics(): void + { + $root = sys_get_temp_dir() . '\\typephp-missing-phpx-' . bin2hex(random_bytes(6)); + mkdir($root); + + try { + $diagnostics = (new Windows())->getBuildLibraryWarnings($root, $root, 'bin'); + $errors = array_column($diagnostics, 'error'); + + $this->assertContains( + 'The PHPX import library was not found at: ' . $root . '\lib\phpx.lib', + $errors, + ); + $this->assertContains( + 'The PHPX runtime library `phpx.dll` was not found under: ' . $root, + $errors, + ); + foreach ($diagnostics as $diagnostic) { + if (isset($diagnostic['error'])) { + $this->assertStringContainsString('Build PHPX first', $diagnostic['info']); + } + } + } finally { + rmdir($root); + } + } + /** * 测试 Windows 路径规范化 */ diff --git a/src/Build/SourcePipelineTrait.php b/src/Build/SourcePipelineTrait.php index 7f212e39..88b7f340 100644 --- a/src/Build/SourcePipelineTrait.php +++ b/src/Build/SourcePipelineTrait.php @@ -14,6 +14,7 @@ use TypePhp\Exception\Unsupported; use TypePhp\Installer\LibPhpInstaller; use TypePhp\Installer\LibPhpxInstaller; use TypePhp\Platform\Linux; +use TypePhp\Platform\Windows; trait SourcePipelineTrait { @@ -98,9 +99,17 @@ trait SourcePipelineTrait // shell_exec 和 define 已通过 php::fn:: 直接调用,无需动态符号表 - // 根据平台检查库文件(仅在构建二进制文件时需要) - if ($this->isBuildModeEmbed()) { + // Windows 的所有构建模式都依赖 PHPX 导入库和运行库。 + // 其他平台仅在嵌入式构建模式下执行现有检查。 + if ($this->isBuildModeEmbed() || $this->getPlatform() instanceof Windows) { foreach ($this->getPlatform()->getBuildLibraryWarnings($this->getPhpDir(), $this->getPhpxDir(), $this->buildMode) as $message) { + if (!empty($message['error'])) { + $detail = $message['error']; + if (!empty($message['info'])) { + $detail .= "\n" . $message['info']; + } + $this->error($detail); + } $this->climate->warning($message['warning']); if (!empty($message['info'])) { $this->climate->info($message['info']); diff --git a/src/Platform/Windows.php b/src/Platform/Windows.php index ad16d6f5..22d69a80 100644 --- a/src/Platform/Windows.php +++ b/src/Platform/Windows.php @@ -200,8 +200,8 @@ class Windows extends PlatformBase $phpxLibPath = $phpxDir . '\lib\phpx.lib'; if (!is_file($phpxLibPath)) { $warnings[] = [ - 'warning' => 'The PHPX import library was not found at: ' . $phpxLibPath, - 'info' => 'Create the PHPX lib directory, reconfigure CMake if needed, then rebuild the phpx target', + 'error' => 'The PHPX import library was not found at: ' . $phpxLibPath, + 'info' => 'Build PHPX first (for example, run `nmake phpx` in ' . $phpxDir . '\build)', ]; } @@ -219,8 +219,8 @@ class Windows extends PlatformBase } if (!$hasPhpxDll) { $warnings[] = [ - 'warning' => 'The PHPX runtime library `phpx.dll` was not found under: ' . $phpxDir, - 'info' => 'Reconfigure CMake if needed, then rebuild the phpx target', + 'error' => 'The PHPX runtime library `phpx.dll` was not found under: ' . $phpxDir, + 'info' => 'Build PHPX first (for example, run `nmake phpx` in ' . $phpxDir . '\build)', ]; }