From 37d0172164841a281e517088925873e4c2ae7ab0 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Mon, 26 Jan 2026 16:28:07 +0800 Subject: [PATCH] =?UTF-8?q?```=20refactor(build):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E7=BC=96=E8=AF=91=E9=93=BE=E6=8E=A5=E9=80=BB=E8=BE=91=E5=B9=B6?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=94=99=E8=AF=AF=E6=A3=80=E6=9F=A5=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 parseLibs 方法,根据构建模式动态添加 php 库依赖 - 将链接命令中的库解析移到条件判断内部,避免不必要的参数传递 - 添加新的 AST 转储脚本用于调试目的 - 更新弃用警告处理,在 gen_stub.php 中屏蔽 E_DEPRECATED 错误 - 修复 Translator 中的链接命令构造,移除重复的库解析调用 - 改进 arginfo 头文件生成的输出验证逻辑,使用 str_contains 替代 str_starts_with ``` --- bin/dump-cpp-ast.php | 2 ++ bin/gen_stub.php | 2 +- src/Php/CompilerBase.php | 13 +++++++++---- src/Php/Translator.php | 4 ++-- 4 files changed, 14 insertions(+), 7 deletions(-) create mode 100644 bin/dump-cpp-ast.php diff --git a/bin/dump-cpp-ast.php b/bin/dump-cpp-ast.php new file mode 100644 index 00000000..e7a7fa26 --- /dev/null +++ b/bin/dump-cpp-ast.php @@ -0,0 +1,2 @@ + test.json'); \ No newline at end of file diff --git a/bin/gen_stub.php b/bin/gen_stub.php index f7d15ca5..33835225 100755 --- a/bin/gen_stub.php +++ b/bin/gen_stub.php @@ -6095,7 +6095,7 @@ function main() { global $argv, $argc, $translator; - error_reporting(E_ALL); + error_reporting(E_ALL & ~E_DEPRECATED); ini_set("precision", "-1"); require __DIR__ . '/bootstrap.php'; diff --git a/src/Php/CompilerBase.php b/src/Php/CompilerBase.php index 420b0b6e..f3da5c1f 100644 --- a/src/Php/CompilerBase.php +++ b/src/Php/CompilerBase.php @@ -1186,10 +1186,10 @@ class CompilerBase extends \PhpAot\Core\Translator protected function parseLibs(): string { - $list = [ - 'phpx', - 'php', - ]; + $list = ['phpx']; + if ($this->buildMode === 'bin') { + $list[] = 'php'; + } $out = ''; foreach ($list as $li) { $out .= '-l' . $li . ' '; @@ -1215,6 +1215,11 @@ class CompilerBase extends \PhpAot\Core\Translator $cmd .= ' -fPIC -D BUILD_PHP_EXTENSION=1'; } } + + if ($link) { + $cmd .= ' ' . $this->parseLdflags(); + $cmd .= ' ' . $this->parseLibs(); + } } protected function parseBinaryOpConcat(mixed $expr): string diff --git a/src/Php/Translator.php b/src/Php/Translator.php index 83c9d7f1..630ae539 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -474,7 +474,7 @@ class Translator extends Preprocessor if ($this->buildMode == 'ext' and !str_ends_with($targetFile, '.so')) { $targetFile .= '.so'; } - $linkCmd = $this->cppCompiler . ' ' . $objectList . ' -o ' . $targetFile . ' ' . $this->parseLdflags() . $this->parseLibs(); + $linkCmd = $this->cppCompiler . ' ' . $objectList . ' -o ' . $targetFile; $this->addCompilationOption($linkCmd, true); $this->climate->comment($linkCmd); shell_exec($linkCmd); @@ -578,7 +578,7 @@ class Translator extends Preprocessor $this->climate->comment($genStubCmd); $stubFilenameWithoutExtension = str_replace([".stub.php", '.php'], "", $file); $headerFile = $this->getArgInfoHeaderFile($stubFilenameWithoutExtension, true); - if (!str_starts_with($output, "Saved")) { + if (!str_contains($output, "Saved")) { $this->error("failed to generate arginfo header file: `$headerFile`, output: $output"); } $this->argInfoHeaderFiles[] = $headerFile;