mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-04 15:25:41 +08:00
Add openssl version getter for Windows, test openssl
This commit is contained in:
@@ -36,4 +36,17 @@ class openssl extends Extension
|
||||
}
|
||||
return $args;
|
||||
}
|
||||
|
||||
public function getWindowsConfigureArg(bool $shared = false): string
|
||||
{
|
||||
$args = '--with-openssl';
|
||||
if (
|
||||
$this->builder->getPHPVersionID() >= 80500 &&
|
||||
($ver = $this->builder->getLib('openssl')->getLibVersion()) &&
|
||||
version_compare($ver, '3.2.0', '>=')
|
||||
) {
|
||||
$args .= ' --with-openssl-argon2';
|
||||
}
|
||||
return $args;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ use SPC\store\FileSystem;
|
||||
|
||||
class openssl extends LinuxLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\openssl;
|
||||
use \SPC\builder\traits\openssl;
|
||||
|
||||
public const NAME = 'openssl';
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ use SPC\store\FileSystem;
|
||||
|
||||
class openssl extends MacOSLibraryBase
|
||||
{
|
||||
use \SPC\builder\unix\library\openssl;
|
||||
use \SPC\builder\traits\openssl;
|
||||
|
||||
public const NAME = 'openssl';
|
||||
|
||||
|
||||
38
src/SPC/builder/traits/openssl.php
Normal file
38
src/SPC/builder/traits/openssl.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\traits;
|
||||
|
||||
use SPC\exception\RuntimeException;
|
||||
use SPC\store\FileSystem;
|
||||
use SPC\util\PkgConfigUtil;
|
||||
|
||||
trait openssl
|
||||
{
|
||||
public function getLibVersion(): ?string
|
||||
{
|
||||
// get openssl version from source directory
|
||||
if (file_exists("{$this->source_dir}/VERSION.dat")) {
|
||||
// parse as INI
|
||||
$version = parse_ini_file("{$this->source_dir}/VERSION.dat");
|
||||
if ($version !== false) {
|
||||
return "{$version['MAJOR']}.{$version['MINOR']}.{$version['PATCH']}";
|
||||
}
|
||||
}
|
||||
// get openssl version from pkg-config
|
||||
if (PHP_OS_FAMILY !== 'Windows') {
|
||||
try {
|
||||
return PkgConfigUtil::getModuleVersion('openssl');
|
||||
} catch (RuntimeException) {
|
||||
}
|
||||
}
|
||||
// get openssl version from header openssl/opensslv.h
|
||||
if (file_exists(BUILD_INCLUDE_PATH . '/openssl/opensslv.h')) {
|
||||
if (preg_match('/OPENSSL_VERSION_STR "(.*)"/', FileSystem::readFile(BUILD_INCLUDE_PATH . '/openssl/opensslv.h'), $match)) {
|
||||
return $match[1];
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace SPC\builder\unix\library;
|
||||
|
||||
trait openssl
|
||||
{
|
||||
public function getLibVersion(): ?string
|
||||
{
|
||||
// get openssl version from source directory
|
||||
if (file_exists("{$this->source_dir}/VERSION.dat")) {
|
||||
// parse as INI
|
||||
$version = parse_ini_file("{$this->source_dir}/VERSION.dat");
|
||||
if ($version !== false) {
|
||||
return "{$version['MAJOR']}.{$version['MINOR']}.{$version['PATCH']}";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,21 @@ use SPC\exception\RuntimeException;
|
||||
|
||||
class PkgConfigUtil
|
||||
{
|
||||
/**
|
||||
* Returns the version of a module.
|
||||
* This method uses `pkg-config --modversion` to get the version of the specified module.
|
||||
* If the module is not found, it will throw a RuntimeException.
|
||||
*
|
||||
* @param string $pkg_config_str .pc file str, accepts multiple files
|
||||
* @return string version string, e.g. "1.2.3"
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
public static function getModuleVersion(string $pkg_config_str): string
|
||||
{
|
||||
$result = self::execWithResult("pkg-config --modversion {$pkg_config_str}");
|
||||
return trim($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns --cflags-only-other output.
|
||||
* The reason we return the string is we cannot use array_unique() on cflags,
|
||||
|
||||
Reference in New Issue
Block a user