TypePHP 编译器
https://swoole.com/aot/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
2.5 KiB
2.5 KiB
构建流水线
Translator::compile() 把生成的 C++ 与 phpx 运行时源文件编译为对象文件,build() 再链接成最终产物。两者都委托给 src/Build/NativeBuilder,它负责真正派发编译/链接进程。
Sources: src/Translator.php · src/Translator.php
compile() 步骤
flowchart TD
A["compile(sourceFiles)"] --> B["追加 phpx misc 源\nfiber_generator / helper / main / cli_title"]
B --> C["preparePhpXPrecompiledHeader()"]
C --> D["compileResourceFile() (Windows)"]
D --> E{"支持 pcntl 且 -j>1?"}
E -- "否" --> F["compileSourceFile() 串行"]
E -- "是" --> G["compileWithPcntl() 并行"]
phpx misc 源(typephp_fiber_generator.cc、typephp_helper.cc、typephp_main.cc、php_cli_process_title.c、ps_title.c)按模式追加:embed 加 typephp_main.cc,bin 加 cli 标题源。
Sources: src/Translator.php
并行编译
compileWithPcntl() 在 Unix/Linux/macOS 用 pcntl_fork 多进程编译,进度条实时刷新;无 pcntl 扩展时自动降级为串行。每个 compileFile() 调用前都会先查 增量缓存,命中则跳过。
Sources: src/Translator.php · src/Translator.php
NativeBuilder 与命令选项
| 组件 | 职责 |
|---|---|
NativeBuilder |
真正执行 compile / link,返回 command/status/output |
NativeCommandOptionsTrait |
汇总编译/链接选项 |
CompileOptions / LinkOptions / CommandOptions |
选项数据对象 |
FileScanner |
识别原生源文件(C/C++/汇编/ObjC) |
SourceCompileQueue / SourcePipelineTrait |
编译队列与流水线调度 |
ResourceCompilationTrait |
Windows .rc → .res |
Sources: src/Build/NativeBuilder.php · src/Build/
build() 链接
build() 调 NativeBuilder::link(),Windows 模式下把 .res 资源文件并入目标;链接失败或产物未生成则 error() 退出。
Sources: src/Translator.php · src/Translator.php