From dfb6f693c3b01aff3e09997fca621c1f2fe4baa8 Mon Sep 17 00:00:00 2001 From: yurunsoft Date: Wed, 17 Jun 2026 10:15:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20Windows=20=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E6=B5=8B=E8=AF=95=20(#1)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Yurun Reviewed-on: https://git.code-galaxy.net/aot/compiler/pulls/1 Co-authored-by: yurunsoft Co-committed-by: yurunsoft --- composer.json | 4 +++- run-tests.php | 14 +++++++++++--- src/Php/CompilerBase.php | 2 +- tests/aot/basic/file_operations.phpt | 8 ++++---- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/composer.json b/composer.json index ff16a7ae..17c643f3 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,6 @@ { "require": { "php": ">=8.2 <8.6", - "ext-pcntl": "*", "nikic/php-parser": "5.6.1", "league/climate": "^3.10", "marcj/topsort": "^2.0", @@ -22,5 +21,8 @@ "cs-fix": "php-cs-fixer fix $1", "analyse": "phpstan analyse --memory-limit 512M -l 5 -c phpstan.neon", "rector": "rector process --clear-cache" + }, + "suggest": { + "ext-pcntl": "Required for process control features." } } diff --git a/run-tests.php b/run-tests.php index acae634a..8755bc52 100755 --- a/run-tests.php +++ b/run-tests.php @@ -2461,7 +2461,7 @@ $message return 'FAILED'; } $args = substr($args, strlen(' -- ')); - $cmd = './' . $bin_file . ' ' . $args . $cmdRedirect; + $cmd = (IS_WINDOWS ? '.\\' : './') . $bin_file . ' ' . $args . $cmdRedirect; } else { $content = file_get_contents($test_file); if (preg_match('/function main\(\)/', $content)) { @@ -2667,7 +2667,7 @@ COMMAND $cmd $file = substr($test_file, 0, strlen($test_file) - 4); @unlink($file . '.cc'); @unlink($file . '.cc.o'); - @unlink('./' . $bin_file); + @unlink($bin_file); } } @unlink($tmp_post); @@ -4249,6 +4249,9 @@ function compile_php_file(string $file): string throw new CompilationFailureException('Invalid PHP file'); } $binary_file = str_replace('-', '_', basename($file, '.php')); + if (IS_WINDOWS) { + $binary_file .= '.exe'; + } if (!str_contains($data, 'function main()')) { file_put_contents($file, "&1', $output, $exitCode); + $cmd = $compiler_path; + // On Windows, .php files need to be run through the PHP interpreter + if (IS_WINDOWS && str_ends_with($cmd, '.php')) { + $cmd = escapeshellarg(PHP_BINARY) . ' ' . $cmd; + } + exec($cmd . ' ' . escapeshellarg($file) . ' 2>&1', $output, $exitCode); clearstatcache(true, $binary_file); if ($exitCode !== 0 || !file_exists($binary_file)) { diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index d9c416af..6edaf650 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1168,7 +1168,7 @@ class CompilerBase extends \PhpAot\Core\Translator $key = $this->parseIdentifier($expr); if (str_starts_with($key, self::LITERAL_STRINGS)) { $key = "{$key}.str()"; - } elseif ($key === '0L') { + } elseif ($key === '0L' || $key === '0LL') { // 0 在 C++ 中是一个特殊的值,存在二义性,既是空指针,也是整数,这会导致产生 ambiguous 错误 // 必须转为 php::zero 常量,保证作为 key 时正确匹配到 IntKeyMap $key = self::VALUE_ZERO; diff --git a/tests/aot/basic/file_operations.phpt b/tests/aot/basic/file_operations.phpt index 64a67dbd..07b3c9b7 100644 --- a/tests/aot/basic/file_operations.phpt +++ b/tests/aot/basic/file_operations.phpt @@ -97,8 +97,8 @@ rmdir($tempDir); echo "Cleanup completed\n"; ?> --EXPECTF-- -Directory created: /tmp/aot_test_%s -File created: /tmp/aot_test_%s/test.txt +Directory created: %s +File created: %s/test.txt File content: Hello, World! This is a test file. @@ -114,8 +114,8 @@ Directory contents: - second_test.txt - test.txt First line from handle: Hello, World! -File copied to: /tmp/aot_test_%s/copied_test.txt -File moved to: /tmp/aot_test_%s/moved_test.txt +File copied to: %s/copied_test.txt +File moved to: %s/moved_test.txt Is test file a file: yes Is temp dir a directory: yes File modification time: %d-%d-%d %d:%d:%d