zstd/build/single_file_libs
Nick Terrell c284569457 [asm] Share portability macros and restrict ASM further
Move portability macros to `lib/common/portability_macros.h`. This file
only contains platform/feature detection (e.g. 0/1 macros). This file is
shared between C and ASM code, so it cannot include any C code.

Rename `HUF_` ASM macros to be `ZSTD_` prefixed, and move to the new
header.

Restrict `ZSTD_ASM_SUPPORTED` to `__GNUC__`, because we need the GAS
assembler.

Finally, only include the ASM code if we are actually going to use it.
This disables it on all Windows platforms, which should resolve the
problem brought up in Issue #2789.
2021-12-02 16:58:04 -08:00
..
examples Move Single-File Build Script from `contrib/` to `build/` 2021-05-05 16:07:51 -04:00
.gitignore Move Single-File Build Script from `contrib/` to `build/` 2021-05-05 16:07:51 -04:00
README.md Rewrite References to Location 2021-05-05 18:03:48 -04:00
build_decoder_test.sh Move Single-File Build Script from `contrib/` to `build/` 2021-05-05 16:07:51 -04:00
build_library_test.sh Move Single-File Build Script from `contrib/` to `build/` 2021-05-05 16:07:51 -04:00
combine.sh Move Single-File Build Script from `contrib/` to `build/` 2021-05-05 16:07:51 -04:00
create_single_file_decoder.sh Move Single-File Build Script from `contrib/` to `build/` 2021-05-05 16:07:51 -04:00
create_single_file_library.sh Move Single-File Build Script from `contrib/` to `build/` 2021-05-05 16:07:51 -04:00
zstd-in.c [asm] Share portability macros and restrict ASM further 2021-12-02 16:58:04 -08:00
zstddeclib-in.c [asm] Share portability macros and restrict ASM further 2021-12-02 16:58:04 -08:00

README.md

Single File Zstandard Libraries

The 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.

All 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.

Decompressor

This 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.

Create zstddeclib.c from the Zstd source using:

cd zstd/build/single_file_libs
./combine.sh -r ../../lib -o zstddeclib.c zstddeclib-in.c

Then add the resulting file to your project (see the example files).

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).

Full Library

The same tool can amalgamate the entire Zstd library for ease of adding both compression and decompression to a project. The roundtrip example 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.

Create zstd.c from the Zstd source using:

cd zstd/build/single_file_libs
./combine.sh -r ../../lib -o zstd.c zstd-in.c

It'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).

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).