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

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

Open
yfaker opened this issue Oct 6, 2024 · 6 comments

Comments

@yfaker
Copy link

yfaker commented Oct 6, 2024

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
Copy link
Contributor

Cyan4973 commented Oct 6, 2024

cc @felixhandte

@aleksazr
Copy link

aleksazr commented Oct 6, 2024

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

@yfaker
Copy link
Author

yfaker commented Oct 7, 2024

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
Copy link

aleksazr commented Oct 7, 2024

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
Copy link
Author

yfaker commented Oct 8, 2024

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_LIB_MINIFY in make
Thanks~

@aleksazr
Copy link

aleksazr commented Oct 9, 2024

I don't know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants