refactor(build): 优化编译链接逻辑并更新错误检查方式

- 修改 parseLibs 方法,根据构建模式动态添加 php 库依赖
- 将链接命令中的库解析移到条件判断内部,避免不必要的参数传递
- 添加新的 AST 转储脚本用于调试目的
- 更新弃用警告处理,在 gen_stub.php 中屏蔽 E_DEPRECATED 错误
- 修复 Translator 中的链接命令构造,移除重复的库解析调用
- 改进 arginfo 头文件生成的输出验证逻辑,使用 str_contains 替代 str_starts_with
```
pull/1/head
韩天峰 7 months ago
parent a6a06ca859
commit 37d0172164
  1. 2
      bin/dump-cpp-ast.php
  2. 2
      bin/gen_stub.php
  3. 13
      src/Php/CompilerBase.php
  4. 4
      src/Php/Translator.php

@ -0,0 +1,2 @@
<?php
shell_exec('clang -Xclang -ast-dump=json examples/project/ext.cc > test.json');

@ -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';

@ -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

@ -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;

Loading…
Cancel
Save