xref: /aosp_15_r20/external/zstd/build/single_file_libs/README.md (revision 01826a4963a0d8a59bc3812d29bdf0fb76416722)
1*01826a49SYabin Cui# Single File Zstandard Libraries
2*01826a49SYabin Cui
3*01826a49SYabin CuiThe script `combine.sh` creates an _amalgamated_ source file that can be used with or without `zstd.h`. This isn't a _header-only_ file but it does offer a similar level of simplicity when integrating into a project.
4*01826a49SYabin Cui
5*01826a49SYabin CuiAll it now takes to support Zstd in your own projects is the addition of a single file, two if using the header, with no configuration or further build steps.
6*01826a49SYabin Cui
7*01826a49SYabin CuiDecompressor
8*01826a49SYabin Cui------------
9*01826a49SYabin Cui
10*01826a49SYabin CuiThis is the most common use case. The decompression library is small, adding, for example, 26kB to an Emscripten compiled WebAssembly project. Native implementations add a little more, 40-70kB depending on the compiler and platform.
11*01826a49SYabin Cui
12*01826a49SYabin CuiCreate `zstddeclib.c` from the Zstd source using:
13*01826a49SYabin Cui```
14*01826a49SYabin Cuicd zstd/build/single_file_libs
15*01826a49SYabin Cuipython3 combine.py -r ../../lib -x legacy/zstd_legacy.h -o zstddeclib.c zstddeclib-in.c
16*01826a49SYabin Cui```
17*01826a49SYabin CuiThen add the resulting file to your project (see the [example files](examples)).
18*01826a49SYabin Cui
19*01826a49SYabin Cui`create_single_file_decoder.sh` will run the above script, creating the file `zstddeclib.c` (`build_decoder_test.sh` will also create `zstddeclib.c`, then compile and test the result).
20*01826a49SYabin Cui
21*01826a49SYabin CuiFull Library
22*01826a49SYabin Cui------------
23*01826a49SYabin Cui
24*01826a49SYabin CuiThe same tool can amalgamate the entire Zstd library for ease of adding both compression and decompression to a project. The [roundtrip example](examples/roundtrip.c) uses the original `zstd.h` with the remaining source files combined into `zstd.c` (currently just over 1.2MB) created from `zstd-in.c`. As with the standalone decoder the most useful compile flags have already been rolled-in and the resulting file can be added to a project as-is.
25*01826a49SYabin Cui
26*01826a49SYabin CuiCreate `zstd.c` from the Zstd source using:
27*01826a49SYabin Cui```
28*01826a49SYabin Cuicd zstd/build/single_file_libs
29*01826a49SYabin Cuipython3 combine.py -r ../../lib -x legacy/zstd_legacy.h -k zstd.h -o zstd.c zstd-in.c
30*01826a49SYabin Cui```
31*01826a49SYabin CuiIt's possible to create a compressor-only library but since the decompressor is so small in comparison this doesn't bring much of a gain (but for the curious, simply remove the files in the _decompress_ section at the end of `zstd-in.c`).
32*01826a49SYabin Cui
33*01826a49SYabin Cui`create_single_file_library.sh` will run the script to create `zstd.c` (`build_library_test.sh` will also create `zstd.c`, then compile and test the result).
34