Skip to content

Commit 78cc0e5

Browse files
authored
Updated zlib to 1.3.2 and static link zlib (#562)
1 parent acb0f0e commit 78cc0e5

29 files changed

+1397
-1020
lines changed

.github/workflows/artifacts.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,29 +12,29 @@ jobs:
1212
include:
1313
- name: x86_64 SDL 2 (OGL)
1414
flags: '-DNBC_PLATFORM=sdl2 -DNBC_GFX_API=OGL'
15-
packages: 'libsdl2-dev libopenal-dev zlib1g-dev'
15+
packages: 'libsdl2-dev libopenal-dev'
1616
runner: ubuntu-24.04
1717
- name: x86_64 SDL 2 (OGL + Shaders)
1818
flags: '-DNBC_PLATFORM=sdl2 -DNBC_GFX_API=OGL_SHADERS'
19-
packages: 'libsdl2-dev libopenal-dev zlib1g-dev'
19+
packages: 'libsdl2-dev libopenal-dev'
2020
runner: ubuntu-24.04
2121
- name: i686 SDL 2 (OGL)
2222
flags: '-DNBC_PLATFORM=sdl2 -DNBC_GFX_API=OGL -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32'
23-
packages: 'gcc-multilib g++-multilib libsdl2-dev:i386 libopenal-dev:i386 zlib1g-dev:i386'
23+
packages: 'gcc-multilib g++-multilib libsdl2-dev:i386 libopenal-dev:i386'
2424
runner: ubuntu-22.04
2525
i386: true
2626
- name: i686 SDL 2 (OGL + Shaders)
2727
flags: '-DNBC_PLATFORM=sdl2 -DNBC_GFX_API=OGL -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32'
28-
packages: 'gcc-multilib g++-multilib libsdl2-dev:i386 libopenal-dev:i386 zlib1g-dev:i386'
28+
packages: 'gcc-multilib g++-multilib libsdl2-dev:i386 libopenal-dev:i386'
2929
runner: ubuntu-22.04
3030
i386: true
3131
- name: aarch64 SDL 2 (OGL)
3232
flags: '-DNBC_PLATFORM=sdl2 -DNBC_GFX_API=OGL'
33-
packages: 'libsdl2-dev libopenal-dev zlib1g-dev'
33+
packages: 'libsdl2-dev libopenal-dev'
3434
runner: ubuntu-24.04-arm
3535
- name: aarch64 SDL 2 (OGL + Shaders)
3636
flags: '-DNBC_PLATFORM=sdl2 -DNBC_GFX_API=OGL_SHADERS'
37-
packages: 'libsdl2-dev libopenal-dev zlib1g-dev'
37+
packages: 'libsdl2-dev libopenal-dev'
3838
runner: ubuntu-24.04-arm
3939
name: Linux (${{ matrix.name }})
4040
runs-on: ${{ matrix.runner }}

.github/workflows/build.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ jobs:
4040
cmake ninja-build \
4141
ccache \
4242
libopenal-dev \
43-
zlib1g-dev \
4443
${{ matrix.packages }}
4544
- name: Build
4645
run: |
@@ -239,8 +238,8 @@ jobs:
239238
- uses: actions/cache@v5
240239
with:
241240
path: ~/ccache.tar.xz
242-
key: switch-${{ steps.get-time.outputs.time }}
243-
restore-keys: switch-
241+
key: mingw-${{ steps.get-time.outputs.time }}
242+
restore-keys: mingw-
244243
- name: Unpack cache
245244
run: cd ~ && [ -f ccache.tar.xz ] && tar xf ccache.tar.xz || true
246245
- name: Checkout Repository

.github/workflows/publish.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ jobs:
1212
include:
1313
- name: x86_64 SDL 2
1414
flags: '-DNBC_PLATFORM=sdl2 -DNBC_GFX_API=OGL'
15-
packages: 'libsdl2-dev libopenal-dev zlib1g-dev'
15+
packages: 'libsdl2-dev libopenal-dev'
1616
runner: ubuntu-24.04
1717
arch: x86_64
1818
- name: i686 SDL 2
1919
flags: '-DNBC_PLATFORM=sdl2 -DNBC_GFX_API=OGL -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32'
20-
packages: 'gcc-multilib g++-multilib libsdl2-dev:i386 libopenal-dev:i386 zlib1g-dev:i386'
20+
packages: 'gcc-multilib g++-multilib libsdl2-dev:i386 libopenal-dev:i386'
2121
runner: ubuntu-22.04
2222
arch: i686
2323
- name: aarch64 SDL 2
2424
flags: '-DNBC_PLATFORM=sdl2 -DNBC_GFX_API=OGL'
25-
packages: 'libsdl2-dev libopenal-dev zlib1g-dev'
25+
packages: 'libsdl2-dev libopenal-dev'
2626
runner: ubuntu-24.04-arm
2727
arch: aarch64
2828
name: Linux (${{ matrix.name }})

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ if(NOT NINTENDO_SWITCH)
1212
endif()
1313

1414
# Warnings
15-
add_compile_options(-Wall -Wignored-qualifiers -Wvariadic-macros -pedantic -Wno-long-long -Wno-c++11-long-long -Wno-newline-eof -Wno-empty-translation-unit)
16-
1715
if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND
1816
CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12)
1917
set(ENABLE_WCXX11_EXTENSIONS ON)
@@ -24,6 +22,8 @@ if (ENABLE_WCXX11_EXTENSIONS)
2422
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Wc++11-extensions>)
2523
endif()
2624

