Skip to content

Commit f5592db

Browse files
committed
Switch back to zlib instead of zlib-ng
Context: dotnet/android#5971 (comment) Context: dotnet/android#5971 (comment) Context: zlib-ng/zlib-ng#850 Context: https://github.com/zlib-ng/zlib-ng/wiki/Deflate-config-comparison `zlib-ng` is mostly about speed and efficiency, however it achieves its goal by sometimes sacrificing the compression ratio which then affects Xamarin.Android, the main LibZipSharp consumer. Add a new `zlib` submodule and switch to using `zlib` by default instead of `zlib-ng`, while retaining `zlib-ng` as an option.
1 parent 263b8e4 commit f5592db

File tree

7 files changed

+59
-6
lines changed

7 files changed

+59
-6
lines changed

.gitmodules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@
1717
url = https://github.com/xz-mirror/xz.git
1818
branch = master
1919

20+
[submodule "zlib"]
21+
path = external/zlib
22+
url = https://github.com/madler/zlib.git
23+
branch = master

CMakeLists.txt

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cmake_minimum_required(VERSION 3.18)
1313
option(BUILD_DEPENDENCIES "Build only libzip dependencies" OFF)
1414
option(BUILD_LIBZIP "Build libzip and libZipSharp" OFF)
1515
option(ENABLE_XZ "Enable XZ (LZMA compression) in the build" OFF)
16+
option(ENABLE_ZLIBNG "Use zlib-ng instead of zlib" OFF)
1617

1718
set(CMAKE_POSITION_INDEPENDENT_CODE True CACHE BOOL "Always build position independent code" FORCE)
1819

@@ -53,9 +54,11 @@ endif()
5354
#
5455
# zlib-ng
5556
#
56-
set(ZLIB_COMPAT ON CACHE BOOL "Build zlib-ng for compatibility with zlib" FORCE)
57-
set(ZLIB_ENABLE_TESTS OFF CACHE BOOL "Do not build zlib-ng tests" FORCE)
58-
set(WITH_NEW_STRATEGIES OFF CACHE BOOL "Disable faster, but with worse compression, deflate strategies" FORCE)
57+
if(ENABLE_ZLIBNG)
58+
set(ZLIB_COMPAT ON CACHE BOOL "Build zlib-ng for compatibility with zlib" FORCE)
59+
set(ZLIB_ENABLE_TESTS OFF CACHE BOOL "Do not build zlib-ng tests" FORCE)
60+
set(WITH_NEW_STRATEGIES OFF CACHE BOOL "Disable faster, but with worse compression, deflate strategies" FORCE)
61+
endif()
5962

6063
#
6164
# Read product version
@@ -289,7 +292,11 @@ endforeach()
289292
set(LZS_CXX_LINKER_FLAGS "${_CHECKED_FLAGS}")
290293

291294
if(BUILD_DEPENDENCIES)
292-
add_subdirectory(external/zlib-ng)
295+
if(ENABLE_ZLIBNG)
296+
add_subdirectory(external/zlib-ng)
297+
else()
298+
add_subdirectory(external/zlib)
299+
endif()
293300

