extzstd 0.3.2 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/contrib/zstd/CHANGELOG +225 -1
- data/contrib/zstd/CONTRIBUTING.md +158 -75
- data/contrib/zstd/LICENSE +4 -4
- data/contrib/zstd/Makefile +106 -69
- data/contrib/zstd/Package.swift +36 -0
- data/contrib/zstd/README.md +64 -36
- data/contrib/zstd/SECURITY.md +15 -0
- data/contrib/zstd/TESTING.md +2 -3
- data/contrib/zstd/lib/BUCK +5 -7
- data/contrib/zstd/lib/Makefile +117 -199
- data/contrib/zstd/lib/README.md +37 -7
- data/contrib/zstd/lib/common/allocations.h +55 -0
- data/contrib/zstd/lib/common/bits.h +200 -0
- data/contrib/zstd/lib/common/bitstream.h +80 -86
- data/contrib/zstd/lib/common/compiler.h +225 -63
- data/contrib/zstd/lib/common/cpu.h +37 -1
- data/contrib/zstd/lib/common/debug.c +7 -1
- data/contrib/zstd/lib/common/debug.h +21 -12
- data/contrib/zstd/lib/common/entropy_common.c +15 -37
- data/contrib/zstd/lib/common/error_private.c +9 -2
- data/contrib/zstd/lib/common/error_private.h +93 -5
- data/contrib/zstd/lib/common/fse.h +12 -87
- data/contrib/zstd/lib/common/fse_decompress.c +37 -117
- data/contrib/zstd/lib/common/huf.h +97 -172
- data/contrib/zstd/lib/common/mem.h +58 -58
- data/contrib/zstd/lib/common/pool.c +38 -17
- data/contrib/zstd/lib/common/pool.h +10 -4
- data/contrib/zstd/lib/common/portability_macros.h +158 -0
- data/contrib/zstd/lib/common/threading.c +74 -14
- data/contrib/zstd/lib/common/threading.h +5 -10
- data/contrib/zstd/lib/common/xxhash.c +6 -814
- data/contrib/zstd/lib/common/xxhash.h +6930 -195
- data/contrib/zstd/lib/common/zstd_common.c +1 -36
- data/contrib/zstd/lib/common/zstd_deps.h +1 -1
- data/contrib/zstd/lib/common/zstd_internal.h +68 -154
- data/contrib/zstd/lib/common/zstd_trace.h +163 -0
- data/contrib/zstd/lib/compress/clevels.h +134 -0
- data/contrib/zstd/lib/compress/fse_compress.c +75 -155
- data/contrib/zstd/lib/compress/hist.c +1 -1
- data/contrib/zstd/lib/compress/hist.h +1 -1
- data/contrib/zstd/lib/compress/huf_compress.c +810 -259
- data/contrib/zstd/lib/compress/zstd_compress.c +2864 -919
- data/contrib/zstd/lib/compress/zstd_compress_internal.h +523 -192
- data/contrib/zstd/lib/compress/zstd_compress_literals.c +117 -40
- data/contrib/zstd/lib/compress/zstd_compress_literals.h +16 -6
- data/contrib/zstd/lib/compress/zstd_compress_sequences.c +28 -19
- data/contrib/zstd/lib/compress/zstd_compress_sequences.h +1 -1
- data/contrib/zstd/lib/compress/zstd_compress_superblock.c +251 -412
- data/contrib/zstd/lib/compress/zstd_compress_superblock.h +1 -1
- data/contrib/zstd/lib/compress/zstd_cwksp.h +284 -97
- data/contrib/zstd/lib/compress/zstd_double_fast.c +382 -133
- data/contrib/zstd/lib/compress/zstd_double_fast.h +14 -2
- data/contrib/zstd/lib/compress/zstd_fast.c +732 -260
- data/contrib/zstd/lib/compress/zstd_fast.h +3 -2
- data/contrib/zstd/lib/compress/zstd_lazy.c +1177 -390
- data/contrib/zstd/lib/compress/zstd_lazy.h +129 -14
- data/contrib/zstd/lib/compress/zstd_ldm.c +280 -210
- data/contrib/zstd/lib/compress/zstd_ldm.h +3 -2
- data/contrib/zstd/lib/compress/zstd_ldm_geartab.h +106 -0
- data/contrib/zstd/lib/compress/zstd_opt.c +516 -285
- data/contrib/zstd/lib/compress/zstd_opt.h +32 -8
- data/contrib/zstd/lib/compress/zstdmt_compress.c +202 -131
- data/contrib/zstd/lib/compress/zstdmt_compress.h +9 -6
- data/contrib/zstd/lib/decompress/huf_decompress.c +1149 -555
- data/contrib/zstd/lib/decompress/huf_decompress_amd64.S +595 -0
- data/contrib/zstd/lib/decompress/zstd_ddict.c +4 -4
- data/contrib/zstd/lib/decompress/zstd_ddict.h +1 -1
- data/contrib/zstd/lib/decompress/zstd_decompress.c +583 -106
- data/contrib/zstd/lib/decompress/zstd_decompress_block.c +1054 -379
- data/contrib/zstd/lib/decompress/zstd_decompress_block.h +14 -3
- data/contrib/zstd/lib/decompress/zstd_decompress_internal.h +56 -6
- data/contrib/zstd/lib/deprecated/zbuff.h +1 -1
- data/contrib/zstd/lib/deprecated/zbuff_common.c +1 -1
- data/contrib/zstd/lib/deprecated/zbuff_compress.c +24 -4
- data/contrib/zstd/lib/deprecated/zbuff_decompress.c +3 -1
- data/contrib/zstd/lib/dictBuilder/cover.c +60 -44
- data/contrib/zstd/lib/dictBuilder/cover.h +6 -11
- data/contrib/zstd/lib/dictBuilder/divsufsort.c +1 -1
- data/contrib/zstd/lib/dictBuilder/fastcover.c +26 -18
- data/contrib/zstd/lib/dictBuilder/zdict.c +100 -101
- data/contrib/zstd/lib/legacy/zstd_legacy.h +38 -1
- data/contrib/zstd/lib/legacy/zstd_v01.c +18 -53
- data/contrib/zstd/lib/legacy/zstd_v01.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v02.c +28 -85
- data/contrib/zstd/lib/legacy/zstd_v02.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v03.c +29 -88
- data/contrib/zstd/lib/legacy/zstd_v03.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v04.c +27 -80
- data/contrib/zstd/lib/legacy/zstd_v04.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v05.c +36 -85
- data/contrib/zstd/lib/legacy/zstd_v05.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v06.c +44 -96
- data/contrib/zstd/lib/legacy/zstd_v06.h +1 -1
- data/contrib/zstd/lib/legacy/zstd_v07.c +37 -92
- data/contrib/zstd/lib/legacy/zstd_v07.h +1 -1
- data/contrib/zstd/lib/libzstd.mk +237 -0
- data/contrib/zstd/lib/libzstd.pc.in +4 -3
- data/contrib/zstd/lib/module.modulemap +35 -0
- data/contrib/zstd/lib/{dictBuilder/zdict.h → zdict.h} +202 -33
- data/contrib/zstd/lib/zstd.h +1030 -332
- data/contrib/zstd/lib/{common/zstd_errors.h → zstd_errors.h} +27 -8
- data/ext/extconf.rb +26 -7
- data/ext/extzstd.c +51 -24
- data/ext/extzstd.h +33 -6
- data/ext/extzstd_stream.c +74 -31
- data/ext/libzstd_conf.h +0 -1
- data/ext/zstd_decompress_asm.S +1 -0
- metadata +17 -7
- data/contrib/zstd/appveyor.yml +0 -292
- data/ext/depend +0 -2
data/contrib/zstd/lib/Makefile
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# ################################################################
|
2
|
-
# Copyright (c)
|
2
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
3
|
# All rights reserved.
|
4
4
|
#
|
5
5
|
# This source code is licensed under both the BSD-style license (found in the
|
@@ -8,103 +8,16 @@
|
|
8
8
|
# You may select, at your option, one of the above-listed licenses.
|
9
9
|
# ################################################################
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# define silent mode as default (verbose mode with V=1 or VERBOSE=1)
|
15
|
-
$(V)$(VERBOSE).SILENT:
|
16
|
-
|
17
|
-
# When cross-compiling from linux to windows,
|
18
|
-
# one might need to specify TARGET_SYSTEM as "Windows."
|
19
|
-
# Building from Fedora fails without it.
|
20
|
-
# (but Ubuntu and Debian don't need to set anything)
|
21
|
-
TARGET_SYSTEM ?= $(OS)
|
22
|
-
|
23
|
-
# Version numbers
|
24
|
-
LIBVER_MAJOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MAJOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
|
25
|
-
LIBVER_MINOR_SCRIPT:=`sed -n '/define ZSTD_VERSION_MINOR/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
|
26
|
-
LIBVER_PATCH_SCRIPT:=`sed -n '/define ZSTD_VERSION_RELEASE/s/.*[[:blank:]]\([0-9][0-9]*\).*/\1/p' < ./zstd.h`
|
27
|
-
LIBVER_SCRIPT:= $(LIBVER_MAJOR_SCRIPT).$(LIBVER_MINOR_SCRIPT).$(LIBVER_PATCH_SCRIPT)
|
28
|
-
LIBVER_MAJOR := $(shell echo $(LIBVER_MAJOR_SCRIPT))
|
29
|
-
LIBVER_MINOR := $(shell echo $(LIBVER_MINOR_SCRIPT))
|
30
|
-
LIBVER_PATCH := $(shell echo $(LIBVER_PATCH_SCRIPT))
|
31
|
-
LIBVER := $(shell echo $(LIBVER_SCRIPT))
|
32
|
-
VERSION?= $(LIBVER)
|
33
|
-
CCVER := $(shell $(CC) --version)
|
34
|
-
|
35
|
-
# ZSTD_LIB_MINIFY is a helper variable that
|
36
|
-
# configures a bunch of other variables to space-optimized defaults.
|
37
|
-
ZSTD_LIB_MINIFY ?= 0
|
38
|
-
ifneq ($(ZSTD_LIB_MINIFY), 0)
|
39
|
-
HAVE_CC_OZ ?= $(shell echo "" | $(CC) -Oz -x c -c - -o /dev/null 2> /dev/null && echo 1 || echo 0)
|
40
|
-
ZSTD_LEGACY_SUPPORT ?= 0
|
41
|
-
ZSTD_LIB_DEPRECATED ?= 0
|
42
|
-
HUF_FORCE_DECOMPRESS_X1 ?= 1
|
43
|
-
ZSTD_FORCE_DECOMPRESS_SHORT ?= 1
|
44
|
-
ZSTD_NO_INLINE ?= 1
|
45
|
-
ZSTD_STRIP_ERROR_STRINGS ?= 1
|
46
|
-
ifneq ($(HAVE_CC_OZ), 0)
|
47
|
-
# Some compilers (clang) support an even more space-optimized setting.
|
48
|
-
CFLAGS += -Oz
|
49
|
-
else
|
50
|
-
CFLAGS += -Os
|
51
|
-
endif
|
52
|
-
CFLAGS += -fno-stack-protector -fomit-frame-pointer -fno-ident \
|
53
|
-
-DDYNAMIC_BMI2=0 -DNDEBUG
|
54
|
-
else
|
55
|
-
CFLAGS += -O3
|
56
|
-
endif
|
57
|
-
|
58
|
-
DEBUGLEVEL ?= 0
|
59
|
-
CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
|
60
|
-
ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
|
61
|
-
CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
|
62
|
-
endif
|
63
|
-
DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
|
64
|
-
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
|
65
|
-
-Wstrict-prototypes -Wundef -Wpointer-arith \
|
66
|
-
-Wvla -Wformat=2 -Winit-self -Wfloat-equal -Wwrite-strings \
|
67
|
-
-Wredundant-decls -Wmissing-prototypes -Wc++-compat
|
68
|
-
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
|
69
|
-
FLAGS = $(CPPFLAGS) $(CFLAGS)
|
70
|
-
|
71
|
-
HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
|
72
|
-
GREP_OPTIONS ?=
|
73
|
-
ifeq ($HAVE_COLORNEVER, 1)
|
74
|
-
GREP_OPTIONS += --color=never
|
75
|
-
endif
|
76
|
-
GREP = grep $(GREP_OPTIONS)
|
77
|
-
SED_ERE_OPT ?= -E
|
78
|
-
|
79
|
-
ZSTDCOMMON_FILES := $(sort $(wildcard common/*.c))
|
80
|
-
ZSTDCOMP_FILES := $(sort $(wildcard compress/*.c))
|
81
|
-
ZSTDDECOMP_FILES := $(sort $(wildcard decompress/*.c))
|
82
|
-
ZDICT_FILES := $(sort $(wildcard dictBuilder/*.c))
|
83
|
-
ZDEPR_FILES := $(sort $(wildcard deprecated/*.c))
|
84
|
-
ZSTD_FILES := $(ZSTDCOMMON_FILES)
|
85
|
-
|
86
|
-
ifeq ($(findstring GCC,$(CCVER)),GCC)
|
87
|
-
decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
|
88
|
-
endif
|
11
|
+
# default target (when running `make` with no argument)
|
12
|
+
lib-release:
|
89
13
|
|
90
14
|
# Modules
|
91
15
|
ZSTD_LIB_COMPRESSION ?= 1
|
92
16
|
ZSTD_LIB_DECOMPRESSION ?= 1
|
93
17
|
ZSTD_LIB_DICTBUILDER ?= 1
|
94
|
-
ZSTD_LIB_DEPRECATED ?=
|
95
|
-
|
96
|
-
# Legacy support
|
97
|
-
ZSTD_LEGACY_SUPPORT ?= 5
|
98
|
-
ZSTD_LEGACY_MULTITHREADED_API ?= 0
|
99
|
-
|
100
|
-
# Build size optimizations
|
101
|
-
HUF_FORCE_DECOMPRESS_X1 ?= 0
|
102
|
-
HUF_FORCE_DECOMPRESS_X2 ?= 0
|
103
|
-
ZSTD_FORCE_DECOMPRESS_SHORT ?= 0
|
104
|
-
ZSTD_FORCE_DECOMPRESS_LONG ?= 0
|
105
|
-
ZSTD_NO_INLINE ?= 0
|
106
|
-
ZSTD_STRIP_ERROR_STRINGS ?= 0
|
18
|
+
ZSTD_LIB_DEPRECATED ?= 0
|
107
19
|
|
20
|
+
# Input variables for libzstd.mk
|
108
21
|
ifeq ($(ZSTD_LIB_COMPRESSION), 0)
|
109
22
|
ZSTD_LIB_DICTBUILDER = 0
|
110
23
|
ZSTD_LIB_DEPRECATED = 0
|
@@ -115,82 +28,45 @@ ifeq ($(ZSTD_LIB_DECOMPRESSION), 0)
|
|
115
28
|
ZSTD_LIB_DEPRECATED = 0
|
116
29
|
endif
|
117
30
|
|
31
|
+
include libzstd.mk
|
32
|
+
|
33
|
+
ZSTD_FILES := $(ZSTD_COMMON_FILES) $(ZSTD_LEGACY_FILES)
|
34
|
+
|
118
35
|
ifneq ($(ZSTD_LIB_COMPRESSION), 0)
|
119
|
-
ZSTD_FILES += $(
|
36
|
+
ZSTD_FILES += $(ZSTD_COMPRESS_FILES)
|
120
37
|
endif
|
121
38
|
|
122
39
|
ifneq ($(ZSTD_LIB_DECOMPRESSION), 0)
|
123
|
-
ZSTD_FILES += $(
|
40
|
+
ZSTD_FILES += $(ZSTD_DECOMPRESS_FILES)
|
124
41
|
endif
|
125
42
|
|
126
43
|
ifneq ($(ZSTD_LIB_DEPRECATED), 0)
|
127
|
-
ZSTD_FILES += $(
|
44
|
+
ZSTD_FILES += $(ZSTD_DEPRECATED_FILES)
|
128
45
|
endif
|
129
46
|
|
130
47
|
ifneq ($(ZSTD_LIB_DICTBUILDER), 0)
|
131
|
-
ZSTD_FILES += $(
|
132
|
-
endif
|
133
|
-
|
134
|
-
ifneq ($(HUF_FORCE_DECOMPRESS_X1), 0)
|
135
|
-
CFLAGS += -DHUF_FORCE_DECOMPRESS_X1
|
136
|
-
endif
|
137
|
-
|
138
|
-
ifneq ($(HUF_FORCE_DECOMPRESS_X2), 0)
|
139
|
-
CFLAGS += -DHUF_FORCE_DECOMPRESS_X2
|
140
|
-
endif
|
141
|
-
|
142
|
-
ifneq ($(ZSTD_FORCE_DECOMPRESS_SHORT), 0)
|
143
|
-
CFLAGS += -DZSTD_FORCE_DECOMPRESS_SHORT
|
144
|
-
endif
|
145
|
-
|
146
|
-
ifneq ($(ZSTD_FORCE_DECOMPRESS_LONG), 0)
|
147
|
-
CFLAGS += -DZSTD_FORCE_DECOMPRESS_LONG
|
148
|
-
endif
|
149
|
-
|
150
|
-
ifneq ($(ZSTD_NO_INLINE), 0)
|
151
|
-
CFLAGS += -DZSTD_NO_INLINE
|
152
|
-
endif
|
153
|
-
|
154
|
-
ifneq ($(ZSTD_STRIP_ERROR_STRINGS), 0)
|
155
|
-
CFLAGS += -DZSTD_STRIP_ERROR_STRINGS
|
48
|
+
ZSTD_FILES += $(ZSTD_DICTBUILDER_FILES)
|
156
49
|
endif
|
157
50
|
|
158
|
-
|
159
|
-
|
160
|
-
|
51
|
+
ZSTD_LOCAL_SRC := $(notdir $(ZSTD_FILES))
|
52
|
+
ZSTD_LOCAL_OBJ0 := $(ZSTD_LOCAL_SRC:.c=.o)
|
53
|
+
ZSTD_LOCAL_OBJ := $(ZSTD_LOCAL_OBJ0:.S=.o)
|
161
54
|
|
162
|
-
|
163
|
-
ifeq ($(shell test $(ZSTD_LEGACY_SUPPORT) -lt 8; echo $$?), 0)
|
164
|
-
ZSTD_FILES += $(shell ls legacy/*.c | $(GREP) 'v0[$(ZSTD_LEGACY_SUPPORT)-7]')
|
165
|
-
endif
|
166
|
-
endif
|
167
|
-
CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
|
55
|
+
VERSION := $(ZSTD_VERSION)
|
168
56
|
|
169
|
-
|
170
|
-
|
57
|
+
# Note: by default, the static library is built single-threaded and dynamic library is built
|
58
|
+
# multi-threaded. It is possible to force multi or single threaded builds by appending
|
59
|
+
# -mt or -nomt to the build target (like lib-mt for multi-threaded, lib-nomt for single-threaded).
|
171
60
|
|
172
|
-
ZSTD_SUBDIR := common compress decompress dictBuilder legacy deprecated
|
173
|
-
vpath %.c $(ZSTD_SUBDIR)
|
174
61
|
|
175
|
-
|
62
|
+
CPPFLAGS_DYNLIB += -DZSTD_MULTITHREAD # dynamic library build defaults to multi-threaded
|
63
|
+
LDFLAGS_DYNLIB += -pthread
|
64
|
+
CPPFLAGS_STATICLIB += # static library build defaults to single-threaded
|
176
65
|
|
177
|
-
ifndef BUILD_DIR
|
178
|
-
ifeq ($(UNAME), Darwin)
|
179
|
-
HASH ?= md5
|
180
|
-
else ifeq ($(UNAME), FreeBSD)
|
181
|
-
HASH ?= gmd5sum
|
182
|
-
else ifeq ($(UNAME), OpenBSD)
|
183
|
-
HASH ?= md5
|
184
|
-
endif
|
185
|
-
HASH ?= md5sum
|
186
66
|
|
187
|
-
|
188
|
-
|
189
|
-
ifeq ($(HAVE_HASH),0)
|
190
|
-
$(info warning : could not find HASH ($(HASH)), needed to differentiate builds using different flags)
|
191
|
-
BUILD_DIR := obj/generic_noconf
|
67
|
+
ifeq ($(findstring GCC,$(CCVER)),GCC)
|
68
|
+
decompress/zstd_decompress_block.o : CFLAGS+=-fno-tree-vectorize
|
192
69
|
endif
|
193
|
-
endif # BUILD_DIR
|
194
70
|
|
195
71
|
|
196
72
|
# macOS linker doesn't support -soname, and use different extension
|
@@ -201,29 +77,31 @@ ifeq ($(UNAME), Darwin)
|
|
201
77
|
SHARED_EXT_VER = $(LIBVER).$(SHARED_EXT)
|
202
78
|
SONAME_FLAGS = -install_name $(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR) -compatibility_version $(LIBVER_MAJOR) -current_version $(LIBVER)
|
203
79
|
else
|
204
|
-
|
80
|
+
ifeq ($(UNAME), AIX)
|
81
|
+
SONAME_FLAGS =
|
82
|
+
else
|
83
|
+
SONAME_FLAGS = -Wl,-soname=libzstd.$(SHARED_EXT).$(LIBVER_MAJOR)
|
84
|
+
endif
|
205
85
|
SHARED_EXT = so
|
206
86
|
SHARED_EXT_MAJOR = $(SHARED_EXT).$(LIBVER_MAJOR)
|
207
87
|
SHARED_EXT_VER = $(SHARED_EXT).$(LIBVER)
|
208
88
|
endif
|
209
89
|
|
90
|
+
|
91
|
+
.PHONY: all
|
92
|
+
all: lib
|
93
|
+
|
94
|
+
|
95
|
+
.PHONY: libzstd.a # must be run every time
|
96
|
+
libzstd.a: CPPFLAGS += $(CPPFLAGS_STATICLIB)
|
97
|
+
|
210
98
|
SET_CACHE_DIRECTORY = \
|
211
|
-
|
99
|
+
+$(MAKE) --no-print-directory $@ \
|
212
100
|
BUILD_DIR=obj/$(HASH_DIR) \
|
213
101
|
CPPFLAGS="$(CPPFLAGS)" \
|
214
102
|
CFLAGS="$(CFLAGS)" \
|
215
103
|
LDFLAGS="$(LDFLAGS)"
|
216
104
|
|
217
|
-
|
218
|
-
.PHONY: lib-all all clean install uninstall
|
219
|
-
|
220
|
-
# alias
|
221
|
-
lib-all: all
|
222
|
-
|
223
|
-
all: lib
|
224
|
-
|
225
|
-
.PHONY: libzstd.a # must be run every time
|
226
|
-
|
227
105
|
ifndef BUILD_DIR
|
228
106
|
# determine BUILD_DIR from compilation flags
|
229
107
|
|
@@ -233,16 +111,19 @@ libzstd.a:
|
|
233
111
|
else
|
234
112
|
# BUILD_DIR is defined
|
235
113
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
$(
|
240
|
-
$(
|
241
|
-
$(
|
242
|
-
|
114
|
+
ZSTD_STATICLIB_DIR := $(BUILD_DIR)/static
|
115
|
+
ZSTD_STATICLIB := $(ZSTD_STATICLIB_DIR)/libzstd.a
|
116
|
+
ZSTD_STATICLIB_OBJ := $(addprefix $(ZSTD_STATICLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
|
117
|
+
$(ZSTD_STATICLIB): ARFLAGS = rcs
|
118
|
+
$(ZSTD_STATICLIB): | $(ZSTD_STATICLIB_DIR)
|
119
|
+
$(ZSTD_STATICLIB): $(ZSTD_STATICLIB_OBJ)
|
120
|
+
# Check for multithread flag at target execution time
|
121
|
+
$(if $(filter -DZSTD_MULTITHREAD,$(CPPFLAGS)),\
|
122
|
+
@echo compiling multi-threaded static library $(LIBVER),\
|
123
|
+
@echo compiling single-threaded static library $(LIBVER))
|
243
124
|
$(AR) $(ARFLAGS) $@ $^
|
244
125
|
|
245
|
-
libzstd.a: $(
|
126
|
+
libzstd.a: $(ZSTD_STATICLIB)
|
246
127
|
cp -f $< $@
|
247
128
|
|
248
129
|
endif
|
@@ -258,8 +139,9 @@ else # not Windows
|
|
258
139
|
|
259
140
|
LIBZSTD = libzstd.$(SHARED_EXT_VER)
|
260
141
|
.PHONY: $(LIBZSTD) # must be run every time
|
261
|
-
$(LIBZSTD):
|
262
|
-
$(LIBZSTD):
|
142
|
+
$(LIBZSTD): CPPFLAGS += $(CPPFLAGS_DYNLIB)
|
143
|
+
$(LIBZSTD): CFLAGS += -fPIC -fvisibility=hidden
|
144
|
+
$(LIBZSTD): LDFLAGS += -shared $(LDFLAGS_DYNLIB)
|
263
145
|
|
264
146
|
ifndef BUILD_DIR
|
265
147
|
# determine BUILD_DIR from compilation flags
|
@@ -276,7 +158,10 @@ ZSTD_DYNLIB_OBJ := $(addprefix $(ZSTD_DYNLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
|
|
276
158
|
|
277
159
|
$(ZSTD_DYNLIB): | $(ZSTD_DYNLIB_DIR)
|
278
160
|
$(ZSTD_DYNLIB): $(ZSTD_DYNLIB_OBJ)
|
279
|
-
|
161
|
+
# Check for multithread flag at target execution time
|
162
|
+
$(if $(filter -DZSTD_MULTITHREAD,$(CPPFLAGS)),\
|
163
|
+
@echo compiling multi-threaded dynamic library $(LIBVER),\
|
164
|
+
@echo compiling single-threaded dynamic library $(LIBVER))
|
280
165
|
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
|
281
166
|
@echo creating versioned links
|
282
167
|
ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
|
@@ -298,10 +183,17 @@ lib : libzstd.a libzstd
|
|
298
183
|
# note : do not define lib-mt or lib-release as .PHONY
|
299
184
|
# make does not consider implicit pattern rule for .PHONY target
|
300
185
|
|
301
|
-
%-mt :
|
302
|
-
%-mt :
|
186
|
+
%-mt : CPPFLAGS_DYNLIB := -DZSTD_MULTITHREAD
|
187
|
+
%-mt : CPPFLAGS_STATICLIB := -DZSTD_MULTITHREAD
|
188
|
+
%-mt : LDFLAGS_DYNLIB := -pthread
|
303
189
|
%-mt : %
|
304
|
-
@echo multi-
|
190
|
+
@echo multi-threaded build completed
|
191
|
+
|
192
|
+
%-nomt : CPPFLAGS_DYNLIB :=
|
193
|
+
%-nomt : LDFLAGS_DYNLIB :=
|
194
|
+
%-nomt : CPPFLAGS_STATICLIB :=
|
195
|
+
%-nomt : %
|
196
|
+
@echo single-threaded build completed
|
305
197
|
|
306
198
|
%-release : DEBUGFLAGS :=
|
307
199
|
%-release : %
|
@@ -310,35 +202,55 @@ lib : libzstd.a libzstd
|
|
310
202
|
|
311
203
|
# Generate .h dependencies automatically
|
312
204
|
|
313
|
-
|
205
|
+
# -MMD: compiler generates dependency information as a side-effect of compilation, without system headers
|
206
|
+
# -MP: adds phony target for each dependency other than main file.
|
207
|
+
DEPFLAGS = -MMD -MP
|
314
208
|
|
315
|
-
|
209
|
+
# ensure that ZSTD_DYNLIB_DIR exists prior to generating %.o
|
210
|
+
$(ZSTD_DYNLIB_DIR)/%.o : %.c | $(ZSTD_DYNLIB_DIR)
|
316
211
|
@echo CC $@
|
317
|
-
$(COMPILE.c) $(DEPFLAGS) $(
|
212
|
+
$(COMPILE.c) $(DEPFLAGS) $(OUTPUT_OPTION) $<
|
318
213
|
|
319
|
-
$(
|
214
|
+
$(ZSTD_STATICLIB_DIR)/%.o : %.c | $(ZSTD_STATICLIB_DIR)
|
320
215
|
@echo CC $@
|
321
|
-
$(COMPILE.c) $(DEPFLAGS) $(
|
216
|
+
$(COMPILE.c) $(DEPFLAGS) $(OUTPUT_OPTION) $<
|
217
|
+
|
218
|
+
$(ZSTD_DYNLIB_DIR)/%.o : %.S | $(ZSTD_DYNLIB_DIR)
|
219
|
+
@echo AS $@
|
220
|
+
$(COMPILE.S) $(OUTPUT_OPTION) $<
|
221
|
+
|
222
|
+
$(ZSTD_STATICLIB_DIR)/%.o : %.S | $(ZSTD_STATICLIB_DIR)
|
223
|
+
@echo AS $@
|
224
|
+
$(COMPILE.S) $(OUTPUT_OPTION) $<
|
322
225
|
|
323
|
-
MKDIR ?= mkdir
|
324
|
-
$(BUILD_DIR) $(ZSTD_DYNLIB_DIR) $(
|
325
|
-
$(MKDIR)
|
226
|
+
MKDIR ?= mkdir -p
|
227
|
+
$(BUILD_DIR) $(ZSTD_DYNLIB_DIR) $(ZSTD_STATICLIB_DIR):
|
228
|
+
$(MKDIR) $@
|
326
229
|
|
327
|
-
DEPFILES := $(ZSTD_DYNLIB_OBJ:.o=.d) $(
|
230
|
+
DEPFILES := $(ZSTD_DYNLIB_OBJ:.o=.d) $(ZSTD_STATICLIB_OBJ:.o=.d)
|
328
231
|
$(DEPFILES):
|
329
232
|
|
330
|
-
include
|
233
|
+
# The leading '-' means: do not fail is include fails (ex: directory does not exist yet)
|
234
|
+
-include $(wildcard $(DEPFILES))
|
331
235
|
|
332
236
|
|
333
|
-
# Special case :
|
334
|
-
|
335
|
-
|
336
|
-
|
237
|
+
# Special case : build library in single-thread mode _and_ without zstdmt_compress.c
|
238
|
+
# Note : we still need threading.c and pool.c for the dictionary builder,
|
239
|
+
# but they will correctly behave single-threaded.
|
240
|
+
ZSTDMT_FILES = zstdmt_compress.c
|
241
|
+
ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(notdir $(ZSTD_FILES)))
|
242
|
+
libzstd-nomt: CFLAGS += -fPIC -fvisibility=hidden
|
243
|
+
libzstd-nomt: LDFLAGS += -shared
|
337
244
|
libzstd-nomt: $(ZSTD_NOMT_FILES)
|
338
245
|
@echo compiling single-thread dynamic library $(LIBVER)
|
339
246
|
@echo files : $(ZSTD_NOMT_FILES)
|
247
|
+
@if echo "$(ZSTD_NOMT_FILES)" | tr ' ' '\n' | $(GREP) -q zstdmt; then \
|
248
|
+
echo "Error: Found zstdmt in list."; \
|
249
|
+
exit 1; \
|
250
|
+
fi
|
340
251
|
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
|
341
252
|
|
253
|
+
.PHONY: clean
|
342
254
|
clean:
|
343
255
|
$(RM) -r *.dSYM # macOS-specific
|
344
256
|
$(RM) core *.o *.a *.gcda *.$(SHARED_EXT) *.$(SHARED_EXT).* libzstd.pc
|
@@ -349,9 +261,9 @@ clean:
|
|
349
261
|
#-----------------------------------------------------------------------------
|
350
262
|
# make install is validated only for below listed environments
|
351
263
|
#-----------------------------------------------------------------------------
|
352
|
-
ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku))
|
264
|
+
ifneq (,$(filter $(UNAME),Linux Darwin GNU/kFreeBSD GNU OpenBSD FreeBSD NetBSD DragonFly SunOS Haiku AIX MSYS_NT CYGWIN_NT))
|
353
265
|
|
354
|
-
|
266
|
+
lib: libzstd.pc
|
355
267
|
|
356
268
|
HAS_EXPLICIT_EXEC_PREFIX := $(if $(or $(EXEC_PREFIX),$(exec_prefix)),1,)
|
357
269
|
|
@@ -396,24 +308,27 @@ INSTALL_PROGRAM ?= $(INSTALL)
|
|
396
308
|
INSTALL_DATA ?= $(INSTALL) -m 644
|
397
309
|
|
398
310
|
|
399
|
-
libzstd.pc:
|
400
311
|
libzstd.pc: libzstd.pc.in
|
401
312
|
@echo creating pkgconfig
|
402
|
-
@sed
|
313
|
+
@sed \
|
403
314
|
-e 's|@PREFIX@|$(PREFIX)|' \
|
404
315
|
-e 's|@EXEC_PREFIX@|$(PCEXEC_PREFIX)|' \
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
316
|
+
-e 's|@INCLUDEDIR@|$(PCINCPREFIX)$(PCINCDIR)|' \
|
317
|
+
-e 's|@LIBDIR@|$(PCLIBPREFIX)$(PCLIBDIR)|' \
|
318
|
+
-e 's|@VERSION@|$(VERSION)|' \
|
319
|
+
-e 's|@LIBS_PRIVATE@|$(LDFLAGS_DYNLIB)|' \
|
320
|
+
$< >$@
|
409
321
|
|
322
|
+
.PHONY: install
|
410
323
|
install: install-pc install-static install-shared install-includes
|
411
324
|
@echo zstd static and shared library installed
|
412
325
|
|
326
|
+
.PHONY: install-pc
|
413
327
|
install-pc: libzstd.pc
|
414
328
|
[ -e $(DESTDIR)$(PKGCONFIGDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
|
415
329
|
$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
|
416
330
|
|
331
|
+
.PHONY: install-static
|
417
332
|
install-static:
|
418
333
|
# only generate libzstd.a if it's not already present
|
419
334
|
[ -e libzstd.a ] || $(MAKE) libzstd.a-release
|
@@ -421,6 +336,7 @@ install-static:
|
|
421
336
|
@echo Installing static library
|
422
337
|
$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
|
423
338
|
|
339
|
+
.PHONY: install-shared
|
424
340
|
install-shared:
|
425
341
|
# only generate libzstd.so if it's not already present
|
426
342
|
[ -e $(LIBZSTD) ] || $(MAKE) libzstd-release
|
@@ -430,13 +346,15 @@ install-shared:
|
|
430
346
|
ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
|
431
347
|
ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
|
432
348
|
|
349
|
+
.PHONY: install-includes
|
433
350
|
install-includes:
|
434
351
|
[ -e $(DESTDIR)$(INCLUDEDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
|
435
352
|
@echo Installing includes
|
436
353
|
$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
|
437
|
-
$(INSTALL_DATA)
|
438
|
-
$(INSTALL_DATA)
|
354
|
+
$(INSTALL_DATA) zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
|
355
|
+
$(INSTALL_DATA) zdict.h $(DESTDIR)$(INCLUDEDIR)
|
439
356
|
|
357
|
+
.PHONY: uninstall
|
440
358
|
uninstall:
|
441
359
|
$(RM) $(DESTDIR)$(LIBDIR)/libzstd.a
|
442
360
|
$(RM) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
|
data/contrib/zstd/lib/README.md
CHANGED
@@ -19,12 +19,16 @@ The scope can be reduced on demand (see paragraph _modular build_).
|
|
19
19
|
|
20
20
|
#### Multithreading support
|
21
21
|
|
22
|
-
|
22
|
+
When building with `make`, by default the dynamic library is multithreaded and static library is single-threaded (for compatibility reasons).
|
23
|
+
|
23
24
|
Enabling multithreading requires 2 conditions :
|
24
25
|
- set build macro `ZSTD_MULTITHREAD` (`-DZSTD_MULTITHREAD` for `gcc`)
|
25
26
|
- for POSIX systems : compile with pthread (`-pthread` compilation flag for `gcc`)
|
26
27
|
|
27
|
-
|
28
|
+
For convenience, we provide a build target to generate multi and single threaded libraries:
|
29
|
+
- Force enable multithreading on both dynamic and static libraries by appending `-mt` to the target, e.g. `make lib-mt`.
|
30
|
+
- Force disable multithreading on both dynamic and static libraries by appending `-nomt` to the target, e.g. `make lib-nomt`.
|
31
|
+
- By default, as mentioned before, dynamic library is multithreaded, and static library is single-threaded, e.g. `make lib`.
|
28
32
|
|
29
33
|
When linking a POSIX program with a multithreaded version of `libzstd`,
|
30
34
|
note that it's necessary to invoke the `-pthread` flag during link stage.
|
@@ -42,8 +46,8 @@ Zstandard's stable API is exposed within [lib/zstd.h](zstd.h).
|
|
42
46
|
|
43
47
|
Optional advanced features are exposed via :
|
44
48
|
|
45
|
-
- `lib/
|
46
|
-
|
49
|
+
- `lib/zstd_errors.h` : translates `size_t` function results
|
50
|
+
into a `ZSTD_ErrorCode`, for accurate error handling.
|
47
51
|
|
48
52
|
- `ZSTD_STATIC_LINKING_ONLY` : if this macro is defined _before_ including `zstd.h`,
|
49
53
|
it unlocks access to the experimental API,
|
@@ -84,10 +88,10 @@ The file structure is designed to make this selection manually achievable for an
|
|
84
88
|
For example, advanced API for version `v0.4` is exposed in `lib/legacy/zstd_v04.h` .
|
85
89
|
|
86
90
|
- While invoking `make libzstd`, it's possible to define build macros
|
87
|
-
`ZSTD_LIB_COMPRESSION
|
91
|
+
`ZSTD_LIB_COMPRESSION`, `ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`,
|
88
92
|
and `ZSTD_LIB_DEPRECATED` as `0` to forgo compilation of the
|
89
93
|
corresponding features. This will also disable compilation of all
|
90
|
-
dependencies (
|
94
|
+
dependencies (e.g. `ZSTD_LIB_COMPRESSION=0` will also disable
|
91
95
|
dictBuilder).
|
92
96
|
|
93
97
|
- There are a number of options that can help minimize the binary size of
|
@@ -115,13 +119,22 @@ The file structure is designed to make this selection manually achievable for an
|
|
115
119
|
binary is achieved by using `HUF_FORCE_DECOMPRESS_X1` and
|
116
120
|
`ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT` (implied by `ZSTD_LIB_MINIFY`).
|
117
121
|
|
122
|
+
On the compressor side, Zstd's compression levels map to several internal
|
123
|
+
strategies. In environments where the higher compression levels aren't used,
|
124
|
+
it is possible to exclude all but the fastest strategy with
|
125
|
+
`ZSTD_LIB_EXCLUDE_COMPRESSORS_DFAST_AND_UP=1`. (Note that this will change
|
126
|
+
the behavior of the default compression level.) Or if you want to retain the
|
127
|
+
default compressor as well, you can set
|
128
|
+
`ZSTD_LIB_EXCLUDE_COMPRESSORS_GREEDY_AND_UP=1`, at the cost of an additional
|
129
|
+
~20KB or so.
|
130
|
+
|
118
131
|
For squeezing the last ounce of size out, you can also define
|
119
132
|
`ZSTD_NO_INLINE`, which disables inlining, and `ZSTD_STRIP_ERROR_STRINGS`,
|
120
133
|
which removes the error messages that are otherwise returned by
|
121
134
|
`ZSTD_getErrorName` (implied by `ZSTD_LIB_MINIFY`).
|
122
135
|
|
123
136
|
Finally, when integrating into your application, make sure you're doing link-
|
124
|
-
time
|
137
|
+
time optimization and unused symbol garbage collection (via some combination of,
|
125
138
|
e.g., `-flto`, `-ffat-lto-objects`, `-fuse-linker-plugin`,
|
126
139
|
`-ffunction-sections`, `-fdata-sections`, `-fmerge-all-constants`,
|
127
140
|
`-Wl,--gc-sections`, `-Wl,-z,norelro`, and an archiver that understands
|
@@ -151,6 +164,23 @@ The file structure is designed to make this selection manually achievable for an
|
|
151
164
|
- The build macro `ZSTD_NO_INTRINSICS` can be defined to disable all explicit intrinsics.
|
152
165
|
Compiler builtins are still used.
|
153
166
|
|
167
|
+
- The build macro `ZSTD_DECODER_INTERNAL_BUFFER` can be set to control
|
168
|
+
the amount of extra memory used during decompression to store literals.
|
169
|
+
This defaults to 64kB. Reducing this value reduces the memory footprint of
|
170
|
+
`ZSTD_DCtx` decompression contexts,
|
171
|
+
but might also result in a small decompression speed cost.
|
172
|
+
|
173
|
+
- The C compiler macros `ZSTDLIB_VISIBLE`, `ZSTDERRORLIB_VISIBLE` and `ZDICTLIB_VISIBLE`
|
174
|
+
can be overridden to control the visibility of zstd's API. Additionally,
|
175
|
+
`ZSTDLIB_STATIC_API` and `ZDICTLIB_STATIC_API` can be overridden to control the visibility
|
176
|
+
of zstd's static API. Specifically, it can be set to `ZSTDLIB_HIDDEN` to hide the symbols
|
177
|
+
from the shared library. These macros default to `ZSTDLIB_VISIBILITY`,
|
178
|
+
`ZSTDERRORLIB_VSIBILITY`, and `ZDICTLIB_VISIBILITY` if unset, for backwards compatibility
|
179
|
+
with the old macro names.
|
180
|
+
|
181
|
+
- The C compiler macro `HUF_DISABLE_FAST_DECODE` disables the newer Huffman fast C
|
182
|
+
and assembly decoding loops. You may want to use this macro if these loops are
|
183
|
+
slower on your platform.
|
154
184
|
|
155
185
|
#### Windows : using MinGW+MSYS to create DLL
|
156
186
|
|
@@ -0,0 +1,55 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
+
* All rights reserved.
|
4
|
+
*
|
5
|
+
* This source code is licensed under both the BSD-style license (found in the
|
6
|
+
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
7
|
+
* 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.
|
9
|
+
*/
|
10
|
+
|
11
|
+
/* This file provides custom allocation primitives
|
12
|
+
*/
|
13
|
+
|
14
|
+
#define ZSTD_DEPS_NEED_MALLOC
|
15
|
+
#include "zstd_deps.h" /* ZSTD_malloc, ZSTD_calloc, ZSTD_free, ZSTD_memset */
|
16
|
+
|
17
|
+
#include "compiler.h" /* MEM_STATIC */
|
18
|
+
#define ZSTD_STATIC_LINKING_ONLY
|
19
|
+
#include "../zstd.h" /* ZSTD_customMem */
|
20
|
+
|
21
|
+
#ifndef ZSTD_ALLOCATIONS_H
|
22
|
+
#define ZSTD_ALLOCATIONS_H
|
23
|
+
|
24
|
+
/* custom memory allocation functions */
|
25
|
+
|
26
|
+
MEM_STATIC void* ZSTD_customMalloc(size_t size, ZSTD_customMem customMem)
|
27
|
+
{
|
28
|
+
if (customMem.customAlloc)
|
29
|
+
return customMem.customAlloc(customMem.opaque, size);
|
30
|
+
return ZSTD_malloc(size);
|
31
|
+
}
|
32
|
+
|
33
|
+
MEM_STATIC void* ZSTD_customCalloc(size_t size, ZSTD_customMem customMem)
|
34
|
+
{
|
35
|
+
if (customMem.customAlloc) {
|
36
|
+
/* calloc implemented as malloc+memset;
|
37
|
+
* not as efficient as calloc, but next best guess for custom malloc */
|
38
|
+
void* const ptr = customMem.customAlloc(customMem.opaque, size);
|
39
|
+
ZSTD_memset(ptr, 0, size);
|
40
|
+
return ptr;
|
41
|
+
}
|
42
|
+
return ZSTD_calloc(1, size);
|
43
|
+
}
|
44
|
+
|
45
|
+
MEM_STATIC void ZSTD_customFree(void* ptr, ZSTD_customMem customMem)
|
46
|
+
{
|
47
|
+
if (ptr!=NULL) {
|
48
|
+
if (customMem.customFree)
|
49
|
+
customMem.customFree(customMem.opaque, ptr);
|
50
|
+
else
|
51
|
+
ZSTD_free(ptr);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
|
55
|
+
#endif /* ZSTD_ALLOCATIONS_H */
|