diff --git a/src/Php/Backend/Clang.php b/src/Php/Backend/Clang.php index 7e1d6c8c..23ed1f2b 100644 --- a/src/Php/Backend/Clang.php +++ b/src/Php/Backend/Clang.php @@ -408,6 +408,11 @@ class Clang extends CompilerBackend $cmd .= ' -march=' . $config['march']; } + // 交叉编译目标平台 (--target=) + 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=) + if (!empty($config['target_platform'])) { + $cmd .= ' --target=' . $config['target_platform']; + } + // LTO(链接时优化) if (!empty($config['lto'])) { $cmd .= ' -flto'; diff --git a/src/Php/Backend/Gcc.php b/src/Php/Backend/Gcc.php index 40c5c643..bfb5a6f9 100644 --- a/src/Php/Backend/Gcc.php +++ b/src/Php/Backend/Gcc.php @@ -294,6 +294,11 @@ class Gcc extends CompilerBackend $cmd .= ' -march=' . $config['march']; } + // 交叉编译目标平台 (--target=) + 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=) + if (!empty($config['target_platform'])) { + $cmd .= ' --target=' . $config['target_platform']; + } + // LTO(链接时优化) if (!empty($config['lto'])) { $cmd .= ' -flto'; diff --git a/src/Php/Constants.php b/src/Php/Constants.php index 937d50cd..c4601188 100644 --- a/src/Php/Constants.php +++ b/src/Php/Constants.php @@ -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', diff --git a/src/Php/Translator.php b/src/Php/Translator.php index b1c9c3c4..92e8c1c5 100644 --- a/src/Php/Translator.php +++ b/src/Php/Translator.php @@ -232,6 +232,7 @@ class Translator extends Preprocessor $climate->tab()->out('-j, --job Number of parallel compilation jobs (default: 4)'); $climate->tab()->out('--cxx-std C++ standard version (c++17, c++20, etc., default: c++17)'); $climate->tab()->out('--march Target CPU instruction set (e.g. native, x86-64-v3, armv8-a)'); + $climate->tab()->out('--target-platform 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(