From 4f27d2d9d1d66b1b1c063ccd8ff2e39cc67b1d30 Mon Sep 17 00:00:00 2001 From: henderkes Date: Sun, 12 Apr 2026 12:28:27 +0700 Subject: [PATCH] add ext-decimal --- config/ext.json | 8 +++++ config/lib.json | 12 +++++++ config/source.json | 18 +++++++++++ src/SPC/builder/extension/decimal.php | 34 ++++++++++++++++++++ src/SPC/builder/freebsd/library/libmpdec.php | 12 +++++++ src/SPC/builder/linux/library/libmpdec.php | 12 +++++++ src/SPC/builder/macos/library/libmpdec.php | 12 +++++++ src/SPC/builder/unix/library/libmpdec.php | 17 ++++++++++ src/SPC/builder/windows/library/libmpdec.php | 31 ++++++++++++++++++ src/globals/ext-tests/decimal.php | 10 ++++++ src/globals/test-extensions.php | 12 +++---- 11 files changed, 172 insertions(+), 6 deletions(-) create mode 100644 src/SPC/builder/extension/decimal.php create mode 100644 src/SPC/builder/freebsd/library/libmpdec.php create mode 100644 src/SPC/builder/linux/library/libmpdec.php create mode 100644 src/SPC/builder/macos/library/libmpdec.php create mode 100644 src/SPC/builder/unix/library/libmpdec.php create mode 100644 src/SPC/builder/windows/library/libmpdec.php create mode 100644 src/globals/ext-tests/decimal.php diff --git a/config/ext.json b/config/ext.json index 16a71c21..573d7623 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" + ] + }, "dio": { "support": { "BSD": "wip" diff --git a/config/lib.json b/config/lib.json index 4792a932..17258b77 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 18bca217..b304b4ce 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" + } + }, "dio": { "type": "url", "url": "https://pecl.php.net/get/dio", @@ -681,6 +691,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/src/SPC/builder/extension/decimal.php b/src/SPC/builder/extension/decimal.php new file mode 100644 index 00000000..72a694ff --- /dev/null +++ b/src/SPC/builder/extension/decimal.php @@ -0,0 +1,34 @@ +source_dir . '/php_decimal.c', + 'zend_module_entry decimal_module_entry', + 'zend_module_entry php_decimal_module_entry' + ); + 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 00000000..9fd38eca --- /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 00000000..3468c58e --- /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 00000000..54f660fb --- /dev/null +++ b/src/globals/ext-tests/decimal.php @@ -0,0 +1,10 @@ + 'curl,swoole', - 'Windows' => 'intl', + 'Linux', 'Darwin' => 'decimal', + 'Windows' => 'decimal', }; // If you want to test shared extensions, add them below (comma separated, example `bcmath,openssl`).