Skip to content

Commit 75be501

Browse files
authored
Merge pull request #31 from arthurschreiber/arthur/upgrade-zstd
feat: update zstd to v1.5.0
2 parents e9d6cac + fccf57b commit 75be501

Some content is hidden

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

87 files changed

+3393
-1192
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.9 (https://github.com/facebook/zstd/tree/v1.4.9)
13+
v1.5.0 (https://github.com/facebook/zstd/tree/v1.5.0)
1414

1515
## Installation
1616

ext/zstdruby/libzstd/BUCK

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,7 @@ cxx_library(
6565
name='zdict',
6666
header_namespace='',
6767
visibility=['PUBLIC'],
68-
exported_headers=subdir_glob([
69-
('dictBuilder', 'zdict.h'),
70-
]),
68+
exported_headers=['zdict.h'],
7169
headers=subdir_glob([
7270
('dictBuilder', 'divsufsort.h'),
7371
('dictBuilder', 'cover.h'),
@@ -131,10 +129,10 @@ cxx_library(
131129
name='errors',
132130
header_namespace='',
133131
visibility=['PUBLIC'],
134-
exported_headers=subdir_glob([
135-
('common', 'error_private.h'),
136-
('common', 'zstd_errors.h'),
137-
]),
132+
exported_headers=[
133+
'zstd_errors.h',
134+
'common/error_private.h',
135+
]
138136
srcs=['common/error_private.c'],
139137
)
140138

ext/zstdruby/libzstd/Makefile

Lines changed: 42 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# ################################################################
2-
# Copyright (c) 2015-2021, Yann Collet, Facebook, Inc.
2+
# Copyright (c) Yann Collet, Facebook, Inc.
33
# All rights reserved.
44
#
55
# This source code is licensed under both the BSD-style license (found in the
@@ -8,6 +8,9 @@
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).
1114
.PHONY: default
1215
default: lib-release
1316

@@ -68,6 +71,10 @@ DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
6871
CFLAGS += $(DEBUGFLAGS) $(MOREFLAGS)
6972
FLAGS = $(CPPFLAGS) $(CFLAGS)
7073

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+
7178
HAVE_COLORNEVER = $(shell echo a | grep --color=never a > /dev/null 2> /dev/null && echo 1 || echo 0)
7279
GREP_OPTIONS ?=
7380
ifeq ($HAVE_COLORNEVER, 1)
@@ -91,7 +98,7 @@ endif
9198
ZSTD_LIB_COMPRESSION ?= 1
9299
ZSTD_LIB_DECOMPRESSION ?= 1
93100
ZSTD_LIB_DICTBUILDER ?= 1
94-
ZSTD_LIB_DEPRECATED ?= 1
101+
ZSTD_LIB_DEPRECATED ?= 0
95102

96103
# Legacy support
97104
ZSTD_LEGACY_SUPPORT ?= 5
@@ -176,7 +183,9 @@ UNAME := $(shell uname)
176183

177184
ifndef BUILD_DIR
178185
ifeq ($(UNAME), Darwin)
179-
HASH ?= md5
186+
ifeq ($(shell md5 < /dev/null > /dev/null; echo $$?), 0)
187+
HASH ?= md5
188+
endif
180189
else ifeq ($(UNAME), FreeBSD)
181190
HASH ?= gmd5sum
182191
else ifeq ($(UNAME), NetBSD)
@@ -222,6 +231,7 @@ all: lib
222231

223232

224233
.PHONY: libzstd.a # must be run every time
234+
libzstd.a: CPPFLAGS += $(CPPFLAGS_STATLIB)
225235

226236
ifndef BUILD_DIR
227237
# determine BUILD_DIR from compilation flags
@@ -238,7 +248,10 @@ ZSTD_STATLIB_OBJ := $(addprefix $(ZSTD_STATLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
238248
$(ZSTD_STATLIB): ARFLAGS = rcs
239249
$(ZSTD_STATLIB): | $(ZSTD_STATLIB_DIR)
240250
$(ZSTD_STATLIB): $(ZSTD_STATLIB_OBJ)
241-
@echo compiling static library
251+
# Check for multithread flag at target execution time
252+
$(if $(filter -DZSTD_MULTITHREAD,$(CPPFLAGS)),\
253+
@echo compiling multi-threaded static library $(LIBVER),\
254+
@echo compiling single-threaded static library $(LIBVER))
242255
$(AR) $(ARFLAGS) $@ $^
243256

244257
libzstd.a: $(ZSTD_STATLIB)
@@ -257,8 +270,9 @@ else # not Windows
257270

258271
LIBZSTD = libzstd.$(SHARED_EXT_VER)
259272
.PHONY: $(LIBZSTD) # must be run every time
260-
$(LIBZSTD): CFLAGS += -fPIC -fvisibility=hidden
261-
$(LIBZSTD): LDFLAGS += -shared
273+
$(LIBZSTD): CPPFLAGS += $(CPPFLAGS_DYNLIB)
274+
$(LIBZSTD): CFLAGS += -fPIC -fvisibility=hidden
275+
$(LIBZSTD): LDFLAGS += -shared $(LDFLAGS_DYNLIB)
262276

263277
ifndef BUILD_DIR
264278
# determine BUILD_DIR from compilation flags
@@ -275,7 +289,10 @@ ZSTD_DYNLIB_OBJ := $(addprefix $(ZSTD_DYNLIB_DIR)/,$(ZSTD_LOCAL_OBJ))
275289

276290
$(ZSTD_DYNLIB): | $(ZSTD_DYNLIB_DIR)
277291
$(ZSTD_DYNLIB): $(ZSTD_DYNLIB_OBJ)
278-
@echo compiling dynamic library $(LIBVER)
292+
# Check for multithread flag at target execution time
293+
$(if $(filter -DZSTD_MULTITHREAD,$(CPPFLAGS)),\
294+
@echo compiling multi-threaded dynamic library $(LIBVER),\
295+
@echo compiling single-threaded dynamic library $(LIBVER))
279296
$(CC) $(FLAGS) $^ $(LDFLAGS) $(SONAME_FLAGS) -o $@
280297
@echo creating versioned links
281298
ln -sf $@ libzstd.$(SHARED_EXT_MAJOR)
@@ -297,10 +314,17 @@ lib : libzstd.a libzstd
297314
# note : do not define lib-mt or lib-release as .PHONY
298315
# make does not consider implicit pattern rule for .PHONY target
299316

300-
%-mt : CPPFLAGS += -DZSTD_MULTITHREAD
301-
%-mt : LDFLAGS += -pthread
317+
%-mt : CPPFLAGS_DYNLIB := -DZSTD_MULTITHREAD
318+
%-mt : CPPFLAGS_STATLIB := -DZSTD_MULTITHREAD
319+
%-mt : LDFLAGS_DYNLIB := -pthread
302320
%-mt : %
303-
@echo multi-threading build completed
321+
@echo multi-threaded build completed
322+
323+
%-nomt : CPPFLAGS_DYNLIB :=
324+
%-nomt : LDFLAGS_DYNLIB :=
325+
%-nomt : CPPFLAGS_STATLIB :=
326+
%-nomt : %
327+
@echo single-threaded build completed
304328

305329
%-release : DEBUGFLAGS :=
306330
%-release : %
@@ -332,7 +356,8 @@ include $(wildcard $(DEPFILES))
332356
# Special case : building library in single-thread mode _and_ without zstdmt_compress.c
333357
ZSTDMT_FILES = compress/zstdmt_compress.c
334358
ZSTD_NOMT_FILES = $(filter-out $(ZSTDMT_FILES),$(ZSTD_FILES))
335-
libzstd-nomt: LDFLAGS += -shared -fPIC -fvisibility=hidden
359+
libzstd-nomt: CFLAGS += -fPIC -fvisibility=hidden
360+
libzstd-nomt: LDFLAGS += -shared
336361
libzstd-nomt: $(ZSTD_NOMT_FILES)
337362
@echo compiling single-thread dynamic library $(LIBVER)
338363
@echo files : $(ZSTD_NOMT_FILES)
@@ -411,17 +436,20 @@ libzstd.pc: libzstd.pc.in
411436
install: install-pc install-static install-shared install-includes
412437
@echo zstd static and shared library installed
413438

439+
.PHONY: install-pc
414440
install-pc: libzstd.pc
415441
[ -e $(DESTDIR)$(PKGCONFIGDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(PKGCONFIGDIR)/
416442
$(INSTALL_DATA) libzstd.pc $(DESTDIR)$(PKGCONFIGDIR)/
417443

444+
.PHONY: install-static
418445
install-static:
419446
# only generate libzstd.a if it's not already present
420447
[ -e libzstd.a ] || $(MAKE) libzstd.a-release
421448
[ -e $(DESTDIR)$(LIBDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(LIBDIR)/
422449
@echo Installing static library
423450
$(INSTALL_DATA) libzstd.a $(DESTDIR)$(LIBDIR)
424451

452+
.PHONY: install-shared
425453
install-shared:
426454
# only generate libzstd.so if it's not already present
427455
[ -e $(LIBZSTD) ] || $(MAKE) libzstd-release
@@ -431,12 +459,13 @@ install-shared:
431459
ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT_MAJOR)
432460
ln -sf $(LIBZSTD) $(DESTDIR)$(LIBDIR)/libzstd.$(SHARED_EXT)
433461

462+
.PHONY: install-includes
434463
install-includes:
435464
[ -e $(DESTDIR)$(INCLUDEDIR) ] || $(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/
436465
@echo Installing includes
437466
$(INSTALL_DATA) zstd.h $(DESTDIR)$(INCLUDEDIR)
438-
$(INSTALL_DATA) common/zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
439-
$(INSTALL_DATA) dictBuilder/zdict.h $(DESTDIR)$(INCLUDEDIR)
467+
$(INSTALL_DATA) zstd_errors.h $(DESTDIR)$(INCLUDEDIR)
468+
$(INSTALL_DATA) zdict.h $(DESTDIR)$(INCLUDEDIR)
440469

441470
.PHONY: uninstall
442471
uninstall:

ext/zstdruby/libzstd/README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ The scope can be reduced on demand (see paragraph _modular build_).
1919

2020
#### Multithreading support
2121

22-
Multithreading is disabled by default when building with `make`.
22+
When building with `make`, by default the dynamic library is multithreaded and static library is single-threaded (for compatibility reasons).
23+
2324
Enabling multithreading requires 2 conditions :
2425
- set build macro `ZSTD_MULTITHREAD` (`-DZSTD_MULTITHREAD` for `gcc`)
2526
- for POSIX systems : compile with pthread (`-pthread` compilation flag for `gcc`)
2627

27-
Both conditions are automatically applied when invoking `make lib-mt` target.
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`.
2832

2933
When linking a POSIX program with a multithreaded version of `libzstd`,
3034
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).
4246

4347
Optional advanced features are exposed via :
4448

45-
- `lib/common/zstd_errors.h` : translates `size_t` function results
46-
into a `ZSTD_ErrorCode`, for accurate error handling.
49+
- `lib/zstd_errors.h` : translates `size_t` function results
50+
into a `ZSTD_ErrorCode`, for accurate error handling.
4751

4852
- `ZSTD_STATIC_LINKING_ONLY` : if this macro is defined _before_ including `zstd.h`,
4953
it unlocks access to the experimental API,

ext/zstdruby/libzstd/common/bitstream.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ******************************************************************
22
* bitstream
33
* Part of FSE library
4-
* Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
4+
* Copyright (c) Yann Collet, Facebook, Inc.
55
*
66
* You can contact the author at :
77
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy

ext/zstdruby/libzstd/common/compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
2+
* Copyright (c) Yann Collet, Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the

ext/zstdruby/libzstd/common/cpu.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018-2021, Facebook, Inc.
2+
* Copyright (c) Facebook, Inc.
33
* All rights reserved.
44
*
55
* This source code is licensed under both the BSD-style license (found in the

ext/zstdruby/libzstd/common/debug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ******************************************************************
22
* debug
33
* Part of FSE library
4-
* Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
4+
* Copyright (c) Yann Collet, Facebook, Inc.
55
*
66
* You can contact the author at :
77
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy

ext/zstdruby/libzstd/common/debug.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ******************************************************************
22
* debug
33
* Part of FSE library
4-
* Copyright (c) 2013-2021, Yann Collet, Facebook, Inc.
4+
* Copyright (c) Yann Collet, Facebook, Inc.
55
*
66
* You can contact the author at :
77
* - Source repository : https://github.com/Cyan4973/FiniteStateEntropy

ext/zstdruby/libzstd/common/entropy_common.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* ******************************************************************
22
* Common functions of New Generation Entropy library
3-
* Copyright (c) 2016-2021, Yann Collet, Facebook, Inc.
3+
* Copyright (c) Yann Collet, Facebook, Inc.
44
*
55
* You can contact the author at :
66
* - FSE+HUF source repository : https://github.com/Cyan4973/FiniteStateEntropy

0 commit comments

Comments
 (0)