git2-rs
git2-rs copied to clipboard
Undefined symbols for architecture x86_64: "_git_branch_name_is_valid"
As of 0454efbaa0447a1d02eb11459a7db5e1c27d98e0, cargo test fails on macOS.
System details:
$ uname -a
Darwin waleedkhan-mbp 20.3.0 Darwin Kernel Version 20.3.0: Thu Jan 21 00:07:06 PST 2021; root:xnu-7195.81.3~1/RELEASE_X86_64 x86_64
$ rustup show
Default host: x86_64-apple-darwin
rustup home: /Users/Waleed/.rustup
stable-x86_64-apple-darwin (default)
rustc 1.52.1 (9bc8c42bb 2021-05-09)
```
Error message:
```
Compiling git2 v0.13.20 (/Users/Waleed/workspace/git2-rs)
error: linking with `cc` failed: exit code: 1
|
= note: "cc" "-m64" "-arch" "x86_64" "-L" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.0.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.1.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.10.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.11.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.12.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.13.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.14.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.15.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.2.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.3.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.4.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.5.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.6.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.7.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.8.rcgu.o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.9.rcgu.o" "-o" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff" "/Users/Waleed/workspace/git2-rs/target/debug/deps/git2-77dec5eea979a8ff.u09cr4b2fds5ba9.rcgu.o" "-Wl,-dead_strip" "-nodefaultlibs" "-L" "/Users/Waleed/workspace/git2-rs/target/debug/deps" "-L" "/usr/local/Cellar/libgit2/1.1.0/lib" "-L" "/Users/Waleed/workspace/git2-rs/target/debug/build/libssh2-sys-34ee49cb41b19d75/out/build" "-L" "/usr/local/opt/[email protected]/lib" "-L" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libtest-db9eca8f5d08050d.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libterm-03ffa4db69efb895.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgetopts-01bd0f519f94c074.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunicode_width-7901380749915546.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_std-ab361ac62179dadb.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liblog-135ef244209a85d4.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liburl-b42a4cec8f8c5eb2.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libidna-5fae12f627455a64.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libunicode_normalization-74a564265e91967d.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libtinyvec-6c23dec31872fc26.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libtinyvec_macros-6a3d9893f1f74a5e.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libunicode_bidi-6d116929acb2ac5f.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libform_urlencoded-ab8796b5b8e83d73.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libpercent_encoding-2dbd0b5d1d2ba49f.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libmatches-a9016931447b6b5e.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libtempfile-1c9892031130ac2e.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/librand-0d9d2110c5342d0f.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/librand_chacha-64b398b5594e7be9.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libppv_lite86-df618e8854d7d514.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/librand_core-7696cd0ce21900dd.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libgetrandom-d9735d083523c02e.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libremove_dir_all-eb405c93cdca49aa.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libcfg_if-e10c2c6247528dd5.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liblibgit2_sys-d2b2004c9dcf63c6.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liblibssh2_sys-293c0a5bd68c1708.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libopenssl_sys-fe4003bb0719f60d.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liblibz_sys-a8082fefcfc7e72e.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/liblibc-fc25c8b902b51cd0.rlib" "/Users/Waleed/workspace/git2-rs/target/debug/deps/libbitflags-7be09f63d9f2d764.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libstd-9225b8e469c32698.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libpanic_unwind-2fe2b8cd4fa63c34.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libobject-80083cf4ee7ee3ff.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libaddr2line-ddf3832e718029e6.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libgimli-ba92c986e8ef2ca8.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_demangle-acd0bd456d8da820.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libhashbrown-55608c4156e4ecbb.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_alloc-4be618026614fdc7.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libunwind-fee25922260aa100.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcfg_if-38ba3c5cc408e14d.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liblibc-899852a009fbe35f.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/liballoc-5687564a0ccea916.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/librustc_std_workspace_core-9ed2c58b16cff4ee.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcore-244bf5611f93ff45.rlib" "/Users/Waleed/.rustup/toolchains/stable-x86_64-apple-darwin/lib/rustlib/x86_64-apple-darwin/lib/libcompiler_builtins-70df686e6b4ebf5b.rlib" "-lgit2" "-lssl" "-lcrypto" "-lz" "-liconv" "-lSystem" "-lresolv" "-lc" "-lm" "-liconv"
= note: Undefined symbols for architecture x86_64:
"_git_branch_name_is_valid", referenced from:
git2::branch::Branch::name_is_valid::hf21c1179aaf6f2cb in git2-77dec5eea979a8ff.git2.4s4bygf1-cgu.11.rcgu.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: aborting due to previous error
error: could not compile `git2`
To learn more, run the command again with --verbose.
```
It looks like you are linking against a homebrew installed version of libgit2. However, since #708, libgit2-sys is expecting a recent master version (which is still called 1.1.0).
@alexcrichton How would you like to proceed? It seems that now that libgit2 is past 1.0, it might show up in package managers more often, and this kind of error will be more common. I think either libgit2-sys would need to stay pinned to the released version, or stop trying to use the system-built package (or, in the middle ground, we'd need to be very careful about referring to new symbols, which I guess could be checked in CI).
As a side note, this test fails for me on both macos and linux with:
thread 'branch::tests::name_is_valid' panicked at 'called Result::unwrap() on an Err value: Error { code: -1, klass: 0, message: "an unknown git error occurred" }', src/branch.rs:191:46
I don't have a moment to investigate more, but I'm surprised as it passes CI.
I'm fine either way, if this is an issue we can add versioning logic and only expose some APIs on some versions
Is there any chance of accelerating the next tagged release? Downstream projects have started releasing things relying on the main branch features and it's blocking distro packaging. It would be really nice to see whatever APIs need to be stabilized stabilized so we can convince downstream projects to use stable release versions again.
@alerque when i was looking into it, it seemed like you can force git2 to build libgit2 from source by setting the zlib_ng_compat feature:
https://github.com/rust-lang/git2-rs/blob/b863968301f0e889fa04afc590d7e2c9a4100dc3/libgit2-sys/build.rs#L13
This might be a good workaround for projects to avoid versioning issues for the time being.
It would probably be best if git2 exposed a "build from source" feature directly, since there are many reasons a consumer might want to statically build it. For example, rusqlite has a bundled feature which lets you build your own version of SQLite into your executable.
@arxanas that would be nice, I would definitely like this approach for gitui (to be honest, I thought thats already what happens, considering the whole libgit2 repo is a submodule here)
That would not help distribution packagers much - many distributions have rules and / or guidelines in place that prohibit building against bundled libraries, if it's possible to build against system-provided libraries. So if git2 added a vendored feature that gitui would then start using, we'd probably end up having to patch it out again anyway.
Even if it doesn't help distribution packagers, it should still help people who are trying to compile from source and end up in the same situation as me in the original report. I opened #739 to add a vendored feature.
Several of my users had compilation problems for SQLite which probably could have been avoided (https://github.com/arxanas/git-branchless/pull/13, https://github.com/arxanas/git-branchless/issues/17). Who knows how many users tried to install my project, but immediately gave up because libgit2 didn't link properly? I'll probably change my own project to build libgit2 by default when in a non-packaged setting.