diff --git a/README.md b/README.md index 462c0f26..ac22dfc1 100644 --- a/README.md +++ b/README.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 diff --git a/bin/compiler.php b/bin/tpc.php similarity index 100% rename from bin/compiler.php rename to bin/tpc.php diff --git a/composer.json b/composer.json index 5a0dd817..9222685e 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/composer.lock b/composer.lock index eca74d3f..4184972d 100644 --- a/composer.lock +++ b/composer.lock @@ -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", diff --git a/docs/AOT_BUILD_SPEED_RESEARCH.md b/docs/AOT_BUILD_SPEED_RESEARCH.md index a3929734..9e61bc0e 100644 --- a/docs/AOT_BUILD_SPEED_RESEARCH.md +++ b/docs/AOT_BUILD_SPEED_RESEARCH.md @@ -6,7 +6,7 @@ 降低以下两类耗时: -1. **冷启动全量构建**:`./bin/compiler.php project.yml` +1. **冷启动全量构建**:`./bin/tpc.php project.yml` 2. **热启动增量构建**:只改少量 PHP 文件后再次编译 重点关注大型项目和编译器自举场景。 diff --git a/docs/COMPILATION_MODES.md b/docs/COMPILATION_MODES.md index 8dfdb149..bac122a5 100644 --- a/docs/COMPILATION_MODES.md +++ b/docs/COMPILATION_MODES.md @@ -15,14 +15,14 @@ PHP AOT 编译器支持两种编译模式,每种模式针对不同的使用场 ### 编译命令 ```bash -php bin/compiler.php --mode=ext -o +php bin/tpc.php --mode=ext -o ``` ### 示例 ```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 -o +php bin/tpc.php -o ``` ### 示例 ```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 ``` **使用**: diff --git a/docs/COMPILER_CLI.md b/docs/COMPILER_CLI.md index 614e6e5b..5a515da8 100644 --- a/docs/COMPILER_CLI.md +++ b/docs/COMPILER_CLI.md @@ -3,26 +3,26 @@ 本文档与 `src/Translator.php::showUsage()` 保持同步。使用: ```bash -bin/compiler.php [options] [-- program-args...] +bin/tpc.php [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)。 diff --git a/docs/HIGH_PRECISION_TYPES.md b/docs/HIGH_PRECISION_TYPES.md index e1f1803e..d13a7d31 100644 --- a/docs/HIGH_PRECISION_TYPES.md +++ b/docs/HIGH_PRECISION_TYPES.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 ``` diff --git a/docs/MIXED_CPP_PHP.md b/docs/MIXED_CPP_PHP.md index 6d59399d..42154cc2 100644 --- a/docs/MIXED_CPP_PHP.md +++ b/docs/MIXED_CPP_PHP.md @@ -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 diff --git a/docs/QUICKSTART.md b/docs/QUICKSTART.md index 8a1f874b..27fe011e 100644 --- a/docs/QUICKSTART.md +++ b/docs/QUICKSTART.md @@ -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 个进程 ``` --- diff --git a/docs/peachpie-review.md b/docs/peachpie-review.md index b2c7c971..c2d1e39f 100644 --- a/docs/peachpie-review.md +++ b/docs/peachpie-review.md @@ -326,7 +326,7 @@ dotnet publish # 发布为独立应用 **AOT 借鉴优先级: P2** -AOT 目前使用 `php bin/compiler.php ` 命令行。可以借鉴: +AOT 目前使用 `php bin/tpc.php ` 命令行。可以借鉴: - 为 AOT 编译器创建一个 Composer plugin 或 CLI phar 包 - 定义 `project.yml` 的 JSON Schema(类似 `.csproj`) - 支持 `composer build` 或 `php-aot build` 统一入口 diff --git a/examples/lib-demo/README.md b/examples/lib-demo/README.md index 4064b02e..8c0667d3 100644 --- a/examples/lib-demo/README.md +++ b/examples/lib-demo/README.md @@ -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`. diff --git a/examples/tetris-sdl/README.md b/examples/tetris-sdl/README.md index 749d1781..4f511f13 100644 --- a/examples/tetris-sdl/README.md +++ b/examples/tetris-sdl/README.md @@ -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 ``` ### 运行 diff --git a/examples/tetris-sdl/USAGE_GUIDE.md b/examples/tetris-sdl/USAGE_GUIDE.md index ce864b12..f6e9d38f 100644 --- a/examples/tetris-sdl/USAGE_GUIDE.md +++ b/examples/tetris-sdl/USAGE_GUIDE.md @@ -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 ``` ## 📊 性能分析 diff --git a/examples/tetris-win32/README.md b/examples/tetris-win32/README.md index 749d1781..4f511f13 100644 --- a/examples/tetris-win32/README.md +++ b/examples/tetris-win32/README.md @@ -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 ``` ### 运行 diff --git a/examples/tetris-win32/USAGE_GUIDE.md b/examples/tetris-win32/USAGE_GUIDE.md index ce864b12..f6e9d38f 100644 --- a/examples/tetris-win32/USAGE_GUIDE.md +++ b/examples/tetris-win32/USAGE_GUIDE.md @@ -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 ``` ## 📊 性能分析 diff --git a/examples/win32-hello/CONFIG_PRIORITY_RULES.md b/examples/win32-hello/CONFIG_PRIORITY_RULES.md index 6c55ab36..59b8fc1e 100644 --- a/examples/win32-hello/CONFIG_PRIORITY_RULES.md +++ b/examples/win32-hello/CONFIG_PRIORITY_RULES.md @@ -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 ``` --- diff --git a/examples/win32-hello/CXX_STD_CONFIG_GUIDE.md b/examples/win32-hello/CXX_STD_CONFIG_GUIDE.md index 7754bcc8..dc2062e9 100644 --- a/examples/win32-hello/CXX_STD_CONFIG_GUIDE.md +++ b/examples/win32-hello/CXX_STD_CONFIG_GUIDE.md @@ -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 ``` --- diff --git a/examples/win32-hello/YAML_CONFIG_NAMING_CONVENTION.md b/examples/win32-hello/YAML_CONFIG_NAMING_CONVENTION.md index 3e55e185..8251427e 100644 --- a/examples/win32-hello/YAML_CONFIG_NAMING_CONVENTION.md +++ b/examples/win32-hello/YAML_CONFIG_NAMING_CONVENTION.md @@ -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 ``` --- diff --git a/run-tests.php b/run-tests.php index 8755bc52..01319706 100755 --- a/run-tests.php +++ b/run-tests.php @@ -131,7 +131,7 @@ Options: --no-aot Run tests without AOT compilation (plain PHP mode). --compiler - 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'); diff --git a/tests/compiler/RUN_TESTS_GUIDE.md b/tests/compiler/RUN_TESTS_GUIDE.md index a6cac574..7ab30a0c 100644 --- a/tests/compiler/RUN_TESTS_GUIDE.md +++ b/tests/compiler/RUN_TESTS_GUIDE.md @@ -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