From 29efc2c5a53b839ad50a35d5beaeea8fd41c2331 Mon Sep 17 00:00:00 2001 From: Jerry Ma Date: Fri, 20 Sep 2024 12:32:31 +0800 Subject: [PATCH] Add extension gmssl support (#544) * Add extension gmssl support * cs-fix * Add framework for gmssl --- config/ext.json | 10 +++++++ config/lib.json | 12 +++++++++ config/source.json | 17 ++++++++++++ src/SPC/builder/extension/gmssl.php | 22 +++++++++++++++ src/SPC/builder/linux/library/gmssl.php | 12 +++++++++ src/SPC/builder/macos/library/gmssl.php | 12 +++++++++ src/SPC/builder/unix/library/gmssl.php | 28 +++++++++++++++++++ src/SPC/builder/windows/library/gmssl.php | 33 +++++++++++++++++++++++ src/globals/ext-tests/gmssl.php | 8 ++++++ src/globals/test-extensions.php | 4 +-- 10 files changed, 156 insertions(+), 2 deletions(-) create mode 100644 src/SPC/builder/extension/gmssl.php create mode 100644 src/SPC/builder/linux/library/gmssl.php create mode 100644 src/SPC/builder/macos/library/gmssl.php create mode 100644 src/SPC/builder/unix/library/gmssl.php create mode 100644 src/SPC/builder/windows/library/gmssl.php create mode 100644 src/globals/ext-tests/gmssl.php diff --git a/config/ext.json b/config/ext.json index 05ef27ee..efd4aad9 100644 --- a/config/ext.json +++ b/config/ext.json @@ -189,6 +189,16 @@ "gmp" ] }, + "gmssl": { + "support": { + "BSD": "wip" + }, + "type": "external", + "source": "ext-gmssl", + "lib-depends": [ + "gmssl" + ] + }, "iconv": { "support": { "BSD": "wip" diff --git a/config/lib.json b/config/lib.json index 55f1d683..7e4525fe 100644 --- a/config/lib.json +++ b/config/lib.json @@ -127,6 +127,18 @@ "gmp.h" ] }, + "gmssl": { + "source": "gmssl", + "static-libs-unix": [ + "libgmssl.a" + ], + "static-libs-windows": [ + "gmssl.lib" + ], + "frameworks": [ + "Security" + ] + }, "icu": { "source": "icu", "cpp-library": true, diff --git a/config/source.json b/config/source.json index 5e342585..1e847421 100644 --- a/config/source.json +++ b/config/source.json @@ -83,6 +83,15 @@ "path": "LICENSE" } }, + "ext-gmssl": { + "type": "ghtar", + "repo": "gmssl/GmSSL-PHP", + "path": "php-src/ext/gmssl", + "license": { + "type": "file", + "path": "LICENSE" + } + }, "ext-imagick": { "type": "url", "url": "https://pecl.php.net/get/imagick", @@ -194,6 +203,14 @@ "text": "Since version 6, GMP is distributed under the dual licenses, GNU LGPL v3 and GNU GPL v2. These licenses make the library free to use, share, and improve, and allow you to pass on the result. The GNU licenses give freedoms, but also set firm restrictions on the use with non-free programs." } }, + "gmssl": { + "type": "ghtar", + "repo": "guanzhi/GmSSL", + "license": { + "type": "file", + "path": "LICENSE" + } + }, "icu": { "type": "ghrel", "repo": "unicode-org/icu", diff --git a/src/SPC/builder/extension/gmssl.php b/src/SPC/builder/extension/gmssl.php new file mode 100644 index 00000000..aabc5841 --- /dev/null +++ b/src/SPC/builder/extension/gmssl.php @@ -0,0 +1,22 @@ +source_dir . '/build'); + // Start build + shell()->cd($this->source_dir . '/build') + ->setEnv(['CFLAGS' => $this->getLibExtraCFlags(), 'LDFLAGS' => $this->getLibExtraLdFlags(), 'LIBS' => $this->getLibExtraLibs()]) + ->execWithEnv("cmake {$this->builder->makeCmakeArgs()} -DBUILD_SHARED_LIBS=OFF ..") + ->execWithEnv("cmake --build . -j {$this->builder->concurrency}") + ->execWithEnv('make install DESTDIR=' . BUILD_ROOT_PATH); + } +} diff --git a/src/SPC/builder/windows/library/gmssl.php b/src/SPC/builder/windows/library/gmssl.php new file mode 100644 index 00000000..ed991635 --- /dev/null +++ b/src/SPC/builder/windows/library/gmssl.php @@ -0,0 +1,33 @@ +source_dir . '\builddir'); + + // start build + cmd()->cd($this->source_dir . '\builddir') + ->execWithWrapper( + $this->builder->makeSimpleWrapper('cmake .. -G "NMake Makefiles" -DWIN32=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG" -DCMAKE_CXX_FLAGS_RELEASE="/MT /O2 /Ob2 /DNDEBUG" -DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH), + '-DCMAKE_INSTALL_PREFIX=' . BUILD_ROOT_PATH + ); + + FileSystem::writeFile($this->source_dir . '\builddir\cmake_install.cmake', 'set(CMAKE_INSTALL_PREFIX "' . str_replace('\\', '/', BUILD_ROOT_PATH) . '")' . PHP_EOL . FileSystem::readFile($this->source_dir . '\builddir\cmake_install.cmake')); + + cmd()->cd($this->source_dir . '\builddir') + ->execWithWrapper( + $this->builder->makeSimpleWrapper('nmake'), + 'install XCFLAGS=/MT' + ); + } +} diff --git a/src/globals/ext-tests/gmssl.php b/src/globals/ext-tests/gmssl.php new file mode 100644 index 00000000..8abd74b8 --- /dev/null +++ b/src/globals/ext-tests/gmssl.php @@ -0,0 +1,8 @@ + 'redis,igbinary,msgpack', - 'Windows' => 'redis,igbinary,msgpack', + 'Linux', 'Darwin' => 'gmssl', + 'Windows' => 'gmssl', }; // If you want to test lib-suggests feature with extension, add them below (comma separated, example `libwebp,libavif`).