Forward-port #1078, add sqlsrv and pdo_sqlsrv extension support for win

This commit is contained in:
crazywhalecc
2026-04-08 11:22:45 +08:00
parent 2a80d5a05d
commit a3624b1510
2 changed files with 29 additions and 1 deletions

View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace Package\Extension;
use Package\Target\php;
use StaticPHP\Attribute\Package\BeforeStage;
use StaticPHP\Attribute\Package\Extension;
use StaticPHP\Attribute\PatchDescription;
use StaticPHP\Package\PackageInstaller;
use StaticPHP\Package\PhpExtensionPackage;
#[Extension('sqlsrv')]
class sqlsrv extends PhpExtensionPackage
{
#[BeforeStage('php', [php::class, 'makeForWindows'], 'ext-sqlsrv')]
#[PatchDescription('Fix sqlsrv Makefile: remove /W4 and /WX flags to prevent build errors on Windows')]
public function patchBeforeMake(PackageInstaller $installer): bool
{
$makefile = $installer->getTargetPackage('php')->getSourceDir() . '\Makefile';
$makeContent = file_get_contents($makefile);
$makeContent = preg_replace('/^(CFLAGS_(?:PDO_)?SQLSRV=.*?)\s+\/W4\b/m', '$1', $makeContent);
$makeContent = preg_replace('/^(CFLAGS_(?:PDO_)?SQLSRV=.*?)\s+\/WX\b/m', '$1', $makeContent);
file_put_contents($makefile, $makeContent);
return true;
}
}

View File

@@ -120,7 +120,7 @@ class FileSystem
$src_path = FileSystem::convertPath($from);
switch (PHP_OS_FAMILY) {
case 'Windows':
cmd(false)->exec('xcopy "' . $src_path . '" "' . $dst_path . '" /s/e/v/y/i');
cmd(false)->exec('xcopy "' . $src_path . '" "' . $dst_path . '" /s/e/y/i');
break;
case 'Linux':
case 'Darwin':