25+
add_compile_options(-Wall -Wignored-qualifiers -Wvariadic-macros -pedantic -Wno-long-long -Wno-c++11-long-long -Wno-newline-eof -Wno-empty-translation-unit)
26+
2727
if(WERROR)
2828
add_compile_options(-Werror)
2929
endif()

platforms/ios/build.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ for target in $targets; do
186186
-DCMAKE_SYSTEM_NAME=Darwin \
187187
-DNBC_PLATFORM=ios \
188188
-DCMAKE_FIND_ROOT_PATH_MODE_PACKAGE=ONLY \
189-
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=ONLY \
190189
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY \
191190
-DCMAKE_AR="$(command -v "$ar")" \
192191
-DCMAKE_RANLIB="$(command -v "$ranlib")" \

platforms/sdl/sdl2/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ if(NBC_GFX_API STREQUAL "OGL")
6767
target_link_libraries(nbcraft-core PUBLIC "${GLES_LIB}")
6868
target_compile_definitions(nbcraft-core PUBLIC USE_GLES)
6969
elseif(NINTENDO_SWITCH)
70-
target_link_libraries(nbcraft-core PUBLIC glapi GLESv1_CM drm_nouveau)
70+
find_package(OpenGL REQUIRED)
71+
target_link_libraries(nbcraft-core PUBLIC OpenGL::EGL GLESv1_CM)
7172
target_compile_definitions(nbcraft-core PUBLIC USE_GLES)
7273
else()
7374
find_package(OpenGL REQUIRED)

source/CMakeLists.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -624,19 +624,19 @@ target_link_libraries(nbcraft-core PUBLIC raknet)
624624

625625
# zlib
626626
add_library(zlib-interface INTERFACE)
627-
if(NBC_WIN32 OR XENON) # @TODO: libXenon has zlib included, how do we get to it?
628-
# Compile Vendored ZLib
629-
add_subdirectory(../thirdparty/zlib zlib)
630-
target_link_libraries(zlib-interface INTERFACE zlib)
627+
if (NBC_SYSTEM_ZLIB)
628+
# Use System ZLib, might be useful for some weird platform that needs to patch zlib
629+
find_package(ZLIB REQUIRED)
630+
target_link_libraries(zlib-interface INTERFACE ZLIB::ZLIB)
631631
elseif(EMSCRIPTEN)
632632
# Use Emscripten's ZLib
633633
set(ZLIB_FLAG -sUSE_ZLIB=1)
634634
target_compile_options(zlib-interface INTERFACE "${ZLIB_FLAG}")
635635
target_link_options(zlib-interface INTERFACE "${ZLIB_FLAG}")
636636
else()
637-
# Use System ZLib
638-
find_package(ZLIB REQUIRED)
639-
target_link_libraries(zlib-interface INTERFACE ZLIB::ZLIB)
637+
# Compile Vendored ZLib
638+
add_subdirectory(../thirdparty/zlib zlib)
639+
target_link_libraries(zlib-interface INTERFACE zlib)
640640
endif()
641641
target_link_libraries(nbcraft-core PUBLIC zlib-interface)
642642

