Add pgsql extension for Windows <#664> (#665)

* Add pgsql extension for Windows <#664>

* Add pgsql to windows test

* Added pdo_pgsql for windows, added missing header files

* Adjust some configure args and deps

---------

Co-authored-by: crazywhalecc <jesse2061@outlook.com>
This commit is contained in:
tricker 2025-03-24 05:47:00 +01:00 committed by GitHub
parent 3ba215c35c
commit ee54b6d347
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 85 additions and 8 deletions

View File

@ -519,17 +519,20 @@
}, },
"pdo_pgsql": { "pdo_pgsql": {
"support": { "support": {
"Windows": "wip",
"BSD": "wip" "BSD": "wip"
}, },
"type": "builtin", "type": "builtin",
"arg-type": "with-prefix", "arg-type": "with-prefix",
"arg-type-windows": "custom",
"ext-depends": [ "ext-depends": [
"pdo", "pdo",
"pgsql" "pgsql"
], ],
"lib-depends": [ "lib-depends-unix": [
"postgresql" "postgresql"
],
"lib-depends-windows": [
"postgresql-win"
] ]
}, },
"pdo_sqlite": { "pdo_sqlite": {
@ -560,14 +563,16 @@
}, },
"pgsql": { "pgsql": {
"support": { "support": {
"Windows": "wip",
"BSD": "wip" "BSD": "wip"
}, },
"notes": true, "notes": true,
"type": "builtin", "type": "builtin",
"arg-type": "custom", "arg-type": "custom",
"lib-depends": [ "lib-depends-unix": [
"postgresql" "postgresql"
],
"lib-depends-windows": [
"postgresql-win"
] ]
}, },
"phar": { "phar": {

View File

@ -671,6 +671,14 @@
"zstd" "zstd"
] ]
}, },
"postgresql-win": {
"source": "postgresql-win",
"static-libs": [
"libpq.lib",
"libpgport.lib",
"libpgcommon.lib"
]
},
"pthreads4w": { "pthreads4w": {
"source": "pthreads4w", "source": "pthreads4w",
"static-libs-windows": [ "static-libs-windows": [

View File

@ -761,6 +761,14 @@
"path": "COPYRIGHT" "path": "COPYRIGHT"
} }
}, },
"postgresql-win": {
"type": "url",
"url": "https://get.enterprisedb.com/postgresql/postgresql-16.8-1-windows-x64-binaries.zip",
"license": {
"type": "text",
"text": "PostgreSQL Database Management System\n(also known as Postgres, formerly as Postgres95)\n\nPortions Copyright (c) 1996-2025, The PostgreSQL Global Development Group\n\nPortions Copyright (c) 1994, The Regents of the University of California\n\nPermission to use, copy, modify, and distribute this software and its\ndocumentation for any purpose, without fee, and without a written\nagreement is hereby granted, provided that the above copyright notice\nand this paragraph and the following two paragraphs appear in all\ncopies.\n\nIN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY\nFOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,\nINCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS\nDOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF\nTHE POSSIBILITY OF SUCH DAMAGE.\n\nTHE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,\nINCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY\nAND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS\nON AN \"AS IS\" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATIONS\nTO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
}
},
"protobuf": { "protobuf": {
"type": "url", "type": "url",
"url": "https://pecl.php.net/get/protobuf", "url": "https://pecl.php.net/get/protobuf",

View File

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\util\CustomExt;
#[CustomExt('pdo_pgsql')]
class pdo_pgsql extends Extension
{
public function getWindowsConfigureArg(): string
{
return '--with-pdo-pgsql=yes';
}
}

View File

@ -40,4 +40,16 @@ class pgsql extends Extension
} }
return '--with-pgsql=' . BUILD_ROOT_PATH; return '--with-pgsql=' . BUILD_ROOT_PATH;
} }
/**
* @throws WrongUsageException
* @throws RuntimeException
*/
public function getWindowsConfigureArg(): string
{
if ($this->builder->getPHPVersionID() >= 80400) {
return '--with-pgsql';
}
return '--with-pgsql=' . BUILD_ROOT_PATH;
}
} }

View File

@ -0,0 +1,27 @@
<?php
declare(strict_types=1);
namespace SPC\builder\windows\library;
class postgresql_win extends WindowsLibraryBase
{
public const NAME = 'postgresql-win';
protected function build(): void
{
copy($this->source_dir . '\pgsql\lib\libpq.lib', BUILD_LIB_PATH . '\libpq.lib');
copy($this->source_dir . '\pgsql\lib\libpgport.lib', BUILD_LIB_PATH . '\libpgport.lib');
copy($this->source_dir . '\pgsql\lib\libpgcommon.lib', BUILD_LIB_PATH . '\libpgcommon.lib');
// create libpq folder in buildroot/includes/libpq
if (!file_exists(BUILD_INCLUDE_PATH . '\libpq')) {
mkdir(BUILD_INCLUDE_PATH . '\libpq');
}
$headerFiles = ['libpq-fe.h', 'postgres_ext.h', 'pg_config_ext.h', 'libpq\libpq-fs.h'];
foreach ($headerFiles as $header) {
copy($this->source_dir . '\pgsql\include\\' . $header, BUILD_INCLUDE_PATH . '\\' . $header);
}
}
}

View File

@ -21,8 +21,8 @@ $test_php_version = [
// test os (macos-13, macos-14, ubuntu-latest, windows-latest are available) // test os (macos-13, macos-14, ubuntu-latest, windows-latest are available)
$test_os = [ $test_os = [
'macos-13', // 'macos-13',
'macos-14', // 'macos-14',
'ubuntu-latest', 'ubuntu-latest',
'windows-latest', 'windows-latest',
]; ];
@ -40,8 +40,8 @@ $prefer_pre_built = false;
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`). // If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) { $extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => 'odbc,pdo_odbc', 'Linux', 'Darwin' => 'pgsql,pdo_pgsql',
'Windows' => 'odbc,pdo_odbc', 'Windows' => 'pgsql,pdo_pgsql',
}; };
// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`). // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).