mirror of
https://github.com/crazywhalecc/static-php-cli.git
synced 2026-07-06 08:15:39 +08:00
Add openssl lib support
This commit is contained in:
@@ -7,6 +7,7 @@ namespace StaticPHP\Package;
|
||||
use StaticPHP\Config\PackageConfig;
|
||||
use StaticPHP\Exception\PatchException;
|
||||
use StaticPHP\Util\FileSystem;
|
||||
use StaticPHP\Util\SPCConfigUtil;
|
||||
|
||||
/**
|
||||
* Represents a library package with platform-specific build functions.
|
||||
@@ -159,6 +160,16 @@ class LibraryPackage extends Package
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get static library files for current package and its dependencies.
|
||||
*/
|
||||
public function getStaticLibFiles(): string
|
||||
{
|
||||
$config = new SPCConfigUtil(['libs_only_deps' => true, 'absolute_libs' => true]);
|
||||
$res = $config->config([$this->getName()]);
|
||||
return $res['libs'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extra LIBS for current package.
|
||||
* You need to define the environment variable in the format of {LIBRARY_NAME}_LIBS
|
||||
|
||||
@@ -135,6 +135,22 @@ abstract class Package
|
||||
return isset($this->build_functions[PHP_OS_FAMILY]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PackageBuilder instance for this package.
|
||||
*/
|
||||
public function getBuilder(): PackageBuilder
|
||||
{
|
||||
return ApplicationContext::get(PackageBuilder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the PackageInstaller instance for this package.
|
||||
*/
|
||||
public function getInstaller(): PackageInstaller
|
||||
{
|
||||
return ApplicationContext::get(PackageInstaller::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the package.
|
||||
*/
|
||||
|
||||
@@ -402,11 +402,64 @@ class PackageInstaller
|
||||
return SPC_STATUS_INSTALLED;
|
||||
}
|
||||
|
||||
/**
|
||||
* @internal internally calling only, for users, please use specific getter, such as 'getLibraryPackage', 'getTaretPackage', etc
|
||||
* @param string $package_name Package name
|
||||
*/
|
||||
public function getPackage(string $package_name): ?Package
|
||||
{
|
||||
return $this->packages[$package_name] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a library package by name.
|
||||
*
|
||||
* @param string $package_name Package name
|
||||
* @return null|LibraryPackage The library package instance or null if not found
|
||||
*/
|
||||
public function getLibraryPackage(string $package_name): ?LibraryPackage
|
||||
{
|
||||
$pkg = $this->getPackage($package_name);
|
||||
if ($pkg instanceof LibraryPackage) {
|
||||
return $pkg;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a target package by name.
|
||||
*
|
||||
* @param string $package_name Package name
|
||||
* @return null|TargetPackage The target package instance or null if not found
|
||||
*/
|
||||
public function getTargetPackage(string $package_name): ?TargetPackage
|
||||
{
|
||||
$pkg = $this->getPackage($package_name);
|
||||
if ($pkg instanceof TargetPackage) {
|
||||
return $pkg;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a PHP extension by name.
|
||||
*
|
||||
* @param string $package_or_ext_name Extension name
|
||||
* @return null|PhpExtensionPackage The target package instance or null if not found
|
||||
*/
|
||||
public function getPhpExtensionPackage(string $package_or_ext_name): ?PhpExtensionPackage
|
||||
{
|
||||
$pkg = $this->getPackage($package_or_ext_name);
|
||||
if ($pkg instanceof PhpExtensionPackage) {
|
||||
return $pkg;
|
||||
}
|
||||
$pkg = $this->getPackage("ext-{$package_or_ext_name}");
|
||||
if ($pkg instanceof PhpExtensionPackage) {
|
||||
return $pkg;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Validate that a package has required artifacts.
|
||||
*/
|
||||
|
||||
@@ -209,18 +209,21 @@ class SPCConfigUtil
|
||||
$frameworks = [];
|
||||
|
||||
foreach ($packages as $package) {
|
||||
// add pkg-configs libs
|
||||
$pkg_configs = PackageConfig::get($package, 'pkg-configs', []);
|
||||
foreach ($pkg_configs as $pkg_config) {
|
||||
if (!file_exists(BUILD_LIB_PATH . "/pkgconfig/{$pkg_config}.pc")) {
|
||||
throw new WrongUsageException("pkg-config file '{$pkg_config}.pc' for lib [{$package}] does not exist in '" . BUILD_LIB_PATH . "/pkgconfig'. Please build it first.");
|
||||
// parse pkg-configs only for unix systems
|
||||
if (SystemTarget::isUnix()) {
|
||||
// add pkg-configs libs
|
||||
$pkg_configs = PackageConfig::get($package, 'pkg-configs', []);
|
||||
foreach ($pkg_configs as $pkg_config) {
|
||||
if (!file_exists(BUILD_LIB_PATH . "/pkgconfig/{$pkg_config}.pc")) {
|
||||
throw new WrongUsageException("pkg-config file '{$pkg_config}.pc' for lib [{$package}] does not exist in '" . BUILD_LIB_PATH . "/pkgconfig'. Please build it first.");
|
||||
}
|
||||
}
|
||||
$pkg_configs = implode(' ', $pkg_configs);
|
||||
if ($pkg_configs !== '') {
|
||||
// static libs with dependencies come in reverse order, so reverse this too
|
||||
$pc_libs = array_reverse(PkgConfigUtil::getLibsArray($pkg_configs));
|
||||
$lib_names = [...$lib_names, ...$pc_libs];
|
||||
}
|
||||
}
|
||||
$pkg_configs = implode(' ', $pkg_configs);
|
||||
if ($pkg_configs !== '') {
|
||||
// static libs with dependencies come in reverse order, so reverse this too
|
||||
$pc_libs = array_reverse(PkgConfigUtil::getLibsArray($pkg_configs));
|
||||
$lib_names = [...$lib_names, ...$pc_libs];
|
||||
}
|
||||
// convert all static-libs to short names
|
||||
$libs = array_reverse(PackageConfig::get($package, 'static-libs', []));
|
||||
|
||||
Reference in New Issue
Block a user