Skip to content

Commit cb47741

Browse files
author
haruyama.makoto
committed
Update zstd to v1.4.5
1 parent 4104960 commit cb47741

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3297
-1694
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ See https://github.com/facebook/zstd
1010
Fork from https://github.com/jarredholman/ruby-zstd.
1111

1212
## Zstd version
13-
v1.4.4 (https://github.com/facebook/zstd/tree/v1.4.4)
13+
v1.4.5 (https://github.com/facebook/zstd/tree/v1.4.5)
1414

1515
## Installation
1616

ext/zstdruby/libzstd/Makefile

Lines changed: 123 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
# ################################################################
2-
# Copyright (c) 2015-present, Yann Collet, Facebook, Inc.
2+
# Copyright (c) 2015-2020, Yann Collet, Facebook, Inc.
33
# All rights reserved.
44
#
55
# This source code is licensed under both the BSD-style license (found in the
66
# LICENSE file in the root directory of this source tree) and the GPLv2 (found
77
# in the COPYING file in the root directory of this source tree).
8+
# You may select, at your option, one of the above-listed licenses.
89
# ################################################################
910

11+
Q = $(if $(filter 1,$(V) $(VERBOSE)),,@)
12+
13+
# When cross-compiling from linux to windows, you might
14+
# need to specify this as "Windows." Fedora build fails
15+
# without it.
16+
#
17+
# Note: mingw-w64 build from linux to windows does not
18+
# fail on other tested distros (ubuntu, debian) even
19+
# without manually specifying the TARGET_SYSTEM.
20+
TARGET_SYSTEM ?= $(OS)
21+
1022
# Version numbers
1123
LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
1224
LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
@@ -19,11 +31,10 @@ LIBVER := $(shell echo $(LIBVER_SCRIPT))
1931
VERSION?= $(LIBVER)
2032
CCVER := $(shell $(CC) --version)
2133

22-
CPPFLAGS+= -I. -I./common -DXXH_NAMESPACE=ZSTD_
23-
ifeq ($(OS),Windows_NT) # MinGW assumed
34+
CPPFLAGS+= -DXXH_NAMESPACE=ZSTD_
35+
ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
2436
CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
2537
endif
26-
CFLAGS ?= -O3
2738
DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
2839
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
2940
-Wstrict-prototypes -Wundef -Wpointer-arith \
@@ -50,18 +61,46 @@ ifeq ($(findstring GCC,$(CCVER)),GCC)
5061
decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
5162
endif
5263

53-
ZSTD_LEGACY_SUPPORT ?= 5
64+
# This is a helper variable that configures a bunch of other variables to new,
65+
# space-optimized defaults.
66+
ZSTD_LIB_MINIFY ?= 0
67+
ifneq ($(ZSTD_LIB_MINIFY), 0)
68+
HAVE_CC_OZ ?= $(shell echo "" | $(CC) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
69+
ZSTD_LEGACY_SUPPORT ?= 0
70+
ZSTD_LIB_DEPRECATED ?= 0
71+
HUF_FORCE_DECOMPRESS_X1 ?= 1
72+
ZSTD_FORCE_DECOMPRESS_SHORT ?= 1
73+
ZSTD_NO_INLINE ?= 1
74+
ZSTD_STRIP_ERROR_STRINGS ?= 1
75+
ifneq ($(HAVE_CC_OZ), 0)
76+
# Some compilers (clang) support an even more space-optimized setting.
77+
CFLAGS += -Oz
78+
else
79+
CFLAGS += -Os
80+
endif
81+
CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
82+
-DDYNAMIC_BMI2=0 -DNDEBUG
83+
else
84+
CFLAGS += -O3
85+
endif
86+
87+
# Modules
5488
ZSTD_LIB_COMPRESSION ?= 1
5589
ZSTD_LIB_DECOMPRESSION ?= 1
5690
ZSTD_LIB_DICTBUILDER ?= 1
5791
ZSTD_LIB_DEPRECATED ?= 1
92+
93+
# Legacy support
94+
ZSTD_LEGACY_SUPPORT ?= 5
95+
ZSTD_LEGACY_MULTITHREADED_API ?= 0
96+
97+
# Build size optimizations
5898
HUF_FORCE_DECOMPRESS_X1 ?= 0
5999
HUF_FORCE_DECOMPRESS_X2 ?= 0
60100
ZSTD_FORCE_DECOMPRESS_SHORT ?= 0
61101
ZSTD_FORCE_DECOMPRESS_LONG ?= 0
62102
ZSTD_NO_INLINE ?= 0
63103
ZSTD_STRIP_ERROR_STRINGS ?= 0
64-
ZSTD_LEGACY_MULTITHREADED_API ?= 0
65104

66105
ifeq ($(ZSTD_LIB_COMPRESSION), 0)
67106
ZSTD_LIB_DICTBUILDER = 0
@@ -121,7 +160,6 @@ ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
121160
ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
122161
ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
123162
endif
124-
CPPFLAGS += -I./legacy
125163
endif
126164
CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
127165

@@ -142,54 +180,57 @@ else
142180
endif
143181

144182

145-
.PHONY: default all clean install uninstall
183+
.PHONY: default lib-all all clean install uninstall
146184

147185
default: lib-release
148186

187+
# alias
188+
lib-all: all
189+
149190
all: lib
150191

151192
libzstd.a: ARFLAGS = rcs
152193
libzstd.a: $(ZSTD_OBJ)
153194
@echo compiling static library
154-
@$(AR) $(ARFLAGS) $@ $^
155-
156-
libzstd.a-mt: CPPFLAGS += -DZSTD_MULTITHREAD
157-
libzstd.a-mt: libzstd.a
195+
$(Q)$(AR) $(ARFLAGS) $@ $^
158196

159-
ifneq (,$(filter Windows%,$(OS)))
197+
ifneq (,$(filter Windows%,$(TARGET_SYSTEM)))
160198

161199
LIBZSTD = dll\libzstd.dll
162200
$(LIBZSTD): $(ZSTD_FILES)
163201
@echo compiling dynamic library $(LIBVER)
164-
$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.lib -shared $^ -o $@
202+
$(CC) $(FLAGS) -DZSTD_DLL_EXPORT=1 -Wl,--out-implib,dll\libzstd.dll.a -shared $^ -o $@
165203

166204
else
167205

168206
LIBZSTD = libzstd.$(SHARED_EXT_VER)
169207
$(LIBZSTD): LDFLAGS += -shared -fPIC -fvisibility=hidden
170208
$(LIBZSTD): $(ZSTD_FILES)
171209
@echo compiling dynamic library $(LIBVER)
172-
@$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
210+
$(Q)$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
173211
@echo creating versioned links
174-
@ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
175-
@ln -sf $@ libzstd.$(SHARED_EXT)
212+
$(Q)ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
213+
$(Q)ln -sf $@ libzstd.$(SHARED_EXT)
176214

177215
endif
178216

179-
217+
.PHONY: libzstd
180218
libzstd : $(LIBZSTD)
181219

182-
libzstd-mt : CPPFLAGS += -DZSTD_MULTITHREAD
183-
libzstd-mt : libzstd
220+
.PHONY: lib
221+
lib : libzstd.a libzstd
184222

185-
lib: libzstd.a libzstd
223+
.PHONY: lib-mt
224+
%-mt : CPPFLAGS += -DZSTD_MULTITHREAD
225+
%-mt : LDFLAGS += -pthread
226+
%-mt : %
227+
@echo multi-threading build completed
186228

187-
lib-mt: CPPFLAGS += -DZSTD_MULTITHREAD
188-
lib-mt: lib
229+
.PHONY: lib-release
230+
%-release : DEBUGFLAGS :=
231+
%-release : %
232+
@echo release build completed
189233

190-
lib-release lib-release-mt: DEBUGFLAGS :=
191-
lib-release: lib
192-
lib-release-mt: lib-mt
193234

194235
# Special case : building library in single-thread mode _and_ without zstdmt_compress.c
195236
ZSTDMT_FILES = compress/zstdmt_compress.c
@@ -198,32 +239,54 @@ libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden
198239
libzstd-nomt: $(ZSTD_NOMT_FILES)
199240
@echo compiling single-thread dynamic library $(LIBVER)
200241
@echo files : $(ZSTD_NOMT_FILES)
201-
@$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
242+
$(Q)$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
202243

203244
clean:
204-
@$(RM) -r *.dSYM # macOS-specific
205-
@$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
206-
@$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt*
207-
@$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o
245+
$(Q)$(RM) -r *.dSYM # macOS-specific
246+
$(Q)$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
247+
$(Q)$(RM) dll/libzstd.dll dll/libzstd.lib libzstd-nomt*
248+
$(Q)$(RM) common/*.o compress/*.o decompress/*.o dictBuilder/*.o legacy/*.o deprecated/*.o
208249
@echo Cleaning library completed
209250

210251
#-----------------------------------------------------------------------------
211-
# make install is validated only for Linux, macOS, BSD, Hurd and Solaris targets
252+
# make install is validated only for below listed environments
212253
#-----------------------------------------------------------------------------
213254
ifneq (,$(filter $(shell uname),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku))
214255

256+
all: libzstd.pc
257+
215258
DESTDIR ?=
216259
# directory variables : GNU conventions prefer lowercase
217260
# see https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html
218261
# support both lower and uppercase (BSD), use uppercase in script
219262
prefix ?= /usr/local
220263
PREFIX ?= $(prefix)
221264
exec_prefix ?= $(PREFIX)
222-
libdir ?= $(exec_prefix)/lib
265+
EXEC_PREFIX ?= $(exec_prefix)
266+
libdir ?= $(EXEC_PREFIX)/lib
223267
LIBDIR ?= $(libdir)
224268
includedir ?= $(PREFIX)/include
225269
INCLUDEDIR ?= $(includedir)
226270

271+
PCLIBDIR ?= $(shell echo "$(LIBDIR)" | sed -n -E -e "s@^$(EXEC_PREFIX)(/|$$)@@p")
272+
PCINCDIR ?= $(shell echo "$(INCLUDEDIR)" | sed -n -E -e "s@^$(PREFIX)(/|$$)@@p")
273+
274+
ifeq (,$(PCLIBDIR))
275+
# Additional prefix check is required, since the empty string is technically a
276+
# valid PCLIBDIR
277+
ifeq (,$(shell echo "$(LIBDIR)" | sed -n -E -e "\\@^$(EXEC_PREFIX)(/|$$)@ p"))
278+
$(error configured libdir ($(LIBDIR)) is outside of prefix ($(PREFIX)), can't generate pkg-config file)
279+
endif
280+
endif
281+
282+
ifeq (,$(PCINCDIR))
283+
# Additional prefix check is required, since the empty string is technically a
284+
# valid PCINCDIR
285+
ifeq (,$(shell echo "$(INCLUDEDIR)" | sed -n -E -e "\\@^$(PREFIX)(/|$$)@ p"))
286+
$(error configured includedir ($(INCLUDEDIR)) is outside of exec_prefix ($(EXEC_PREFIX)), can't generate pkg-config file)
287+
endif
288+
endif
289+
227290
ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly))
228291
PKGCONFIGDIR ?= $(PREFIX)/libdata/pkgconfig
229292
else
@@ -243,47 +306,49 @@ INSTALL_DATA ?= $(INSTALL) -m 644
243306
libzstd.pc:
244307
libzstd.pc: libzstd.pc.in
245308
@echo creating pkgconfig
246-
@sed -e 's|@PREFIX@|$(PREFIX)|' \
247-
-e 's|@VERSION@|$(VERSION)|' \
248-
$< >$@
309+
$(Q)@sed -E -e 's|@PREFIX@|$(PREFIX)|' \
310+
-e 's|@LIBDIR@|$(PCLIBDIR)|' \
311+
-e 's|@INCLUDEDIR@|$(PCINCDIR)|' \
312+
-e 's|@VERSION@|$(VERSION)|' \
313+
$< >$@
249314

250315
install: install-pc install-static install-shared install-includes
251316
@echo zstd static and shared library installed
252317

253318
install-pc: libzstd.pc
254-
@$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
255-
@$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
319+
$(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
320+
$(Q)$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
256321

257322
install-static: libzstd.a
258323
@echo Installing static library
259-
@$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
260-
@$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
324+
$(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
325+
$(Q)$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
261326

262327
install-shared: libzstd
263328
@echo Installing shared library
264-
@$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
265-
@$(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR)
266-
@ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
267-
@ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
329+
$(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
330+
$(Q)$(INSTALL_PROGRAM) $(LIBZSTD) $(DESTDIR)$(LIBDIR)
331+
$(Q)ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
332+
$(Q)ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
268333

269334
install-includes:
270335
@echo Installing includes
271-
@$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
272-
@$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
273-
@$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
274-
@$(INSTALL_DATA) deprecated/zbuff.h $(DESTDIR)$(INCLUDEDIR) # prototypes generate deprecation warnings
275-
@$(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR)
336+
$(Q)$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
337+
$(Q)$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
338+
$(Q)$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
339+
$(Q)$(INSTALL_DATA) deprecated/zbuff.h $(DESTDIR)$(INCLUDEDIR) # prototypes generate deprecation warnings
340+
$(Q)$(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR)
276341

277342
uninstall:
278-
@$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
279-
@$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
280-
@$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
281-
@$(RM) $(DESTDIR)$(LIBDIR)/$(LIBZSTD)
282-
@$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc
283-
@$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h
284-
@$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h
285-
@$(RM) $(DESTDIR)$(INCLUDEDIR)/zbuff.h # Deprecated streaming functions
286-
@$(RM) $(DESTDIR)$(INCLUDEDIR)/zdict.h
343+
$(Q)$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
344+
$(Q)$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
345+
$(Q)$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
346+
$(Q)$(RM) $(DESTDIR)$(LIBDIR)/$(LIBZSTD)
347+
$(Q)$(RM) $(DESTDIR)$(PKGCONFIGDIR)/libzstd.pc
348+
$(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd.h
349+
$(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/zstd_errors.h
350+
$(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/zbuff.h # Deprecated streaming functions
351+
$(Q)$(RM) $(DESTDIR)$(INCLUDEDIR)/zdict.h
287352
@echo zstd libraries successfully uninstalled
288353

289354
endif

ext/zstdruby/libzstd/README.md

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,28 +85,48 @@ The file structure is designed to make this selection manually achievable for an
8585

8686
- While invoking `make libzstd`, it's possible to define build macros
8787
`ZSTD_LIB_COMPRESSION, ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`,
88-
and `ZSTD_LIB_DEPRECATED` as `0` to forgo compilation of the corresponding features.
89-
This will also disable compilation of all dependencies
90-
(eg. `ZSTD_LIB_COMPRESSION=0` will also disable dictBuilder).
91-
92-
- There are some additional build macros that can be used to minify the decoder.
93-
94-
Zstandard often has more than one implementation of a piece of functionality,
95-
where each implementation optimizes for different scenarios. For example, the
96-
Huffman decoder has complementary implementations that decode the stream one
97-
symbol at a time or two symbols at a time. Zstd normally includes both (and
98-
dispatches between them at runtime), but by defining `HUF_FORCE_DECOMPRESS_X1`
99-
or `HUF_FORCE_DECOMPRESS_X2`, you can force the use of one or the other, avoiding
88+
and `ZSTD_LIB_DEPRECATED` as `0` to forgo compilation of the
89+
corresponding features. This will also disable compilation of all
90+
dependencies (eg. `ZSTD_LIB_COMPRESSION=0` will also disable
91+
dictBuilder).
92+
93+
- There are a number of options that can help minimize the binary size of
94+
`libzstd`.
95+
96+
The first step is to select the components needed (using the above-described
97+
`ZSTD_LIB_COMPRESSION` etc.).
98+
99+
The next step is to set `ZSTD_LIB_MINIFY` to `1` when invoking `make`. This
100+
disables various optional components and changes the compilation flags to
101+
prioritize space-saving.
102+
103+
Detailed options: Zstandard's code and build environment is set up by default
104+
to optimize above all else for performance. In pursuit of this goal, Zstandard
105+
makes significant trade-offs in code size. For example, Zstandard often has
106+
more than one implementation of a particular component, with each
107+
implementation optimized for different scenarios. For example, the Huffman
108+
decoder has complementary implementations that decode the stream one symbol at
109+
a time or two symbols at a time. Zstd normally includes both (and dispatches
110+
between them at runtime), but by defining `HUF_FORCE_DECOMPRESS_X1` or
111+
`HUF_FORCE_DECOMPRESS_X2`, you can force the use of one or the other, avoiding
100112
compilation of the other. Similarly, `ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT`
101113
and `ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG` force the compilation and use of
102114
only one or the other of two decompression implementations. The smallest
103115
binary is achieved by using `HUF_FORCE_DECOMPRESS_X1` and
104-
`ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT`.
116+
`ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT` (implied by `ZSTD_LIB_MINIFY`).
105117

106118
For squeezing the last ounce of size out, you can also define
107119
`ZSTD_NO_INLINE`, which disables inlining, and `ZSTD_STRIP_ERROR_STRINGS`,
108120
which removes the error messages that are otherwise returned by
109-
`ZSTD_getErrorName`.
121+
`ZSTD_getErrorName` (implied by `ZSTD_LIB_MINIFY`).
122+
123+
Finally, when integrating into your application, make sure you're doing link-
124+
time optimation and unused symbol garbage collection (via some combination of,
125+
e.g., `-flto`, `-ffat-lto-objects`, `-fuse-linker-plugin`,
126+
`-ffunction-sections`, `-fdata-sections`, `-fmerge-all-constants`,
127+
`-Wl,--gc-sections`, `-Wl,-z,norelro`, and an archiver that understands
128+
the compiler's intermediate representation, e.g., `AR=gcc-ar`). Consult your
129+
compiler's documentation.
110130

111131
- While invoking `make libzstd`, the build macro `ZSTD_LEGACY_MULTITHREADED_API=1`
112132
will expose the deprecated `ZSTDMT` API exposed by `zstdmt_compress.h` in

0 commit comments

Comments
 (0)