From 873222299b933846e637e9db9c7438d3df0fd2a6 Mon Sep 17 00:00:00 2001 From: crazywhalecc Date: Wed, 15 Jul 2026 13:02:52 +0800 Subject: [PATCH] Apply openssl patch changes in feat/pgo-v3 --- src/Package/Library/openssl.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Package/Library/openssl.php b/src/Package/Library/openssl.php index f673bb67..8e3c53b7 100644 --- a/src/Package/Library/openssl.php +++ b/src/Package/Library/openssl.php @@ -11,6 +11,7 @@ use StaticPHP\Package\LibraryPackage; use StaticPHP\Package\PackageBuilder; use StaticPHP\Package\ToolPackage; use StaticPHP\Registry\PackageLoader; +use StaticPHP\Runtime\SystemTarget; use StaticPHP\Util\FileSystem; use StaticPHP\Util\System\LinuxUtil; @@ -57,7 +58,7 @@ class openssl public function buildForDarwin(LibraryPackage $pkg): void { $zlib_libs = $pkg->getInstaller()->getLibraryPackage('zlib')->getStaticLibFiles(); - $arch = getenv('SPC_ARCH'); + $arch = SystemTarget::getTargetArch(); shell()->cd($pkg->getSourceDir())->initializeEnv($pkg) ->exec( @@ -76,12 +77,7 @@ class openssl #[BuildFor('Linux')] public function build(LibraryPackage $lib): void { - $arch = getenv('SPC_ARCH'); - - $env = "CC='" . getenv('CC') . ' -idirafter ' . BUILD_INCLUDE_PATH . - ' -idirafter /usr/include/ ' . - ' -idirafter /usr/include/' . getenv('SPC_ARCH') . '-linux-gnu/ ' . - "' "; + $arch = SystemTarget::getTargetArch(); $ex_lib = trim($lib->getInstaller()->getLibraryPackage('zlib')->getStaticLibFiles()) . ' -ldl -pthread'; $zlib_extra = @@ -92,9 +88,15 @@ class openssl $openssl_dir ??= LinuxUtil::getOSRelease()['dist'] === 'redhat' ? '/etc/pki/tls' : '/etc/ssl'; $ex_lib = trim($ex_lib); + // anything we want included (PGO -fprofile-*, LTO, custom hardening) + // has to be appended on the command line *after* the target name. + $userCFlags = trim((string) getenv('SPC_DEFAULT_CFLAGS')); + $userLdFlags = trim((string) getenv('SPC_DEFAULT_LDFLAGS')); + $userExtra = trim($userCFlags . ' ' . $userLdFlags); + shell()->cd($lib->getSourceDir())->initializeEnv($lib) ->exec( - "{$env} ./Configure no-shared zlib " . + './Configure no-shared zlib ' . "--prefix={$lib->getBuildRootPath()} " . "--libdir={$lib->getLibDir()} " . "--openssldir={$openssl_dir} " . @@ -102,7 +104,8 @@ class openssl 'enable-pie ' . 'no-legacy ' . 'no-tests ' . - "linux-{$arch}" + "linux-{$arch} " . + $userExtra ) ->exec('make clean') ->exec("make -j{$lib->getBuilder()->concurrency} CNF_EX_LIBS=\"{$ex_lib}\"")