Skip to content

Commit 565ff27

Browse files
authored
add ext-decimal (crazywhalecc#1095)
2 parents 562fbf2 + f48961c commit 565ff27

File tree

12 files changed

+183
-10
lines changed

12 files changed

+183
-10
lines changed

config/ext.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@
7474
"qdbm"
7575
]
7676
},
77+
"decimal": {
78+
"type": "external",
79+
"source": "ext-decimal",
80+
"arg-type": "custom",
81+
"lib-depends": [
82+
"libmpdec"
83+
]
84+
},
7785
"deepclone": {
7886
"type": "external",
7987
"source": "deepclone",

config/lib.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,18 @@
528528
"maxminddb_config.h"
529529
]
530530
},
531+
"libmpdec": {
532+
"source": "libmpdec",
533+
"static-libs-unix": [
534+
"libmpdec.a"
535+
],
536+
"static-libs-windows": [
537+
"libmpdec_a.lib"
538+
],
539+
"headers": [
540+
"mpdecimal.h"
541+
]
542+
},
531543
"libmemcached": {
532544
"source": "libmemcached",
533545
"cpp-library": true,

config/source.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@
8484
"path": "COPYING"
8585
}
8686
},
87+
"ext-decimal": {
88+
"type": "ghtagtar",
89+
"repo": "php-decimal/ext-decimal",
90+
"match": "v2\\.\\d.*",
91+
"path": "php-src/ext/decimal",
92+
"license": {
93+
"type": "file",
94+
"path": "LICENSE"
95+
}
96+
},
8797
"deepclone": {
8898
"type": "ghtagtar",
8999
"repo": "symfony/php-ext-deepclone",
@@ -690,6 +700,14 @@
690700
"path": "LICENSE"
691701
}
692702
},
703+
"libmpdec": {
704+
"type": "url",
705+
"url": "https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-4.0.1.tar.gz",
706+
"license": {
707+
"type": "file",
708+
"path": "COPYRIGHT.txt"
709+
}
710+
},
693711
"libmemcached": {
694712
"type": "ghtagtar",
695713
"repo": "awesomized/libmemcached",

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ parameters:
1414
- PHP_OS_FAMILY
1515
excludePaths:
1616
analyseAndScan:
17+
- ./src/globals/ext-tests/decimal.php
1718
- ./src/globals/ext-tests/swoole.php
1819
- ./src/globals/ext-tests/swoole.phpt
1920
- ./src/globals/test-extensions.php
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\extension;
6+
7+
use SPC\builder\Extension;
8+
use SPC\store\FileSystem;
9+
use SPC\util\CustomExt;
10+
11+
#[CustomExt('decimal')]
12+
class decimal extends Extension
13+
{
14+
// TODO: remove this when https://github.com/php-decimal/ext-decimal/issues/92 is merged
15+
public function patchBeforeBuildconf(): bool
16+
{
17+
FileSystem::replaceFileStr(
18+
$this->source_dir . '/php_decimal.c',
19+
'zend_module_entry decimal_module_entry',
20+
'zend_module_entry php_decimal_module_entry'
21+
);
22+
FileSystem::replaceFileStr(
23+
$this->source_dir . '/config.w32',
24+
'ARG_WITH("decimal", "for decimal support", "no");',
25+
'ARG_WITH("decimal", "for decimal support", "no");' . "\n" .
26+
'ADD_EXTENSION_DEP("decimal", "json");'
27+
);
28+
return true;
29+
}
30+
31+
public function getUnixConfigureArg(bool $shared = false): string
32+
{
33+
return '--enable-decimal --with-libmpdec-path="' . BUILD_ROOT_PATH . '"';
34+
}
35+
36+
public function getWindowsConfigureArg(bool $shared = false): string
37+
{
38+
return '--with-decimal';
39+
}
40+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\freebsd\library;
6+
7+
class libmpdec extends BSDLibraryBase
8+
{
9+
use \SPC\builder\unix\library\libmpdec;
10+
11+
public const NAME = 'libmpdec';
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\linux\library;
6+
7+
class libmpdec extends LinuxLibraryBase
8+
{
9+
use \SPC\builder\unix\library\libmpdec;
10+
11+
public const NAME = 'libmpdec';
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\macos\library;
6+
7+
class libmpdec extends MacOSLibraryBase
8+
{
9+
use \SPC\builder\unix\library\libmpdec;
10+
11+
public const NAME = 'libmpdec';
12+
}
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\unix\library;
6+
7+
use SPC\util\executor\UnixAutoconfExecutor;
8+
9+
trait libmpdec
10+
{
11+
protected function build(): void
12+
{
13+
UnixAutoconfExecutor::create($this)
14+
->configure('--disable-cxx --disable-shared --enable-static')
15+
->make();
16+
}
17+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SPC\builder\windows\library;
6+
7+
class libmpdec extends WindowsLibraryBase
8+
{
9+
public const NAME = 'libmpdec';
10+
11+
protected function build(): void
12+
{
13+
$makefile_dir = $this->source_dir . '\libmpdec';
14+
$nmake = $this->builder->makeSimpleWrapper('nmake /nologo');
15+
16+
cmd()->cd($makefile_dir)
17+
->exec('copy /y Makefile.vc Makefile')
18+
->execWithWrapper($nmake, 'clean')
19+
->execWithWrapper($nmake, 'MACHINE=x64');
20+
21+
// Copy static lib (rename from versioned name to libmpdec_a.lib)
22+
$libs = glob($makefile_dir . '\libmpdec-*.lib');
23+
foreach ($libs as $lib) {
24+
if (!str_contains($lib, '.dll.')) {
25+
copy($lib, BUILD_LIB_PATH . '\libmpdec_a.lib');
26+
break;
27+
}
28+
}
29+
copy($makefile_dir . '\mpdecimal.h', BUILD_INCLUDE_PATH . '\mpdecimal.h');
30+
}
31+
}

0 commit comments

Comments
 (0)