Skip to content

Commit ee54b6d

Browse files
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 <[email protected]>
1 parent 3ba215c commit ee54b6d

File tree

7 files changed

+85
-8
lines changed

7 files changed

+85
-8
lines changed

config/ext.json

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -519,17 +519,20 @@
519519
},
520520
"pdo_pgsql": {
521521
"support": {
522-
"Windows": "wip",
523522
"BSD": "wip"
524523
},
525524
"type": "builtin",
526525
"arg-type": "with-prefix",
526+
"arg-type-windows": "custom",
527527
"ext-depends": [
528528
"pdo",
529529
"pgsql"
530530
],
531-
"lib-depends": [
531+
"lib-depends-unix": [
532532
"postgresql"
533+
],
534+
"lib-depends-windows": [
535+
"postgresql-win"
533536
]
534537
},
535538
"pdo_sqlite": {
@@ -560,14 +563,16 @@
560563
},
561564
"pgsql": {
562565
"support": {
563-
"Windows": "wip",
564566
"BSD": "wip"
565567
},
566568
"notes": true,
567569
"type": "builtin",
568570
"arg-type": "custom",
569-
"lib-depends": [
571+
"lib-depends-unix": [
570572
"postgresql"
573+
],
574+
"lib-depends-windows": [
575+
"postgresql-win"
571576
]
572577
},
573578
"phar": {

config/lib.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,14 @@
671671
"zstd"
672672
]
673673
},
674+
"postgresql-win": {
675+
"source": "postgresql-win",
676+
"static-libs": [
677+
"libpq.lib",
678+
"libpgport.lib",
679+
"libpgcommon.lib"
680+
]
681+
},
674682
"pthreads4w": {
675683
"source": "pthreads4w",
676684
"static-libs-windows": [

config/source.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,14 @@
761761
"path": "COPYRIGHT"
762762
}
763763
},
764+
"postgresql-win": {
765+
"type": "url",
766+
"url": "https://get.enterprisedb.com/postgresql/postgresql-16.8-1-windows-x64-binaries.zip",
767+
"license": {
768+
"type": "text",
769+
"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."
770+
}
771+
},
764772
"protobuf": {
765773
"type": "url",
766774
"url": "https://pecl.php.net/get/protobuf",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\extension;
6+
7+
use SPC\builder\Extension;
8+
use SPC\util\CustomExt;
9+
10+
#[CustomExt('pdo_pgsql')]
11+
class pdo_pgsql extends Extension
12+
{
13+
public function getWindowsConfigureArg(): string
14+
{
15+
return '--with-pdo-pgsql=yes';
16+
}
17+
}

src/SPC/builder/extension/pgsql.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,16 @@ public function getUnixConfigureArg(): string
4040
}
4141
return '--with-pgsql=' . BUILD_ROOT_PATH;
4242
}
43+
44+
/**
45+
* @throws WrongUsageException
46+
* @throws RuntimeException
47+
*/
48+
public function getWindowsConfigureArg(): string
49+
{
50+
if ($this->builder->getPHPVersionID() >= 80400) {
51+
return '--with-pgsql';
52+
}
53+
return '--with-pgsql=' . BUILD_ROOT_PATH;
54+
}
4355
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\windows\library;
6+
7+
class postgresql_win extends WindowsLibraryBase
8+
{
9+
public const NAME = 'postgresql-win';
10+
11+
protected function build(): void
12+
{
13+
copy($this->source_dir . '\pgsql\lib\libpq.lib', BUILD_LIB_PATH . '\libpq.lib');
14+
copy($this->source_dir . '\pgsql\lib\libpgport.lib', BUILD_LIB_PATH . '\libpgport.lib');
15+
copy($this->source_dir . '\pgsql\lib\libpgcommon.lib', BUILD_LIB_PATH . '\libpgcommon.lib');
16+
17+
// create libpq folder in buildroot/includes/libpq
18+
if (!file_exists(BUILD_INCLUDE_PATH . '\libpq')) {
19+
mkdir(BUILD_INCLUDE_PATH . '\libpq');
20+
}
21+
22+
$headerFiles = ['libpq-fe.h', 'postgres_ext.h', 'pg_config_ext.h', 'libpq\libpq-fs.h'];
23+
foreach ($headerFiles as $header) {
24+
copy($this->source_dir . '\pgsql\include\\' . $header, BUILD_INCLUDE_PATH . '\\' . $header);
25+
}
26+
}
27+
}

src/globals/test-extensions.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121

2222
// test os (macos-13, macos-14, ubuntu-latest, windows-latest are available)
2323
$test_os = [
24-
'macos-13',
25-
'macos-14',
24+
// 'macos-13',
25+
// 'macos-14',
2626
'ubuntu-latest',
2727
'windows-latest',
2828
];
@@ -40,8 +40,8 @@
4040

4141
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
4242
$extensions = match (PHP_OS_FAMILY) {
43-
'Linux', 'Darwin' => 'odbc,pdo_odbc',
44-
'Windows' => 'odbc,pdo_odbc',
43+
'Linux', 'Darwin' => 'pgsql,pdo_pgsql',
44+
'Windows' => 'pgsql,pdo_pgsql',
4545
};
4646

4747
// If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).

0 commit comments

Comments
 (0)