Skip to content

Commit 8dad5a8

Browse files
committed
feat: Update zstd to v1.5.1
1 parent ced2558 commit 8dad5a8

Some content is hidden

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

59 files changed

+11132
-3333
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.5.0 (https://github.com/facebook/zstd/tree/v1.5.0)
13+
v1.5.1 (https://github.com/facebook/zstd/tree/v1.5.1)
1414

1515
## Installation
1616

ext/zstdruby/libzstd/Makefile

Lines changed: 50 additions & 175 deletions
Original file line numberDiff line numberDiff line change
@@ -8,110 +8,13 @@
88
# You may select, at your option, one of the above-listed licenses.
99
# ################################################################
1010

11-
# Note: by default, the static library is built single-threaded and dynamic library is built
12-
# multi-threaded. It is possible to force multi or single threaded builds by appending
13-
# -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
14-
.PHONY: default
15-
default: lib-release
16-
17-
# define silent mode as default (verbose mode with V=1 or VERBOSE=1)
18-
$(V)$(VERBOSE).SILENT:
19-
20-
# When cross-compiling from linux to windows,
21-
# one might need to specify TARGET_SYSTEM as "Windows."
22-
# Building from Fedora fails without it.
23-
# (but Ubuntu and Debian don't need to set anything)
24-
TARGET_SYSTEM ?= $(OS)
25-
26-
# Version numbers
27-
LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
28-
LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
29-
LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
30-
LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
31-
LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
32-
LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
33-
LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
34-
LIBVER := $(shell echo $(LIBVER_SCRIPT))
35-
VERSION?= $(LIBVER)
36-
CCVER := $(shell $(CC) --version)
37-
38-
# ZSTD_LIB_MINIFY is a helper variable that
39-
# configures a bunch of other variables to space-optimized defaults.
40-
ZSTD_LIB_MINIFY ?= 0
41-
ifneq ($(ZSTD_LIB_MINIFY), 0)
42-
HAVE_CC_OZ ?= $(shell echo "" | $(CC) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
43-
ZSTD_LEGACY_SUPPORT ?= 0
44-
ZSTD_LIB_DEPRECATED ?= 0
45-
HUF_FORCE_DECOMPRESS_X1 ?= 1
46-
ZSTD_FORCE_DECOMPRESS_SHORT ?= 1
47-
ZSTD_NO_INLINE ?= 1
48-
ZSTD_STRIP_ERROR_STRINGS ?= 1
49-
ifneq ($(HAVE_CC_OZ), 0)
50-
# Some compilers (clang) support an even more space-optimized setting.
51-
CFLAGS += -Oz
52-
else
53-
CFLAGS += -Os
54-
endif
55-
CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
56-
-DDYNAMIC_BMI2=0 -DNDEBUG
57-
else
58-
CFLAGS += -O3
59-
endif
60-
61-
DEBUGLEVEL ?= 0
62-
CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
63-
ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
64-
CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
65-
endif
66-
DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
67-
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
68-
-Wstrict-prototypes -Wundef -Wpointer-arith \
69-
-Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
70-
-Wredundant-decls -Wmissing-prototypes -Wc++-compat
71-
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
72-
FLAGS = $(CPPFLAGS) $(CFLAGS)
73-
74-
CPPFLAGS_DYNLIB = -DZSTD_MULTITHREAD # dynamic library build defaults to multi-threaded
75-
LDFLAGS_DYNLIB = -pthread
76-
CPPFLAGS_STATLIB = # static library build defaults to single-threaded
77-
78-
HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
79-
GREP_OPTIONS ?=
80-
ifeq ($HAVE_COLORNEVER, 1)
81-
GREP_OPTIONS += --color=never
82-
endif
83-
GREP = grep $(GREP_OPTIONS)
84-
SED_ERE_OPT ?= -E
85-
86-
ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c))
87-
ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c))
88-
ZSTDDECOMP_FILES := $(sort $(wildcard decompress/*.c))
89-
ZDICT_FILES := $(sort $(wildcard dictBuilder/*.c))
90-
ZDEPR_FILES := $(sort $(wildcard deprecated/*.c))
91-
ZSTD_FILES := $(ZSTDCOMMON_FILES)
92-
93-
ifeq ($(findstring GCC,$(CCVER)),GCC)
94-
decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
95-
endif
96-
9711
# Modules
9812
ZSTD_LIB_COMPRESSION ?= 1
9913
ZSTD_LIB_DECOMPRESSION ?= 1
10014
ZSTD_LIB_DICTBUILDER ?= 1
10115
ZSTD_LIB_DEPRECATED ?= 0
10216

103-
# Legacy support
104-
ZSTD_LEGACY_SUPPORT ?= 5
105-
ZSTD_LEGACY_MULTITHREADED_API ?= 0
106-
107-
# Build size optimizations
108-
HUF_FORCE_DECOMPRESS_X1 ?= 0
109-
HUF_FORCE_DECOMPRESS_X2 ?= 0
110-
ZSTD_FORCE_DECOMPRESS_SHORT ?= 0
111-
ZSTD_FORCE_DECOMPRESS_LONG ?= 0
112-
ZSTD_NO_INLINE ?= 0
113-
ZSTD_STRIP_ERROR_STRINGS ?= 0
114-
17+
# Input variables for libzstd.mk
11518
ifeq ($(ZSTD_LIB_COMPRESSION), 0)
11619
ZSTD_LIB_DICTBUILDER = 0
11720
ZSTD_LIB_DEPRECATED = 0
@@ -122,86 +25,46 @@ ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
12225
ZSTD_LIB_DEPRECATED = 0
12326
endif
12427

28+
include libzstd.mk
29+
30+
ZSTD_FILES := $(ZSTD_COMMON_FILES) $(ZSTD_LEGACY_FILES)
31+
12532
ifneq ($(ZSTD_LIB_COMPRESSION), 0)
126-
ZSTD_FILES += $(ZSTDCOMP_FILES)
33+
ZSTD_FILES += $(ZSTD_COMPRESS_FILES)
12734
endif
12835

12936
ifneq ($(ZSTD_LIB_DECOMPRESSION), 0)
130-
ZSTD_FILES += $(ZSTDDECOMP_FILES)
37+
ZSTD_FILES += $(ZSTD_DECOMPRESS_FILES)
13138
endif
13239

13340
ifneq ($(ZSTD_LIB_DEPRECATED), 0)
134-
ZSTD_FILES += $(ZDEPR_FILES)
41+
ZSTD_FILES += $(ZSTD_DEPRECATED_FILES)
13542
endif
13643

13744
ifneq ($(ZSTD_LIB_DICTBUILDER), 0)
138-
ZSTD_FILES += $(ZDICT_FILES)
139-
endif
140-
141-
ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0)
142-
CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
143-
endif
144-
145-
ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0)
146-
CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
147-
endif
148-
149-
ifneq ($(ZSTD_FORCE_DECOMPRESS_SHORT), 0)
150-
CFLAGS += -DZSTD_FORCE_DECOMPRESS_SHORT
151-
endif
152-
153-
ifneq ($(ZSTD_FORCE_DECOMPRESS_LONG), 0)
154-
CFLAGS += -DZSTD_FORCE_DECOMPRESS_LONG
155-
endif
156-
157-
ifneq ($(ZSTD_NO_INLINE), 0)
158-
CFLAGS += -DZSTD_NO_INLINE
159-
endif
160-
161-
ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0)
162-
CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
45+
ZSTD_FILES += $(ZSTD_DICTBUILDER_FILES)
16346
endif
16447

165-
ifneq ($(ZSTD_LEGACY_MULTITHREADED_API), 0)
166-
CFLAGS += -DZSTD_LEGACY_MULTITHREADED_API
167-
endif
168-
169-
ifneq ($(ZSTD_LEGACY_SUPPORT), 0)
170-
ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
171-
ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
172-
endif
173-
endif
174-
CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
175-
17648
ZSTD_LOCAL_SRC := $(notdir $(ZSTD_FILES))
177-
ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_SRC:.c=.o)
49+
ZSTD_LOCAL_OBJ0 := $(ZSTD_LOCAL_SRC:.c=.o)
50+
ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_OBJ0:.S=.o)
17851

179-
ZSTD_SUBDIR := common compress decompress dictBuilder legacy deprecated
180-
vpath %.c $(ZSTD_SUBDIR)
52+
VERSION := $(ZSTD_VERSION)
18153

182-
UNAME := $(shell uname)
54+
# Note: by default, the static library is built single-threaded and dynamic library is built
55+
# multi-threaded. It is possible to force multi or single threaded builds by appending
56+
# -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
57+
.PHONY: default
58+
default: lib-release
59+
60+
CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # dynamic library build defaults to multi-threaded
61+
LDFLAGS_DYNLIB += -pthread
62+
CPPFLAGS_STATLIB += # static library build defaults to single-threaded
18363

184-
ifndef BUILD_DIR
185-
ifeq ($(UNAME), Darwin)
186-
ifeq ($(shell md5 < /dev/null > /dev/null; echo $$?), 0)
187-
HASH ?= md5
188-
endif
189-
else ifeq ($(UNAME), FreeBSD)
190-
HASH ?= gmd5sum
191-
else ifeq ($(UNAME), NetBSD)
192-
HASH ?= md5 -n
193-
else ifeq ($(UNAME), OpenBSD)
194-
HASH ?= md5
195-
endif
196-
HASH ?= md5sum
19764

198-
HASH_DIR = conf_$(shell echo $(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(ZSTD_FILES) | $(HASH) | cut -f 1 -d " " )
199-
HAVE_HASH :=$(shell echo 1 | $(HASH) > /dev/null && echo 1 || echo 0)
200-
ifeq ($(HAVE_HASH),0)
201-
$(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
202-
BUILD_DIR := obj/generic_noconf
65+
ifeq ($(findstring GCC,$(CCVER)),GCC)
66+
decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
20367
endif
204-
endif # BUILD_DIR
20568

20669

20770
# macOS linker doesn't support -soname, and use different extension
@@ -212,19 +75,16 @@ ifeq ($(UNAME), Darwin)
21275
SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
21376
SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
21477
else
215-
SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
78+
ifeq ($(UNAME), AIX)
79+
SONAME_FLAGS =
80+
else
81+
SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
82+
endif
21683
SHARED_EXT = so
21784
SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
21885
SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
21986
endif
22087

221-
SET_CACHE_DIRECTORY = \
222-
+$(MAKE) --no-print-directory $@ \
223-
BUILD_DIR=obj/$(HASH_DIR) \
224-
CPPFLAGS="$(CPPFLAGS)" \
225-
CFLAGS="$(CFLAGS)" \
226-
LDFLAGS="$(LDFLAGS)"
227-
22888

22989
.PHONY: all
23090
all: lib
@@ -233,6 +93,13 @@ all: lib
23393
.PHONY: libzstd.a # must be run every time
23494
libzstd.a: CPPFLAGS += $(CPPFLAGS_STATLIB)
23595

96+
SET_CACHE_DIRECTORY = \
97+
+$(MAKE) --no-print-directory $@ \
98+
BUILD_DIR=obj/$(HASH_DIR) \
99+
CPPFLAGS="$(CPPFLAGS)" \
100+
CFLAGS="$(CFLAGS)" \
101+
LDFLAGS="$(LDFLAGS)"
102+
236103
ifndef BUILD_DIR
237104
# determine BUILD_DIR from compilation flags
238105

@@ -343,6 +210,14 @@ $(ZSTD_STATLIB_DIR)/%.o : %.c $(ZSTD_STATLIB_DIR)/%.d | $(ZSTD_STATLIB_DIR)
343210
@echo CC $@
344211
$(COMPILE.c) $(DEPFLAGS) $(ZSTD_STATLIB_DIR)/$*.d $(OUTPUT_OPTION) $<
345212

213+
$(ZSTD_DYNLIB_DIR)/%.o : %.S | $(ZSTD_DYNLIB_DIR)
214+
@echo AS $@
215+
$(COMPILE.c) $(OUTPUT_OPTION) $<
216+
217+
$(ZSTD_STATLIB_DIR)/%.o : %.S | $(ZSTD_STATLIB_DIR)
218+
@echo AS $@
219+
$(COMPILE.c) $(OUTPUT_OPTION) $<
220+
346221
MKDIR ?= mkdir
347222
$(BUILD_DIR) $(ZSTD_DYNLIB_DIR) $(ZSTD_STATLIB_DIR):
348223
$(MKDIR) -p $@
@@ -374,9 +249,9 @@ clean:
374249
#-----------------------------------------------------------------------------
375250
# make install is validated only for below listed environments
376251
#-----------------------------------------------------------------------------
377-
ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku))
252+
ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX))
378253

379-
all: libzstd.pc
254+
lib: libzstd.pc
380255

381256
HAS_EXPLICIT_EXEC_PREFIX := $(if $(or $(EXEC_PREFIX),$(exec_prefix)),1,)
382257

@@ -421,16 +296,16 @@ INSTALL_PROGRAM ?= $(INSTALL)
421296
INSTALL_DATA ?= $(INSTALL) -m 644
422297

423298

424-
libzstd.pc:
425299
libzstd.pc: libzstd.pc.in
426300
@echo creating pkgconfig
427301
@sed $(SED_ERE_OPT) \
428302
-e 's|@PREFIX@|$(PREFIX)|' \
429303
-e 's|@EXEC_PREFIX@|$(PCEXEC_PREFIX)|' \
430-
-e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
431-
-e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
432-
-e 's|@VERSION@|$(VERSION)|' \
433-
$< >$@
304+
-e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
305+
-e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
306+
-e 's|@VERSION@|$(VERSION)|' \
307+
-e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \
308+
$< >$@
434309

435310
.PHONY: install
436311
install: install-pc install-static install-shared install-includes

ext/zstdruby/libzstd/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ The file structure is designed to make this selection manually achievable for an
125125
`ZSTD_getErrorName` (implied by `ZSTD_LIB_MINIFY`).
126126

127127
Finally, when integrating into your application, make sure you're doing link-
128-
time optimation and unused symbol garbage collection (via some combination of,
128+
time optimization and unused symbol garbage collection (via some combination of,
129129
e.g., `-flto`, `-ffat-lto-objects`, `-fuse-linker-plugin`,
130130
`-ffunction-sections`, `-fdata-sections`, `-fmerge-all-constants`,
131131
`-Wl,--gc-sections`, `-Wl,-z,norelro`, and an archiver that understands
@@ -155,6 +155,12 @@ The file structure is designed to make this selection manually achievable for an
155155
- The build macro `ZSTD_NO_INTRINSICS` can be defined to disable all explicit intrinsics.
156156
Compiler builtins are still used.
157157

158+
- The build macro `ZSTD_DECODER_INTERNAL_BUFFER` can be set to control
159+
the amount of extra memory used during decompression to store literals.
160+
This defaults to 64kB. Reducing this value reduces the memory footprint of
161+
`ZSTD_DCtx` decompression contexts,
162+
but might also result in a small decompression speed cost.
163+
158164

159165
#### Windows : using MinGW+MSYS to create DLL
160166

0 commit comments

Comments
 (0)