facebook / zstd

Zstandard - Fast real-time compression algorithm
http://www.zstd.net
Other
23.73k stars 2.11k forks source link

[Help Wanted, Questions]How to build zstd with cmake to minimize the binary size? #4161

Open yfaker opened 1 month ago

yfaker commented 1 month ago

Is your feature request related to a problem? Please describe.

Hi, How to minimize the binary size of libzstd when build with cmake , I've tried both cmake and make, and it turn out when I use make command ,the binary size is smallest, so how can I use cmake command to achive the same size of make does?

Here is my cmake cmd: cmake .. -DCMAKE_BUILD_WITH_INSTALL_RPATH=OFF -DCMAKE_SKIP_RPATH=ON -DZSTD_BUILD_STATIC=ON -DZSTD_BUILD_SHARED=OFF -DZSTD_BUILD_PROGRAMS=OFF -DZSTD_BUILD_DECOMPRESSION=ON -DZSTD_BUILD_COMPRESSION=OFF -DZSTD_BUILD_DICTBUILDER=OFF -DZSTD_LEGACY_SUPPORT=OFF -DZSTD_BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX=./lib_install -DCMAKE_C_FLAGS=" -DHUF_FORCE_DECOMPRESS_X1 -DZSTD_FORCE_DECOMPRESS_SEQUENCES_SHORT -DZSTD_NO_INLINE -DZSTD_STRIP_ERROR_STRINGS -DZSTD_NO_UNUSED_FUNCTIONS -DZSTD_NO_INLINE -DHUF_DISABLE_FAST_DECODE -DZDICTLIB_STATIC_API" and the binary size is 102728 bytes

make cmd: make -j8 ZSTD_LIB_MINIFY=1 ZSTD_LIB_COMPRESSION=0 ZSTD_LIB_DICTBUILDER=0 ZSTD_LIB_DECOMPRESSION=1 and the binary size is 79432 bytes

Describe the solution you'd like Wonder how to build zstd with cmake to minimize the binary size,as close as possible to the size of the binary compiled with make?

Thanks a lot!

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

Cyan4973 commented 1 month ago

cc @felixhandte

aleksazr commented 1 month ago

By "binary size" you mean obj, lib, exe, X86/X64, debug/release?

yfaker commented 1 month ago

By "binary size" you mean obj, lib, exe, X86/X64, debug/release?

binary size of libzstd.a with release version, as our Client side SDK has size limit

aleksazr commented 1 month ago

I don't use gcc, so I get obj files. (*.a in gcc) Anyway, I would ignore the size diff in obj files.

Just create a minimal C exe, call compress and/or decompress functions with NULL params, and check the final exe size - link it with cmake obj, then with make obj and compare exe sizes.

And if the exe sizes are not equal (enough) - ask again 🙂

yfaker commented 1 month ago

I don't use gcc, so I get obj files. (*.a in gcc) Anyway, I would ignore the size diff in obj files.

Just create a minimal C exe, call compress and/or decompress functions with NULL params, and check the final exe size - link it with cmake obj, then with make obj and compare exe sizes.

And if the exe sizes are not equal (enough) - ask again 🙂

My need is minimize the size of libzstd.a, currently we build zstd with cmake and the size of libzstd.a is 102728 bytes, and of size 79432 with make, so I want to know is there any other cmake options can be used to optimize binary size of libzstd, such as _ZSTD_LIBMINIFY in make Thanks~

aleksazr commented 1 month ago

I don't know.