Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
d91067a
ZipCompressTests: performance testing
Fedr Apr 22, 2026
d5b1c37
Merge branch 'master' into test/compress-times
Fedr Apr 22, 2026
af4499a
MRZlib: implement zlibCompressStream via zlib-ng (native mode)
Fedr Apr 22, 2026
e66838a
MRZlib: merge zlib-ng compress path back into MRZlib.cpp
Fedr Apr 22, 2026
f6796b2
Revert "MRZlib: merge zlib-ng compress path back into MRZlib.cpp"
Fedr Apr 22, 2026
d1b60f3
thirdparty(zlib-ng): force static-only on Emscripten
Fedr Apr 22, 2026
0addcf5
MRMesh.vcxproj: register MRZlibNg.cpp for the MSBuild Windows build
Fedr Apr 22, 2026
0e63f61
MRZlibNg: use MAX_WBITS not non-existent Z_MAX_WINDOWBITS
Fedr Apr 22, 2026
b8a22c8
test: make MRMesh.ZlibCompressStats engine-agnostic
Fedr Apr 22, 2026
46a3a9a
Merge branch 'master' into test/compress-times
Fedr Apr 22, 2026
ab7c167
Merge remote-tracking branch 'origin/test/compress-times' into feat/z…
Fedr Apr 22, 2026
2a4a5ac
thirdparty(zlib-ng, emscripten): restore BUILD_SHARED_LIBS after add_…
Fedr Apr 22, 2026
049bd26
ci: retrigger with skip-image-rebuild label removed (image needs rebu…
Fedr Apr 22, 2026
b557a4b
thirdparty(zlib-ng, emscripten): unset BUILD_SHARED_LIBS after, not r…
Fedr Apr 22, 2026
cb9dfb0
ci(windows): add DLL-not-found diagnostic steps
Fedr Apr 23, 2026
729e7af
ci: retrigger with Windows-only labels (skip images + disable non-Win…
Fedr Apr 23, 2026
83e7169
MRMesh: on Windows find zlib-ng via find_package(CONFIG), not find_li…
Fedr Apr 23, 2026
46340ab
MRMesh: manually construct zlib-ng imported target on Windows
Fedr Apr 23, 2026
86ead07
MRZlib: route zlibDecompressStream through zlib-ng (zng_inflate*)
Fedr Apr 23, 2026
3058248
Revert "ci(windows): add DLL-not-found diagnostic steps"
Fedr Apr 23, 2026
e5187e2
MRZlib: rename MRZlibNg.cpp -> MRZlib.cpp; restore test scale
Fedr Apr 23, 2026
d5331c7
Merge branch 'master' into feat/zlib-compress-stream-zlib-ng
Fedr Apr 23, 2026
fdb004a
ci: retrigger CI (previous run's vcpkg cache restore failed silently)
Fedr Apr 23, 2026
af9bfcf
Merge branch 'master' into feat/zlib-compress-stream-zlib-ng
Fedr Apr 24, 2026
29057ae
thirdparty(vcpkg): overlay zlib-ng port to strip its GNU symbol versi…
Fedr Apr 24, 2026
6032709
ci: retrigger with skip-image-rebuild label removed (image needs rebu…
Fedr Apr 24, 2026
1c1793a
Merge remote-tracking branch 'origin/master' into feat/zlib-compress-…
Fedr Apr 25, 2026
226b5c3
MRMesh: simplify zlib-ng wiring to find_package(CONFIG)
Fedr Apr 27, 2026
4d254c8
cmake: add Findzlib-ng module + propagate zlib-ng dep through MRMeshC…
Fedr Apr 27, 2026
2c23d5f
react to PR #5959 review comments
Fedr Apr 27, 2026
3b0aa15
zlib-ng: force CONFIG mode on build, gate consumer find_dependency on…
Fedr Apr 27, 2026
a3d3507
ci(windows): pass --overlay-ports to vcpkg in install.bat
Fedr Apr 27, 2026
20bf2b7
ci(linux-vcpkg): static-link zlib-ng
Fedr Apr 27, 2026
e357531
zlib-ng: simplify thirdparty/CMakeLists.txt guard, drop --exclude lib…
Fedr Apr 27, 2026
a313fba
zlib-ng: address review feedback
Fedr Apr 28, 2026
d826e11
Merge branch 'master' into feat/zlib-compress-stream-zlib-ng
Fedr Apr 28, 2026
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
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,6 @@
[submodule "thirdparty/cpp-httplib"]
path = thirdparty/cpp-httplib
url = https://github.com/yhirose/cpp-httplib
[submodule "thirdparty/zlib-ng"]
path = thirdparty/zlib-ng
url = https://github.com/zlib-ng/zlib-ng.git
40 changes: 40 additions & 0 deletions cmake/Modules/Findzlib-ng.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# https://cmake.org/cmake/help/latest/manual/cmake-developer.7.html#a-sample-find-module

find_package(PkgConfig QUIET)
if(PkgConfig_FOUND)
pkg_check_modules(PC_zlib_ng QUIET zlib-ng)
endif()

find_path(zlib-ng_INCLUDE_DIR
NAMES zlib-ng.h
HINTS ${PC_zlib_ng_INCLUDE_DIRS}
)
find_library(zlib-ng_LIBRARY
NAMES z-ng zlib-ng
HINTS ${PC_zlib_ng_LIBRARY_DIRS}
)

if(zlib-ng_INCLUDE_DIR)
file(READ "${zlib-ng_INCLUDE_DIR}/zlib-ng.h" zlib-ng_VERSION_FILE)
string(REGEX MATCH "ZLIBNG_VERSION \"([0-9\\.]+)\"" _ "${zlib-ng_VERSION_FILE}")
set(zlib-ng_VERSION "${CMAKE_MATCH_1}")
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(zlib-ng
REQUIRED_VARS zlib-ng_INCLUDE_DIR zlib-ng_LIBRARY
VERSION_VAR zlib-ng_VERSION
)
mark_as_advanced(
zlib-ng_INCLUDE_DIR
zlib-ng_LIBRARY
)

if(zlib-ng_FOUND AND NOT TARGET zlib-ng::zlib)
add_library(zlib-ng::zlib UNKNOWN IMPORTED)
set_target_properties(zlib-ng::zlib PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${zlib-ng_INCLUDE_DIR}"
IMPORTED_LOCATION "${zlib-ng_LIBRARY}"
VERSION "${zlib-ng_VERSION}"
)
endif()
1 change: 1 addition & 0 deletions requirements/macos.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ tbb
tinyxml2
tl-expected
zlib
zlib-ng
1 change: 1 addition & 0 deletions requirements/vcpkg-linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,4 @@ tiff
tinygltf
tinyxml2
tl-expected
zlib-ng
1 change: 1 addition & 0 deletions requirements/windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ tiff
tinygltf
tinyxml2
tl-expected
zlib-ng
glad
glfw3
2 changes: 2 additions & 0 deletions source/MRMesh/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ find_package(JsonCpp REQUIRED)
find_package(spdlog 1.9 REQUIRED)
find_package(TBB 2020.1 COMPONENTS tbb REQUIRED)
find_package(tl-expected REQUIRED)
find_package(zlib-ng CONFIG REQUIRED)

target_link_libraries(${PROJECT_NAME}
PUBLIC
Expand All @@ -45,6 +46,7 @@ target_link_libraries(${PROJECT_NAME}
tl::expected
PRIVATE
${CMAKE_DL_LIBS}
zlib-ng::zlib
)

# libzip on Emscripten is unable to resolve its dependencies by itself
Expand Down
1 change: 1 addition & 0 deletions source/MRMesh/MRMeshConfig.cmake.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ if(EMSCRIPTEN)
find_package(MbedTLS 1.0 REQUIRED)
find_package(ZLIB REQUIRED)
find_dependency(libzip)
find_dependency(zlib-ng)

set(MRMESH_NO_GTEST @MRMESH_NO_GTEST@)
if(NOT MRMESH_NO_GTEST)
Expand Down
30 changes: 15 additions & 15 deletions source/MRMesh/MRZlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "MRBuffer.h"
#include "MRFinally.h"

#include <zlib.h>
#include <zlib-ng.h>

#include <cassert>

Expand All @@ -22,7 +22,7 @@ constexpr int kRawDeflateBits = -MAX_WBITS;
constexpr int kDefaultMemLevel = 8;
static_assert( kDefaultMemLevel <= MAX_MEM_LEVEL );

std::string zlibToString( int code )
std::string zngToString( int code )
{
switch ( code )
{
Expand Down Expand Up @@ -62,17 +62,17 @@ namespace MR
Expected<void> zlibCompressStream( std::istream& in, std::ostream& out, const ZlibCompressParams& params )
{
Buffer<char> inChunk( cChunkSize ), outChunk( cChunkSize );
z_stream stream {
zng_stream stream {
.zalloc = Z_NULL,
.zfree = Z_NULL,
.opaque = Z_NULL,
};
int ret;
if ( Z_OK != ( ret = deflateInit2( &stream, params.level, Z_DEFLATED, windowBitsFor( params.rawDeflate ), kDefaultMemLevel, Z_DEFAULT_STRATEGY ) ) )
return unexpected( zlibToString( ret ) );
if ( Z_OK != ( ret = zng_deflateInit2( &stream, params.level, Z_DEFLATED, windowBitsFor( params.rawDeflate ), kDefaultMemLevel, Z_DEFAULT_STRATEGY ) ) )
return unexpected( zngToString( ret ) );

MR_FINALLY {
deflateEnd( &stream );
zng_deflateEnd( &stream );
};

if ( params.stats )
Expand All @@ -89,7 +89,7 @@ Expected<void> zlibCompressStream( std::istream& in, std::ostream& out, const Zl

if ( params.stats )
{
params.stats->crc32 = (uint32_t)crc32( params.stats->crc32, stream.next_in, stream.avail_in );
params.stats->crc32 = (uint32_t)zng_crc32( params.stats->crc32, stream.next_in, stream.avail_in );
params.stats->uncompressedSize += stream.avail_in;
}

Expand All @@ -98,9 +98,9 @@ Expected<void> zlibCompressStream( std::istream& in, std::ostream& out, const Zl
{
stream.next_out = reinterpret_cast<uint8_t*>( outChunk.data() );
stream.avail_out = (unsigned)outChunk.size();
ret = deflate( &stream, flush );
ret = zng_deflate( &stream, flush );
if ( Z_OK != ret && Z_STREAM_END != ret )
return unexpected( zlibToString( ret ) );
return unexpected( zngToString( ret ) );

assert( stream.avail_out <= (unsigned)outChunk.size() );
const unsigned written = (unsigned)outChunk.size() - stream.avail_out;
Expand All @@ -124,17 +124,17 @@ Expected<void> zlibCompressStream( std::istream& in, std::ostream& out, int leve
Expected<void> zlibDecompressStream( std::istream& in, std::ostream& out, const ZlibParams& params )
{
Buffer<char> inChunk( cChunkSize ), outChunk( cChunkSize );
z_stream stream {
zng_stream stream {
.zalloc = Z_NULL,
.zfree = Z_NULL,
.opaque = Z_NULL,
};
int ret;
if ( Z_OK != ( ret = inflateInit2( &stream, windowBitsFor( params.rawDeflate ) ) ) )
return unexpected( zlibToString( ret ) );
if ( Z_OK != ( ret = zng_inflateInit2( &stream, windowBitsFor( params.rawDeflate ) ) ) )
return unexpected( zngToString( ret ) );

MR_FINALLY {
inflateEnd( &stream );
zng_inflateEnd( &stream );
};

while ( !in.eof() )
Expand All @@ -150,9 +150,9 @@ Expected<void> zlibDecompressStream( std::istream& in, std::ostream& out, const
{
stream.next_out = reinterpret_cast<uint8_t*>( outChunk.data() );
stream.avail_out = (unsigned)outChunk.size();
ret = inflate( &stream, Z_NO_FLUSH );
ret = zng_inflate( &stream, Z_NO_FLUSH );
if ( Z_OK != ret && Z_STREAM_END != ret )
return unexpected( zlibToString( ret ) );
return unexpected( zngToString( ret ) );

assert( stream.avail_out <= (unsigned)outChunk.size() );
out.write( outChunk.data(), (unsigned)outChunk.size() - stream.avail_out );
Expand Down
18 changes: 18 additions & 0 deletions thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,24 @@ ENDIF()

add_subdirectory(./OpenCTM-git ./OpenCTM)

IF(NOT APPLE)
set(ZLIB_COMPAT OFF CACHE BOOL "")
set(ZLIB_ENABLE_TESTS OFF CACHE BOOL "")
set(ZLIBNG_ENABLE_TESTS OFF CACHE BOOL "")
set(WITH_GTEST OFF CACHE BOOL "")
set(WITH_GZFILEOP OFF CACHE BOOL "")
IF(EMSCRIPTEN)
# Force static: undefined BUILD_SHARED_LIBS makes zlib-ng emit duplicate
# libz-ng.a rules under Emscripten. Restore to undefined (not empty)
# afterwards -- jsoncpp downstream breaks on empty BUILD_SHARED_LIBS.
set(BUILD_SHARED_LIBS OFF)
add_subdirectory(./zlib-ng)
unset(BUILD_SHARED_LIBS)
ELSE()
add_subdirectory(./zlib-ng)
ENDIF()
ENDIF()

option(PHMAP_INSTALL "" ON)
add_subdirectory(./parallel-hashmap)

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/install.bat
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ REM Install vcpkg core dependencies
vcpkg install vcpkg-cmake vcpkg-cmake-config --host-triplet %VCPKG_DEFAULT_TRIPLET% --overlay-triplets "%~dp0vcpkg\triplets" --debug --x-abi-tools-use-exact-versions || goto :error

REM Install all required dependencies
vcpkg install !packages! --host-triplet %VCPKG_DEFAULT_TRIPLET% --overlay-triplets "%~dp0vcpkg\triplets" --debug --x-abi-tools-use-exact-versions || goto :error
vcpkg install !packages! --host-triplet %VCPKG_DEFAULT_TRIPLET% --overlay-triplets "%~dp0vcpkg\triplets" --overlay-ports "%~dp0vcpkg\ports" --debug --x-abi-tools-use-exact-versions || goto :error

endlocal
goto :EOF
Expand Down
66 changes: 66 additions & 0 deletions thirdparty/vcpkg/ports/zlib-ng/portfile.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
vcpkg_from_github(
OUT_SOURCE_PATH SOURCE_PATH
REPO zlib-ng/zlib-ng
REF "${VERSION}"
SHA512 e2057c764f1d5aaee738edee7e977182c5b097e3c95489dcd8de813f237d92a05daaa86d68d44b331d9fec5d1802586a8f6cfb658ba849874aaa14e72a8107f5
HEAD_REF develop
)

# Set ZLIB_COMPAT in the triplet file to turn on
if(NOT DEFINED ZLIB_COMPAT)
set(ZLIB_COMPAT OFF)
endif()

vcpkg_cmake_configure(
SOURCE_PATH "${SOURCE_PATH}"
OPTIONS
"-DZLIB_FULL_VERSION=${ZLIB_FULL_VERSION}"
-DZLIB_ENABLE_TESTS=OFF
-DWITH_NEW_STRATEGIES=ON
-DZLIB_COMPAT=${ZLIB_COMPAT}
OPTIONS_RELEASE
-DWITH_OPTIM=ON
)
vcpkg_cmake_install()
vcpkg_copy_pdbs()

# Condition in `WIN32`, from https://github.com/zlib-ng/zlib-ng/blob/2.1.5/CMakeLists.txt#L1081-L1100
# (dynamic) for `zlib` or (static `MSVC) for `zlibstatic` or default `z`
# i.e. (windows) and not (static mingw) https://learn.microsoft.com/en-us/vcpkg/maintainers/variables#vcpkg_target_is_system
if(VCPKG_TARGET_IS_WINDOWS AND (NOT (VCPKG_LIBRARY_LINKAGE STREQUAL static AND VCPKG_TARGET_IS_MINGW)))
set(_port_suffix)
if(ZLIB_COMPAT)
set(_port_suffix "")
else()
set(_port_suffix "-ng")
endif()

set(_port_output_name)
if(VCPKG_LIBRARY_LINKAGE STREQUAL "dynamic")
set(_port_output_name "zlib${_port_suffix}")
else()
set(_port_output_name "zlibstatic${_port_suffix}")
endif()

# CMAKE_DEBUG_POSTFIX from https://github.com/zlib-ng/zlib-ng/blob/2.1.5/CMakeLists.txt#L494
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "release")
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/lib/pkgconfig/zlib${_port_suffix}.pc" " -lz${_port_suffix}" " -l${_port_output_name}")
endif()
if(NOT DEFINED VCPKG_BUILD_TYPE OR VCPKG_BUILD_TYPE STREQUAL "debug")
vcpkg_replace_string("${CURRENT_PACKAGES_DIR}/debug/lib/pkgconfig/zlib${_port_suffix}.pc" " -lz${_port_suffix}" " -l${_port_output_name}d")
endif()
endif()

vcpkg_fixup_pkgconfig()

if(ZLIB_COMPAT)
set(_cmake_dir "ZLIB")
else()
set(_cmake_dir "zlib-ng")
endif()
vcpkg_cmake_config_fixup(CONFIG_PATH lib/cmake/${_cmake_dir})

file(REMOVE_RECURSE "${CURRENT_PACKAGES_DIR}/debug/share"
"${CURRENT_PACKAGES_DIR}/debug/include"
)
vcpkg_install_copyright(FILE_LIST "${SOURCE_PATH}/LICENSE.md")
18 changes: 18 additions & 0 deletions thirdparty/vcpkg/ports/zlib-ng/vcpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "zlib-ng",
"version": "2.3.3",
"port-version": 1,
"description": "zlib replacement with optimizations for 'next generation' systems",
"homepage": "https://github.com/zlib-ng/zlib-ng",
"license": "Zlib",
"dependencies": [
{
"name": "vcpkg-cmake",
"host": true
},
{
"name": "vcpkg-cmake-config",
"host": true
}
]
}
6 changes: 6 additions & 0 deletions thirdparty/vcpkg/triplets/arm64-linux-meshlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ set(VCPKG_TARGET_ARCHITECTURE arm64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)

# Have to build zlib-ng as a static library due to the auditwheel issue:
# https://github.com/pypa/auditwheel/issues/613
if(PORT STREQUAL "zlib-ng")
set(VCPKG_LIBRARY_LINKAGE static)
endif()

set(VCPKG_CMAKE_SYSTEM_NAME Linux)
set(VCPKG_BUILD_TYPE release)

Expand Down
6 changes: 6 additions & 0 deletions thirdparty/vcpkg/triplets/x64-linux-meshlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE dynamic)
set(VCPKG_LIBRARY_LINKAGE dynamic)

# Have to build zlib-ng as a static library due to the auditwheel issue:
# https://github.com/pypa/auditwheel/issues/613
if(PORT STREQUAL "zlib-ng")
set(VCPKG_LIBRARY_LINKAGE static)
endif()

set(VCPKG_CMAKE_SYSTEM_NAME Linux)
set(VCPKG_BUILD_TYPE release)

Expand Down
1 change: 1 addition & 0 deletions thirdparty/zlib-ng
Submodule zlib-ng added at 860e4c
Loading