mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-18 04:44:53 +08:00
Merge branch 'main' of https://github.com/crazywhalecc/static-php-cli into zig
This commit is contained in:
commit
199b3b5582
@ -34,7 +34,6 @@
|
|||||||
; SPC_LINUX_DEFAULT_CXX: the default c++ compiler for linux. (For alpine linux: `g++`, default: `$GNU_ARCH-linux-musl-g++`)
|
; SPC_LINUX_DEFAULT_CXX: the default c++ compiler for linux. (For alpine linux: `g++`, default: `$GNU_ARCH-linux-musl-g++`)
|
||||||
; SPC_LINUX_DEFAULT_AR: the default archiver for linux. (For alpine linux: `ar`, default: `$GNU_ARCH-linux-musl-ar`)
|
; SPC_LINUX_DEFAULT_AR: the default archiver for linux. (For alpine linux: `ar`, default: `$GNU_ARCH-linux-musl-ar`)
|
||||||
|
|
||||||
|
|
||||||
[global]
|
[global]
|
||||||
; Build concurrency for make -jN, default is CPU_COUNT, this value are used in every libs.
|
; Build concurrency for make -jN, default is CPU_COUNT, this value are used in every libs.
|
||||||
SPC_CONCURRENCY=${CPU_COUNT}
|
SPC_CONCURRENCY=${CPU_COUNT}
|
||||||
@ -102,11 +101,11 @@ SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force"
|
|||||||
; configure command
|
; configure command
|
||||||
SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --disable-shared --enable-static --disable-all --disable-cgi --disable-phpdbg --with-pic"
|
SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --disable-shared --enable-static --disable-all --disable-cgi --disable-phpdbg --with-pic"
|
||||||
; make command
|
; make command
|
||||||
SPC_CMD_PREFIX_PHP_MAKE="make -j${CPU_COUNT}"
|
SPC_CMD_PREFIX_PHP_MAKE="make -j${SPC_CONCURRENCY}"
|
||||||
; embed type for php, static (libphp.a) or shared (libphp.so)
|
|
||||||
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
|
|
||||||
|
|
||||||
; *** default build vars for building php ***
|
; *** default build vars for building php ***
|
||||||
|
; embed type for php, static (libphp.a) or shared (libphp.so)
|
||||||
|
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
|
||||||
; CFLAGS for configuring php
|
; CFLAGS for configuring php
|
||||||
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fPIE"
|
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -fPIE"
|
||||||
; CPPFLAGS for configuring php
|
; CPPFLAGS for configuring php
|
||||||
@ -137,9 +136,11 @@ SPC_CMD_PREFIX_PHP_BUILDCONF="./buildconf --force"
|
|||||||
; configure command
|
; configure command
|
||||||
SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg"
|
SPC_CMD_PREFIX_PHP_CONFIGURE="./configure --prefix= --with-valgrind=no --enable-shared=no --enable-static=yes --disable-all --disable-cgi --disable-phpdbg"
|
||||||
; make command
|
; make command
|
||||||
SPC_CMD_PREFIX_PHP_MAKE="make -j${CPU_COUNT}"
|
SPC_CMD_PREFIX_PHP_MAKE="make -j${SPC_CONCURRENCY}"
|
||||||
|
|
||||||
; *** default build vars for building php ***
|
; *** default build vars for building php ***
|
||||||
|
; embed type for php, static (libphp.a) or shared (libphp.dylib)
|
||||||
|
SPC_CMD_VAR_PHP_EMBED_TYPE="static"
|
||||||
; CFLAGS for configuring php
|
; CFLAGS for configuring php
|
||||||
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -Werror=unknown-warning-option"
|
SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS="${SPC_DEFAULT_C_FLAGS} -Werror=unknown-warning-option"
|
||||||
; CPPFLAGS for configuring php
|
; CPPFLAGS for configuring php
|
||||||
|
|||||||
@ -96,7 +96,7 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
$envs_build_php = SystemUtil::makeEnvVarString([
|
$envs_build_php = SystemUtil::makeEnvVarString([
|
||||||
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
|
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
|
||||||
'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'),
|
'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'),
|
||||||
'LDFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS'),
|
'LDFLAGS' => '-L' . BUILD_LIB_PATH,
|
||||||
'LIBS' => $config['libs'],
|
'LIBS' => $config['libs'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -336,11 +336,13 @@ class LinuxBuilder extends UnixBuilderBase
|
|||||||
private function getMakeExtraVars(): array
|
private function getMakeExtraVars(): array
|
||||||
{
|
{
|
||||||
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true, 'absolute_libs' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
|
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true, 'absolute_libs' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
|
||||||
|
$static = SPCTarget::isStatic() ? '-all-static' : '';
|
||||||
|
$lib = BUILD_LIB_PATH;
|
||||||
return [
|
return [
|
||||||
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
|
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
|
||||||
'EXTRA_LIBS' => $config['libs'],
|
'EXTRA_LIBS' => $config['libs'],
|
||||||
'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'),
|
'EXTRA_LDFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'),
|
||||||
'EXTRA_LDFLAGS_PROGRAM' => SPCTarget::isStatic() ? '-all-static -pie' : '-pie',
|
'EXTRA_LDFLAGS_PROGRAM' => "-L{$lib} {$static} -pie",
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -116,7 +116,7 @@ class MacOSBuilder extends UnixBuilderBase
|
|||||||
$envs_build_php = SystemUtil::makeEnvVarString([
|
$envs_build_php = SystemUtil::makeEnvVarString([
|
||||||
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
|
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
|
||||||
'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'),
|
'CPPFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CPPFLAGS'),
|
||||||
'LDFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_LDFLAGS'),
|
'LDFLAGS' => '-L' . BUILD_LIB_PATH,
|
||||||
'LIBS' => $mimallocLibs . getenv('SPC_CMD_VAR_PHP_CONFIGURE_LIBS'),
|
'LIBS' => $mimallocLibs . getenv('SPC_CMD_VAR_PHP_CONFIGURE_LIBS'),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -280,6 +280,7 @@ class MacOSBuilder extends UnixBuilderBase
|
|||||||
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
|
$config = (new SPCConfigUtil($this, ['libs_only_deps' => true]))->config($this->ext_list, $this->lib_list, $this->getOption('with-suggested-exts'), $this->getOption('with-suggested-libs'));
|
||||||
return [
|
return [
|
||||||
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
|
'EXTRA_CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
|
||||||
|
'EXTRA_LDFLAGS_PROGRAM' => '-L' . BUILD_LIB_PATH,
|
||||||
'EXTRA_LIBS' => $config['libs'],
|
'EXTRA_LIBS' => $config['libs'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -248,10 +248,9 @@ class DownloadCommand extends BaseCommand
|
|||||||
$alt_sources = Config::getSource($source)['alt'] ?? null;
|
$alt_sources = Config::getSource($source)['alt'] ?? null;
|
||||||
if ($alt_sources === null) {
|
if ($alt_sources === null) {
|
||||||
logger()->warning("No alternative sources found for {$source}, using default alternative source");
|
logger()->warning("No alternative sources found for {$source}, using default alternative source");
|
||||||
$alt_config = array_merge($config, $this->getDefaultAlternativeSource($source));
|
$alt_config = array_merge($config, Downloader::getDefaultAlternativeSource($source));
|
||||||
} elseif ($alt_sources === false) {
|
} elseif ($alt_sources === false) {
|
||||||
logger()->warning("No alternative sources found for {$source}, skipping alternative download");
|
throw new DownloaderException("No alternative sources found for {$source}, skipping alternative download");
|
||||||
throw $e;
|
|
||||||
} else {
|
} else {
|
||||||
logger()->notice("Trying to download alternative sources for {$source}");
|
logger()->notice("Trying to download alternative sources for {$source}");
|
||||||
$alt_config = array_merge($config, $alt_sources);
|
$alt_config = array_merge($config, $alt_sources);
|
||||||
@ -399,27 +398,4 @@ class DownloadCommand extends BaseCommand
|
|||||||
}
|
}
|
||||||
return static::FAILURE;
|
return static::FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDefaultAlternativeSource(string $source_name): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
'type' => 'custom',
|
|
||||||
'func' => function (bool $force, array $source, int $download_as) use ($source_name) {
|
|
||||||
logger()->debug("Fetching alternative source for {$source_name}");
|
|
||||||
// get from dl.static-php.dev
|
|
||||||
$url = "https://dl.static-php.dev/static-php-cli/deps/spc-download-mirror/{$source_name}/?format=json";
|
|
||||||
$json = json_decode(Downloader::curlExec(url: $url, retries: intval(getenv('SPC_DOWNLOAD_RETRIES') ?: 0)), true);
|
|
||||||
if (!is_array($json)) {
|
|
||||||
throw new RuntimeException('failed http fetch');
|
|
||||||
}
|
|
||||||
$item = $json[0] ?? null;
|
|
||||||
if ($item === null) {
|
|
||||||
throw new RuntimeException('failed to parse json');
|
|
||||||
}
|
|
||||||
$full_url = 'https://dl.static-php.dev' . $item['full_path'];
|
|
||||||
$filename = basename($item['full_path']);
|
|
||||||
Downloader::downloadFile($source_name, $full_url, $filename, $source['path'] ?? null, $download_as);
|
|
||||||
},
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,6 +24,8 @@ class InstallPkgCommand extends BaseCommand
|
|||||||
$this->addArgument('packages', InputArgument::REQUIRED, 'The packages will be installed, comma separated');
|
$this->addArgument('packages', InputArgument::REQUIRED, 'The packages will be installed, comma separated');
|
||||||
$this->addOption('shallow-clone', null, null, 'Clone shallow');
|
$this->addOption('shallow-clone', null, null, 'Clone shallow');
|
||||||
$this->addOption('custom-url', 'U', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"');
|
$this->addOption('custom-url', 'U', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_REQUIRED, 'Specify custom source download url, e.g "php-src:https://downloads.php.net/~eric/php-8.3.0beta1.tar.gz"');
|
||||||
|
$this->addOption('no-alt', null, null, 'Do not download alternative packages');
|
||||||
|
$this->addOption('skip-extract', null, null, 'Skip package extraction, just download the package archive');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -66,10 +68,20 @@ class InstallPkgCommand extends BaseCommand
|
|||||||
$new_config['filename'] = $config['filename'];
|
$new_config['filename'] = $config['filename'];
|
||||||
}
|
}
|
||||||
logger()->info("Installing source {$pkg} from custom url [{$ni}/{$cnt}]");
|
logger()->info("Installing source {$pkg} from custom url [{$ni}/{$cnt}]");
|
||||||
PackageManager::installPackage($pkg, $new_config);
|
PackageManager::installPackage(
|
||||||
|
$pkg,
|
||||||
|
$new_config,
|
||||||
|
allow_alt: false,
|
||||||
|
extract: !$this->getOption('skip-extract')
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
logger()->info("Fetching package {$pkg} [{$ni}/{$cnt}]");
|
logger()->info("Fetching package {$pkg} [{$ni}/{$cnt}]");
|
||||||
PackageManager::installPackage($pkg, Config::getPkg($pkg));
|
PackageManager::installPackage(
|
||||||
|
$pkg,
|
||||||
|
Config::getPkg($pkg),
|
||||||
|
allow_alt: !$this->getOption('no-alt'),
|
||||||
|
extract: !$this->getOption('skip-extract')
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$time = round(microtime(true) - START_TIME, 3);
|
$time = round(microtime(true) - START_TIME, 3);
|
||||||
|
|||||||
@ -368,6 +368,11 @@ class Downloader
|
|||||||
break;
|
break;
|
||||||
case 'custom': // Custom download method, like API-based download or other
|
case 'custom': // Custom download method, like API-based download or other
|
||||||
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/pkg', 'SPC\store\pkg');
|
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/pkg', 'SPC\store\pkg');
|
||||||
|
if (isset($pkg['func']) && is_callable($pkg['func'])) {
|
||||||
|
$pkg['name'] = $name;
|
||||||
|
$pkg['func']($force, $pkg, SPC_DOWNLOAD_PACKAGE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
foreach ($classes as $class) {
|
foreach ($classes as $class) {
|
||||||
if (is_a($class, CustomPackage::class, true) && $class !== CustomPackage::class) {
|
if (is_a($class, CustomPackage::class, true) && $class !== CustomPackage::class) {
|
||||||
$cls = new $class();
|
$cls = new $class();
|
||||||
@ -608,6 +613,29 @@ class Downloader
|
|||||||
return "{$source}-{$os_family}-{$gnu_arch}-{$libc}-{$libc_version}";
|
return "{$source}-{$os_family}-{$gnu_arch}-{$libc}-{$libc_version}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getDefaultAlternativeSource(string $source_name): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'type' => 'custom',
|
||||||
|
'func' => function (bool $force, array $source, int $download_as) use ($source_name) {
|
||||||
|
logger()->debug("Fetching alternative source for {$source_name}");
|
||||||
|
// get from dl.static-php.dev
|
||||||
|
$url = "https://dl.static-php.dev/static-php-cli/deps/spc-download-mirror/{$source_name}/?format=json";
|
||||||
|
$json = json_decode(Downloader::curlExec(url: $url, retries: intval(getenv('SPC_DOWNLOAD_RETRIES') ?: 0)), true);
|
||||||
|
if (!is_array($json)) {
|
||||||
|
throw new RuntimeException('failed http fetch');
|
||||||
|
}
|
||||||
|
$item = $json[0] ?? null;
|
||||||
|
if ($item === null) {
|
||||||
|
throw new RuntimeException('failed to parse json');
|
||||||
|
}
|
||||||
|
$full_url = 'https://dl.static-php.dev' . $item['full_path'];
|
||||||
|
$filename = basename($item['full_path']);
|
||||||
|
Downloader::downloadFile($source_name, $full_url, $filename, $source['path'] ?? null, $download_as);
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register CTRL+C event for different OS.
|
* Register CTRL+C event for different OS.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -4,13 +4,14 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace SPC\store;
|
namespace SPC\store;
|
||||||
|
|
||||||
|
use SPC\exception\DownloaderException;
|
||||||
use SPC\exception\FileSystemException;
|
use SPC\exception\FileSystemException;
|
||||||
use SPC\exception\WrongUsageException;
|
use SPC\exception\WrongUsageException;
|
||||||
use SPC\store\pkg\CustomPackage;
|
use SPC\store\pkg\CustomPackage;
|
||||||
|
|
||||||
class PackageManager
|
class PackageManager
|
||||||
{
|
{
|
||||||
public static function installPackage(string $pkg_name, ?array $config = null, bool $force = false): void
|
public static function installPackage(string $pkg_name, ?array $config = null, bool $force = false, bool $allow_alt = true, bool $extract = true): void
|
||||||
{
|
{
|
||||||
if ($config === null) {
|
if ($config === null) {
|
||||||
$config = Config::getPkg($pkg_name);
|
$config = Config::getPkg($pkg_name);
|
||||||
@ -32,7 +33,31 @@ class PackageManager
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Download package
|
// Download package
|
||||||
Downloader::downloadPackage($pkg_name, $config, $force);
|
try {
|
||||||
|
Downloader::downloadPackage($pkg_name, $config, $force);
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
if (!$allow_alt) {
|
||||||
|
throw new DownloaderException("Download package {$pkg_name} failed: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
// if download failed, we will try to download alternative packages
|
||||||
|
logger()->warning("Download package {$pkg_name} failed: " . $e->getMessage());
|
||||||
|
$alt = $config['alt'] ?? null;
|
||||||
|
if ($alt === null) {
|
||||||
|
logger()->warning("No alternative package found for {$pkg_name}, using default mirror.");
|
||||||
|
$alt_config = array_merge($config, Downloader::getDefaultAlternativeSource($pkg_name));
|
||||||
|
} elseif ($alt === false) {
|
||||||
|
logger()->error("No alternative package found for {$pkg_name}.");
|
||||||
|
throw $e;
|
||||||
|
} else {
|
||||||
|
logger()->notice("Trying alternative package for {$pkg_name}.");
|
||||||
|
$alt_config = array_merge($config, $alt);
|
||||||
|
}
|
||||||
|
Downloader::downloadPackage($pkg_name, $alt_config, $force);
|
||||||
|
}
|
||||||
|
if (!$extract) {
|
||||||
|
logger()->info("Package [{$pkg_name}] downloaded, but extraction is skipped.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Config::getPkg($pkg_name)['type'] === 'custom') {
|
if (Config::getPkg($pkg_name)['type'] === 'custom') {
|
||||||
// Custom extract function
|
// Custom extract function
|
||||||
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/pkg', 'SPC\store\pkg');
|
$classes = FileSystem::getClassesPsr4(ROOT_DIR . '/src/SPC/store/pkg', 'SPC\store\pkg');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user