Skip to content

fix(build): broken shared library symlinks on Linux with dynamic-link#980

Open
Ryaningli wants to merge 5 commits intoutilityai:mainfrom
Ryaningli:fix-linux-dynamic-link
Open

fix(build): broken shared library symlinks on Linux with dynamic-link#980
Ryaningli wants to merge 5 commits intoutilityai:mainfrom
Ryaningli:fix-linux-dynamic-link

Conversation

@Ryaningli
Copy link
Copy Markdown

On Linux, CMake produces a soname symlink chain for shared libraries:
libllama.so -> libllama.so.0 -> libllama.so.0.0.8233

The previous code used glob("*.so") which only matched the top-level symlinks (libllama.so), and std::fs::hard_link on a symlink creates another symlink rather than a hard link to the real file. This left target/release/ full of broken symlinks with no actual .so files.

Fix by:

  • Changing glob pattern from ".so" to ".so*" to match all files in the soname chain
  • Introducing copy_lib_asset() which uses symlink() for symlinks and hard_link() for regular files, correctly recreating the entire symlink chain in the target directory

lining and others added 2 commits April 2, 2026 16:50
On Linux, CMake produces a soname symlink chain for shared libraries:
  libllama.so -> libllama.so.0 -> libllama.so.0.0.8233

The previous code used glob("*.so") which only matched the top-level
symlinks (libllama.so), and std::fs::hard_link on a symlink creates
another symlink rather than a hard link to the real file. This left
target/release/ full of broken symlinks with no actual .so files.

Fix by:
- Changing glob pattern from "*.so" to "*.so*" to match all files
  in the soname chain
- Introducing copy_lib_asset() which uses symlink() for symlinks
  and hard_link() for regular files, correctly recreating the
  entire symlink chain in the target directory

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MarcusDunn
Copy link
Copy Markdown
Contributor

not sure if merge broke, but CI need to be passing before I can merge. Thanks for the PR!

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@MarcusDunn
Copy link
Copy Markdown
Contributor

I'm not sure this is required, can we get confirmation of the bug this fixes?

@Ryaningli
Copy link
Copy Markdown
Author

I'm not sure this is required, can we get confirmation of the bug this fixes?

Hi, thanks for taking a look.

The core fix is in commit 0e08c56 — when building with the dynamic-link feature on Linux, CMake produces a soname symlink chain like:

libllama.so -> libllama.so.0 -> libllama.so.0.x.x

The previous code used glob("*.so") which only matched the top-level symlink (libllama.so), and std::fs::hard_link on a symlink creates another dangling symlink rather than linking to the real file. This left target/release/ full of broken symlinks — ldd would report "not found" and any binary expecting to load libllama.so at runtime would fail.

To reproduce:

  1. Build with cargo build --features dynamic-link on Linux
  2. Check target/release/libllama.so* — before the fix, only the top-level .so symlink exists and points to nothing

You can also verify by running ldd target/release/ and seeing libllama.so => not found.

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.

2 participants