mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-03-19 13:24:51 +08:00
run go mod frankenphp automatically when running craft
This commit is contained in:
parent
2bc9fef758
commit
5f3f999222
@ -69,7 +69,7 @@ SPC_LIBC=musl
|
||||
CC=${SPC_LINUX_DEFAULT_CC}
|
||||
CXX=${SPC_LINUX_DEFAULT_CXX}
|
||||
AR=${SPC_LINUX_DEFAULT_AR}
|
||||
LD=ld.gold
|
||||
LD=${SPC_LINUX_DEFAULT_LD}
|
||||
; default compiler flags, used in CMake toolchain file, openssl and pkg-config build
|
||||
SPC_DEFAULT_C_FLAGS="-fPIC -Os"
|
||||
SPC_DEFAULT_CXX_FLAGS="-fPIC -Os"
|
||||
|
||||
@ -33,7 +33,6 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
if (getenv('SPC_LIBC') === 'musl' && !SystemUtil::isMuslDist()) {
|
||||
$this->setOptionIfNotExist('library_path', "LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\"");
|
||||
$this->setOptionIfNotExist('ld_library_path', "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\"");
|
||||
GlobalEnvManager::putenv("PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . getenv('PATH'));
|
||||
$configure = getenv('SPC_CMD_PREFIX_PHP_CONFIGURE');
|
||||
$configure = "LD_LIBRARY_PATH=\"/usr/local/musl/{$arch}-linux-musl/lib\" " . $configure;
|
||||
GlobalEnvManager::putenv("SPC_CMD_PREFIX_PHP_CONFIGURE={$configure}");
|
||||
|
||||
@ -324,7 +324,7 @@ abstract class UnixBuilderBase extends BuilderBase
|
||||
$xcaddyModules = str_replace('--with github.com/dunglas/caddy-cbrotli', '', $xcaddyModules);
|
||||
}
|
||||
$lrt = PHP_OS_FAMILY === 'Linux' ? '-lrt' : '';
|
||||
$releaseInfo = json_decode(Downloader::curlExec('https://api.github.com/repos/php/frankenphp/releases/latest'), true);
|
||||
$releaseInfo = json_decode(Downloader::curlExec('https://api.github.com/repos/php/frankenphp/releases/latest', retries: 3), true);
|
||||
$frankenPhpVersion = $releaseInfo['tag_name'];
|
||||
$libphpVersion = $this->getPHPVersion();
|
||||
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'shared') {
|
||||
|
||||
@ -66,6 +66,15 @@ class CraftCommand extends BaseCommand
|
||||
return static::FAILURE;
|
||||
}
|
||||
}
|
||||
// install go and xcaddy for frankenphp
|
||||
if (in_array('frankenphp', $craft['sapi'])) {
|
||||
$retcode = $this->runCommand('install-pkg', 'go-mod-frankenphp');
|
||||
if ($retcode !== 0) {
|
||||
$this->output->writeln('<error>craft go-mod-frankenphp failed</error>');
|
||||
$this->log("craft go-mod-frankenphp failed with code: {$retcode}", true);
|
||||
return static::FAILURE;
|
||||
}
|
||||
}
|
||||
// craft download
|
||||
if ($craft['craft-options']['download']) {
|
||||
$sharedAppend = $shared_extensions ? ',' . $shared_extensions : '';
|
||||
|
||||
@ -7,6 +7,7 @@ namespace SPC\store\pkg;
|
||||
use SPC\store\Downloader;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\store\LockFile;
|
||||
use SPC\util\GlobalEnvManager;
|
||||
|
||||
class GoModFrankenphp extends CustomPackage
|
||||
{
|
||||
@ -22,6 +23,12 @@ class GoModFrankenphp extends CustomPackage
|
||||
|
||||
public function fetch(string $name, bool $force = false, ?array $config = null): void
|
||||
{
|
||||
$pkgroot = PKG_ROOT_PATH;
|
||||
$go_exec = "{$pkgroot}/{$name}/bin/go";
|
||||
$xcaddy_exec = "{$pkgroot}/{$name}/bin/xcaddy";
|
||||
if (file_exists($go_exec) && file_exists($xcaddy_exec)) {
|
||||
return;
|
||||
}
|
||||
$arch = match (explode('-', $name)[3]) {
|
||||
'x86_64' => 'amd64',
|
||||
'aarch64' => 'arm64',
|
||||
@ -43,6 +50,11 @@ class GoModFrankenphp extends CustomPackage
|
||||
public function extract(string $name): void
|
||||
{
|
||||
$pkgroot = PKG_ROOT_PATH;
|
||||
$go_exec = "{$pkgroot}/{$name}/bin/go";
|
||||
$xcaddy_exec = "{$pkgroot}/{$name}/bin/xcaddy";
|
||||
if (file_exists($go_exec) && file_exists($xcaddy_exec)) {
|
||||
return;
|
||||
}
|
||||
$lock = json_decode(FileSystem::readFile(LockFile::LOCK_FILE), true);
|
||||
$source_type = $lock[$name]['source_type'];
|
||||
$filename = DOWNLOAD_PATH . '/' . ($lock[$name]['filename'] ?? $lock[$name]['dirname']);
|
||||
@ -50,9 +62,8 @@ class GoModFrankenphp extends CustomPackage
|
||||
|
||||
FileSystem::extractPackage($name, $source_type, $filename, $extract);
|
||||
|
||||
GlobalEnvManager::init();
|
||||
// install xcaddy
|
||||
$go_exec = "{$pkgroot}/{$name}/bin/go";
|
||||
// $xcaddy_exec = PKG_ROOT_PATH . "$pkgroot/$name/bin/xcaddy";
|
||||
shell()
|
||||
->appendEnv([
|
||||
'PATH' => "{$pkgroot}/{$name}/bin:" . getenv('PATH'),
|
||||
|
||||
@ -43,16 +43,19 @@ class GlobalEnvManager
|
||||
}
|
||||
|
||||
// Define env vars for linux
|
||||
if (PHP_OS_FAMILY === 'Linux') {
|
||||
if (PHP_OS_FAMILY === 'Linux' && getenv('SPC_LIBC') === 'musl') {
|
||||
$arch = getenv('GNU_ARCH');
|
||||
if (SystemUtil::isMuslDist()) {
|
||||
self::putenv('SPC_LINUX_DEFAULT_CC=gcc');
|
||||
self::putenv('SPC_LINUX_DEFAULT_CXX=g++');
|
||||
self::putenv('SPC_LINUX_DEFAULT_AR=ar');
|
||||
self::putenv('SPC_LINUX_DEFAULT_LD=ld.gold');
|
||||
} else {
|
||||
self::putenv("SPC_LINUX_DEFAULT_CC={$arch}-linux-musl-gcc");
|
||||
self::putenv("SPC_LINUX_DEFAULT_CXX={$arch}-linux-musl-g++");
|
||||
self::putenv("SPC_LINUX_DEFAULT_AR={$arch}-linux-musl-ar");
|
||||
self::putenv("SPC_LINUX_DEFAULT_LD={$arch}-linux-musl-ld");
|
||||
GlobalEnvManager::putenv("PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . getenv('PATH'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user