294301
target_compile_options(
295302
zlib
@@ -521,8 +528,14 @@ else()
521528
endif()
522529
else()
523530
if(WIN32)
531+
if(ENABLE_ZLIBNG)
532+
set(ZLIB_NAME "zlib.lib")
533+
else()
534+
set(ZLIB_NAME "zlibstatic.lib")
535+
endif()
536+
524537
set(LIBS
525-
${ARTIFACTS_ROOT_DIR}/lib/zlib.lib
538+
${ARTIFACTS_ROOT_DIR}/lib/${ZLIB_NAME}
526539
${ARTIFACTS_ROOT_DIR}/lib/bz2.lib
527540
)
528541

LibZipSharp.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
22
<PropertyGroup>
3-
<_LibZipSharpNugetVersion>2.0.0-alpha5</_LibZipSharpNugetVersion>
3+
<_LibZipSharpNugetVersion>2.0.0-alpha6</_LibZipSharpNugetVersion>
44
<_NativeBuildDir>$(MSBuildThisFileDirectory)lzsbuild</_NativeBuildDir>
55
<_ExternalDir>$(MSBuildThisFileDirectory)external</_ExternalDir>
66
<_MonoPosixNugetVersion>7.0.0-alpha8.21302.6</_MonoPosixNugetVersion>

build.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ BUILD_DIR_ROOT="${MY_DIR}/lzsbuild"
66
OS=$(uname -s)
77
LZS_BUILD_DIR="${BUILD_DIR_ROOT}/lib/${OS}"
88
DEPS_BASE_BUILD_DIR="${BUILD_DIR_ROOT}/deps/${OS}"
9+
ZLIB_DIR="external/zlib"
910

1011
if [ "${OS}" == "Darwin" ]; then
1112
DEPS_BUILD_DIR="${DEPS_BASE_BUILD_DIR}/native"
@@ -29,6 +30,7 @@ CONFIGURATION="RelWithDebInfo"
2930
REBUILD="no"
3031
VERBOSE="no"
3132
USE_XZ="no"
33+
USE_ZLIBNG="no"
3234

3335
# The color block is pilfered from the dotnet installer script
3436
#
@@ -77,6 +79,7 @@ where OPTIONS are one or more of:
7779
-m|--cmake PATH use cmake at PATH instead of the default of '${CMAKE}'
7880
7981
-x|--xz use the XZ library for LZMA support (default: ${USE_XZ})
82+
-g|--zlib-ng use the zlib-ng library instead of zlib (default: ${USE_ZLIBNG}
8083
-c|--configuration NAME build using configuration NAME instead of the default of '${CONFIGURATION}'
8184
-j|--jobs NUM run at most this many build jobs in parallel
8285
-v|--verbose make cmake and ninja verbose
@@ -233,6 +236,8 @@ while (( "$#" )); do
233236

234237
-x|--xz) USE_XZ="yes"; shift ;;
235238

239+
-g|--zlib-ng) USE_ZLIBNG="yes"; shift ;;
240+
236241
-v|--verbose) VERBOSE="yes"; shift ;;
237242

238243
-r|--rebuild) REBUILD="yes"; shift ;;
@@ -254,6 +259,14 @@ if [ -z "${NINJA}" ]; then
254259
die ninja binary must be specified
255260
fi
256261

262+
if [ "${USE_ZLIBNG}" == "no" ]; then
263+
ZLIB_CMAKELISTS_PATH="${ZLIB_DIR}/CMakeLists.txt"
264+
if ! $(grep 'lzs: disable-examples' "${ZLIB_CMAKELISTS_PATH}" > /dev/null 2>&1); then
265+
print_banner Applying zlib patch
266+
$(cd "${ZLIB_DIR}"; git apply "${MY_DIR}/zlib-changes.patch")
267+
fi
268+
fi
269+
257270
if [ "${REBUILD}" == "yes" ]; then
258271
rm -rf "${BUILD_DIR_ROOT}"
259272
rm -rf "${ARTIFACTS_DIR_ROOT}"

external/zlib

Submodule zlib added at cacf7f1

native/version.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
constexpr char libzipsharp_version[] = LIBZIPSHARP_VERSION;
1212
constexpr char libzip_version[] = LIBZIP_VERSION;
1313
constexpr char libzlib_version[] = ZLIB_VERSION;
14+
#if defined (ZLIBNG_VERSION)
1415
constexpr char libzlibng_version[] = ZLIBNG_VERSION;
16+
#else
17+
constexpr char libzlibng_version[] = "not used";
18+
#endif // ndef ZLIBNG_VERSION
1519
#if defined (HAVE_XZ)
1620
constexpr char lzma_version[] = LZMA_VERSION_STRING;
1721
#else

zlib-changes.patch

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
diff --git a/CMakeLists.txt b/CMakeLists.txt
2+
index 0fe939d..f3ad0ed 100644
3+
--- a/CMakeLists.txt
4+
+++ b/CMakeLists.txt
5+
@@ -229,7 +229,7 @@ endif()
6+
#============================================================================
7+
# Example binaries
8+
#============================================================================
9+
-
10+
+if(False) # lzs: disable-examples
11+
add_executable(example test/example.c)
12+
target_link_libraries(example zlib)
13+
add_test(example example)
14+
@@ -247,3 +247,4 @@ if(HAVE_OFF64_T)
15+
target_link_libraries(minigzip64 zlib)
16+
set_target_properties(minigzip64 PROPERTIES COMPILE_FLAGS "-D_FILE_OFFSET_BITS=64")
17+
endif()
18+
+endif()

0 commit comments

Comments
 (0)