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.
 
 
韩天峰 7418b6247e feat(parser): optimize string concatenation assignment operations 5 days ago
.claude/plans docs(architecture): 添加代码复用改进计划和封装审查文档 2 months ago
.github refactor(tests): replace native_types and complex_types with Type constants 1 month ago
bin refactor(bin): replace define with const in tpc.php 4 weeks ago
completions 移除 8.2、8.3 版本的支持 2 weeks ago
docs fix(array-def): update list index validation to use PHP's append position 6 days ago
examples feat(parser): optimize string concatenation assignment operations 5 days ago
phpunit feat(parser): optimize string concatenation assignment operations 5 days ago
src feat(parser): optimize string concatenation assignment operations 5 days ago
tests feat(parser): optimize string concatenation assignment operations 5 days ago
wasm build(wasm): update wit-bindgen dependency management 2 weeks ago
.clang-format update 8 months ago
.gitignore fix(parser): handle constant expression type detection with namespace fallback 2 weeks ago
.php-cs-fixer.dist.php Revert "style(config): 更新PHP代码样式配置" 4 months ago
CLAUDE.md rename(tests): move aot tests directory to compiler 1 month ago
LICENSE.md Native Class 支持 [第五阶段] 1 week ago
README.md 移除 8.2、8.3 版本的支持 2 weeks ago
app.manifest feat(build): 支持 Windows 应用程序清单文件配置 2 months ago
ast.py 支持目录处理 8 months ago
clean-elf.sh chore(build): 更新版本号并优化打包脚本 2 months ago
cli.php feat(cli): add polyfill requirement to CLI bootstrap 1 month ago
composer.json chore(deps): update swoole/phpx dependency to version ~2.6.1 6 days ago
composer.lock 修复 macOS 下的问题 4 weeks ago
package.json Native Class 支持 [第五阶段] 1 week ago
package.php build(wasm): update wit-bindgen dependency management 2 weeks ago
phpunit.xml feat(compiler): 添加测试模式和静态变量重复检测功能 5 months ago
project.yml refactor(docs): update file paths and directory structure references 2 months ago
rounds.txt update 8 months ago
run-tests.php Native Class 支持 [第九阶段] 1 week ago
swoole-logo.ico feat(build): 添加 Windows 资源文件支持功能 4 months ago
swoole-logo.svg feat(build): 添加 Windows 资源文件支持功能 4 months ago
version.txt feat(parser): optimize string concatenation assignment operations 5 days ago

README.md

依赖

  • 编译器和生成程序均需要 PHP 8.4 以上版本,支持 PHP 8.4~8.5
  • 需要 GCC-9 以上版本,支持 C++17 标准
  • 需要 CMake-3.24 以上版本
  • 需要高精度数学库:GMPMPFRlibmpdec

Composer 安装

在项目中安装 TypePHP:

composer require --dev swoole/typephp

安装后可直接编译项目:

vendor/bin/tpc.php project.yml

在 TypePHP 源码仓库中则使用:

bin/tpc.php project.yml

Linux 环境缺少 libphp.so 时,tpc.php 可以交互式下载 PHP 源码并自动构建,详见 自动构建 libphp.so

Python namespace IDE helper 与 Python 源码转换也使用同一入口:

./tpc --gen-python-helper math
./tpc --gen-python-helper numpy --output-dir .ide-helper
./tpc --convert-python-to-php script.py > script.php

详细说明见 Python 工具子模块

# Ubuntu/Debian
sudo apt install libgmp-dev libmpfr-dev libmpdec-dev

# RHEL/CentOS/Fedora
sudo dnf install gmp-devel mpfr-devel libmpdec-devel

# Arch Linux
sudo pacman -S gmp mpfr mpdecimal

GMP 用于 BigInt 任意精度整数,MPFR 用于 BigFloat 高精度浮点数,libmpdec 用于 Decimal 十进制高精度小数。

预览版目前仅支持 Linux 系统,建议使用 Ubuntu 22.04

PHP

必须包含 embed 模块

PHPX

可使用 composer install 安装依赖。 进入 vendor/swoole/phpx 目录,编译 phpx

cd vendor/swoole/phpx
cmake .
make -j32

动态链接库

sudo ldconfig -p | grep php

必须包含 libphp.solibphpx.so

若编译完成,但找不到动态链接库,需要修改

vim /etc/ld.so.conf.d/swoole.conf 

添加路径

/home/swoole/workspace/projects/phpx/lib
/opt/php-8.4/lib/

Release packaging

Use the same PHP entry point on Windows, Linux, and macOS:

php package.php

Windows packaging requires PHP_HOME and PHPX_HOME; Linux packaging requires UPX; macOS uses strip when available. TypePHP rejects 32-bit targets and supports common 64-bit CPU architectures, including x86-64 and ARM64.