Skip to content

Commit d7ee946

Browse files
committed
Add mpir for windows gmp support
1 parent 9a0d239 commit d7ee946

3 files changed

Lines changed: 57 additions & 1 deletion

File tree

config/pkg/ext/builtin-extensions.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,13 @@ ext-gettext:
8282
arg-type: with-path
8383
ext-gmp:
8484
type: php-extension
85-
depends:
85+
depends@unix:
8686
- gmp
87+
depends@windows:
88+
- mpir
8789
php-extension:
8890
arg-type: with-path
91+
arg-type@windows: with
8992
ext-iconv:
9093
type: php-extension
9194
depends@unix:

config/pkg/lib/mpir.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
mpir:
2+
type: library
3+
artifact:
4+
source:
5+
type: git
6+
url: 'https://github.com/winlibs/mpir.git'
7+
rev: master
8+
static-libs@windows:
9+
- mpir_a.lib

src/Package/Library/mpir.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Package\Library;
6+
7+
use StaticPHP\Attribute\Package\BuildFor;
8+
use StaticPHP\Attribute\Package\Library;
9+
use StaticPHP\Attribute\Package\Validate;
10+
use StaticPHP\DI\ApplicationContext;
11+
use StaticPHP\Exception\EnvironmentException;
12+
use StaticPHP\Package\LibraryPackage;
13+
use StaticPHP\Util\FileSystem;
14+
use StaticPHP\Util\System\WindowsUtil;
15+
16+
#[Library('mpir')]
17+
class mpir
18+
{
19+
#[Validate]
20+
public function validate(): void
21+
{
22+
$ver = WindowsUtil::findVisualStudio();
23+
$vs_ver_dir = match ($ver['major_version']) {
24+
'17' => '\build.vc17',
25+
'16' => '\build.vc16',
26+
default => throw new EnvironmentException("Current VS version {$ver['major_version']} is not supported yet!"),
27+
};
28+
ApplicationContext::set('mpir_vs_ver_dir', $vs_ver_dir);
29+
}
30+
31+
#[BuildFor('Windows')]
32+
public function build(LibraryPackage $lib): void
33+
{
34+
$vs_ver_dir = ApplicationContext::get('mpir_vs_ver_dir');
35+
cmd()->cd("{$lib->getSourceDir()}{$vs_ver_dir}\\lib_mpir_gc")
36+
->exec('msbuild lib_mpir_gc.vcxproj /t:Rebuild /p:Configuration=Release /p:Platform=x64');
37+
FileSystem::createDir($lib->getLibDir());
38+
FileSystem::createDir($lib->getIncludeDir());
39+
FileSystem::copy("{$lib->getSourceDir()}{$vs_ver_dir}\\lib_mpir_gc\\x64\\Release\\mpir_a.lib", "{$lib->getLibDir()}\\mpir_a.lib");
40+
// mpir.h and gmp.h are generated by the prebuild step into the source root
41+
FileSystem::copy("{$lib->getSourceDir()}\\mpir.h", "{$lib->getIncludeDir()}\\mpir.h");
42+
FileSystem::copy("{$lib->getSourceDir()}\\gmp.h", "{$lib->getIncludeDir()}\\gmp.h");
43+
}
44+
}

0 commit comments

Comments
 (0)