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.
45 lines
2.0 KiB
45 lines
2.0 KiB
<blog>
|
|
|
|
# 跨平台支持
|
|
|
|
TypePHP 目标 **Windows / Linux / macOS** 三大桌面平台,通过 `Platform` 抽象隔离系统差异(编译器名、目标扩展名、PHP embed 库查找等)。
|
|
|
|
Sources: [src/Translator.php](src/Translator.php#L164-L190) · [src/Platform/](src/Platform/)
|
|
|
|
## 平台抽象
|
|
|
|
`PlatformFactory::create()` 按 OS 返回具体 `Platform` 对象(Windows / Linux / macOS)。`detectPlatform()` 在 `Translator` 构造时调用,得到平台名 + 后端名(如 `Windows + MSVC`)。
|
|
|
|
Sources: [src/Translator.php](src/Translator.php#L164-L190)
|
|
|
|
## 各平台要点
|
|
|
|
| 平台 | 默认后端 | 链接产物 | 特殊点 |
|
|
|---|---|---|---|
|
|
| Linux | GCC/Clang | ELF 可执行 / `.so` | 推荐 Ubuntu 22.04,需 `libphp.so` |
|
|
| macOS | Clang | Mach-O / `.dylib` | `strip` 可选 |
|
|
| Windows | MSVC | PE `.exe` / `.dll` | 需 Windows SDK + `php8ts.lib`;资源文件编译 |
|
|
|
|
Windows 分支会额外 `detectPhpLibs()` 探测 embed 与 core 的 `.lib`,并把 `isZts`、SDK 路径注入 `Windows` 对象。
|
|
|
|
Sources: [src/Translator.php](src/Translator.php#L170-L181) · [README.md](README.md#L42-L43)
|
|
|
|
## Windows 资源文件
|
|
|
|
`bin` 模式在 Windows 下编译 `.rc`(图标、版本信息、UAC 等,由 `project.yml` 的 `resource` 配置),生成的 `.res` 在 `build()` 链接时并入。资源文件生成见 `Generator/ResourceFileGenerator` 与 `Build/ResourceCompilationTrait`。
|
|
|
|
Sources: [project.yml](project.yml#L10-L24) · [src/Translator.php](src/Translator.php#L1653-L1659) · [src/Build/ResourceCompilationTrait.php](src/Build/ResourceCompilationTrait.php)
|
|
|
|
## libphp.so 自动安装
|
|
|
|
Linux 缺 `libphp.so` 时,`tpc.php` 可交互式下载 PHP 源码并自动构建,详见 `docs/LIBPHP_INSTALLER.md`;安装器逻辑在 `src/Installer/`。
|
|
|
|
Sources: [README.md](README.md#L27) · [src/Installer/](src/Installer/)
|
|
|
|
## 相关阅读
|
|
|
|
- 后端命令如何生成 → [编译器后端](backend)
|
|
- 链接与资源并入 → [构建流水线](build-pipeline)
|
|
- 二进制打包(UPX/strip) → README 的 Release packaging 段
|
|
|
|
</blog>
|
|
|