diff --git a/config/ext.json b/config/ext.json index b4fe1a68f..3134ab7bb 100644 --- a/config/ext.json +++ b/config/ext.json @@ -74,6 +74,14 @@ "qdbm" ] }, + "decimal": { + "type": "external", + "source": "ext-decimal", + "arg-type": "custom", + "lib-depends": [ + "libmpdec" + ] + }, "deepclone": { "type": "external", "source": "deepclone", diff --git a/config/lib.json b/config/lib.json index 4792a9329..17258b771 100644 --- a/config/lib.json +++ b/config/lib.json @@ -528,6 +528,18 @@ "maxminddb_config.h" ] }, + "libmpdec": { + "source": "libmpdec", + "static-libs-unix": [ + "libmpdec.a" + ], + "static-libs-windows": [ + "libmpdec_a.lib" + ], + "headers": [ + "mpdecimal.h" + ] + }, "libmemcached": { "source": "libmemcached", "cpp-library": true, diff --git a/config/source.json b/config/source.json index 6b3e465bc..d7224d4d6 100644 --- a/config/source.json +++ b/config/source.json @@ -84,6 +84,16 @@ "path": "COPYING" } }, + "ext-decimal": { + "type": "ghtagtar", + "repo": "php-decimal/ext-decimal", + "match": "v2\\.\\d.*", + "path": "php-src/ext/decimal", + "license": { + "type": "file", + "path": "LICENSE" + } + }, "deepclone": { "type": "ghtagtar", "repo": "symfony/php-ext-deepclone", @@ -690,6 +700,14 @@ "path": "LICENSE" } }, + "libmpdec": { + "type": "url", + "url": "https://www.bytereef.org/software/mpdecimal/releases/mpdecimal-4.0.1.tar.gz", + "license": { + "type": "file", + "path": "COPYRIGHT.txt" + } + }, "libmemcached": { "type": "ghtagtar", "repo": "awesomized/libmemcached", diff --git a/phpstan.neon b/phpstan.neon index a8c1c72c5..482f97d78 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -14,6 +14,7 @@ parameters: - PHP_OS_FAMILY excludePaths: analyseAndScan: + - ./src/globals/ext-tests/decimal.php - ./src/globals/ext-tests/swoole.php - ./src/globals/ext-tests/swoole.phpt - ./src/globals/test-extensions.php diff --git a/src/SPC/builder/extension/decimal.php b/src/SPC/builder/extension/decimal.php new file mode 100644 index 000000000..795bce2d2 --- /dev/null +++ b/src/SPC/builder/extension/decimal.php @@ -0,0 +1,40 @@ +source_dir . '/php_decimal.c', + 'zend_module_entry decimal_module_entry', + 'zend_module_entry php_decimal_module_entry' + ); + FileSystem::replaceFileStr( + $this->source_dir . '/config.w32', + 'ARG_WITH("decimal", "for decimal support", "no");', + 'ARG_WITH("decimal", "for decimal support", "no");' . "\n" . + 'ADD_EXTENSION_DEP("decimal", "json");' + ); + return true; + } + + public function getUnixConfigureArg(bool $shared = false): string + { + return '--enable-decimal --with-libmpdec-path="' . BUILD_ROOT_PATH . '"'; + } + + public function getWindowsConfigureArg(bool $shared = false): string + { + return '--with-decimal'; + } +} diff --git a/src/SPC/builder/freebsd/library/libmpdec.php b/src/SPC/builder/freebsd/library/libmpdec.php new file mode 100644 index 000000000..9fd38eca8 --- /dev/null +++ b/src/SPC/builder/freebsd/library/libmpdec.php @@ -0,0 +1,12 @@ +configure('--disable-cxx --disable-shared --enable-static') + ->make(); + } +} diff --git a/src/SPC/builder/windows/library/libmpdec.php b/src/SPC/builder/windows/library/libmpdec.php new file mode 100644 index 000000000..3468c58e8 --- /dev/null +++ b/src/SPC/builder/windows/library/libmpdec.php @@ -0,0 +1,31 @@ +source_dir . '\libmpdec'; + $nmake = $this->builder->makeSimpleWrapper('nmake /nologo'); + + cmd()->cd($makefile_dir) + ->exec('copy /y Makefile.vc Makefile') + ->execWithWrapper($nmake, 'clean') + ->execWithWrapper($nmake, 'MACHINE=x64'); + + // Copy static lib (rename from versioned name to libmpdec_a.lib) + $libs = glob($makefile_dir . '\libmpdec-*.lib'); + foreach ($libs as $lib) { + if (!str_contains($lib, '.dll.')) { + copy($lib, BUILD_LIB_PATH . '\libmpdec_a.lib'); + break; + } + } + copy($makefile_dir . '\mpdecimal.h', BUILD_INCLUDE_PATH . '\mpdecimal.h'); + } +} diff --git a/src/globals/ext-tests/decimal.php b/src/globals/ext-tests/decimal.php new file mode 100644 index 000000000..54f660fbb --- /dev/null +++ b/src/globals/ext-tests/decimal.php @@ -0,0 +1,10 @@ + 'deepclone', - 'Windows' => 'deepclone', + 'Linux', 'Darwin' => 'decimal', + 'Windows' => 'decimal', }; // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).