From dac14ae16e38252e3d5b7eb6f63c6e53144376e1 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Fri, 30 Jun 2023 20:36:51 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E6=B7=BB=E5=8A=A0pgsql=20=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SPC/builder/linux/library/postgresql.php | 12 +++ src/SPC/builder/macos/library/postgresql.php | 12 +++ src/SPC/builder/unix/library/postgresql.php | 98 ++++++++++++++++++++ 3 files changed, 122 insertions(+) create mode 100644 src/SPC/builder/linux/library/postgresql.php create mode 100644 src/SPC/builder/macos/library/postgresql.php create mode 100644 src/SPC/builder/unix/library/postgresql.php 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; + $packages = 'openssl zlib icu-uc icu-io icu-i18n readline libxml-2.0 libzstd'; + + $output = shell()->execWithResult($envs . ' pkg-config --cflags-only-I --static ' . $packages); + if (!empty($output[1][0])) { + $cppflags = $output[1][0]; + $envs .= " CPPFLAGS=\"{$cppflags}\""; + } + $output = shell()->execWithResult($envs . ' pkg-config --libs-only-L --static ' . $packages); + if (!empty($output[1][0])) { + $ldflags = $output[1][0]; + $envs .= " LDFLAGS=\"{$ldflags}\" "; + } + $output = shell()->execWithResult($envs . ' pkg-config --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( + <<<'EOF' + sed -i.backup "s/invokes exit\'; exit 1;/invokes exit\';/" ../src/interfaces/libpq/Makefile +EOF + ); + + shell()->cd($this->source_dir . '/build') + ->exec( + <<cd($this->source_dir . '/build')->exec( + <<<'EOF' + make -C src/bin/pg_config install + make -C src/include install + + make -C src/common install + + make -C src/backend/port install + make -C src/port install + + make -C src/backend/libpq install + make -C src/interfaces/libpq install + +EOF + ); + + shell()->cd($this->source_dir . '/build')->exec( + << Date: Fri, 30 Jun 2023 20:53:18 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=20=E6=B7=BB=E5=8A=A0pgsql=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/ext.json | 11 +++++++++-- config/lib.json | 13 ++++++++++++- config/source.json | 3 ++- 3 files changed, 23 insertions(+), 4 deletions(-) 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..1d572794 100644 --- a/config/lib.json +++ b/config/lib.json @@ -381,7 +381,18 @@ "postgresql": { "source": "postgresql", "static-libs-unix": [ - "libpg.a" + "libpq.a", + "libpgport.a", + "libpgcommon.a" + ], + "lib-depends": [ + "libiconv", + "libxml2", + "zstd", + "openssl", + "zlib", + "readline", + "icu" ] }, "pthreads4w": { diff --git a/config/source.json b/config/source.json index f5662d63..e28376db 100644 --- a/config/source.json +++ b/config/source.json @@ -319,7 +319,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" From 9c2ea79beceb6086168f476b339fb1b9071d5dd0 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Fri, 30 Jun 2023 21:00:49 +0800 Subject: [PATCH 3/8] update pgsql config --- src/SPC/builder/unix/library/postgresql.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 5fc19bef..3f48e7a9 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -18,20 +18,21 @@ trait postgresql { [$libdir, , $destdir] = SEPARATED_PATH; $builddir = BUILD_ROOT_PATH; - $envs = $this->builder->configure_env; + $env = $this->builder->configure_env; + $envs = $env; $packages = 'openssl zlib icu-uc icu-io icu-i18n readline libxml-2.0 libzstd'; - $output = shell()->execWithResult($envs . ' pkg-config --cflags-only-I --static ' . $packages); + $output = shell()->execWithResult($env . ' pkg-config --cflags-only-I --static ' . $packages); if (!empty($output[1][0])) { $cppflags = $output[1][0]; $envs .= " CPPFLAGS=\"{$cppflags}\""; } - $output = shell()->execWithResult($envs . ' pkg-config --libs-only-L --static ' . $packages); + $output = shell()->execWithResult($env . ' pkg-config --libs-only-L --static ' . $packages); if (!empty($output[1][0])) { $ldflags = $output[1][0]; $envs .= " LDFLAGS=\"{$ldflags}\" "; } - $output = shell()->execWithResult($envs . ' pkg-config --libs-only-l --static ' . $packages); + $output = shell()->execWithResult($env . ' pkg-config --libs-only-l --static ' . $packages); if (!empty($output[1][0])) { $libs = $output[1][0]; $envs .= " LIBS=\"{$libs}\" "; From 78c1484570a06e630cd544f9e4ed9319b3247692 Mon Sep 17 00:00:00 2001 From: jingjingxyk Date: Sat, 1 Jul 2023 13:01:53 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E8=A7=A3=E5=86=B3debian=20=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E4=B8=8B=20pgsql=20=E6=9E=84=E5=BB=BA=E5=85=B1?= =?UTF-8?q?=E4=BA=AB=E5=BA=93=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SPC/builder/unix/library/postgresql.php | 47 +++++++++++++++------ 1 file changed, 34 insertions(+), 13 deletions(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 3f48e7a9..7efa2559 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -43,7 +43,18 @@ trait postgresql # 有静态链接配置 参考文件: src/interfaces/libpq/Makefile shell()->cd($this->source_dir . '/build')->exec( <<<'EOF' - sed -i.backup "s/invokes exit\'; exit 1;/invokes exit\';/" ../src/interfaces/libpq/Makefile + sed -i.backup "s/invokes exit'; exit 1;/invokes exit';/" ../src/interfaces/libpq/Makefile +EOF + ); + + shell()->cd($this->source_dir . '/build')->exec( + <<<'EOF' + sed -i.backup "293 s/^/#$/" ../src/Makefile.shlib +EOF + ); + shell()->cd($this->source_dir . '/build')->exec( + <<<'EOF' + sed -i.backup "441 s/^/#$/" ../src/Makefile.shlib EOF ); @@ -71,22 +82,32 @@ EOF --without-tcl EOF ); + // 方便调试, + shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/bin/pg_config install'); + shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/include install'); + shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/common install'); + shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/backend/port install'); + shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/port install'); + shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/backend/libpq install'); + shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/interfaces/libpq install'); - shell()->cd($this->source_dir . '/build')->exec( - <<<'EOF' - make -C src/bin/pg_config install - make -C src/include install + /* + shell()->cd($this->source_dir . '/build')->exec( + <<<'EOF' + make -C src/bin/pg_config install + make -C src/include install - make -C src/common install + make -C src/common install - make -C src/backend/port install - make -C src/port install + make -C src/backend/port install + make -C src/port install - make -C src/backend/libpq install - make -C src/interfaces/libpq install - -EOF - ); + make -C src/backend/libpq install + make -C src/interfaces/libpq install + + EOF + ); + */ shell()->cd($this->source_dir . '/build')->exec( << Date: Sat, 1 Jul 2023 17:31:46 +0800 Subject: [PATCH 5/8] =?UTF-8?q?pgsql=20=20=E7=A6=81=E7=94=A8=20=E4=BE=9D?= =?UTF-8?q?=E8=B5=96libzstd=20icu=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/lib.json | 4 +--- src/SPC/builder/unix/library/postgresql.php | 24 +++------------------ 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/config/lib.json b/config/lib.json index 1d572794..40422539 100644 --- a/config/lib.json +++ b/config/lib.json @@ -388,11 +388,9 @@ "lib-depends": [ "libiconv", "libxml2", - "zstd", "openssl", "zlib", - "readline", - "icu" + "readline" ] }, "pthreads4w": { diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 7efa2559..056797e8 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -20,7 +20,7 @@ trait postgresql $builddir = BUILD_ROOT_PATH; $env = $this->builder->configure_env; $envs = $env; - $packages = 'openssl zlib icu-uc icu-io icu-i18n readline libxml-2.0 libzstd'; + $packages = 'openssl zlib readline libxml-2.0 '; // icu-uc icu-io icu-i18n libzstd $output = shell()->execWithResult($env . ' pkg-config --cflags-only-I --static ' . $packages); if (!empty($output[1][0])) { @@ -30,7 +30,7 @@ trait postgresql $output = shell()->execWithResult($env . ' pkg-config --libs-only-L --static ' . $packages); if (!empty($output[1][0])) { $ldflags = $output[1][0]; - $envs .= " LDFLAGS=\"{$ldflags}\" "; + $envs .= " LDFLAGS=\"{$ldflags} -static\" "; } $output = shell()->execWithResult($env . ' pkg-config --libs-only-l --static ' . $packages); if (!empty($output[1][0])) { @@ -73,7 +73,7 @@ EOF --with-libxml \\ --without-libxslt \\ --without-lz4 \\ - --with-zstd \\ + --without-zstd \\ --without-perl \\ --without-python \\ --without-pam \\ @@ -91,24 +91,6 @@ EOF shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/backend/libpq install'); shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/interfaces/libpq install'); - /* - shell()->cd($this->source_dir . '/build')->exec( - <<<'EOF' - make -C src/bin/pg_config install - make -C src/include install - - make -C src/common install - - make -C src/backend/port install - make -C src/port install - - make -C src/backend/libpq install - make -C src/interfaces/libpq install - - EOF - ); - */ - shell()->cd($this->source_dir . '/build')->exec( << Date: Sat, 1 Jul 2023 18:04:42 +0800 Subject: [PATCH 6/8] =?UTF-8?q?pgsql=20=20=E7=A6=81=E7=94=A8=20=E4=BE=9D?= =?UTF-8?q?=E8=B5=96libzstd=20icu=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SPC/builder/unix/library/postgresql.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 056797e8..e370a394 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -68,7 +68,7 @@ EOF --enable-coverage=no \\ --with-ssl=openssl \\ --with-readline \\ - --with-icu \\ + --without-icu \\ --without-ldap \\ --with-libxml \\ --without-libxslt \\ From bc978ecbde78ff02a36952d4a53fb8ace4963382 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 22 Jul 2023 15:07:53 +0800 Subject: [PATCH 7/8] add macOS support for pgsql --- src/SPC/builder/unix/library/postgresql.php | 4 +++- src/SPC/store/SourcePatcher.php | 3 +++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index e370a394..09d1e25b 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -4,6 +4,8 @@ declare(strict_types=1); namespace SPC\builder\unix\library; +use SPC\builder\linux\library\LinuxLibraryBase; +use SPC\builder\macos\library\MacOSLibraryBase; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; use SPC\store\FileSystem; @@ -30,7 +32,7 @@ trait postgresql $output = shell()->execWithResult($env . ' pkg-config --libs-only-L --static ' . $packages); if (!empty($output[1][0])) { $ldflags = $output[1][0]; - $envs .= " LDFLAGS=\"{$ldflags} -static\" "; + $envs .= $this instanceof MacOSLibraryBase ? " LDFLAGS=\"{$ldflags}\" " : " LDFLAGS=\"{$ldflags} -static\" "; } $output = shell()->execWithResult($env . ' pkg-config --libs-only-l --static ' . $packages); if (!empty($output[1][0])) { 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]); From 47101d058bd7a26cfdb6df1df605b6e566425616 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Sat, 22 Jul 2023 16:12:12 +0800 Subject: [PATCH 8/8] reformat code --- src/SPC/builder/unix/library/postgresql.php | 101 +++++++++----------- 1 file changed, 43 insertions(+), 58 deletions(-) diff --git a/src/SPC/builder/unix/library/postgresql.php b/src/SPC/builder/unix/library/postgresql.php index 09d1e25b..eb3b388f 100644 --- a/src/SPC/builder/unix/library/postgresql.php +++ b/src/SPC/builder/unix/library/postgresql.php @@ -4,7 +4,6 @@ declare(strict_types=1); namespace SPC\builder\unix\library; -use SPC\builder\linux\library\LinuxLibraryBase; use SPC\builder\macos\library\MacOSLibraryBase; use SPC\exception\FileSystemException; use SPC\exception\RuntimeException; @@ -18,23 +17,23 @@ trait postgresql */ protected function build() { - [$libdir, , $destdir] = SEPARATED_PATH; $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 + $packages = 'openssl zlib readline libxml-2.0'; // icu-uc icu-io icu-i18n libzstd - $output = shell()->execWithResult($env . ' pkg-config --cflags-only-I --static ' . $packages); + $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 . ' pkg-config --libs-only-L --static ' . $packages); + $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 . ' pkg-config --libs-only-l --static ' . $packages); + $output = shell()->execWithResult($env . " {$pkgconfig_executable} --libs-only-l --static " . $packages); if (!empty($output[1][0])) { $libs = $output[1][0]; $envs .= " LIBS=\"{$libs}\" "; @@ -43,62 +42,48 @@ trait postgresql FileSystem::resetDir($this->source_dir . '/build'); # 有静态链接配置 参考文件: src/interfaces/libpq/Makefile - shell()->cd($this->source_dir . '/build')->exec( - <<<'EOF' - sed -i.backup "s/invokes exit'; exit 1;/invokes exit';/" ../src/interfaces/libpq/Makefile -EOF - ); - - shell()->cd($this->source_dir . '/build')->exec( - <<<'EOF' - sed -i.backup "293 s/^/#$/" ../src/Makefile.shlib -EOF - ); - shell()->cd($this->source_dir . '/build')->exec( - <<<'EOF' - sed -i.backup "441 s/^/#$/" ../src/Makefile.shlib -EOF - ); + 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( - <<cd($this->source_dir . '/build')->exec($envs . ' make -C src/bin/pg_config install'); - shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/include install'); - shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/common install'); - shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/backend/port install'); - shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/port install'); - shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/backend/libpq install'); - shell()->cd($this->source_dir . '/build')->exec($envs . ' make -C src/interfaces/libpq install'); - shell()->cd($this->source_dir . '/build')->exec( - <<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"); } }