static-php-cli icon indicating copy to clipboard operation
static-php-cli copied to clipboard

zlib 1.3.2 Windows build: cmake output file names changed, breaking library detection

Open GhostPirateBob opened this issue 9 months ago • 4 comments

Description

zlib 1.3.2 changed its cmake output file names on Windows. The static-php-cli zlib builder (src/SPC/builder/windows/library/zlib.php) expects the old names and fails when they don't exist.

Old names (zlib <= 1.3.1)

  • zlibstatic.lib (static library)
  • zlib.lib (import library)
  • zlib.dll (shared library)

New names (zlib 1.3.2)

  • zs.lib (static library)
  • z.lib (import library)
  • z.dll (shared library)

Impact

The zlib builder in zlib.php (lines ~34-36) tries to:

  1. Copy zlibstatic.lib → this file no longer exists
  2. Delete zlib.dll → this file no longer exists
  3. Delete zlib.lib → this file no longer exists

These operations emit PHP warnings but the build continues. However, since the static library is never properly renamed, PHP's configure step cannot find zlib (--enable-zlib looks for zlib_a.lib or zlib.lib), and the final link fails with unresolved zlib symbols from curl, openssl, and libssh2.

Errors observed

PHP Warning: copy(...\buildroot\lib\zlibstatic.lib): Failed to open stream: No such file or directory in phar://...spc.exe/src/SPC/builder/windows/library/zlib.php on 34
PHP Warning: unlink(...\buildroot\bin\zlib.dll): No such file or directory in phar://...spc.exe/src/SPC/builder/windows/library/zlib.php on 35
PHP Warning: unlink(...\buildroot\lib\zlib.lib): No such file or directory in phar://...spc.exe/src/SPC/builder/windows/library/zlib.php on 36

Then at PHP link time:

libcurl_a.lib(content_encoding.obj) : error LNK2019: unresolved external symbol inflate referenced in function Curl_unencode_deflate_write
... (12 unresolved zlib symbols total)

Suggested fix

Update zlib.php to handle both old and new naming conventions, e.g.:

// After cmake install, ensure the expected library names exist
$buildroot = $this->builder->getBuildRoot();
$libDir = $buildroot . '/lib';

// zlib 1.3.2+ uses zs.lib instead of zlibstatic.lib
if (file_exists("$libDir/zs.lib") && !file_exists("$libDir/zlibstatic.lib")) {
    copy("$libDir/zs.lib", "$libDir/zlibstatic.lib");
    copy("$libDir/zs.lib", "$libDir/zlib_a.lib");
}

Environment

  • SPC version: v2.8.2 (nightly)
  • OS: Windows Server 2025 (GitHub Actions windows-2025)
  • Visual Studio: 2022 Enterprise (vs17)
  • zlib version: 1.3.2

Workaround

I have a PR currently working around this by renaming the files after spc craft fails, then re-running PHP configure and nmake manually. See: https://github.com/php/pie/pull/512 for context.

GhostPirateBob avatar Feb 19 '26 19:02 GhostPirateBob

Wonderful when breaking changes are introduced in a patch version.

Thanks for the report, will fix tomorrow.

henderkes avatar Feb 19 '26 22:02 henderkes

Unless I can beat you to it!

I gave it a crack with #1041 but I don't know what I'm doing.

(╯°□°)╯︵ ¡Bᴉlz

GhostPirateBob avatar Feb 20 '26 01:02 GhostPirateBob

Wonderful when breaking changes are introduced in a patch version.

Thanks for the report, will fix tomorrow.

as a heads up - this is reported here https://github.com/madler/zlib/issues/1181, but apparently the names in 1.3.2 are not correct either, and will change a second time in a future release too (so there'll be 3 variantions, zlib up to 1.3.1, zlib 1.3.2, and a future release, all will have the CMakeLists scripts generating different filenames)

jcar87 avatar Mar 02 '26 16:03 jcar87

I prefer using a full-compatible way to achieve it. Either we extract or fetch the name of zlib from CMake output, or just detect every possible names to try copying. Regardless of the approach, we should still ultimately use zlibstatic.lib and zlib_a.lib for now, which are still being used by PHP and other libraries unless changes occur.

Otherwise, unless we can push for an update to the source code of all PHP versions and make all other libs stop hardcoding filenames for other dependencies, I think this will reduce our workload. Given that this issue is causing StaticPHP's weekly builds to fail, perhaps this problem should be addressed ASAP.

We consistently use the latest versions of all packages, so even if a real major version update with breaking changes occurs, we will still be aware of this issue.

crazywhalecc avatar Mar 03 '26 15:03 crazywhalecc