Merge pull request #84 from jingjingxyk/pgsql

添加pgsql 库
This commit is contained in:
Jerry Ma 2023-07-22 16:19:43 +08:00 committed by GitHub
commit 0902f80b46
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 137 additions and 4 deletions

View File

@ -211,12 +211,19 @@
},
"pdo_pgsql": {
"type": "builtin",
"arg-type": "with",
"arg-type": "with-prefix",
"ext-depends": [
"pdo"
],
"lib-depends": [
"pq"
"postgresql"
]
},
"pgsql": {
"type": "builtin",
"arg-type": "with-prefix",
"lib-depends": [
"postgresql"
]
},
"pdo_sqlite": {

View File

@ -381,7 +381,16 @@
"postgresql": {
"source": "postgresql",
"static-libs-unix": [
"libpg.a"
"libpq.a",
"libpgport.a",
"libpgcommon.a"
],
"lib-depends": [
"libiconv",
"libxml2",
"openssl",
"zlib",
"readline"
]
},
"pthreads4w": {

View File

@ -318,7 +318,8 @@
}
},
"postgresql": {
"type": "custom",
"type": "url",
"url": "https://ftp.postgresql.org/pub/source/v15.1/postgresql-15.1.tar.gz",
"license": {
"type": "file",
"path": "COPYRIGHT"

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
class postgresql extends LinuxLibraryBase
{
use \SPC\builder\unix\library\postgresql;
public const NAME = 'postgresql';
}

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
class postgresql extends MacOSLibraryBase
{
use \SPC\builder\unix\library\postgresql;
public const NAME = 'postgresql';
}

View File

@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\builder\macos\library\MacOSLibraryBase;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
trait postgresql
{
/**
* @throws RuntimeException
* @throws FileSystemException
*/
protected function build()
{
$builddir = BUILD_ROOT_PATH;
$env = $this->builder->configure_env;
$envs = $env;
$packages = 'openssl zlib readline libxml-2.0'; // icu-uc icu-io icu-i18n libzstd
$pkgconfig_executable = $builddir . '/bin/pkg-config';
$output = shell()->execWithResult($env . " {$pkgconfig_executable} --cflags-only-I --static " . $packages);
if (!empty($output[1][0])) {
$cppflags = $output[1][0];
$envs .= " CPPFLAGS=\"{$cppflags}\"";
}
$output = shell()->execWithResult($env . " {$pkgconfig_executable} --libs-only-L --static " . $packages);
if (!empty($output[1][0])) {
$ldflags = $output[1][0];
$envs .= $this instanceof MacOSLibraryBase ? " LDFLAGS=\"{$ldflags}\" " : " LDFLAGS=\"{$ldflags} -static\" ";
}
$output = shell()->execWithResult($env . " {$pkgconfig_executable} --libs-only-l --static " . $packages);
if (!empty($output[1][0])) {
$libs = $output[1][0];
$envs .= " LIBS=\"{$libs}\" ";
}
FileSystem::resetDir($this->source_dir . '/build');
# 有静态链接配置 参考文件: src/interfaces/libpq/Makefile
shell()->cd($this->source_dir . '/build')
->exec('sed -i.backup "s/invokes exit\'; exit 1;/invokes exit\';/" ../src/interfaces/libpq/Makefile')
->exec(' sed -i.backup "293 s/^/#$/" ../src/Makefile.shlib')
->exec('sed -i.backup "441 s/^/#$/" ../src/Makefile.shlib');
// configure
shell()->cd($this->source_dir . '/build')
->exec(
"{$env} ../configure " .
"--prefix={$builddir} " .
'--disable-thread-safety ' .
'--enable-coverage=no ' .
'--with-ssl=openssl ' .
'--with-readline ' .
'--with-libxml ' .
'--without-icu ' .
'--without-ldap ' .
'--without-libxslt ' .
'--without-lz4 ' .
'--without-zstd ' .
'--without-perl ' .
'--without-python ' .
'--without-pam ' .
'--without-ldap ' .
'--without-bonjour ' .
'--without-tcl '
);
// build
shell()->cd($this->source_dir . '/build')
->exec($envs . ' make -C src/bin/pg_config install')
->exec($envs . ' make -C src/include install')
->exec($envs . ' make -C src/common install')
->exec($envs . ' make -C src/backend/port install')
->exec($envs . ' make -C src/port install')
->exec($envs . ' make -C src/backend/libpq install')
->exec($envs . ' make -C src/interfaces/libpq install');
// remove dynamic libs
shell()->cd($this->source_dir . '/build')
->exec("rm -rf {$builddir}/lib/*.so.*")
->exec("rm -rf {$builddir}/lib/*.so")
->exec("rm -rf {$builddir}/lib/*.dylib");
}
}

View File

@ -88,6 +88,9 @@ class SourcePatcher
if ($ssh2 = $builder->getExt('ssh2')) {
$patch[] = ['ssh2 patch', '/-lssh2/', $ssh2->getLibFilesString()];
}
if ($pgsql = $builder->getExt('pgsql')) {
$patch[] = ['pgsql patch', '/-lpq/', $pgsql->getLibFilesString()];
}
$patch[] = ['disable capstone', '/have_capstone="yes"/', 'have_capstone="no"'];
foreach ($patch as $item) {
logger()->info('Patching configure: ' . $item[0]);