Skip to content

Commit 930814a

Browse files
committed
[erts] Make it possible to use the systems libzstd
1 parent 5b25035 commit 930814a

6 files changed

Lines changed: 162 additions & 3 deletions

File tree

erts/config.h.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@
8484
/* Define if builtin zlib should be used */
8585
#undef ERTS_USE_BUILTIN_ZLIB
8686

87+
/* Define if builtin zstd should be used */
88+
#undef ERTS_USE_BUILTIN_ZSTD
89+
8790
/* Define to 1 if alternatives to embedded 3pps should be used, 0 if not, and
8891
-1 to use the default */
8992
#undef ERTS_USE_EMBEDDED_3PP_ALTS

erts/configure

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,7 @@ SYSTEMD_DAEMON_LIBS
671671
SOCKET_LIBS
672672
Z_LIB
673673
ERTS_USE_BUILTIN_ZLIB
674+
LIBZSTD
674675
ERTS_USE_BUILTIN_ERRNO_ID
675676
TERMCAP_LIB
676677
THR_DEFS
@@ -856,6 +857,7 @@ enable_ppc_lwsync_instruction
856857
with_threadnames
857858
enable_use_embedded_3pp_alternatives
858859
enable_builtin_errno_id
860+
enable_builtin_zstd
859861
enable_builtin_zlib
860862
enable_esock
861863
enable_esock_use_rcvsndtimeo
@@ -1608,6 +1610,7 @@ Optional Features:
16081610
do not use any alternatives to embedded 3pps
16091611
--enable-builtin-errno-id
16101612
force use of our own built-in errno id
1613+
--enable-builtin-zstd force use of our own built-in zstd
16111614
--enable-builtin-zlib force use of our own built-in zlib
16121615
--enable-esock enable builtin socket (as a nif) support (default)
16131616
--disable-esock disable builtin socket (as a nif) support
@@ -16643,12 +16646,14 @@ then :
1664316646
enableval=$enable_use_embedded_3pp_alternatives; case "$enableval" in
1664416647
no)
1664516648
enable_builtin_errno_id=yes
16649+
enable_builtin_zstd=yes
1664616650
enable_builtin_zlib=yes
1664716651
use_embedded_3pp_alts=no
1664816652
use_embedded_3pp_alts_val=0
1664916653
;;
1665016654
*)
1665116655
enable_builtin_errno_id=no
16656+
enable_builtin_zstd=no
1665216657
enable_builtin_zlib=no
1665316658
use_embedded_3pp_alts=yes
1665416659
use_embedded_3pp_alts_val=1
@@ -16658,6 +16663,7 @@ then :
1665816663
else case e in #(
1665916664
e)
1666016665
enable_builtin_errno_id=yes
16666+
enable_builtin_zstd=yes
1666116667
enable_builtin_zlib=no
1666216668
use_embedded_3pp_alts=default
1666316669
use_embedded_3pp_alts_val=-1
@@ -16699,6 +16705,82 @@ ERTS_USE_BUILTIN_ERRNO_ID=$enable_builtin_errno_id
1669916705

1670016706

1670116707

