File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 "dio" : {
7886 "support" : {
7987 "BSD" : " wip"
Original file line number Diff line number Diff line change 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 ,
Original file line number Diff line number Diff line change 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 "dio" : {
8898 "type" : " url" ,
8999 "url" : " https://pecl.php.net/get/dio" ,
681691 "path" : " LICENSE"
682692 }
683693 },
694+ "libmpdec" : {
695+ "type" : " url" ,
696+ "url" : " https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-4.0.1.tar.gz" ,
697+ "license" : {
698+ "type" : " file" ,
699+ "path" : " COPYRIGHT.txt"
700+ }
701+ },
684702 "libmemcached" : {
685703 "type" : " ghtagtar" ,
686704 "repo" : " awesomized/libmemcached" ,
Original file line number Diff line number Diff line change 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+ return true ;
23+ }
24+
25+ public function getUnixConfigureArg (bool $ shared = false ): string
26+ {
27+ return '--enable-decimal --with-libmpdec-path=" ' . BUILD_ROOT_PATH . '" ' ;
28+ }
29+
30+ public function getWindowsConfigureArg (bool $ shared = false ): string
31+ {
32+ return '--with-decimal ' ;
33+ }
34+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ assert (class_exists ('Decimal\Decimal ' ));
6+ assert (method_exists ('Decimal\Decimal ' , 'valueOf ' ));
7+ assert (0.1 + 0.2 !== 0.3 );
8+ $ result = Decimal \Decimal::valueOf ('0.1 ' ) + Decimal \Decimal::valueOf ('0.2 ' );
9+ $ expected = Decimal \Decimal::valueOf ('0.3 ' );
10+ assert ($ result == $ expected );
You can’t perform that action at this time.
0 commit comments