rust-lang / rust-lang/git2-rs

`libgit2` found for linking, but not loading (i.e. missing `rpath`).

Open
#1,138 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
2.1k
Forks
450
Avg merge
11m
Merged PRs (30d)
1

Description

I have a build script using git2, which builds fine, but when it is executed, fails with:

/target/debug/build/built2-42d7a0628db36d4d/build-script-build: error while loading shared libraries: libgit2.so.1.9: cannot open shared object file: No such file or directory

The problem is libgit2.so.1.9 is found in /home/linuxbrew/.linuxbrew/Cellar/libgit2/1.9.0/lib/libgit2.so.1.9 (via Homebrew-installed pkg-config), but when executing cannot find it since it is not in the load path.

Ideally, the libgit2-sys build script should add that directory as rpath, but cargo has no way of forwarding this to a dependent binary (yet) using e.g. cargo:rustc-link-arg.

For normal binaries, you can hack the rpath into build.rs, but there is no way to set it for the build.rs itself other than setting RUSTFLAGS manually.

Maybe there is a way to detect when a package is found with pkg-config but cannot actually be loaded (e.g. using ldconfig -p) and fall back to using the vendored version in that case.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the libgit2-sys build script and its pkg-config handling, then trace how the dependency is loaded when the build script runs. Compare the available rpath and vendored-version options described in the issue; done should mean a Homebrew-installed libgit2 can be used without manually setting RUSTFLAGS, or the vendored version is selected when it cannot be loaded.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
build-system
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.