thirdparty/zlib/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Copyright notice:
22

3-
(C) 1995-2022 Jean-loup Gailly and Mark Adler
3+
(C) 1995-2026 Jean-loup Gailly and Mark Adler
44

55
This software is provided 'as-is', without any express or implied
66
warranty. In no event will the authors be held liable for any damages

thirdparty/zlib/compress.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* compress.c -- compress a memory buffer
2-
* Copyright (C) 1995-2005, 2014, 2016 Jean-loup Gailly, Mark Adler
2+
* Copyright (C) 1995-2026 Jean-loup Gailly, Mark Adler
33
* For conditions of distribution and use, see copyright notice in zlib.h
44
*/
55

@@ -18,13 +18,19 @@
1818
compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough
1919
memory, Z_BUF_ERROR if there was not enough room in the output buffer,
2020
Z_STREAM_ERROR if the level parameter is invalid.
21+
22+
The _z versions of the functions take size_t length arguments.
2123
*/
22-
int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
23-
uLong sourceLen, int level) {
24+
int ZEXPORT compress2_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
25+
z_size_t sourceLen, int level) {
2426
z_stream stream;
2527
int err;
2628
const uInt max = (uInt)-1;
27-
uLong left;
29+
z_size_t left;
30+
31+
if ((sourceLen > 0 && source == NULL) ||
32+
destLen == NULL || (*destLen > 0 && dest == NULL))
33+
return Z_STREAM_ERROR;
2834

2935
left = *destLen;
3036
*destLen = 0;
@@ -43,23 +49,36 @@ int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
4349

4450
do {
4551
if (stream.avail_out == 0) {
46-
stream.avail_out = left > (uLong)max ? max : (uInt)left;
52+
stream.avail_out = left > (z_size_t)max ? max : (uInt)left;
4753
left -= stream.avail_out;
4854
}
4955
if (stream.avail_in == 0) {
50-
stream.avail_in = sourceLen > (uLong)max ? max : (uInt)sourceLen;
56+
stream.avail_in = sourceLen > (z_size_t)max ? max :
57+
(uInt)sourceLen;
5158
sourceLen -= stream.avail_in;
5259
}
5360
err = deflate(&stream, sourceLen ? Z_NO_FLUSH : Z_FINISH);
5461
} while (err == Z_OK);
5562

56-
*destLen = stream.total_out;
63+
*destLen = (z_size_t)(stream.next_out - dest);
5764
deflateEnd(&stream);
5865
return err == Z_STREAM_END ? Z_OK : err;
5966
}
60-
67+
int ZEXPORT compress2(Bytef *dest, uLongf *destLen, const Bytef *source,
68+
uLong sourceLen, int level) {
69+
int ret;
70+
z_size_t got = *destLen;
71+
ret = compress2_z(dest, &got, source, sourceLen, level);
72+
*destLen = (uLong)got;
73+
return ret;
74+
}
6175
/* ===========================================================================
6276
*/
77+
int ZEXPORT compress_z(Bytef *dest, z_size_t *destLen, const Bytef *source,
78+
z_size_t sourceLen) {
79+
return compress2_z(dest, destLen, source, sourceLen,
80+
Z_DEFAULT_COMPRESSION);
81+
}
6382
int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
6483
uLong sourceLen) {
6584
return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
@@ -69,7 +88,12 @@ int ZEXPORT compress(Bytef *dest, uLongf *destLen, const Bytef *source,
6988
If the default memLevel or windowBits for deflateInit() is changed, then
7089
this function needs to be updated.
7190
*/
91+
z_size_t ZEXPORT compressBound_z(z_size_t sourceLen) {
92+
z_size_t bound = sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
93+
(sourceLen >> 25) + 13;
94+
return bound < sourceLen ? (z_size_t)-1 : bound;
95+
}
7296
uLong ZEXPORT compressBound(uLong sourceLen) {
73-
return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) +
74-
(sourceLen >> 25) + 13;
97+
z_size_t bound = compressBound_z(sourceLen);
98+
return (uLong)bound != bound ? (uLong)-1 : (uLong)bound;
7599
}

0 commit comments

Comments
 (0)