Add extension gmssl support (#544)

* Add extension gmssl support

* cs-fix

* Add framework for gmssl
This commit is contained in:
Jerry Ma 2024-09-20 12:32:31 +08:00 committed by GitHub
parent e35836943e
commit 29efc2c5a5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 156 additions and 2 deletions

View File

@ -189,6 +189,16 @@
"gmp"
]
},
"gmssl": {
"support": {
"BSD": "wip"
},
"type": "external",
"source": "ext-gmssl",
"lib-depends": [
"gmssl"
]
},
"iconv": {
"support": {
"BSD": "wip"

View File

@ -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,

View File

@ -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",

View File

@ -0,0 +1,22 @@
<?php
declare(strict_types=1);
namespace SPC\builder\extension;
use SPC\builder\Extension;
use SPC\store\FileSystem;
use SPC\util\CustomExt;
#[CustomExt('gmssl')]
class gmssl extends Extension
{
public function patchBeforeBuildconf(): bool
{
if (str_contains(file_get_contents(SOURCE_PATH . '/php-src/ext/gmssl/config.w32'), 'CHECK_LIB(')) {
return false;
}
FileSystem::replaceFileStr(SOURCE_PATH . '/php-src/ext/gmssl/config.w32', 'AC_DEFINE(', 'CHECK_LIB("gmssl.lib", "gmssl", PHP_GMSSL);' . PHP_EOL . 'AC_DEFINE(');
return true;
}
}

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\linux\library;
class gmssl extends LinuxLibraryBase
{
use \SPC\builder\unix\library\gmssl;
public const NAME = 'gmssl';
}

View File

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace SPC\builder\macos\library;
class gmssl extends MacOSLibraryBase
{
use \SPC\builder\unix\library\gmssl;
public const NAME = 'gmssl';
}

View File

@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace SPC\builder\unix\library;
use SPC\exception\FileSystemException;
use SPC\exception\RuntimeException;
use SPC\store\FileSystem;
trait gmssl
{
/**
* @throws FileSystemException
* @throws RuntimeException
*/
protected function build(): void
{
// CMake needs a clean build directory
FileSystem::resetDir($this->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);
}
}

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace SPC\builder\windows\library;
use SPC\store\FileSystem;
class gmssl extends WindowsLibraryBase
{
public const NAME = 'gmssl';
protected function build(): void
{
// reset cmake
FileSystem::resetDir($this->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'
);
}
}

View File

@ -0,0 +1,8 @@
<?php
declare(strict_types=1);
assert(function_exists('gmssl_rand_bytes'));
assert(function_exists('gmssl_sm3'));
assert(bin2hex(gmssl_sm3('123456')) === '207cf410532f92a47dee245ce9b11ff71f578ebd763eb3bbea44ebd043d018fb');

View File

@ -19,8 +19,8 @@ $upx = true;
// If you want to test your added extensions and libs, add below (comma separated, example `bcmath,openssl`).
$extensions = match (PHP_OS_FAMILY) {
'Linux', 'Darwin' => '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`).