Skip to content

build: disable soname to reduce binary size#2177

Open
Bing-su wants to merge 1 commit intoabetlen:mainfrom
Bing-su:fix/no-soname
Open

build: disable soname to reduce binary size#2177
Bing-su wants to merge 1 commit intoabetlen:mainfrom
Bing-su:fix/no-soname

Conversation

@Bing-su
Copy link
Copy Markdown

@Bing-su Bing-su commented Apr 9, 2026

Disable soname to reduce binary size.

As explained in pep-778, wheel files currently do not handle symbolic links (it replaces the symbolic link with the original file). This causes the llama-cpp-python wheel file to become larger than the original.

By setting the NO_SONAME flag to prevent the creation of symbolic links, it resolves this issue.

image

https://github.com/Bing-su/llama-cpp-python/actions/runs/24200306300

Please also check the built files.

wheels-ubuntu-22.04.zip
wheels-windows-2022.zip

  • It looks like macos require some different configuration. However, I don't have a Apple machine to test it on...
    wheels-macos-15.zip

Comment on lines +46 to +47
RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these two settings were not configured, an issue arose where the library referenced files under the bin/ folder that did not exist.

❯ readelf -d dist/llama_cpp_python-0.3.20-py3-none-linux_x86_64/llama_cpp/lib/libggml.so

Dynamic section at offset 0xbd98 contains 29 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [bin/libggml-cpu.so]
 0x0000000000000001 (NEEDED)             Shared library: [bin/libggml-base.so]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]


❯ readelf -d dist/llama_cpp_python-0.3.20-py3-none-linux_x86_64/llama_cpp/lib/libllama.so

Dynamic section at offset 0x2dc128 contains 31 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [bin/libggml.so]
 0x0000000000000001 (NEEDED)             Shared library: [bin/libggml-base.so]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]
 0x000000000000001d (RUNPATH)            Library runpath: [$ORIGIN]

https://github.com/ggml-org/llama.cpp/blob/d6f3030047f85a98b009189e76f441fe818ea44d/CMakeLists.txt#L20-L21

So I overrode the settings in llama-cpp.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant