diff --git a/src/Package/Extension/pgsql.php b/src/Package/Extension/pgsql.php index b5b22a00..5b7f50a0 100644 --- a/src/Package/Extension/pgsql.php +++ b/src/Package/Extension/pgsql.php @@ -5,11 +5,15 @@ declare(strict_types=1); namespace Package\Extension; use Package\Target\php; +use StaticPHP\Attribute\Package\BeforeStage; use StaticPHP\Attribute\Package\CustomPhpConfigureArg; use StaticPHP\Attribute\Package\Extension; +use StaticPHP\Attribute\PatchDescription; use StaticPHP\Package\PackageBuilder; use StaticPHP\Package\PackageInstaller; use StaticPHP\Package\PhpExtensionPackage; +use StaticPHP\Package\TargetPackage; +use StaticPHP\Util\FileSystem; use StaticPHP\Util\SPCConfigUtil; #[Extension('pgsql')] @@ -39,6 +43,27 @@ class pgsql extends PhpExtensionPackage return "--with-pgsql={$builder->getBuildRootPath()}"; } + #[BeforeStage('php', [php::class, 'buildconfForWindows'], 'ext-pgsql')] + #[PatchDescription('Link the Win32 system libraries the static libpq needs')] + public function patchConfigW32ForWindows(TargetPackage $package): void + { + $config = "{$package->getSourceDir()}\\ext\\pgsql\\config.w32"; + + if (str_contains(FileSystem::readFile($config), 'LIBS_PGSQL')) { + return; + } + + // libpq uses SSPI for Windows auth (secur32) and the static libcrypto behind it + // reads the system cert store (crypt32). Nothing else puts these on the link line + // when the openssl extension itself is not part of the build. + FileSystem::replaceFileStr( + $config, + 'EXTENSION("pgsql", "pgsql.c", PHP_PGSQL_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");', + 'EXTENSION("pgsql", "pgsql.c", PHP_PGSQL_SHARED, "/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1");' . "\n\t\t" . + 'ADD_FLAG("LIBS_PGSQL", "secur32.lib crypt32.lib");' + ); + } + public function getSharedExtensionEnv(): array { $parent = parent::getSharedExtensionEnv();