From d04d82a1f1e5765cc6c251d5576a9c26adeb0049 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Thu, 9 Jul 2026 12:27:41 +0900 Subject: [PATCH] Fix strawberry-perl detect time --- src/Package/Library/openssl.php | 45 ++++++++++++++++----------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/src/Package/Library/openssl.php b/src/Package/Library/openssl.php index 2f59da22..f673bb67 100644 --- a/src/Package/Library/openssl.php +++ b/src/Package/Library/openssl.php @@ -6,43 +6,24 @@ namespace Package\Library; use StaticPHP\Attribute\Package\BuildFor; use StaticPHP\Attribute\Package\Library; -use StaticPHP\Attribute\Package\Validate; -use StaticPHP\DI\ApplicationContext; use StaticPHP\Exception\EnvironmentException; use StaticPHP\Package\LibraryPackage; use StaticPHP\Package\PackageBuilder; -use StaticPHP\Runtime\SystemTarget; +use StaticPHP\Package\ToolPackage; +use StaticPHP\Registry\PackageLoader; use StaticPHP\Util\FileSystem; use StaticPHP\Util\System\LinuxUtil; -use StaticPHP\Util\System\WindowsUtil; #[Library('openssl')] class openssl { - #[Validate] - public function validate(): void - { - if (SystemTarget::getTargetOS() === 'Windows') { - global $argv; - $perl_path_native = PKG_ROOT_PATH . '\strawberry-perl\perl\bin\perl.exe'; - $perl = file_exists($perl_path_native) ? ($perl_path_native) : WindowsUtil::findCommand('perl.exe'); - if ($perl === null) { - throw new EnvironmentException( - 'You need to install perl first!', - "Please run \"{$argv[0]} doctor\" to fix the environment.", - ); - } - ApplicationContext::set('perl', $perl); - } - } - #[BuildFor('Windows')] public function buildWin(LibraryPackage $lib, PackageBuilder $builder): void { - $perl = ApplicationContext::get('perl'); + $perl = $this->resolveWindowsPerl(); $cmd = cmd()->cd($lib->getSourceDir()) ->exec( - "{$perl} Configure zlib VC-WIN64A " . + escapeshellarg($perl) . ' Configure zlib VC-WIN64A ' . 'no-shared ' . '--prefix=' . quote($lib->getBuildRootPath()) . ' ' . '--with-zlib-lib=' . quote($lib->getLibDir()) . ' ' . @@ -145,4 +126,22 @@ class openssl FileSystem::replaceFileRegex("{$pkg->getLibDir()}/pkgconfig/libcrypto.pc", '/Libs.private:.*/m', 'Requires.private: zlib'); FileSystem::replaceFileRegex("{$pkg->getLibDir()}/cmake/OpenSSL/OpenSSLConfig.cmake", '/set\(OPENSSL_LIBCRYPTO_DEPENDENCIES .*\)/m', 'set(OPENSSL_LIBCRYPTO_DEPENDENCIES "${OPENSSL_LIBRARY_DIR}/libz.a")'); } + + private function resolveWindowsPerl(): string + { + global $argv; + + $tool = PackageLoader::getPackage('strawberry-perl'); + if ($tool instanceof ToolPackage) { + $perl = $tool->getBinary('perl.exe'); + if (file_exists($perl)) { + return $perl; + } + } + + throw new EnvironmentException( + 'OpenSSL requires strawberry-perl, but it is not installed.', + "Please run \"{$argv[0]} install-pkg strawberry-perl\" or retry the build with downloads enabled.", + ); + } }