2023-03-18 17:32:21 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2024-01-10 21:08:25 +08:00
|
|
|
namespace SPC\builder\unix;
|
2023-03-18 17:32:21 +08:00
|
|
|
|
2024-01-10 21:08:25 +08:00
|
|
|
use SPC\builder\BuilderBase;
|
2025-08-06 20:43:23 +08:00
|
|
|
use SPC\exception\SPCInternalException;
|
|
|
|
|
use SPC\exception\ValidationException;
|
2023-08-20 19:51:45 +08:00
|
|
|
use SPC\exception\WrongUsageException;
|
2024-01-10 21:08:25 +08:00
|
|
|
use SPC\store\Config;
|
2025-06-19 12:51:00 +08:00
|
|
|
use SPC\store\CurlHook;
|
2025-06-18 15:50:55 +07:00
|
|
|
use SPC\store\Downloader;
|
2023-03-26 22:27:51 +08:00
|
|
|
use SPC\store\FileSystem;
|
2025-06-26 14:24:00 +07:00
|
|
|
use SPC\store\pkg\GoXcaddy;
|
2025-08-25 18:44:03 +07:00
|
|
|
use SPC\toolchain\GccNativeToolchain;
|
|
|
|
|
use SPC\toolchain\ToolchainManager;
|
2024-01-10 21:08:25 +08:00
|
|
|
use SPC\util\DependencyUtil;
|
2025-06-26 17:23:37 +07:00
|
|
|
use SPC\util\GlobalEnvManager;
|
2024-12-10 23:08:01 +08:00
|
|
|
use SPC\util\SPCConfigUtil;
|
2025-06-28 16:36:05 +08:00
|
|
|
use SPC\util\SPCTarget;
|
2023-03-18 17:32:21 +08:00
|
|
|
|
2024-01-10 21:08:25 +08:00
|
|
|
abstract class UnixBuilderBase extends BuilderBase
|
2023-03-18 17:32:21 +08:00
|
|
|
{
|
2023-08-20 19:51:45 +08:00
|
|
|
/** @var string cflags */
|
2023-03-18 17:32:21 +08:00
|
|
|
public string $arch_c_flags;
|
|
|
|
|
|
2023-08-20 19:51:45 +08:00
|
|
|
/** @var string C++ flags */
|
2023-03-18 17:32:21 +08:00
|
|
|
public string $arch_cxx_flags;
|
|
|
|
|
|
2025-07-28 19:43:01 +07:00
|
|
|
/** @var string LD flags */
|
|
|
|
|
public string $arch_ld_flags;
|
|
|
|
|
|
2024-05-16 13:01:11 +08:00
|
|
|
public function proveLibs(array $sorted_libraries): void
|
2024-01-10 21:08:25 +08:00
|
|
|
{
|
|
|
|
|
// search all supported libs
|
|
|
|
|
$support_lib_list = [];
|
|
|
|
|
$classes = FileSystem::getClassesPsr4(
|
|
|
|
|
ROOT_DIR . '/src/SPC/builder/' . osfamily2dir() . '/library',
|
2024-06-20 14:46:08 +08:00
|
|
|
'SPC\builder\\' . osfamily2dir() . '\library'
|
2024-01-10 21:08:25 +08:00
|
|
|
);
|
|
|
|
|
foreach ($classes as $class) {
|
|
|
|
|
if (defined($class . '::NAME') && $class::NAME !== 'unknown' && Config::getLib($class::NAME) !== null) {
|
|
|
|
|
$support_lib_list[$class::NAME] = $class;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// if no libs specified, compile all supported libs
|
|
|
|
|
if ($sorted_libraries === [] && $this->isLibsOnly()) {
|
|
|
|
|
$libraries = array_keys($support_lib_list);
|
2024-02-16 18:56:33 +08:00
|
|
|
$sorted_libraries = DependencyUtil::getLibs($libraries);
|
2024-01-10 21:08:25 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add lib object for builder
|
|
|
|
|
foreach ($sorted_libraries as $library) {
|
2025-03-08 14:29:44 +08:00
|
|
|
if (!in_array(Config::getLib($library, 'type', 'lib'), ['lib', 'package'])) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2024-01-10 21:08:25 +08:00
|
|
|
// if some libs are not supported (but in config "lib.json", throw exception)
|
|
|
|
|
if (!isset($support_lib_list[$library])) {
|
2025-08-06 20:43:23 +08:00
|
|
|
$os = match (PHP_OS_FAMILY) {
|
|
|
|
|
'Linux' => 'Linux',
|
|
|
|
|
'Darwin' => 'macOS',
|
|
|
|
|
'Windows' => 'Windows',
|
|
|
|
|
'BSD' => 'FreeBSD',
|
|
|
|
|
default => PHP_OS_FAMILY,
|
|
|
|
|
};
|
|
|
|
|
throw new WrongUsageException("library [{$library}] is in the lib.json list but not supported to build on {$os}.");
|
2024-01-10 21:08:25 +08:00
|
|
|
}
|
|
|
|
|
$lib = new ($support_lib_list[$library])($this);
|
|
|
|
|
$this->addLib($lib);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// calculate and check dependencies
|
|
|
|
|
foreach ($this->libs as $lib) {
|
|
|
|
|
$lib->calcDependency();
|
|
|
|
|
}
|
2024-12-10 23:08:01 +08:00
|
|
|
$this->lib_list = $sorted_libraries;
|
2024-01-10 21:08:25 +08:00
|
|
|
}
|
|
|
|
|
|
2023-03-18 17:32:21 +08:00
|
|
|
/**
|
2025-08-06 20:17:26 +08:00
|
|
|
* Sanity check after build complete.
|
2023-03-18 17:32:21 +08:00
|
|
|
*/
|
2024-01-10 11:10:40 +08:00
|
|
|
protected function sanityCheck(int $build_target): void
|
2023-03-18 17:32:21 +08:00
|
|
|
{
|
2023-04-23 20:31:58 +08:00
|
|
|
// sanity check for php-cli
|
2025-06-12 11:40:32 +07:00
|
|
|
if (($build_target & BUILD_TARGET_CLI) === BUILD_TARGET_CLI) {
|
2023-04-23 20:31:58 +08:00
|
|
|
logger()->info('running cli sanity check');
|
2025-05-21 18:35:48 +07:00
|
|
|
[$ret, $output] = shell()->execWithResult(BUILD_BIN_PATH . '/php -n -r "echo \"hello\";"');
|
2025-02-11 03:34:43 +01:00
|
|
|
$raw_output = implode('', $output);
|
|
|
|
|
if ($ret !== 0 || trim($raw_output) !== 'hello') {
|
2025-08-06 20:43:23 +08:00
|
|
|
throw new ValidationException("cli failed sanity check. code: {$ret}, output: {$raw_output}", validation_module: 'php-cli sanity check');
|
2023-03-18 17:32:21 +08:00
|
|
|
}
|
2023-09-13 13:07:22 +02:00
|
|
|
|
2025-05-21 17:57:53 +07:00
|
|
|
foreach ($this->getExts() as $ext) {
|
2023-03-26 22:27:51 +08:00
|
|
|
logger()->debug('testing ext: ' . $ext->getName());
|
2024-01-10 21:08:25 +08:00
|
|
|
$ext->runCliCheckUnix();
|
2023-03-18 17:32:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-04-23 20:31:58 +08:00
|
|
|
|
|
|
|
|
// sanity check for phpmicro
|
|
|
|
|
if (($build_target & BUILD_TARGET_MICRO) === BUILD_TARGET_MICRO) {
|
2024-06-03 23:16:15 +08:00
|
|
|
$test_task = $this->getMicroTestTasks();
|
|
|
|
|
foreach ($test_task as $task_name => $task) {
|
|
|
|
|
$test_file = SOURCE_PATH . '/' . $task_name . '.exe';
|
|
|
|
|
if (file_exists($test_file)) {
|
|
|
|
|
@unlink($test_file);
|
|
|
|
|
}
|
|
|
|
|
file_put_contents($test_file, file_get_contents(SOURCE_PATH . '/php-src/sapi/micro/micro.sfx') . $task['content']);
|
|
|
|
|
chmod($test_file, 0755);
|
|
|
|
|
[$ret, $out] = shell()->execWithResult($test_file);
|
|
|
|
|
foreach ($task['conditions'] as $condition => $closure) {
|
|
|
|
|
if (!$closure($ret, $out)) {
|
|
|
|
|
$raw_out = trim(implode('', $out));
|
2025-08-06 20:43:23 +08:00
|
|
|
throw new ValidationException(
|
|
|
|
|
"failure info: {$condition}, code: {$ret}, output: {$raw_out}",
|
|
|
|
|
validation_module: "phpmicro sanity check item [{$task_name}]"
|
|
|
|
|
);
|
2024-06-03 23:16:15 +08:00
|
|
|
}
|
2024-01-29 10:04:21 +08:00
|
|
|
}
|
2023-03-18 17:32:21 +08:00
|
|
|
}
|
|
|
|
|
}
|
2024-12-10 23:08:01 +08:00
|
|
|
|
|
|
|
|
// sanity check for embed
|
2025-06-12 00:41:33 +08:00
|
|
|
if (($build_target & BUILD_TARGET_EMBED) === BUILD_TARGET_EMBED) {
|
2024-12-10 23:08:01 +08:00
|
|
|
logger()->info('running embed sanity check');
|
|
|
|
|
$sample_file_path = SOURCE_PATH . '/embed-test';
|
|
|
|
|
if (!is_dir($sample_file_path)) {
|
|
|
|
|
@mkdir($sample_file_path);
|
|
|
|
|
}
|
|
|
|
|
// copy embed test files
|
|
|
|
|
copy(ROOT_DIR . '/src/globals/common-tests/embed.c', $sample_file_path . '/embed.c');
|
|
|
|
|
copy(ROOT_DIR . '/src/globals/common-tests/embed.php', $sample_file_path . '/embed.php');
|
|
|
|
|
$util = new SPCConfigUtil($this);
|
|
|
|
|
$config = $util->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
|
|
|
|
|
$lens = "{$config['cflags']} {$config['ldflags']} {$config['libs']}";
|
2025-06-29 22:49:48 +08:00
|
|
|
if (SPCTarget::isStatic()) {
|
2024-12-10 23:08:01 +08:00
|
|
|
$lens .= ' -static';
|
2025-06-27 22:51:53 +07:00
|
|
|
}
|
2025-07-01 13:02:59 +07:00
|
|
|
// if someone changed to EMBED_TYPE=shared, we need to add LD_LIBRARY_PATH
|
|
|
|
|
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') {
|
2025-07-25 16:24:22 +07:00
|
|
|
if (PHP_OS_FAMILY === 'Darwin') {
|
|
|
|
|
$ext_path = 'DYLD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$DYLD_LIBRARY_PATH ';
|
|
|
|
|
} else {
|
|
|
|
|
$ext_path = 'LD_LIBRARY_PATH=' . BUILD_LIB_PATH . ':$LD_LIBRARY_PATH ';
|
|
|
|
|
}
|
2025-07-01 13:02:59 +07:00
|
|
|
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '/libphp.a');
|
|
|
|
|
} else {
|
|
|
|
|
$ext_path = '';
|
2025-07-25 16:26:02 +07:00
|
|
|
$suffix = PHP_OS_FAMILY === 'Darwin' ? 'dylib' : 'so';
|
|
|
|
|
foreach (glob(BUILD_LIB_PATH . "/libphp*.{$suffix}") as $file) {
|
2025-07-01 13:02:59 +07:00
|
|
|
unlink($file);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-27 22:51:53 +07:00
|
|
|
[$ret, $out] = shell()->cd($sample_file_path)->execWithResult(getenv('CC') . ' -o embed embed.c ' . $lens);
|
|
|
|
|
if ($ret !== 0) {
|
2025-08-06 20:43:23 +08:00
|
|
|
throw new ValidationException(
|
|
|
|
|
'embed failed sanity check: build failed. Error message: ' . implode("\n", $out),
|
|
|
|
|
validation_module: 'static libphp.a sanity check'
|
|
|
|
|
);
|
2025-03-10 16:15:47 +08:00
|
|
|
}
|
|
|
|
|
[$ret, $output] = shell()->cd($sample_file_path)->execWithResult($ext_path . './embed');
|
2024-12-10 23:08:01 +08:00
|
|
|
if ($ret !== 0 || trim(implode('', $output)) !== 'hello') {
|
2025-08-06 20:43:23 +08:00
|
|
|
throw new ValidationException(
|
|
|
|
|
'embed failed sanity check: run failed. Error message: ' . implode("\n", $output),
|
|
|
|
|
validation_module: 'static libphp.a sanity check'
|
|
|
|
|
);
|
2024-12-10 23:08:01 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-06-18 20:56:07 +08:00
|
|
|
|
|
|
|
|
// sanity check for frankenphp
|
|
|
|
|
if (($build_target & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP) {
|
|
|
|
|
logger()->info('running frankenphp sanity check');
|
|
|
|
|
$frankenphp = BUILD_BIN_PATH . '/frankenphp';
|
|
|
|
|
if (!file_exists($frankenphp)) {
|
2025-08-06 20:43:23 +08:00
|
|
|
throw new ValidationException(
|
|
|
|
|
"FrankenPHP binary not found: {$frankenphp}",
|
|
|
|
|
validation_module: 'FrankenPHP sanity check'
|
|
|
|
|
);
|
2025-06-18 20:56:07 +08:00
|
|
|
}
|
2025-07-22 14:46:41 +08:00
|
|
|
$prefix = PHP_OS_FAMILY === 'Darwin' ? 'DYLD_' : 'LD_';
|
2025-06-19 09:08:42 +07:00
|
|
|
[$ret, $output] = shell()
|
2025-07-22 14:46:41 +08:00
|
|
|
->setEnv(["{$prefix}LIBRARY_PATH" => BUILD_LIB_PATH])
|
2025-06-19 09:08:42 +07:00
|
|
|
->execWithResult("{$frankenphp} version");
|
2025-06-18 20:56:07 +08:00
|
|
|
if ($ret !== 0 || !str_contains(implode('', $output), 'FrankenPHP')) {
|
2025-08-06 20:43:23 +08:00
|
|
|
throw new ValidationException(
|
|
|
|
|
'FrankenPHP failed sanity check: ret[' . $ret . ']. out[' . implode('', $output) . ']',
|
|
|
|
|
validation_module: 'FrankenPHP sanity check'
|
|
|
|
|
);
|
2025-06-18 20:56:07 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-03-18 17:32:21 +08:00
|
|
|
}
|
2023-03-26 22:27:51 +08:00
|
|
|
|
|
|
|
|
/**
|
2025-08-06 20:17:26 +08:00
|
|
|
* Deploy the binary file to the build bin path.
|
2023-03-26 22:27:51 +08:00
|
|
|
*
|
2025-08-06 20:17:26 +08:00
|
|
|
* @param int $type Type integer, one of BUILD_TARGET_CLI, BUILD_TARGET_MICRO, BUILD_TARGET_FPM
|
2023-03-26 22:27:51 +08:00
|
|
|
*/
|
2024-01-10 11:10:40 +08:00
|
|
|
protected function deployBinary(int $type): bool
|
2023-03-26 22:27:51 +08:00
|
|
|
{
|
|
|
|
|
$src = match ($type) {
|
2023-04-23 20:31:58 +08:00
|
|
|
BUILD_TARGET_CLI => SOURCE_PATH . '/php-src/sapi/cli/php',
|
|
|
|
|
BUILD_TARGET_MICRO => SOURCE_PATH . '/php-src/sapi/micro/micro.sfx',
|
|
|
|
|
BUILD_TARGET_FPM => SOURCE_PATH . '/php-src/sapi/fpm/php-fpm',
|
2025-08-06 20:43:23 +08:00
|
|
|
default => throw new SPCInternalException("Deployment does not accept type {$type}"),
|
2023-03-26 22:27:51 +08:00
|
|
|
};
|
2023-04-23 20:31:58 +08:00
|
|
|
logger()->info('Deploying ' . $this->getBuildTypeName($type) . ' file');
|
2025-05-15 23:30:07 +07:00
|
|
|
FileSystem::createDir(BUILD_BIN_PATH);
|
|
|
|
|
shell()->exec('cp ' . escapeshellarg($src) . ' ' . escapeshellarg(BUILD_BIN_PATH));
|
2023-03-26 22:27:51 +08:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2023-08-20 19:51:45 +08:00
|
|
|
* Run php clean
|
2023-03-26 22:27:51 +08:00
|
|
|
*/
|
2024-01-10 11:10:40 +08:00
|
|
|
protected function cleanMake(): void
|
2023-03-26 22:27:51 +08:00
|
|
|
{
|
2025-08-06 20:43:23 +08:00
|
|
|
logger()->info('cleaning up php-src build files');
|
2023-03-26 22:27:51 +08:00
|
|
|
shell()->cd(SOURCE_PATH . '/php-src')->exec('make clean');
|
|
|
|
|
}
|
2025-03-24 23:50:12 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Patch phpize and php-config if needed
|
|
|
|
|
*/
|
|
|
|
|
protected function patchPhpScripts(): void
|
|
|
|
|
{
|
|
|
|
|
// patch phpize
|
|
|
|
|
if (file_exists(BUILD_BIN_PATH . '/phpize')) {
|
|
|
|
|
logger()->debug('Patching phpize prefix');
|
|
|
|
|
FileSystem::replaceFileStr(BUILD_BIN_PATH . '/phpize', "prefix=''", "prefix='" . BUILD_ROOT_PATH . "'");
|
|
|
|
|
FileSystem::replaceFileStr(BUILD_BIN_PATH . '/phpize', 's##', 's#/usr/local#');
|
|
|
|
|
}
|
|
|
|
|
// patch php-config
|
|
|
|
|
if (file_exists(BUILD_BIN_PATH . '/php-config')) {
|
|
|
|
|
logger()->debug('Patching php-config prefix and libs order');
|
|
|
|
|
$php_config_str = FileSystem::readFile(BUILD_BIN_PATH . '/php-config');
|
|
|
|
|
$php_config_str = str_replace('prefix=""', 'prefix="' . BUILD_ROOT_PATH . '"', $php_config_str);
|
|
|
|
|
// move mimalloc to the beginning of libs
|
|
|
|
|
$php_config_str = preg_replace('/(libs=")(.*?)\s*(' . preg_quote(BUILD_LIB_PATH, '/') . '\/mimalloc\.o)\s*(.*?)"/', '$1$3 $2 $4"', $php_config_str);
|
|
|
|
|
// move lstdc++ to the end of libs
|
|
|
|
|
$php_config_str = preg_replace('/(libs=")(.*?)\s*(-lstdc\+\+)\s*(.*?)"/', '$1$2 $4 $3"', $php_config_str);
|
|
|
|
|
FileSystem::writeFile(BUILD_BIN_PATH . '/php-config', $php_config_str);
|
|
|
|
|
}
|
2025-07-10 12:59:27 +08:00
|
|
|
foreach ($this->getLibs() as $lib) {
|
|
|
|
|
if ($lib->patchPhpConfig()) {
|
|
|
|
|
logger()->debug("Library {$lib->getName()} patched php-config");
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-03-24 23:50:12 +08:00
|
|
|
}
|
2025-06-18 10:48:09 +07:00
|
|
|
|
|
|
|
|
protected function buildFrankenphp(): void
|
|
|
|
|
{
|
|
|
|
|
$nobrotli = $this->getLib('brotli') === null ? ',nobrotli' : '';
|
|
|
|
|
$nowatcher = $this->getLib('watcher') === null ? ',nowatcher' : '';
|
2025-06-18 11:54:03 +07:00
|
|
|
$xcaddyModules = getenv('SPC_CMD_VAR_FRANKENPHP_XCADDY_MODULES');
|
2025-06-18 12:19:33 +07:00
|
|
|
// make it possible to build from a different frankenphp directory!
|
2025-06-19 12:23:33 +07:00
|
|
|
if (!str_contains($xcaddyModules, '--with github.com/dunglas/frankenphp')) {
|
2025-06-19 12:08:53 +07:00
|
|
|
$xcaddyModules = '--with github.com/dunglas/frankenphp ' . $xcaddyModules;
|
2025-06-18 12:19:33 +07:00
|
|
|
}
|
|
|
|
|
if ($this->getLib('brotli') === null && str_contains($xcaddyModules, '--with github.com/dunglas/caddy-cbrotli')) {
|
2025-06-18 20:56:07 +08:00
|
|
|
logger()->warning('caddy-cbrotli module is enabled, but brotli library is not built. Disabling caddy-cbrotli.');
|
2025-06-18 12:19:33 +07:00
|
|
|
$xcaddyModules = str_replace('--with github.com/dunglas/caddy-cbrotli', '', $xcaddyModules);
|
2025-06-18 11:54:03 +07:00
|
|
|
}
|
2025-06-23 13:12:40 +07:00
|
|
|
$releaseInfo = json_decode(Downloader::curlExec(
|
|
|
|
|
'https://api.github.com/repos/php/frankenphp/releases/latest',
|
|
|
|
|
hooks: [[CurlHook::class, 'setupGithubToken']],
|
|
|
|
|
), true);
|
2025-06-18 15:50:55 +07:00
|
|
|
$frankenPhpVersion = $releaseInfo['tag_name'];
|
|
|
|
|
$libphpVersion = $this->getPHPVersion();
|
2025-06-18 15:55:14 +07:00
|
|
|
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') {
|
|
|
|
|
$libphpVersion = preg_replace('/\.\d$/', '', $libphpVersion);
|
|
|
|
|
}
|
2025-07-05 19:19:17 +07:00
|
|
|
$debugFlags = $this->getOption('no-strip') ? '-w -s ' : '';
|
2025-06-19 11:59:41 +07:00
|
|
|
$extLdFlags = "-extldflags '-pie'";
|
|
|
|
|
$muslTags = '';
|
2025-07-01 13:02:59 +07:00
|
|
|
$staticFlags = '';
|
2025-06-29 22:49:48 +08:00
|
|
|
if (SPCTarget::isStatic()) {
|
2025-06-19 11:59:41 +07:00
|
|
|
$extLdFlags = "-extldflags '-static-pie -Wl,-z,stack-size=0x80000'";
|
|
|
|
|
$muslTags = 'static_build,';
|
2025-07-29 13:34:01 +07:00
|
|
|
$staticFlags = '-static-pie';
|
2025-06-19 11:59:41 +07:00
|
|
|
}
|
2025-06-18 20:56:07 +08:00
|
|
|
|
2025-07-24 22:01:32 +07:00
|
|
|
$config = (new SPCConfigUtil($this))->config($this->ext_list, $this->lib_list);
|
2025-08-25 19:29:10 +07:00
|
|
|
$cflags = "{$this->arch_c_flags} {$config['cflags']} " . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS');
|
2025-08-25 18:44:03 +07:00
|
|
|
$libs = $config['libs'];
|
2025-08-25 19:31:15 +07:00
|
|
|
$libs .= PHP_OS_FAMILY === 'Linux' ? ' -lrt' : '';
|
2025-08-25 18:44:03 +07:00
|
|
|
if ((str_contains((string) getenv('SPC_DEFAULT_C_FLAGS'), '-fprofile') ||
|
|
|
|
|
str_contains((string) getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'), '-fprofile')) &&
|
|
|
|
|
ToolchainManager::getToolchainClass() === GccNativeToolchain::class) {
|
2025-08-25 19:29:10 +07:00
|
|
|
$cflags .= ' -Wno-error=missing-profile';
|
2025-08-25 18:44:03 +07:00
|
|
|
$libs .= ' -lgcov';
|
|
|
|
|
}
|
2025-06-26 17:23:37 +07:00
|
|
|
$env = [
|
2025-06-18 10:48:09 +07:00
|
|
|
'CGO_ENABLED' => '1',
|
2025-08-25 19:29:10 +07:00
|
|
|
'CGO_CFLAGS' => clean_spaces($cflags),
|
2025-08-25 19:31:15 +07:00
|
|
|
'CGO_LDFLAGS' => "{$this->arch_ld_flags} {$staticFlags} {$config['ldflags']} {$libs}",
|
2025-06-18 15:50:55 +07:00
|
|
|
'XCADDY_GO_BUILD_FLAGS' => '-buildmode=pie ' .
|
2025-06-19 11:59:41 +07:00
|
|
|
'-ldflags \"-linkmode=external ' . $extLdFlags . ' ' . $debugFlags .
|
2025-06-18 15:50:55 +07:00
|
|
|
'-X \'github.com/caddyserver/caddy/v2.CustomVersion=FrankenPHP ' .
|
|
|
|
|
"{$frankenPhpVersion} PHP {$libphpVersion} Caddy'\\\" " .
|
2025-06-19 11:59:41 +07:00
|
|
|
"-tags={$muslTags}nobadger,nomysql,nopgx{$nobrotli}{$nowatcher}",
|
2025-06-18 11:30:04 +07:00
|
|
|
'LD_LIBRARY_PATH' => BUILD_LIB_PATH,
|
2025-06-26 17:23:37 +07:00
|
|
|
];
|
|
|
|
|
foreach (GoXcaddy::getEnvironment() as $key => $value) {
|
|
|
|
|
if ($key === 'PATH') {
|
|
|
|
|
GlobalEnvManager::addPathIfNotExists($value);
|
|
|
|
|
} else {
|
|
|
|
|
$env[$key] = $value;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-06-18 10:48:09 +07:00
|
|
|
shell()->cd(BUILD_BIN_PATH)
|
|
|
|
|
->setEnv($env)
|
2025-06-26 14:24:00 +07:00
|
|
|
->exec("xcaddy build --output frankenphp {$xcaddyModules}");
|
2025-06-27 22:48:15 +07:00
|
|
|
|
|
|
|
|
if (!$this->getOption('no-strip', false) && file_exists(BUILD_BIN_PATH . '/frankenphp')) {
|
2025-07-02 14:26:15 +07:00
|
|
|
if (PHP_OS_FAMILY === 'Linux') {
|
2025-07-05 13:52:47 +07:00
|
|
|
shell()->cd(BUILD_BIN_PATH)->exec('strip --strip-unneeded frankenphp');
|
|
|
|
|
} else { // macOS doesn't understand strip-unneeded
|
2025-07-02 14:26:15 +07:00
|
|
|
shell()->cd(BUILD_BIN_PATH)->exec('strip -S frankenphp');
|
|
|
|
|
}
|
2025-06-27 22:48:15 +07:00
|
|
|
}
|
2025-06-18 10:48:09 +07:00
|
|
|
}
|
2023-03-18 17:32:21 +08:00
|
|
|
}
|