diff --git a/src/SPC/builder/extension/swoole.php b/src/SPC/builder/extension/swoole.php index 3dd570a1..b98e74f8 100644 --- a/src/SPC/builder/extension/swoole.php +++ b/src/SPC/builder/extension/swoole.php @@ -13,12 +13,23 @@ class swoole extends Extension public function getUnixConfigureArg(): string { $arg = '--enable-swoole'; - // pgsql hook is buggy for static php - $arg .= ' --disable-swoole-pgsql'; + + $options = ''; + if ($this->builder->getLib('postgresql')) { + if (!$this->builder->getExt('pdo_pgsql')) { + $options .= '--enable-swoole-pgsql'; + } + } else { + $options .= '--disable-swoole-pgsql'; + } + $arg .= $options; $arg .= $this->builder->getLib('openssl') ? ' --enable-openssl' : ' --disable-openssl --without-openssl'; - $arg .= $this->builder->getLib('brotli') ? (' --enable-brotli --with-brotli-dir=' . BUILD_ROOT_PATH) : ' --disable-brotli'; + $arg .= $this->builder->getLib( + 'brotli' + ) ? (' --enable-brotli --with-brotli-dir=' . BUILD_ROOT_PATH) : ' --disable-brotli'; // swoole curl hook is buggy for php 8.0 - $arg .= $this->builder->getExt('curl') && $this->builder->getPHPVersionID() >= 80100 ? ' --enable-swoole-curl' : ' --disable-swoole-curl'; + $arg .= $this->builder->getExt('curl') && $this->builder->getPHPVersionID( + ) >= 80100 ? ' --enable-swoole-curl' : ' --disable-swoole-curl'; return $arg; } } diff --git a/src/SPC/builder/linux/LinuxBuilder.php b/src/SPC/builder/linux/LinuxBuilder.php index da7f793d..758a561d 100644 --- a/src/SPC/builder/linux/LinuxBuilder.php +++ b/src/SPC/builder/linux/LinuxBuilder.php @@ -46,15 +46,23 @@ class LinuxBuilder extends BuilderBase f_putenv("CXX={$this->getOption('cxx', "{$arch}-linux-musl-g++")}"); f_putenv("AR={$this->getOption('ar', "{$arch}-linux-musl-ar")}"); f_putenv("LD={$this->getOption('ld', 'ld.gold')}"); - f_putenv("PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . BUILD_ROOT_PATH . '/bin:' . getenv('PATH')); + f_putenv( + "PATH=/usr/local/musl/bin:/usr/local/musl/{$arch}-linux-musl/bin:" . BUILD_ROOT_PATH . '/bin:' . getenv( + 'PATH' + ) + ); // set library path, some libraries need it. (We cannot use `putenv` here, because cmake will be confused) $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"); // check musl-cross make installed if we use musl-cross-make - if (str_ends_with(getenv('CC'), 'linux-musl-gcc') && !file_exists("/usr/local/musl/bin/{$arch}-linux-musl-gcc")) { - throw new WrongUsageException('musl-cross-make not installed, please install it first. (You can use `doctor` command to install it)'); + if (str_ends_with(getenv('CC'), 'linux-musl-gcc') && !file_exists( + "/usr/local/musl/bin/{$arch}-linux-musl-gcc" + )) { + throw new WrongUsageException( + 'musl-cross-make not installed, please install it first. (You can use `doctor` command to install it)' + ); } } @@ -72,7 +80,10 @@ class LinuxBuilder extends BuilderBase // cflags $this->arch_c_flags = SystemUtil::getArchCFlags(getenv('CC'), $this->getOption('arch')); $this->arch_cxx_flags = SystemUtil::getArchCFlags(getenv('CXX'), $this->getOption('arch')); - $this->tune_c_flags = SystemUtil::checkCCFlags(SystemUtil::getTuneCFlags($this->getOption('arch')), getenv('CC')); + $this->tune_c_flags = SystemUtil::checkCCFlags( + SystemUtil::getTuneCFlags($this->getOption('arch')), + getenv('CC') + ); // cmake toolchain $this->cmake_toolchain_file = SystemUtil::makeCmakeToolchainFile( 'Linux', @@ -133,7 +144,10 @@ class LinuxBuilder extends BuilderBase if (!$this->getOption('bloat', false)) { $extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', $this->getAllStaticLibFiles()); } else { - $extra_libs .= (empty($extra_libs) ? '' : ' ') . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", array_filter($this->getAllStaticLibFiles()))); + $extra_libs .= (empty($extra_libs) ? '' : ' ') . implode( + ' ', + array_map(fn ($x) => "-Xcompiler {$x}", array_filter($this->getAllStaticLibFiles())) + ); } // add libstdc++, some extensions or libraries need it $extra_libs .= (empty($extra_libs) ? '' : ' ') . ($this->hasCpp() ? '-lstdc++ ' : ''); @@ -212,7 +226,11 @@ class LinuxBuilder extends BuilderBase if ($enableEmbed) { logger()->info('building embed'); if ($enableMicro) { - FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/Makefile', 'OVERALL_TARGET =', 'OVERALL_TARGET = libphp.la'); + FileSystem::replaceFileStr( + SOURCE_PATH . '/php-src/Makefile', + 'OVERALL_TARGET =', + 'OVERALL_TARGET = libphp.la' + ); } $this->buildEmbed(); } @@ -259,9 +277,11 @@ class LinuxBuilder extends BuilderBase SourcePatcher::patchMicro(['phar']); } - $vars = SystemUtil::makeEnvVarString($this->getBuildVars([ - 'EXTRA_CFLAGS' => $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '', - ])); + $vars = SystemUtil::makeEnvVarString( + $this->getBuildVars([ + 'EXTRA_CFLAGS' => $this->getOption('with-micro-fake-cli', false) ? ' -DPHP_MICRO_FAKE_CLI' : '', + ]) + ); shell()->cd(SOURCE_PATH . '/php-src') ->exec('sed -i "s|//lib|/lib|g" Makefile') ->exec("make -j{$this->concurrency} {$vars} micro"); @@ -322,10 +342,25 @@ class LinuxBuilder extends BuilderBase $cflags = isset($input['EXTRA_CFLAGS']) && $input['EXTRA_CFLAGS'] ? " {$input['EXTRA_CFLAGS']}" : ''; $libs = isset($input['EXTRA_LIBS']) && $input['EXTRA_LIBS'] ? " {$input['EXTRA_LIBS']}" : ''; $ldflags = isset($input['EXTRA_LDFLAGS_PROGRAM']) && $input['EXTRA_LDFLAGS_PROGRAM'] ? " {$input['EXTRA_LDFLAGS_PROGRAM']}" : ''; - return [ - 'EXTRA_CFLAGS' => "{$optimization} -fno-ident -fPIE " . implode(' ', array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags)) . $cflags, + + $export_variables = []; + if ($this->getLib('postgresql') && $this->getExt('swoole')) { + $output = shell()->execWithResult('pkg-config --cflags --static libpq'); + if (!empty($output[1][0])) { + $export_variables['LIBPQ_CFLAGS'] = $output[1][0]; + } + $output = shell()->execWithResult('pkg-config --libs --static libpq'); + if (!empty($output[1][0])) { + $export_variables['LIBPQ_LIBS'] = $output[1][0]; + } + } + return array_merge($export_variables, [ + 'EXTRA_CFLAGS' => "{$optimization} -fno-ident -fPIE " . implode( + ' ', + array_map(fn ($x) => "-Xcompiler {$x}", $this->tune_c_flags) + ) . $cflags, 'EXTRA_LIBS' => $this->getOption('extra-libs', '') . $libs, 'EXTRA_LDFLAGS_PROGRAM' => "{$use_lld} -all-static" . $ldflags, - ]; + ]); } } diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 4c50f783..0e52224b 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -31,7 +31,6 @@ trait postgresql foreach ($optional_packages as $lib => $pkg) { if ($this->getBuilder()->getLib($lib)) { $packages .= ' ' . $pkg; - $output = shell()->execWithResult("pkg-config --cflags --libs --static {$pkg}")[1][0]; if (!empty($output[1][0])) { logger()->info($output[1][0]);