10c16b537SWarner LoshZstandard library files 20c16b537SWarner Losh================================ 30c16b537SWarner Losh 40c16b537SWarner LoshThe __lib__ directory is split into several sub-directories, 519fcbaf1SConrad Meyerin order to make it easier to select or exclude features. 60c16b537SWarner Losh 70c16b537SWarner Losh 80c16b537SWarner Losh#### Building 90c16b537SWarner Losh 10*a0483764SConrad Meyer`Makefile` script is provided, supporting [Makefile conventions](https://www.gnu.org/prep/standards/html_node/Makefile-Conventions.html#Makefile-Conventions), 1119fcbaf1SConrad Meyerincluding commands variables, staged install, directory variables and standard targets. 120c16b537SWarner Losh- `make` : generates both static and dynamic libraries 13*a0483764SConrad Meyer- `make install` : install libraries and headers in target system directories 140c16b537SWarner Losh 15*a0483764SConrad Meyer`libzstd` default scope is pretty large, including compression, decompression, dictionary builder, 16*a0483764SConrad Meyerand support for decoding legacy formats >= v0.5.0. 17*a0483764SConrad MeyerThe scope can be reduced on demand (see paragraph _modular build_). 18*a0483764SConrad Meyer 19*a0483764SConrad Meyer 20*a0483764SConrad Meyer#### Multithreading support 21*a0483764SConrad Meyer 22*a0483764SConrad MeyerMultithreading is disabled by default when building with `make`. 23*a0483764SConrad MeyerEnabling multithreading requires 2 conditions : 24*a0483764SConrad Meyer- set build macro `ZSTD_MULTITHREAD` (`-DZSTD_MULTITHREAD` for `gcc`) 25*a0483764SConrad Meyer- for POSIX systems : compile with pthread (`-pthread` compilation flag for `gcc`) 26*a0483764SConrad Meyer 27*a0483764SConrad MeyerBoth conditions are automatically applied when invoking `make lib-mt` target. 28*a0483764SConrad Meyer 29*a0483764SConrad MeyerWhen linking a POSIX program with a multithreaded version of `libzstd`, 30*a0483764SConrad Meyernote that it's necessary to request the `-pthread` flag during link stage. 31*a0483764SConrad Meyer 32*a0483764SConrad MeyerMultithreading capabilities are exposed 33*a0483764SConrad Meyervia the [advanced API defined in `lib/zstd.h`](https://github.com/facebook/zstd/blob/v1.3.8/lib/zstd.h#L592). 34*a0483764SConrad MeyerThis API is still labelled experimental, 35*a0483764SConrad Meyerbut is expected to become "stable" in the near future. 3619fcbaf1SConrad Meyer 370c16b537SWarner Losh 380c16b537SWarner Losh#### API 390c16b537SWarner Losh 400c16b537SWarner LoshZstandard's stable API is exposed within [lib/zstd.h](zstd.h). 410c16b537SWarner Losh 420c16b537SWarner Losh 430c16b537SWarner Losh#### Advanced API 440c16b537SWarner Losh 450c16b537SWarner LoshOptional advanced features are exposed via : 460c16b537SWarner Losh 470c16b537SWarner Losh- `lib/common/zstd_errors.h` : translates `size_t` function results 48*a0483764SConrad Meyer into a `ZSTD_ErrorCode`, for accurate error handling. 49*a0483764SConrad Meyer 500c16b537SWarner Losh- `ZSTD_STATIC_LINKING_ONLY` : if this macro is defined _before_ including `zstd.h`, 51*a0483764SConrad Meyer it unlocks access to the experimental API, 52*a0483764SConrad Meyer exposed in the second part of `zstd.h`. 53*a0483764SConrad Meyer All definitions in the experimental APIs are unstable, 54*a0483764SConrad Meyer they may still change in the future, or even be removed. 55*a0483764SConrad Meyer As a consequence, experimental definitions shall ___never be used with dynamic library___ ! 560c16b537SWarner Losh Only static linking is allowed. 570c16b537SWarner Losh 580c16b537SWarner Losh 590c16b537SWarner Losh#### Modular build 600c16b537SWarner Losh 61*a0483764SConrad MeyerIt's possible to compile only a limited set of features within `libzstd`. 62*a0483764SConrad MeyerThe file structure is designed to make this selection manually achievable for any build system : 6319fcbaf1SConrad Meyer 640c16b537SWarner Losh- Directory `lib/common` is always required, for all variants. 65*a0483764SConrad Meyer 660c16b537SWarner Losh- Compression source code lies in `lib/compress` 67*a0483764SConrad Meyer 680c16b537SWarner Losh- Decompression source code lies in `lib/decompress` 69*a0483764SConrad Meyer 700c16b537SWarner Losh- It's possible to include only `compress` or only `decompress`, they don't depend on each other. 71*a0483764SConrad Meyer 720c16b537SWarner Losh- `lib/dictBuilder` : makes it possible to generate dictionaries from a set of samples. 730c16b537SWarner Losh The API is exposed in `lib/dictBuilder/zdict.h`. 740c16b537SWarner Losh This module depends on both `lib/common` and `lib/compress` . 75*a0483764SConrad Meyer 76*a0483764SConrad Meyer- `lib/legacy` : makes it possible to decompress legacy zstd formats, starting from `v0.1.0`. 770c16b537SWarner Losh This module depends on `lib/common` and `lib/decompress`. 780f743729SConrad Meyer To enable this feature, define `ZSTD_LEGACY_SUPPORT` during compilation. 790f743729SConrad Meyer Specifying a number limits versions supported to that version onward. 8019fcbaf1SConrad Meyer For example, `ZSTD_LEGACY_SUPPORT=2` means : "support legacy formats >= v0.2.0". 81*a0483764SConrad Meyer Conversely, `ZSTD_LEGACY_SUPPORT=0` means "do __not__ support legacy formats". 82*a0483764SConrad Meyer By default, this build macro is set as `ZSTD_LEGACY_SUPPORT=5`. 83*a0483764SConrad Meyer Decoding supported legacy format is a transparent capability triggered within decompression functions. 84*a0483764SConrad Meyer It's also allowed to invoke legacy API directly, exposed in `lib/legacy/zstd_legacy.h`. 85*a0483764SConrad Meyer Each version does also provide its own set of advanced API. 860c16b537SWarner Losh For example, advanced API for version `v0.4` is exposed in `lib/legacy/zstd_v04.h` . 870c16b537SWarner Losh 88*a0483764SConrad Meyer- While invoking `make libzstd`, it's possible to define build macros 89*a0483764SConrad Meyer `ZSTD_LIB_COMPRESSION, ZSTD_LIB_DECOMPRESSION`, `ZSTD_LIB_DICTBUILDER`, 90*a0483764SConrad Meyer and `ZSTD_LIB_DEPRECATED` as `0` to forgo compilation of the corresponding features. 91*a0483764SConrad Meyer This will also disable compilation of all dependencies 92*a0483764SConrad Meyer (eg. `ZSTD_LIB_COMPRESSION=0` will also disable dictBuilder). 930c16b537SWarner Losh 94*a0483764SConrad Meyer- There are some additional build macros that can be used to minify the decoder. 950c16b537SWarner Losh 96*a0483764SConrad Meyer Zstandard often has more than one implementation of a piece of functionality, 97*a0483764SConrad Meyer where each implementation optimizes for different scenarios. For example, the 98*a0483764SConrad Meyer Huffman decoder has complementary implementations that decode the stream one 99*a0483764SConrad Meyer symbol at a time or two symbols at a time. Zstd normally includes both (and 100*a0483764SConrad Meyer dispatches between them at runtime), but by defining `HUF_FORCE_DECOMPRESS_X1` 101*a0483764SConrad Meyer or `HUF_FORCE_DECOMPRESS_X2`, you can force the use of one or the other, avoiding 102*a0483764SConrad Meyer compilation of the other. Similarly, `ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT` 103*a0483764SConrad Meyer and `ZSTD_FORCE_DECOMPRESS_SEQUENCES_LONG` force the compilation and use of 104*a0483764SConrad Meyer only one or the other of two decompression implementations. The smallest 105*a0483764SConrad Meyer binary is achieved by using `HUF_FORCE_DECOMPRESS_X1` and 106*a0483764SConrad Meyer `ZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT`. 1070c16b537SWarner Losh 108*a0483764SConrad Meyer For squeezing the last ounce of size out, you can also define 109*a0483764SConrad Meyer `ZSTD_NO_INLINE`, which disables inlining, and `ZSTD_STRIP_ERROR_STRINGS`, 110*a0483764SConrad Meyer which removes the error messages that are otherwise returned by 111*a0483764SConrad Meyer `ZSTD_getErrorName`. 1120c16b537SWarner Losh 1130c16b537SWarner Losh 1140c16b537SWarner Losh#### Windows : using MinGW+MSYS to create DLL 1150c16b537SWarner Losh 1160c16b537SWarner LoshDLL can be created using MinGW+MSYS with the `make libzstd` command. 1170c16b537SWarner LoshThis command creates `dll\libzstd.dll` and the import library `dll\libzstd.lib`. 1180c16b537SWarner LoshThe import library is only required with Visual C++. 1190c16b537SWarner LoshThe header file `zstd.h` and the dynamic library `dll\libzstd.dll` are required to 1200c16b537SWarner Loshcompile a project using gcc/MinGW. 1210c16b537SWarner LoshThe dynamic library has to be added to linking options. 1220c16b537SWarner LoshIt means that if a project that uses ZSTD consists of a single `test-dll.c` 1230c16b537SWarner Loshfile it should be linked with `dll\libzstd.dll`. For example: 1240c16b537SWarner Losh``` 1250c16b537SWarner Losh gcc $(CFLAGS) -Iinclude/ test-dll.c -o test-dll dll\libzstd.dll 1260c16b537SWarner Losh``` 1270c16b537SWarner LoshThe compiled executable will require ZSTD DLL which is available at `dll\libzstd.dll`. 1280c16b537SWarner Losh 1290c16b537SWarner Losh 1300c16b537SWarner Losh#### Deprecated API 1310c16b537SWarner Losh 1320c16b537SWarner LoshObsolete API on their way out are stored in directory `lib/deprecated`. 1330c16b537SWarner LoshAt this stage, it contains older streaming prototypes, in `lib/deprecated/zbuff.h`. 1340c16b537SWarner LoshThese prototypes will be removed in some future version. 1350c16b537SWarner LoshConsider migrating code towards supported streaming API exposed in `zstd.h`. 1360c16b537SWarner Losh 1370c16b537SWarner Losh 1380c16b537SWarner Losh#### Miscellaneous 1390c16b537SWarner Losh 1400c16b537SWarner LoshThe other files are not source code. There are : 1410c16b537SWarner Losh 1420c16b537SWarner Losh - `BUCK` : support for `buck` build system (https://buckbuild.com/) 143*a0483764SConrad Meyer - `Makefile` : `make` script to build and install zstd library (static and dynamic) 1440c16b537SWarner Losh - `README.md` : this file 145*a0483764SConrad Meyer - `dll/` : resources directory for Windows compilation 146*a0483764SConrad Meyer - `libzstd.pc.in` : script for `pkg-config` (used in `make install`) 147