diff --git a/config/ext.json b/config/ext.json index e160d93a..cc6b067d 100644 --- a/config/ext.json +++ b/config/ext.json @@ -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": { diff --git a/config/lib.json b/config/lib.json index f7f2a86d..40422539 100644 --- a/config/lib.json +++ b/config/lib.json @@ -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": { diff --git a/config/source.json b/config/source.json index f531538a..8410e5bd 100644 --- a/config/source.json +++ b/config/source.json @@ -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" diff --git a/src/SPC/builder/linux/library/postgresql.php b/src/SPC/builder/linux/library/postgresql.php new file mode 100644 index 00000000..04fb76e7 --- /dev/null +++ b/src/SPC/builder/linux/library/postgresql.php @@ -0,0 +1,12 @@ +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"); + } +} diff --git a/src/SPC/store/SourcePatcher.php b/src/SPC/store/SourcePatcher.php index aba47b92..dfefae54 100644 --- a/src/SPC/store/SourcePatcher.php +++ b/src/SPC/store/SourcePatcher.php @@ -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]);