mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-20 15:25:36 +08:00
Compare commits
6 Commits
2cb1a95132
...
05053b5cd6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
05053b5cd6 | ||
|
|
978552136c | ||
|
|
fb62a0e338 | ||
|
|
630f861c62 | ||
|
|
c2b3b78846 | ||
|
|
6e74dabc1c |
@@ -655,7 +655,7 @@
|
||||
"mimalloc": {
|
||||
"source": "mimalloc",
|
||||
"static-libs-unix": [
|
||||
"mimalloc.o"
|
||||
"libmimalloc.a"
|
||||
]
|
||||
},
|
||||
"ncurses": {
|
||||
|
||||
@@ -548,6 +548,9 @@ class Extension
|
||||
$libs = explode(' ', $allLibs);
|
||||
foreach ($libs as $lib) {
|
||||
$staticLib = BUILD_LIB_PATH . '/lib' . str_replace('-l', '', $lib) . '.a';
|
||||
if (str_starts_with($lib, BUILD_LIB_PATH . '/lib') && str_ends_with($lib, '.a')) {
|
||||
$staticLib = $lib;
|
||||
}
|
||||
if ($lib === '-lphp' || !file_exists($staticLib)) {
|
||||
$sharedLibString .= " {$lib}";
|
||||
} else {
|
||||
|
||||
@@ -88,12 +88,11 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
$enableFrankenphp = ($build_target & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP;
|
||||
|
||||
// prepare build php envs
|
||||
$mimallocLibs = $this->getLib('mimalloc') !== null ? BUILD_LIB_PATH . '/mimalloc.o ' : '';
|
||||
$php_configure_env = SystemUtil::makeEnvVarString([
|
||||
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
|
||||
'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH,
|
||||
'LDFLAGS' => '-L' . BUILD_LIB_PATH,
|
||||
'LIBS' => $mimallocLibs . SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions!
|
||||
'LIBS' => SPCTarget::getRuntimeLibs(), // do not pass static libraries here yet, they may contain polyfills for libc functions!
|
||||
]);
|
||||
|
||||
$embed_type = getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') ?: 'static';
|
||||
@@ -105,6 +104,7 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
}
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec(
|
||||
$php_configure_env . ' ' .
|
||||
getenv('SPC_CMD_PREFIX_PHP_CONFIGURE') . ' ' .
|
||||
($enableCli ? '--enable-cli ' : '--disable-cli ') .
|
||||
($enableFpm ? '--enable-fpm ' . ($this->getLib('libacl') !== null ? '--with-fpm-acl ' : '') : '--disable-fpm ') .
|
||||
@@ -116,8 +116,8 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
$json_74 .
|
||||
$zts .
|
||||
$maxExecutionTimers .
|
||||
$this->makeStaticExtensionArgs() .
|
||||
' ' . $php_configure_env . ' '
|
||||
$this->makeStaticExtensionArgs() . ' '
|
||||
// 'ac_cv_lib_readline_rl_pending_input=yes'
|
||||
);
|
||||
|
||||
$this->emitPatchPoint('before-php-make');
|
||||
@@ -323,6 +323,10 @@ class LinuxBuilder extends UnixBuilderBase
|
||||
}
|
||||
}
|
||||
|
||||
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') {
|
||||
f_passthru('ar -t ' . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a');
|
||||
}
|
||||
|
||||
if (!$this->getOption('no-strip', false) && file_exists(BUILD_LIB_PATH . '/' . $realLibName)) {
|
||||
shell()->cd(BUILD_LIB_PATH)->exec("strip --strip-unneeded {$realLibName}");
|
||||
}
|
||||
|
||||
@@ -112,12 +112,10 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
$enableFrankenphp = ($build_target & BUILD_TARGET_FRANKENPHP) === BUILD_TARGET_FRANKENPHP;
|
||||
|
||||
// prepare build php envs
|
||||
$mimallocLibs = $this->getLib('mimalloc') !== null ? BUILD_LIB_PATH . '/mimalloc.o ' : '';
|
||||
$envs_build_php = SystemUtil::makeEnvVarString([
|
||||
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_CONFIGURE_CFLAGS'),
|
||||
'CPPFLAGS' => '-I' . BUILD_INCLUDE_PATH,
|
||||
'LDFLAGS' => '-L' . BUILD_LIB_PATH,
|
||||
'LIBS' => $mimallocLibs . getenv('SPC_CMD_VAR_PHP_CONFIGURE_LIBS'),
|
||||
]);
|
||||
|
||||
if ($this->getLib('postgresql')) {
|
||||
@@ -269,8 +267,7 @@ class MacOSBuilder extends UnixBuilderBase
|
||||
->exec(getenv('SPC_CMD_PREFIX_PHP_MAKE') . ' INSTALL_ROOT=' . BUILD_ROOT_PATH . " {$vars} install");
|
||||
|
||||
if (getenv('SPC_CMD_VAR_PHP_EMBED_TYPE') === 'static') {
|
||||
shell()->cd(SOURCE_PATH . '/php-src')
|
||||
->exec('ar -t ' . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a');
|
||||
f_passthru('ar -t ' . BUILD_LIB_PATH . "/libphp.a | grep '\\.a$' | xargs -n1 ar d " . BUILD_LIB_PATH . '/libphp.a');
|
||||
}
|
||||
$this->patchPhpScripts();
|
||||
}
|
||||
|
||||
@@ -17,6 +17,14 @@ trait librdkafka
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
$cflags = $this->builder->arch_c_flags;
|
||||
$cxxflags = $this->builder->arch_cxx_flags;
|
||||
$patched_cflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cflags);
|
||||
$patched_cxxflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cxxflags);
|
||||
|
||||
$this->builder->arch_c_flags = $patched_cflags;
|
||||
$this->builder->arch_cxx_flags = $patched_cxxflags;
|
||||
|
||||
FileSystem::replaceFileStr(
|
||||
$this->source_dir . '/lds-gen.py',
|
||||
"funcs.append('rd_ut_coverage_check')",
|
||||
@@ -56,5 +64,8 @@ trait librdkafka
|
||||
->exec("rm -rf {$this->getLibDir()}/*.so.*")
|
||||
->exec("rm -rf {$this->getLibDir()}/*.so")
|
||||
->exec("rm -rf {$this->getLibDir()}/*.dylib");
|
||||
|
||||
$this->builder->arch_c_flags = $cflags;
|
||||
$this->builder->arch_cxx_flags = $cxxflags;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ trait mimalloc
|
||||
$cmake = UnixCMakeExecutor::create($this)
|
||||
->addConfigureArgs(
|
||||
'-DMI_BUILD_SHARED=OFF',
|
||||
'-DMI_BUILD_OBJECT=OFF',
|
||||
'-DMI_INSTALL_TOPLEVEL=ON',
|
||||
);
|
||||
if (SPCTarget::getLibc() === 'musl') {
|
||||
|
||||
@@ -16,6 +16,14 @@ trait unixodbc
|
||||
*/
|
||||
protected function build(): void
|
||||
{
|
||||
$cflags = $this->builder->arch_c_flags;
|
||||
$cxxflags = $this->builder->arch_cxx_flags;
|
||||
$patched_cflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cflags);
|
||||
$patched_cxxflags = preg_replace('/\s*-flto(=\S*)?\s*/', ' ', $cxxflags);
|
||||
|
||||
$this->builder->arch_c_flags = $patched_cflags;
|
||||
$this->builder->arch_cxx_flags = $patched_cxxflags;
|
||||
|
||||
UnixAutoconfExecutor::create($this)
|
||||
->configure(
|
||||
'--disable-debug',
|
||||
@@ -27,5 +35,8 @@ trait unixodbc
|
||||
->make();
|
||||
$this->patchPkgconfPrefix(['odbc.pc', 'odbccr.pc', 'odbcinst.pc']);
|
||||
$this->patchLaDependencyPrefix();
|
||||
|
||||
$this->builder->arch_c_flags = $cflags;
|
||||
$this->builder->arch_cxx_flags = $cxxflags;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace SPC\doctor\item;
|
||||
|
||||
use SPC\builder\linux\SystemUtil;
|
||||
use SPC\doctor\AsCheckItem;
|
||||
use SPC\doctor\AsFixItem;
|
||||
use SPC\doctor\CheckResult;
|
||||
@@ -17,13 +18,15 @@ use SPC\store\FileSystem;
|
||||
use SPC\store\PackageManager;
|
||||
use SPC\store\SourcePatcher;
|
||||
use SPC\toolchain\MuslToolchain;
|
||||
use SPC\toolchain\ZigToolchain;
|
||||
|
||||
#[OptionalCheck([self::class, 'optionalCheck'])]
|
||||
class LinuxMuslCheck
|
||||
{
|
||||
public static function optionalCheck(): bool
|
||||
{
|
||||
return getenv('SPC_TOOLCHAIN') === MuslToolchain::class;
|
||||
return getenv('SPC_TOOLCHAIN') === MuslToolchain::class ||
|
||||
(getenv('SPC_TOOLCHAIN') === ZigToolchain::class && !SystemUtil::isMuslDist());
|
||||
}
|
||||
|
||||
/** @noinspection PhpUnused */
|
||||
@@ -31,7 +34,7 @@ class LinuxMuslCheck
|
||||
public function checkMusl(): CheckResult
|
||||
{
|
||||
$musl_wrapper_lib = sprintf('/lib/ld-musl-%s.so.1', php_uname('m'));
|
||||
if (file_exists($musl_wrapper_lib) && file_exists('/usr/local/musl/lib/libc.a')) {
|
||||
if (file_exists($musl_wrapper_lib) && (file_exists('/usr/local/musl/lib/libc.a') || getenv('SPC_TOOLCHAIN') === ZigToolchain::class)) {
|
||||
return CheckResult::ok();
|
||||
}
|
||||
return CheckResult::fail('musl-wrapper is not installed on your system', 'fix-musl-wrapper');
|
||||
@@ -40,6 +43,9 @@ class LinuxMuslCheck
|
||||
#[AsCheckItem('if musl-cross-make is installed', limit_os: 'Linux', level: 799)]
|
||||
public function checkMuslCrossMake(): CheckResult
|
||||
{
|
||||
if (getenv('SPC_TOOLCHAIN') === ZigToolchain::class && !SystemUtil::isMuslDist()) {
|
||||
return CheckResult::ok();
|
||||
}
|
||||
$arch = arch2gnu(php_uname('m'));
|
||||
$cross_compile_lib = "/usr/local/musl/{$arch}-linux-musl/lib/libc.a";
|
||||
$cross_compile_gcc = "/usr/local/musl/bin/{$arch}-linux-musl-gcc";
|
||||
|
||||
@@ -31,7 +31,7 @@ class LinuxToolCheckList
|
||||
'tar', 'unzip', 'gzip',
|
||||
'bzip2', 'cmake', 'patch',
|
||||
'xz', 'libtoolize', 'which',
|
||||
'patchelf', 'musl',
|
||||
'patchelf',
|
||||
];
|
||||
|
||||
public const TOOLS_RHEL = [
|
||||
@@ -40,7 +40,7 @@ class LinuxToolCheckList
|
||||
'tar', 'unzip', 'gzip', 'gcc',
|
||||
'bzip2', 'cmake', 'patch', 'which',
|
||||
'xz', 'libtool', 'gettext-devel',
|
||||
'perl', 'patchelf', 'musl-libc',
|
||||
'perl', 'patchelf',
|
||||
];
|
||||
|
||||
public const TOOLS_ARCH = [
|
||||
|
||||
@@ -162,6 +162,12 @@ class Zig extends CustomPackage
|
||||
|
||||
$script_content = str_replace('zig cc', 'zig c++', $script_content);
|
||||
file_put_contents("{$bin_dir}/zig-c++", $script_content);
|
||||
file_put_contents("{$bin_dir}/zig-ar", "#!/usr/bin/env bash\nexec zig ar $@");
|
||||
file_put_contents("{$bin_dir}/zig-ranlib", "#!/usr/bin/env bash\nexec zig ranlib $@");
|
||||
file_put_contents("{$bin_dir}/zig-objcopy", "#!/usr/bin/env bash\nexec zig objcopy $@");
|
||||
chmod("{$bin_dir}/zig-c++", 0755);
|
||||
chmod("{$bin_dir}/zig-ar", 0755);
|
||||
chmod("{$bin_dir}/zig-ranlib", 0755);
|
||||
chmod("{$bin_dir}/zig-objcopy", 0755);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,10 +15,12 @@ class ZigToolchain implements ToolchainInterface
|
||||
// Set environment variables for zig toolchain
|
||||
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CC=zig-cc');
|
||||
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_CXX=zig-c++');
|
||||
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=ar');
|
||||
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=ld');
|
||||
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_AR=zig-ar');
|
||||
GlobalEnvManager::putenv('SPC_LINUX_DEFAULT_LD=zig-cc');
|
||||
GlobalEnvManager::putenv('RANLIB=zig-ranlib');
|
||||
GlobalEnvManager::putenv('OBJCOPY=zig-objcopy');
|
||||
|
||||
// Generate additional object needed for zig toolchain
|
||||
// Generate additional objects needed for zig toolchain
|
||||
$paths = ['/usr/lib/gcc', '/usr/local/lib/gcc'];
|
||||
$objects = ['crtbeginS.o', 'crtendS.o'];
|
||||
$found = [];
|
||||
|
||||
@@ -94,8 +94,8 @@ class SPCConfigUtil
|
||||
|
||||
if ($this->libs_only_deps) {
|
||||
// mimalloc must come first
|
||||
if (str_contains($libs, BUILD_LIB_PATH . '/mimalloc.o')) {
|
||||
$libs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $libs);
|
||||
if ($this->builder->getLib('mimalloc') && file_exists(BUILD_LIB_PATH . '/libmimalloc.a')) {
|
||||
$libs = BUILD_LIB_PATH . '/libmimalloc.a ' . str_replace([BUILD_LIB_PATH . '/libmimalloc.a', '-lmimalloc'], ['', ''], $libs);
|
||||
}
|
||||
return [
|
||||
'cflags' => clean_spaces(getenv('CFLAGS') . ' ' . $cflags),
|
||||
@@ -112,8 +112,8 @@ class SPCConfigUtil
|
||||
$allLibs = getenv('LIBS') . ' ' . $libs;
|
||||
|
||||
// mimalloc must come first
|
||||
if (str_contains($libs, BUILD_LIB_PATH . '/mimalloc.o')) {
|
||||
$allLibs = BUILD_LIB_PATH . '/mimalloc.o ' . str_replace(BUILD_LIB_PATH . '/mimalloc.o', '', $allLibs);
|
||||
if ($this->builder->getLib('mimalloc') && file_exists(BUILD_LIB_PATH . '/libmimalloc.a')) {
|
||||
$allLibs = BUILD_LIB_PATH . '/libmimalloc.a ' . str_replace([BUILD_LIB_PATH . '/libmimalloc.a', '-lmimalloc'], ['', ''], $allLibs);
|
||||
}
|
||||
|
||||
return [
|
||||
|
||||
@@ -61,9 +61,9 @@ class UnixShell
|
||||
{
|
||||
$this->setEnv([
|
||||
'CFLAGS' => $library->getLibExtraCFlags(),
|
||||
'CXXFLAGS' => $library->getLibExtraCXXFlags(),
|
||||
'LDFLAGS' => $library->getLibExtraLdFlags(),
|
||||
'LIBS' => $library->getLibExtraLibs(),
|
||||
'CXXFLAGS' => $library->getLibExtraCXXFlags(),
|
||||
]);
|
||||
return $this;
|
||||
}
|
||||
|
||||
@@ -135,6 +135,7 @@ class UnixAutoconfExecutor extends Executor
|
||||
{
|
||||
$this->shell = shell()->cd($this->library->getSourceDir())->initializeEnv($this->library)->appendEnv([
|
||||
'CFLAGS' => "-I{$this->library->getIncludeDir()}",
|
||||
'CXXFLAGS' => "-I{$this->library->getIncludeDir()}",
|
||||
'LDFLAGS' => "-L{$this->library->getLibDir()}",
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -57,18 +57,18 @@ class SPCConfigUtilTest extends TestCase
|
||||
$result = (new SPCConfigUtil())->config(['rar']);
|
||||
$this->assertStringContainsString(PHP_OS_FAMILY === 'Darwin' ? '-lc++' : '-lstdc++', $result['libs']);
|
||||
|
||||
// has mimalloc.o in lib dir
|
||||
// has libmimalloc.a in lib dir
|
||||
// backup first
|
||||
if (file_exists(BUILD_LIB_PATH . '/mimalloc.o')) {
|
||||
$bak = file_get_contents(BUILD_LIB_PATH . '/mimalloc.o');
|
||||
@unlink(BUILD_LIB_PATH . '/mimalloc.o');
|
||||
if (file_exists(BUILD_LIB_PATH . '/libmimalloc.a')) {
|
||||
$bak = file_get_contents(BUILD_LIB_PATH . '/libmimalloc.a');
|
||||
@unlink(BUILD_LIB_PATH . '/libmimalloc.a');
|
||||
}
|
||||
file_put_contents(BUILD_LIB_PATH . '/mimalloc.o', '');
|
||||
file_put_contents(BUILD_LIB_PATH . '/libmimalloc.a', '');
|
||||
$result = (new SPCConfigUtil())->config(['bcmath'], ['mimalloc']);
|
||||
$this->assertStringStartsWith(BUILD_LIB_PATH . '/mimalloc.o', $result['libs']);
|
||||
@unlink(BUILD_LIB_PATH . '/mimalloc.o');
|
||||
$this->assertStringStartsWith(BUILD_LIB_PATH . '/libmimalloc.a', $result['libs']);
|
||||
@unlink(BUILD_LIB_PATH . '/libmimalloc.a');
|
||||
if (isset($bak)) {
|
||||
file_put_contents(BUILD_LIB_PATH . '/mimalloc.o', $bak);
|
||||
file_put_contents(BUILD_LIB_PATH . '/libmimalloc.a', $bak);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user