16708+
# Check whether --enable-builtin-zstd was given.
16709+
if test ${enable_builtin_zstd+y}
16710+
then :
16711+
enableval=$enable_builtin_zstd; case "$enableval" in
16712+
no) enable_builtin_zstd=no ;;
16713+
*) enable_builtin_zstd=yes ;;
16714+
esac
16715+
fi
16716+
16717+
16718+
LIBZSTD=
16719+
16720+
if test "$enable_builtin_zstd" = "no"
16721+
then :
16722+
16723+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for libzstd of version 1.5 or higher" >&5
16724+
printf %s "checking for libzstd of version 1.5 or higher... " >&6; }
16725+
zstd_save_LIBS=$LIBS
16726+
LIBS="-lzstd $LIBS"
16727+
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
16728+
/* end confdefs.h. */
16729+
16730+
#define ZSTD_STATIC_LINKING_ONLY
16731+
#include <zstd.h>
16732+
#include <zdict.h>
16733+
16734+
int
16735+
main (void)
16736+
{
16737+
16738+
#if ZSTD_VERSION_NUMBER >= 1500
16739+
(void) ZSTD_createCCtx_advanced(ZSTD_defaultCMem);
16740+
#else
16741+
#error "No libzstd of version 1.5 or higher found"
16742+
error
16743+
#endif
16744+
16745+
;
16746+
return 0;
16747+
}
16748+
16749+
_ACEOF
16750+
if ac_fn_c_try_link "$LINENO"
16751+
then :
16752+
16753+
LIBZSTD="-lzstd"
16754+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: yes" >&5
16755+
printf "%s\n" "yes" >&6; }
16756+
16757+
else case e in #(
16758+
e)
16759+
{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: no, using builtin zstd instead" >&5
16760+
printf "%s\n" "no, using builtin zstd instead" >&6; }
16761+
;;
16762+
esac
16763+
fi
16764+
rm -f core conftest.err conftest.$ac_objext conftest.beam \
16765+
conftest$ac_exeext conftest.$ac_ext
16766+
16767+
LIBS="$zstd_save_LIBS"
16768+
16769+
16770+
fi
16771+
16772+
16773+
16774+
if test "$LIBZSTD" = ""
16775+
then :
16776+
16777+
16778+
printf "%s\n" "#define ERTS_USE_BUILTIN_ZSTD 1" >>confdefs.h
16779+
16780+
16781+
fi
16782+
16783+
1670216784
# Check whether --enable-builtin-zlib was given.
1670316785
if test ${enable_builtin_zlib+y}
1670416786
then :

erts/configure.ac

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1259,12 +1259,14 @@ AS_HELP_STRING([--disable-use-embedded-3pp-alternatives],
12591259
[ case "$enableval" in
12601260
no)
12611261
enable_builtin_errno_id=yes
1262+
enable_builtin_zstd=yes
12621263
enable_builtin_zlib=yes
12631264
use_embedded_3pp_alts=no
12641265
use_embedded_3pp_alts_val=0
12651266
;;
12661267
*)
12671268
enable_builtin_errno_id=no
1269+
enable_builtin_zstd=no
12681270
enable_builtin_zlib=no
12691271
use_embedded_3pp_alts=yes
12701272
use_embedded_3pp_alts_val=1
@@ -1273,6 +1275,7 @@ AS_HELP_STRING([--disable-use-embedded-3pp-alternatives],
12731275
],
12741276
[
12751277
enable_builtin_errno_id=yes
1278+
enable_builtin_zstd=yes
12761279
enable_builtin_zlib=no
12771280
use_embedded_3pp_alts=default
12781281
use_embedded_3pp_alts_val=-1
@@ -1304,6 +1307,57 @@ AS_IF([test $enable_builtin_errno_id = yes],
13041307
ERTS_USE_BUILTIN_ERRNO_ID=$enable_builtin_errno_id
13051308
AC_SUBST(ERTS_USE_BUILTIN_ERRNO_ID)
13061309

1310+
dnl -------------
1311+
dnl zstd
1312+
dnl -------------
1313+
1314+
AC_ARG_ENABLE(builtin-zstd,
1315+
AS_HELP_STRING([--enable-builtin-zstd],
1316+
[force use of our own built-in zstd]),
1317+
[ case "$enableval" in
1318+
no) enable_builtin_zstd=no ;;
1319+
*) enable_builtin_zstd=yes ;;
1320+
esac ])
1321+
1322+
LIBZSTD=
1323+
1324+
AS_IF([test "$enable_builtin_zstd" = "no"],
1325+
[
1326+
AC_MSG_CHECKING(for libzstd of version 1.5 or higher)
1327+
zstd_save_LIBS=$LIBS
1328+
LIBS="-lzstd $LIBS"
1329+
AC_LINK_IFELSE(
1330+
[AC_LANG_PROGRAM([[
1331+
#define ZSTD_STATIC_LINKING_ONLY
1332+
#include <zstd.h>
1333+
#include <zdict.h>
1334+
]],[[
1335+
#if ZSTD_VERSION_NUMBER >= 1500
1336+
(void) ZSTD_createCCtx_advanced(ZSTD_defaultCMem);
1337+
#else
1338+
#error "No libzstd of version 1.5 or higher found"
1339+
error
1340+
#endif
1341+
]])
1342+
],
1343+
[
1344+
LIBZSTD="-lzstd"
1345+
AC_MSG_RESULT(yes)
1346+
],[
1347+
AC_MSG_RESULT([no, using builtin zstd instead])
1348+
])
1349+
1350+
LIBS="$zstd_save_LIBS"
1351+
1352+
])
1353+
1354+
AC_SUBST(LIBZSTD)
1355+
1356+
AS_IF([test "$LIBZSTD" = ""],
1357+
[
1358+
AC_DEFINE(ERTS_USE_BUILTIN_ZSTD, [1], [Define if builtin zstd should be used])
1359+
])
1360+
13071361
dnl -------------
13081362
dnl zlib
13091363
dnl -------------

