feat(build): 添加交叉编译目标平台支持

- 在 Clang 和 GCC 编译器后端中添加 --target 参数支持
- 添加 target-platform 配置选项的常量定义
- 在命令行参数解析中添加对 target-platform 的支持
- 将 target-platform 配置传递给编译器命令生成逻辑
- 更新帮助文档显示新的交叉编译选项
- 支持指定交叉编译目标三元组 (如 aarch64-linux-gnu)
pull/3/head
韩天峰 2 months ago
parent 22c2d17954
commit 8267ae2bf4
  1. 10
      src/Php/Backend/Clang.php
  2. 10
      src/Php/Backend/Gcc.php
  3. 6
      src/Php/Constants.php
  4. 9
      src/Php/Translator.php

@ -408,6 +408,11 @@ class Clang extends CompilerBackend
$cmd .= ' -march=' . $config['march'];
}
// 交叉编译目标平台 (--target=<triple>)
if (!empty($config['target_platform'])) {
$cmd .= ' --target=' . $config['target_platform'];
}
// PIC (Position Independent Code)
if ((!empty($config['build_mode']) && $config['build_mode'] === 'ext') || !empty($config['pic'])) {
if ($this->platform instanceof \PhpAot\Php\Platform\Windows) {
@ -495,6 +500,11 @@ class Clang extends CompilerBackend
$cmd .= ' -fsanitize=' . $config['sanitize'];
}
// 交叉编译目标平台 (--target=<triple>)
if (!empty($config['target_platform'])) {
$cmd .= ' --target=' . $config['target_platform'];
}
// LTO(链接时优化)
if (!empty($config['lto'])) {
$cmd .= ' -flto';

@ -294,6 +294,11 @@ class Gcc extends CompilerBackend
$cmd .= ' -march=' . $config['march'];
}
// 交叉编译目标平台 (--target=<triple>)
if (!empty($config['target_platform'])) {
$cmd .= ' --target=' . $config['target_platform'];
}
// PIC (Position Independent Code)
if ((!empty($config['build_mode']) && $config['build_mode'] === 'ext') || !empty($config['pic'])) {
$cmd .= ' -fPIC';
@ -359,6 +364,11 @@ class Gcc extends CompilerBackend
}
}
// 交叉编译目标平台 (--target=<triple>)
if (!empty($config['target_platform'])) {
$cmd .= ' --target=' . $config['target_platform'];
}
// LTO(链接时优化)
if (!empty($config['lto'])) {
$cmd .= ' -flto';

@ -169,6 +169,12 @@ class Constants
'required' => false,
'defaultValue' => '',
],
'target-platform' => [
'longPrefix' => 'target-platform',
'description' => 'Cross-compilation target triple (e.g. aarch64-linux-gnu, x86_64-w64-mingw32)',
'required' => false,
'defaultValue' => '',
],
'no-color' => [
'longPrefix' => 'no-color',
'description' => 'Disable ANSI color output',

@ -232,6 +232,7 @@ class Translator extends Preprocessor
$climate->tab()->out('-j, --job <num> Number of parallel compilation jobs (default: 4)');
$climate->tab()->out('--cxx-std <ver> C++ standard version (c++17, c++20, etc., default: c++17)');
$climate->tab()->out('--march <arch> Target CPU instruction set (e.g. native, x86-64-v3, armv8-a)');
$climate->tab()->out('--target-platform <triple> Cross-compilation target triple (e.g. aarch64-linux-gnu)');
$climate->tab()->out('--lto Enable Link Time Optimization (-flto)');
$climate->tab()->out('--no-literal-strings Disable literal strings optimization');
$climate->tab()->out('--no-console Hide console window (Windows only, GUI application)');
@ -311,6 +312,11 @@ class Translator extends Preprocessor
$this->march = $this->climate->arguments->get('march');
}
// 交叉编译目标平台
if ($this->climate->arguments->defined('target-platform')) {
$this->targetPlatform = $this->climate->arguments->get('target-platform');
}
// 构建目录
if ($this->climate->arguments->defined('build-dir')) {
$buildDir = $this->climate->arguments->get('build-dir');
@ -1403,6 +1409,7 @@ CODE;
'sanitize' => $this->sanitize,
'cpp_std' => $this->cxxStd,
'march' => $this->march,
'target_platform' => $this->targetPlatform,
'is_zts' => $this->isPhpZts,
'build_mode' => $this->buildMode,
'enable_profiler' => $this->enableProfiler,
@ -1442,6 +1449,7 @@ CODE;
'enable_profiler' => $this->enableProfiler,
'suppressed_warnings' => Constants::MSVC_SUPPRESSED_WARNINGS ?? [],
'march' => $this->march,
'target_platform' => $this->targetPlatform,
];
}
@ -1472,6 +1480,7 @@ CODE;
'build_mode' => $this->buildMode,
'sanitize' => $this->sanitize,
'lto' => $this->enableLto,
'target_platform' => $this->targetPlatform,
];
$rpaths = $this->getPlatform()->getDefaultRpaths(

Loading…
Cancel
Save