Skip to content

feat: add SaiAdmin AOT profile and native compilation - #1

Open
supdger wants to merge 17 commits into
Tinywan:mainfrom
supdger:feat/saiadmin-aot-profile
Open

supdger wants to merge 17 commits into
Tinywan:mainfrom
supdger:feat/saiadmin-aot-profile

Conversation

@supdger

@supdger supdger commented Sep 14, 2026

Copy link
Copy Markdown

背景

SaiAdmin 及其随附依赖包含一批 TypePHP v0.8 当前无法直接编译或运行的动态写法。这个 PR 复用现有 doctor、Docker builder、TypePHP 编译和 portable-dir 打包链,增加一个失败关闭的 SaiAdmin Linux amd64 profile,不另建编译器或同功能插件。

使用方式

php webman typephp:doctor
php webman typephp:package --profile=saiadmin

主要改动

  • 自动发现 SaiAdmin 核心、appsupport 和所有 plugin/*/app 服务端业务 PHP。
  • .typephp/build/ 生成版本和源码结构受约束的兼容副本,不修改普通 PHP 源码或项目 vendor。
  • 为每条规则校验依赖版本、源码 reference 和预期命中数量;版本漂移、未命中或重复命中立即失败。
  • 生成逐文件 source-coverage.json,阻止业务 PHP 漏编译、静默排除或泄漏进 portable-dir。
  • 修复实际复现的 Webman、Workerman、ThinkORM、Carbon、SaiAdmin 与 TypePHP v0.8 兼容缺口。
  • 增加开发规范、迁移指南、支持矩阵、配置样例、中立插件及产物/业务验收脚本。

验证

  • Pest:128 passed,1,369 assertions(1 个既有 fixture warning)
  • PHP 8.4 syntax:通过
  • Shell syntax 与 git diff --check:通过
  • Linux amd64 完整编译/链接:2,283 / 2,283
  • SaiAdmin 业务源码覆盖:142 / 142(131 直接编译,11 由等价 AOT 副本替代)
  • portable-dir、ELF x86-64、动态库、运行资源、manifest、coverage hash 与业务源码泄漏检查:通过
  • 隔离环境:验证码、登录、用户信息、权限拒绝和中立插件路由通过
  • 普通 PHP 对照:相同业务路径通过

当前边界

  • 首版仅支持 Linux amd64/glibc 和文档中锁定的 SaiAdmin 6.1.1 依赖组合。
  • 未知插件或依赖版本漂移会停止构建,不会静默丢失功能。
  • Windows exe/DLL 不在本 PR 范围。

@supdger

supdger commented Sep 15, 2026

Copy link
Copy Markdown
Author

已补充脱敏的 Linux amd64 AOT 实跑证据,包含锁定版本、完整编译数量、ELF/动态库/coverage 校验、三组产物 SHA-256、Workerman 启动记录、验证码/登录/用户信息/权限拒绝/中立插件路径,以及普通 PHP 对照和复现命令:

https://github.com/supdger/webman-typephp/blob/feat/saiadmin-aot-profile/docs/saiadmin-aot/docs/verification-evidence.md

Tinywan pushed a commit that referenced this pull request Sep 17, 2026
TypePHP 编译产物以严格类型模式调用内置函数,实参不再经 coercive 模式做
__toString 宽松转换,而 webman `Config::loadFromDir()` 与 `Route::load()`
把 RecursiveDirectoryIterator 产出的 SplFileInfo 直接交给 is_dir()/substr()/
pathinfo()/include,编译后启动即抛
`is_dir(): Argument #1 ($filename) must be of type string, SplFileInfo given`。

新增 STRINGABLE_ARG_SOURCES 与 generateStringableArgSources(),把这些迭代器
实参统一改写为 `$file->getPathname()` 并忽略 vendor 原版,取值语义不变。
需要按缩进消歧的同名语句只在行首 \n 锚定:行尾锚定在 CRLF 源上永不命中
(分号与 \n 之间还夹着 \r),LF/CRLF 两种行尾因此都能命中。PackageCommand
同步登记 stringable-arg 分组,补丁产物写入 build-manifest.json 的
stringable_arg_hashes。补充单元测试覆盖五处改写点,并断言 read() 与
loadAnnotationRoutes() 中同名不同缩进的字符串实参不被误伤。
@supdger supdger changed the title feat: add SaiAdmin Linux AOT profile feat: add SaiAdmin AOT profile and native compilation Sep 18, 2026
@supdger

supdger commented Sep 18, 2026

Copy link
Copy Markdown
Author

补充非 Docker 原生编译支持与实跑证据(提交 77570d8)。

新增命令:

php webman typephp:doctor --target=native
php webman typephp:compile --profile=saiadmin

本机验证组合:macOS arm64、PHP ZTS 8.5.10、TypePHP 0.9.0、Apple Clang、SaiAdmin 6.1.5、Webman v2.2.4。

验证结果:

  • TypePHP 编译、C++ 编译与链接完成:2056 / 2056
  • 产物:Mach-O 64-bit arm64,82,796,672 bytes
  • SHA-256:d44177577a346bd76f2a5d96048634fb9c2c94b5ac97f668560f0584028899c0
  • AOT 安全启动:Workerman 监听 127.0.0.1:8787,1 worker
  • 验证码:HTTP 200 / JSON 业务码 200,包含 UUID 和图片
  • 未登录权限拒绝:HTTP 200 / JSON 业务码 401
  • 普通 PHP 对照:相同两条路径分别为 200/200、200/401
  • 插件测试:164 passed,1571 assertions;格式、PHP 语法与 git diff --check 通过

原生模式生成当前宿主平台程序,不承诺跨平台:macOS 输出为 Mach-O,不作为 Linux portable-dir。Linux 发布路径仍使用 typephp:package --profile=saiadmin。完整命令、工具链要求、支持矩阵和证据已写入仓库文档。

@Tinywan

Tinywan commented Sep 19, 2026

Copy link
Copy Markdown
Owner

代码有冲突

  1. 让 PR rebase 最新 main 分支:
    git fetch upstream
    git rebase upstream/main

  2. 重点适配 TypePHP v0.9.0:因为 main 分支已经移除了 docker/CompilerBase.php 等一整套本地热补丁代码(转由 TypePHP v0.9.0 官方镜像直接支持),需要确认其在旧编译器里打的补丁在 v0.9.0 下是否依然需要;如果不需要,应丢弃对已删除文件的改动;如果仍需要,应考虑通过 TypePHP v0.9.0 的机制或新方式引入。

  3. 解决冲突后强推到 PR 分支,GitHub 冲突状态即可解除并允许合并。

@Tinywan Tinywan added the good first issue Good for newcomers label Sep 19, 2026
@supdger

supdger commented Sep 19, 2026

Copy link
Copy Markdown
Author

目标 SaiAdmin 项目在 Docker/Linux 主路径复现到新的首个真实阻碍:

Fatal error: Conversion method Illuminate\Http\Resources\Json\JsonResource::toArray() must not accept arguments

提交 1f18de0 增加 Illuminate JSON Resource AOT 副本规则:

  • 普通 vendor 源码保持不变。
  • AOT 副本提供 TypePHP 要求的零参数 toArray(): array
  • 请求感知转换迁移到 toResourceArray(Request),覆盖 JsonResourceResourceCollectionJsonApiResource
  • 规则对当前项目的真实 Illuminate 源码逐项命中,并在源码结构漂移时失败关闭。

验证:新增 12 条断言;插件全量测试 165 passed / 1583 assertions(保留 1 条既有 fixture warning);格式和语法检查通过。完整 Docker 编译需要目标项目更新到该提交后继续,以发现下一个真实阻碍。

@supdger

supdger commented Sep 19, 2026

Copy link
Copy Markdown
Author

SaiAdmin 6.1.5 Linux amd64 follow-up is complete in 0ecbb29.

  • Full TypePHP generation: 2,231 / 2,231
  • Full C++ compilation: 2,235 / 2,235
  • ELF link and portable-dir packaging: passed
  • First-party coverage: 151 / 151 classified (134 direct, 17 generated AOT copies)
  • Isolated MySQL 8.4 acceptance: captcha, administrator login, authenticated user info, limited-user login, and permission denial all passed
  • Plugin suite: 166 passed, 1,599 assertions; one existing fixture warning
  • Portable-dir contract, formatter, and diff checks: passed

The follow-up fixes the Docker compiler late-static optimization, Grapheme constant generation, Fiber context writes, and Workerman pool WeakMap writes. The compatibility matrix and verification evidence include the supported versions, artifact hashes, and the remaining ordinary-PHP 8.4 SystemException nullable deprecation boundary.

@Tinywan

Tinywan commented Sep 19, 2026

Copy link
Copy Markdown
Owner

#1 以下文件冲突了,合并不了

This branch has conflicts that must be resolved
Use the command line to resolve conflicts before continuing.

README.md
docker/AssignOpTrait.php
docker/CompilerBase.php
docker/Dockerfile
docker/FuncCallOptimizer.php
docker/Translator.php
docker/gen_stub.php
src/Commands/PackageCommand.php
src/Compiler/ProjectGenerator.php
src/config/plugin/tinywan/typephp/app.php
tests/Unit/CompilerBaseCompatibilityTest.php
tests/Unit/PackageCommandTest.php

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants