rename(compiler): update compiler executable name from compiler.php to tpc.php

- Change all documentation references from bin/compiler.php to bin/tpc.php
- Update composer.json with new binary entry point
- Update run-tests.php default compiler path
- Update all example commands and guides to use new executable name
- Add composer package configuration for swoole/typephp
- Update README installation instructions for new naming convention
pull/17/head
韩天峰 1 month ago
parent 1ac190959c
commit b0455f143a
  1. 20
      README.md
  2. 0
      bin/tpc.php
  3. 6
      composer.json
  4. 2
      composer.lock
  5. 2
      docs/AOT_BUILD_SPEED_RESEARCH.md
  6. 12
      docs/COMPILATION_MODES.md
  7. 14
      docs/COMPILER_CLI.md
  8. 2
      docs/HIGH_PRECISION_TYPES.md
  9. 6
      docs/MIXED_CPP_PHP.md
  10. 10
      docs/QUICKSTART.md
  11. 2
      docs/peachpie-review.md
  12. 2
      examples/lib-demo/README.md
  13. 4
      examples/tetris-sdl/README.md
  14. 16
      examples/tetris-sdl/USAGE_GUIDE.md
  15. 4
      examples/tetris-win32/README.md
  16. 16
      examples/tetris-win32/USAGE_GUIDE.md
  17. 36
      examples/win32-hello/CONFIG_PRIORITY_RULES.md
  18. 20
      examples/win32-hello/CXX_STD_CONFIG_GUIDE.md
  19. 8
      examples/win32-hello/YAML_CONFIG_NAMING_CONVENTION.md
  20. 4
      run-tests.php
  21. 2
      tests/compiler/RUN_TESTS_GUIDE.md

@ -4,6 +4,26 @@
- 需要 CMake-3.24 以上版本
- 需要高精度数学库:`GMP`、`MPFR`、`libmpdec`
# Composer 安装
在项目中安装 TypePHP:
```bash
composer require --dev swoole/typephp
```
安装后可直接编译项目:
```bash
vendor/bin/tpc.php project.yml
```
在 TypePHP 源码仓库中则使用:
```bash
bin/tpc.php project.yml
```
```shell
# Ubuntu/Debian
sudo apt install libgmp-dev libmpfr-dev libmpdec-dev

@ -1,4 +1,10 @@
{
"name": "swoole/typephp",
"description": "TypePHP native AOT compiler",
"type": "library",
"bin": [
"bin/tpc.php"
],
"require": {
"php": ">=8.4 <8.6",
"nikic/php-parser": "5.6.1",

2
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "72caced27fd0c3469dae5d4f4db591d0",
"content-hash": "ad62f0e0eada43bfe6673b9830c827b9",
"packages": [
{
"name": "ajaxray/ansikit",

@ -6,7 +6,7 @@
降低以下两类耗时:
1. **冷启动全量构建**:`./bin/compiler.php project.yml`
1. **冷启动全量构建**:`./bin/tpc.php project.yml`
2. **热启动增量构建**:只改少量 PHP 文件后再次编译
重点关注大型项目和编译器自举场景。

@ -15,14 +15,14 @@ PHP AOT 编译器支持两种编译模式,每种模式针对不同的使用场
### 编译命令
```bash
php bin/compiler.php <source_dir> --mode=ext -o <output_name>
php bin/tpc.php <source_dir> --mode=ext -o <output_name>
```
### 示例
```bash
# 编译 Coolify 项目
php bin/compiler.php projects/coolify/app/ --mode=ext -o coolify
php bin/tpc.php projects/coolify/app/ --mode=ext -o coolify
# 输出文件
coolify.so # Linux
@ -117,14 +117,14 @@ function route_handler($path) {
### 编译命令
```bash
php bin/compiler.php <source_dir> -o <output_binary>
php bin/tpc.php <source_dir> -o <output_binary>
```
### 示例
```bash
# 编译 Workerman 项目
php bin/compiler.php projects/workerman/src/ -o workerman
php bin/tpc.php projects/workerman/src/ -o workerman
# 输出文件
workerman # Linux 可执行文件
@ -300,7 +300,7 @@ echo json_encode($data);
**编译**:
```bash
php bin/compiler.php api-project/src/ --mode=ext -o api_extension
php bin/tpc.php api-project/src/ --mode=ext -o api_extension
```
**使用**:
@ -343,7 +343,7 @@ function main(int $argc, array $argv) {
**编译**:
```bash
php bin/compiler.php cli-tool/src/ -o mytool
php bin/tpc.php cli-tool/src/ -o mytool
```
**使用**:

@ -3,26 +3,26 @@
本文档与 `src/Translator.php::showUsage()` 保持同步。使用:
```bash
bin/compiler.php <file|dir|project.yml> [options] [-- program-args...]
bin/tpc.php <file|dir|project.yml> [options] [-- program-args...]
```
## 常用示例
```bash
# 编译单文件
bin/compiler.php app.php
bin/tpc.php app.php
# 优化并运行,`--` 后参数传给生成的程序
bin/compiler.php app.php -O2 -r -- --flag value
bin/tpc.php app.php -O2 -r -- --flag value
# 编译项目配置
bin/compiler.php project.yml -O2 -j 8
bin/tpc.php project.yml -O2 -j 8
# 生成 PHP 扩展
bin/compiler.php extension/ -m ext -o my_extension
bin/tpc.php extension/ -m ext -o my_extension
# 只生成 C++,不编译和链接
bin/compiler.php app.php --dry --build-dir /tmp/typephp-build
bin/tpc.php app.php --dry --build-dir /tmp/typephp-build
```
## 构建选项
@ -86,7 +86,7 @@ bin/compiler.php app.php --dry --build-dir /tmp/typephp-build
命令行实现可能继续演进,发布版本的实际参数以以下命令为准:
```bash
bin/compiler.php --help
bin/tpc.php --help
```
兼容性边界参见 [INCOMPATIBLE_PHP_FEATURES.md](INCOMPATIBLE_PHP_FEATURES.md),构建模式参见 [COMPILATION_MODES.md](COMPILATION_MODES.md)。

@ -70,7 +70,7 @@ function main(): void {
编译运行:
```bash
php bin/compiler.php my_program.php -o my_program
php bin/tpc.php my_program.php -o my_program
./my_program
```

@ -626,7 +626,7 @@ sources:
```bash
# 编译项目
php bin/compiler.php examples/prime -o prime
php bin/tpc.php examples/prime -o prime
# 运行生成的可执行文件
./prime
@ -911,7 +911,7 @@ function get_adult_users() {
```bash
# 保留中间文件
php bin/compiler.php project --dry --build-dir /tmp/typephp-build
php bin/tpc.php project --dry --build-dir /tmp/typephp-build
# 查看生成的 C++ 代码
find /tmp/typephp-build -name '*.cc' -o -name '*.cpp'
@ -934,7 +934,7 @@ php::Int php_safe_add(php::Int a, php::Int b) {
```bash
# 编译时添加调试信息
php bin/compiler.php project -o app --debug
php bin/tpc.php project -o app --debug
# 使用 perf 分析性能
perf record ./app

@ -46,7 +46,7 @@ composer install
### 3. 验证安装
```bash
php bin/compiler.php --help
php bin/tpc.php --help
```
如果看到帮助信息,说明安装成功!
@ -102,7 +102,7 @@ function main() {
#### 编译命令
```bash
php bin/compiler.php my-project/src/ -o my-app
php bin/tpc.php my-project/src/ -o my-app
```
#### 运行程序
@ -132,7 +132,7 @@ php bin/compiler.php my-project/src/ -o my-app
#### 编译命令
```bash
php bin/compiler.php my-project/src/ --mode=ext -o calculator
php bin/tpc.php my-project/src/ --mode=ext -o calculator
```
#### 安装扩展
@ -269,14 +269,14 @@ project/
**A**: 使用 `--dry` 只生成中间代码,并通过 `--build-dir` 指定目录。
```bash
php bin/compiler.php src/ --dry --build-dir /tmp/typephp-build
php bin/tpc.php src/ --dry --build-dir /tmp/typephp-build
```
### Q: 编译速度慢怎么办?
**A**: 使用并行编译选项 `-j`
```bash
php bin/compiler.php src/ -o app -j4 # 使用 4 个进程
php bin/tpc.php src/ -o app -j4 # 使用 4 个进程
```
---

@ -326,7 +326,7 @@ dotnet publish # 发布为独立应用
**AOT 借鉴优先级: P2**
AOT 目前使用 `php bin/compiler.php <project>` 命令行。可以借鉴:
AOT 目前使用 `php bin/tpc.php <project>` 命令行。可以借鉴:
- 为 AOT 编译器创建一个 Composer plugin 或 CLI phar 包
- 定义 `project.yml` 的 JSON Schema(类似 `.csproj`
- 支持 `composer build``php-aot build` 统一入口

@ -5,7 +5,7 @@ This example compiles TypePHP code into a shared library and exposes a stable C
Build it from the repository root:
```sh
php bin/compiler.php examples/lib-demo/project.yml --no-progress
php bin/tpc.php examples/lib-demo/project.yml --no-progress
```
The resulting library uses the configured project name: currently `libdemo.so` on Linux, `libdemo.dylib` on macOS, and `demo.dll` on Windows. Set `output: demo.so` in `project.yml` to use an exact output filename. Its public API is declared in `include/typephp_lib_demo.h`.

@ -46,12 +46,12 @@ tetris/
### 编译
```bash
cd examples/tetris
php ../../bin/compiler.php build
php ../../bin/tpc.php build
```
或在项目根目录:
```bash
php bin/compiler.php build examples/tetris
php bin/tpc.php build examples/tetris
```
### 运行

@ -35,37 +35,37 @@ tetris/
```bash
cd examples/tetris
php ../../bin/compiler.php build main.php
php ../../bin/tpc.php build main.php
```
或使用 project.yml:
```bash
cd examples/tetris
php ../../bin/compiler.php build .
php ../../bin/tpc.php build .
```
### 方法二:编译简化测试版
```bash
cd examples/tetris
php ../../bin/compiler.php build test-simple.php
php ../../bin/tpc.php build test-simple.php
```
### 编译选项
```bash
# 启用优化
php ../../bin/compiler.php build -O2 main.php
php ../../bin/tpc.php build -O2 main.php
# 启用调试信息
php ../../bin/compiler.php build --debug-info main.php
php ../../bin/tpc.php build --debug-info main.php
# 指定输出文件名
php ../../bin/compiler.php build -o tetris-game main.php
php ../../bin/tpc.php build -o tetris-game main.php
# 并行编译(加速)
php ../../bin/compiler.php build -j 8 main.php
php ../../bin/tpc.php build -j 8 main.php
```
## 🚀 运行游戏
@ -280,7 +280,7 @@ file_put_contents('game.log', $message, FILE_APPEND);
tetris_messagebox(0, $message, "Debug", MB_OK);
// 4. 使用调试模式编译
php ../../bin/compiler.php build --debug-info main.php
php ../../bin/tpc.php build --debug-info main.php
```
## 📊 性能分析

@ -46,12 +46,12 @@ tetris/
### 编译
```bash
cd examples/tetris
php ../../bin/compiler.php build
php ../../bin/tpc.php build
```
或在项目根目录:
```bash
php bin/compiler.php build examples/tetris
php bin/tpc.php build examples/tetris
```
### 运行

@ -35,37 +35,37 @@ tetris/
```bash
cd examples/tetris
php ../../bin/compiler.php build main.php
php ../../bin/tpc.php build main.php
```
或使用 project.yml:
```bash
cd examples/tetris
php ../../bin/compiler.php build .
php ../../bin/tpc.php build .
```
### 方法二:编译简化测试版
```bash
cd examples/tetris
php ../../bin/compiler.php build test-simple.php
php ../../bin/tpc.php build test-simple.php
```
### 编译选项
```bash
# 启用优化
php ../../bin/compiler.php build -O2 main.php
php ../../bin/tpc.php build -O2 main.php
# 启用调试信息
php ../../bin/compiler.php build --debug-info main.php
php ../../bin/tpc.php build --debug-info main.php
# 指定输出文件名
php ../../bin/compiler.php build -o tetris-game main.php
php ../../bin/tpc.php build -o tetris-game main.php
# 并行编译(加速)
php ../../bin/compiler.php build -j 8 main.php
php ../../bin/tpc.php build -j 8 main.php
```
## 🚀 运行游戏
@ -280,7 +280,7 @@ file_put_contents('game.log', $message, FILE_APPEND);
tetris_messagebox(0, $message, "Debug", MB_OK);
// 4. 使用调试模式编译
php ../../bin/compiler.php build --debug-info main.php
php ../../bin/tpc.php build --debug-info main.php
```
## 📊 性能分析

@ -66,7 +66,7 @@ cxx-std: c++14
#### 命令行覆盖
```bash
php bin/compiler.php project.yml --cxx-std=c++17
php bin/tpc.php project.yml --cxx-std=c++17
```
#### 结果
@ -84,7 +84,7 @@ build-mode: bin
#### 命令行覆盖
```bash
php bin/compiler.php project.yml --mode=ext
php bin/tpc.php project.yml --mode=ext
```
#### 结果
@ -104,7 +104,7 @@ cxx-flags:
#### 命令行覆盖
```bash
php bin/compiler.php project.yml -O3
php bin/tpc.php project.yml -O3
```
#### 结果
@ -118,7 +118,7 @@ php bin/compiler.php project.yml -O3
### 类型 1:YAML 配置文件
```bash
php bin/compiler.php project.yml --cxx-std=c++17
php bin/tpc.php project.yml --cxx-std=c++17
```
**执行流程:**
@ -136,7 +136,7 @@ php bin/compiler.php project.yml --cxx-std=c++17
### 类型 2:单个 PHP 文件
```bash
php bin/compiler.php hello.php --cxx-std=c++17 -O2
php bin/tpc.php hello.php --cxx-std=c++17 -O2
```
**执行流程:**
@ -154,7 +154,7 @@ php bin/compiler.php hello.php --cxx-std=c++17 -O2
### 类型 3:目录
```bash
php bin/compiler.php src/ --mode=ext --cxx-std=c++17
php bin/tpc.php src/ --mode=ext --cxx-std=c++17
```
**执行流程:**
@ -197,7 +197,7 @@ sources:
### 场景 1:使用默认配置
```bash
php bin/compiler.php project.yml
php bin/tpc.php project.yml
```
**结果:**
@ -210,7 +210,7 @@ php bin/compiler.php project.yml
### 场景 2:部分覆盖
```bash
php bin/compiler.php project.yml --cxx-std=c++17
php bin/tpc.php project.yml --cxx-std=c++17
```
**结果:**
@ -223,7 +223,7 @@ php bin/compiler.php project.yml --cxx-std=c++17
### 场景 3:完全覆盖
```bash
php bin/compiler.php project.yml --cxx-std=c++20 --mode=ext -O3
php bin/tpc.php project.yml --cxx-std=c++20 --mode=ext -O3
```
**结果:**
@ -237,7 +237,7 @@ php bin/compiler.php project.yml --cxx-std=c++20 --mode=ext -O3
### 场景 4:单文件编译
```bash
php bin/compiler.php test.php --cxx-std=c++17 -O2
php bin/tpc.php test.php --cxx-std=c++17 -O2
```
**结果:**
@ -296,13 +296,13 @@ cxx-flags:
```bash
# 开发时使用调试模式
php bin/compiler.php project.yml --debug
php bin/tpc.php project.yml --debug
# 发布时使用优化
php bin/compiler.php project.yml -O3
php bin/tpc.php project.yml -O3
# 测试不同的 C++ 标准
php bin/compiler.php project.yml --cxx-std=c++20
php bin/tpc.php project.yml --cxx-std=c++20
```
---
@ -311,7 +311,7 @@ php bin/compiler.php project.yml --cxx-std=c++20
```bash
# 不需要 YAML,直接编译
php bin/compiler.php test.php -O2 --cxx-std=c++17
php bin/tpc.php test.php -O2 --cxx-std=c++17
```
---
@ -324,10 +324,10 @@ A: 确保使用了正确的参数名称:
```bash
# ✅ 正确
php bin/compiler.php project.yml --cxx-std=c++17
php bin/tpc.php project.yml --cxx-std=c++17
# ❌ 错误(参数名不对)
php bin/compiler.php project.yml --cxx_std=c++17
php bin/tpc.php project.yml --cxx_std=c++17
```
---
@ -342,7 +342,7 @@ cxx-std: c++14
```
```bash
php bin/compiler.php project.yml --cxx-std=c++17
php bin/tpc.php project.yml --cxx-std=c++17
# 结果:使用 c++17
```
@ -353,7 +353,7 @@ php bin/compiler.php project.yml --cxx-std=c++17
A: 目前不支持。优化级别只能通过命令行设置:
```bash
php bin/compiler.php project.yml -O2
php bin/tpc.php project.yml -O2
```
---

@ -14,19 +14,19 @@ PHPX 编译器现在支持独立配置 C++ 标准版本,不再需要从 `cxxfl
```bash
# 使用 C++14
php bin/compiler.php app.php --cxx-std=c++14
php bin/tpc.php app.php --cxx-std=c++14
# 使用 C++17(默认)
php bin/compiler.php app.php --cxx-std=c++17
php bin/tpc.php app.php --cxx-std=c++17
# 使用 C++20
php bin/compiler.php app.php --cxx-std=c++20
php bin/tpc.php app.php --cxx-std=c++20
# Windows MSVC
php bin/compiler.php app.php --cxx-std=c++17
php bin/tpc.php app.php --cxx-std=c++17
# Linux/macOS GCC/Clang
php bin/compiler.php app.php --cxx-std=c++17
php bin/tpc.php app.php --cxx-std=c++17
```
---
@ -114,7 +114,7 @@ cxx_std: c++14
```bash
# 命令行覆盖配置文件
php bin/compiler.php project.yml --cxx-std=c++17
php bin/tpc.php project.yml --cxx-std=c++17
# 最终使用 c++17
```
@ -189,7 +189,7 @@ cxx_std: c++17
编译命令:
```bash
php bin/compiler.php project.yml
php bin/tpc.php project.yml
```
生成的编译命令:
@ -237,7 +237,7 @@ cxx_std: c++14 # 配置文件中的默认值
```bash
# 使用 C++17 覆盖配置文件
php bin/compiler.php project.yml --cxx-std=c++17
php bin/tpc.php project.yml --cxx-std=c++17
```
---
@ -278,7 +278,7 @@ cxxflags:
编译时查看输出,确认 C++ 标准是否正确设置:
```bash
php bin/compiler.php project.yml --verbose
php bin/tpc.php project.yml --verbose
```
应该看到类似这样的输出:
@ -309,7 +309,7 @@ cxx_std: c++17 # 确保是 c++17 而不是 c++14
或者使用命令行:
```bash
php bin/compiler.php app.php --cxx-std=c++17
php bin/tpc.php app.php --cxx-std=c++17
```
---

@ -163,7 +163,7 @@ ignore:
1. **命令行参数**(最高优先级)
```bash
php bin/compiler.php project.yml --cxx-std=c++20
php bin/tpc.php project.yml --cxx-std=c++20
```
2. **YAML 配置文件**
@ -441,13 +441,13 @@ A: 使用命令行参数:
```bash
# 覆盖 cxx-std
php bin/compiler.php project.yml --cxx-std=c++20
php bin/tpc.php project.yml --cxx-std=c++20
# 覆盖 build-mode
php bin/compiler.php project.yml --mode=ext
php bin/tpc.php project.yml --mode=ext
# 启用调试信息
php bin/compiler.php project.yml --debug
php bin/tpc.php project.yml --debug
```
---

@ -131,7 +131,7 @@ Options:
--no-aot Run tests without AOT compilation (plain PHP mode).
--compiler <path>
Use specified compiler binary (default: ./bin/compiler.php).
Use specified compiler binary (default: ./bin/tpc.php).
For bootstrap testing, use: --compiler ./swoole_compiler
--bless Bless failed tests using scripts/dev/bless_tests.php.
@ -675,7 +675,7 @@ function main(): void
$php = getenv('TEST_PHP_EXECUTABLE') ?: PHP_BINARY;
}
if (!$compiler_path) {
$compiler_path = './bin/compiler.php';
$compiler_path = './bin/tpc.php';
}
$php_cgi = getenv('TEST_PHP_CGI_EXECUTABLE') ?: get_binary($php, 'php-cgi', 'sapi/cgi/php-cgi');

@ -181,7 +181,7 @@ cat build/tests/compiler/test-name.cc
php bin/gen_stub.php -f tests/compiler/test-name.php
# 2. 转换为 C++
php bin/compiler.php tests/compiler/test-name.php
php bin/tpc.php tests/compiler/test-name.php
# 3. 编译 C++ 代码
cd build && make test-name

Loading…
Cancel
Save