erts/emulator/Makefile.in

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ DTRACE_ENABLED=@DTRACE_ENABLED@
3232
DTRACE_ENABLED_2STEP=@DTRACE_ENABLED_2STEP@
3333
USE_VM_PROBES=@USE_VM_PROBES@
3434
LIBS = @LIBS@
35+
LIBZSTD=@LIBZSTD@
3536
Z_LIB=@Z_LIB@
3637
CROSS_COMPILING = @CROSS_COMPILING@
3738
NO_INLINE_FUNCTIONS=false
@@ -398,6 +399,10 @@ else
398399
LIBS += $(OPENSSL_LIB)
399400
endif
400401

402+
ifdef LIBZSTD
403+
# Use system libzstd
404+
LIBS += $(LIBZSTD)
405+
else
401406
ZSTD_DIR = $(ERL_TOP)/erts/emulator/zstd/obj/$(TARGET)/$(TYPE)
402407
ZSTD_LIB = $(ZSTD_DIR)/$(LIB_PREFIX)zstd$(LIB_SUFFIX)
403408
DEPLIBS += $(ZSTD_LIB)
@@ -408,6 +413,7 @@ else
408413
# Build on darwin fails if -l$(ZSTD_LIB) is used
409414
LIBS += $(ZSTD_LIB)
410415
endif
416+
endif
411417

412418
LIBSCTP = @LIBSCTP@
413419

@@ -828,7 +834,10 @@ COMMON_INCLUDES = -Ibeam -Isys/$(ERLANG_OSTYPE) -Isys/common -I$(TARGET)
828834
ifeq ($(ERTS_USE_BUILTIN_ZLIB),yes)
829835
COMMON_INCLUDES += -Izlib
830836
endif
831-
COMMON_INCLUDES += -Ipcre -Iryu -Iopenssl/include -Izstd
837+
ifndef LIBZSTD
838+
COMMON_INCLUDES += -Izstd
839+
endif
840+
COMMON_INCLUDES += -Ipcre -Iryu -Iopenssl/include
832841
COMMON_INCLUDES += -I../include -I../include/$(TARGET)
833842
COMMON_INCLUDES += -I../include/internal -I../include/internal/$(TARGET)
834843

erts/emulator/beam/erl_bif_info.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,7 +3588,11 @@ BIF_RETTYPE system_info_1(BIF_ALIST_1)
35883588
xtra -= 2;
35893589

35903590
hp = erts_produce_heap(&hfact, 2, xtra);
3591+
#ifdef ERTS_USE_BUILTIN_ZSTD
35913592
included = CONS(hp, AM_zstd, included);
3593+
#else
3594+
excluded = CONS(hp, AM_zstd, excluded);
3595+
#endif
35923596
xtra -= 2;
35933597

35943598
hp = erts_produce_heap(&hfact, 2, xtra);

erts/emulator/nifs/common/zstd_nif.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,16 @@
2828
#define STATIC_ERLANG_NIF 1
2929

3030
#include "erl_nif.h"
31+
#include "config.h"
3132
#define ZSTD_STATIC_LINKING_ONLY
32-
#include "erl_zstd.h"
33-
#include "erl_zdict.h"
33+
34+
#ifdef ERTS_USE_BUILTIN_ZSTD
35+
# include "erl_zstd.h"
36+
# include "erl_zdict.h"
37+
#else
38+
# include <zstd.h>
39+
# include <zdict.h>
40+
#endif
3441

3542
static ErlNifResourceType *compress_type;
3643
static ErlNifResourceType *decompress_type;

0 commit comments

Comments
 (0)