Skip to content

Commit 4ed6d22

Browse files
author
Hendrik Mennen
committed
Improve zlib Windows library detection: add libz.lib candidate, error on missing lib, safe cleanup
The existing detection list misses `libz.lib` which zlib 1.3.3+ may produce. This adds it as a fourth candidate and throws a clear RuntimeException when no known static library is found, instead of silently continuing with a broken build. Also ensures shared-lib cleanup skips whichever file was detected as the static library, and looks for DLLs in the correct bin/ directory.
1 parent 4c6b7a3 commit 4ed6d22

1 file changed

Lines changed: 23 additions & 7 deletions

File tree

src/SPC/builder/windows/library/zlib.php

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,39 @@ protected function build(): void
3131
$this->builder->makeSimpleWrapper('cmake'),
3232
"--build build --config Release --target install -j{$this->builder->concurrency}"
3333
);
34+
// zlib >=1.3.2 changed output names (zlibstatic.lib -> zs.lib),
35+
// and 1.3.3+ may use libz.lib. Detect whichever exists and
36+
// normalize to the names PHP and other consumers expect.
3437
$detect_list = [
3538
'zlibstatic.lib',
3639
'zs.lib',
3740
'libzs.lib',
41+
'libz.lib',
3842
];
43+
$found = null;
3944
foreach ($detect_list as $item) {
4045
if (file_exists(BUILD_LIB_PATH . '\\' . $item)) {
41-
FileSystem::copy(BUILD_LIB_PATH . '\\' . $item, BUILD_LIB_PATH . '\zlib_a.lib');
42-
FileSystem::copy(BUILD_LIB_PATH . '\\' . $item, BUILD_LIB_PATH . '\zlibstatic.lib');
46+
$found = $item;
4347
break;
4448
}
4549
}
50+
if ($found === null) {
51+
throw new \RuntimeException('zlib build produced no known static library. Looked for: ' . implode(', ', $detect_list));
52+
}
53+
FileSystem::copy(BUILD_LIB_PATH . '\\' . $found, BUILD_LIB_PATH . '\zlib_a.lib');
54+
if ($found !== 'zlibstatic.lib') {
55+
FileSystem::copy(BUILD_LIB_PATH . '\\' . $found, BUILD_LIB_PATH . '\zlibstatic.lib');
56+
}
57+
58+
// Clean up shared lib artifacts
4659
FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '\bin\zlib.dll');
47-
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '\zlib.lib');
48-
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '\libz.dll');
49-
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '\libz.lib');
50-
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '\z.lib');
51-
FileSystem::removeFileIfExists(BUILD_LIB_PATH . '\z.dll');
60+
FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '\bin\z.dll');
61+
FileSystem::removeFileIfExists(BUILD_ROOT_PATH . '\bin\libz.dll');
62+
foreach (['zlib.lib', 'z.lib', 'libz.lib'] as $implib) {
63+
$path = BUILD_LIB_PATH . '\\' . $implib;
64+
if ($implib !== $found) {
65+
FileSystem::removeFileIfExists($path);
66+
}
67+
}
5268
}
5369
}

0 commit comments

Comments
 (0)