Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Package/Library/openssl.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function build(LibraryPackage $lib): void
'--with-zlib-lib=' . BUILD_LIB_PATH . ' ';

$openssl_dir = getenv('OPENSSLDIR') ?: null;
$openssl_dir ??= LinuxUtil::getOSRelease()['dist'] === 'redhat' ? '/etc/pki/tls' : '/etc/ssl';
$openssl_dir ??= self::detectOpenSSLDir();
$ex_lib = trim($ex_lib);

// anything we want included (PGO -fprofile-*, LTO, custom hardening)
Expand Down Expand Up @@ -117,6 +117,19 @@ public function build(LibraryPackage $lib): void
$this->patchPkgConfig($lib);
}

private static function detectOpenSSLDir(): string
{
// /etc/centos-release exists on AlmaLinux and Rocky, so getOSRelease() reports
// 'centos' there and the name check missed the RHEL layout
foreach (['/etc/ssl', '/etc/pki/tls'] as $dir) {
if (file_exists("{$dir}/cert.pem") || glob("{$dir}/certs/*.0")) {
return $dir;
}
}

return LinuxUtil::getOSRelease()['dist'] === 'redhat' ? '/etc/pki/tls' : '/etc/ssl';
}

private function patchPkgConfig(LibraryPackage $pkg): void
{
$pkg->patchPkgconfPrefix(['libssl.pc', 'openssl.pc', 'libcrypto.pc']);
Expand Down
5 changes: 1 addition & 4 deletions src/Package/Target/php/unix.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,12 @@ public function configureForUnix(TargetPackage $package, PackageInstaller $insta
$configure_str = str_replace('--with-pic', '--enable-pic', $configure_str);
}

// reuse the same make vars so configure conftest links use the same LIBS (incl. -framework flags)
$vars = $this->makeVars($installer);

// run ./configure with args
$this->seekPhpSrcLogFileOnException(fn () => shell()->cd($package->getSourceDir())->setEnv([
'CFLAGS' => getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_CFLAGS'),
'CPPFLAGS' => "-I{$package->getIncludeDir()}",
'LDFLAGS' => "-L{$package->getLibDir()} " . getenv('SPC_CMD_VAR_PHP_MAKE_EXTRA_LDFLAGS'),
'LIBS' => $vars['EXTRA_LIBS'] ?? '',
'LIBS' => SystemTarget::getRuntimeLibs(),

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@henderkes

The LIBS configuration in PHP's ./configure was downgraded from makeVars()['EXTRA_LIBS'] (the complete library, including -lstdc++/-lc++, -lssl -lcrypto, and frameworks) to SystemTarget::getRuntimeLibs() (only the basic runtime library).

Then, the conftest linker test in configure failed due to missing C++ runtime and OpenSSL symbols, causing some jobs crash with the error configure: error.

This leads to a regression problem.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SystemTarget::getRuntimeLibs() should be returning -lstdc++ if we have any C++ extensions.

The problem with passing $vars['EXTRA_LIBS'] is passing all the polyfill libraries which will make php get wrong HAVE_XXX defines which will lead to make fail.

Are frameworks missing from getRuntimeLibs()? Then they need to be added. The implementation we have in main branch is correct.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in my PR

])->exec($configure_str), $package->getSourceDir());
}

Expand Down
15 changes: 11 additions & 4 deletions src/StaticPHP/Artifact/ArtifactExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ protected function extractWithType(string $cache_type, string $source_file, stri
*
* Supports: tar, tar.gz, tgz, tar.bz2, tar.xz, txz, zip, exe
*
* @param bool $merge when true, merge zip contents into existing target dir instead of wiping it
* @param bool $merge when true, merge contents into existing target dir instead of wiping it
*/
protected function extractArchive(string $filename, string $target, bool $merge = false): void
{
Expand All @@ -532,10 +532,17 @@ protected function extractArchive(string $filename, string $target, bool $merge

$extname = FileSystem::extname($filename);

if ($extname !== 'exe' && !is_dir($target)) {
FileSystem::createDir($target);
if ($extname !== 'exe') {
// tar extraction merges into whatever is already there, so a re-extract would
// leave files from the previous version behind
if (!$merge && is_dir($target)) {
FileSystem::removeDir($target);
}
if (!is_dir($target)) {
throw new FileSystemException("Failed to create target directory: {$target}");
FileSystem::createDir($target);
if (!is_dir($target)) {
throw new FileSystemException("Failed to create target directory: {$target}");
}
}
}
match (SystemTarget::getTargetOS()) {
Expand Down
Loading