Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make: Add ZSTD_PROGRAMS_LINK_SHARED to dll-link zstd #2450

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ CPPFLAGS += -DXXH_NAMESPACE=ZSTD_ -DDEBUGLEVEL=$(DEBUGLEVEL)
ifeq ($(TARGET_SYSTEM),Windows_NT) # MinGW assumed
CPPFLAGS += -D__USE_MINGW_ANSI_STDIO # compatibility with %zu formatting
endif
ifdef ZSTD_PROGRAMS_LINK_SHARED
CPPFLAGS += -DZSTD_PROGRAMS_LINK_SHARED
endif
DEBUGFLAGS= -Wall -Wextra -Wcast-qual -Wcast-align -Wshadow \
-Wstrict-aliasing=1 -Wswitch-enum -Wdeclaration-after-statement \
-Wstrict-prototypes -Wundef -Wpointer-arith \
Expand Down
3 changes: 3 additions & 0 deletions lib/compress/zstd_compress_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -1198,6 +1198,9 @@ size_t ZSTD_referenceExternalSequences(ZSTD_CCtx* cctx, rawSeq* seq, size_t nbSe

/** ZSTD_cycleLog() :
* condition for correct operation : hashLog > 1 */
#if defined(ZSTD_PROGRAMS_LINK_SHARED)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could instead be some conditionally-defined ZSTDLIB_CLI_DLL_API (or whatever) in lib/zstd.h. I don't feel strongly about it; the number of instances needed will probably remain very small.

Copy link
Contributor

@Cyan4973 Cyan4973 Jan 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably remove ZSTD_cycleLog() dependency. It's a trivial code to copy.

ZSTDLIB_API
#endif
U32 ZSTD_cycleLog(U32 hashLog, ZSTD_strategy strat);

#endif /* ZSTD_COMPRESS_H */
3 changes: 3 additions & 0 deletions lib/dictBuilder/zdict.c
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,9 @@ static size_t ZDICT_addEntropyTablesFromBuffer_advanced(
}

/* Hidden declaration for dbio.c */
#if defined(ZSTD_PROGRAMS_LINK_SHARED)
ZSTDLIB_API
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, we could make ZDICT_trainFromBuffer_unsafe_legacy() function part of the "unstable"/"experimental" section of zdict API.

Another alternative is to not use it in dibio.c and use the safe variant instead.
It comes at an additional memory allocation cost, but might be worth it to remove this dependency.

#endif
size_t ZDICT_trainFromBuffer_unsafe_legacy(
void* dictBuffer, size_t maxDictSize,
const void* samplesBuffer, const size_t* samplesSizes, unsigned nbSamples,
Expand Down
22 changes: 8 additions & 14 deletions programs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ zstd : CPPFLAGS += $(THREAD_CPP) $(ZLIBCPP) $(LZMACPP) $(LZ4CPP)
zstd : LDFLAGS += $(THREAD_LD) $(DEBUGFLAGS_LD)
zstd : LDLIBS += $(ZLIBLD) $(LZMALD) $(LZ4LD)
zstd : CPPFLAGS += -DZSTD_LEGACY_SUPPORT=$(ZSTD_LEGACY_SUPPORT)
ifdef ZSTD_PROGRAMS_LINK_SHARED
zstd : LDFLAGS+= -L$(ZSTDDIR) -lzstd
zstd : ZSTDLIB_FULL_SRC =
endif
ifneq (,$(filter Windows%,$(OS)))
zstd : $(RES_FILE)
endif
Expand All @@ -226,7 +230,11 @@ zstd:
else
# BUILD_DIR is defined

ifndef ZSTD_PROGRAMS_LINK_SHARED
ZSTD_OBJ := $(addprefix $(BUILD_DIR)/, $(ZSTD_ALL_OBJ))
else
ZSTD_OBJ := $(addprefix $(BUILD_DIR)/, $(ZSTD_CLI_OBJ))
endif
$(BUILD_DIR)/zstd : $(ZSTD_OBJ)
@echo "$(THREAD_MSG)"
@echo "$(ZLIB_MSG)"
Expand Down Expand Up @@ -288,20 +296,6 @@ zstd-noxz : LZMALD :=
zstd-noxz : LZMA_MSG := - xz/lzma support is disabled
zstd-noxz : zstd

## zstd-dll: zstd executable linked to dynamic library libzstd (must already exist)
# note : the following target doesn't link
# because zstd uses non-public symbols from libzstd
# such as XXH64 (for benchmark),
# ZDICT_trainFromBuffer_unsafe_legacy (for dictionary builder)
# and ZSTD_cycleLog (likely for --patch-from).
# It's unclear at this stage if this is a scenario that must be supported
.PHONY: zstd-dll
zstd-dll : LDFLAGS+= -L$(ZSTDDIR) -lzstd
zstd-dll : ZSTDLIB_FULL_SRC =
zstd-dll : $(ZSTD_CLI_OBJ)
$(CC) $(FLAGS) $^ -o $@$(EXT) $(LDFLAGS)


## zstd-pgo: zstd executable optimized with PGO.
zstd-pgo :
$(MAKE) clean
Expand Down