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

Fails to build when a different version of libgit2 is already installed (with custom CFLAGS) #60

Closed
eminence opened this issue May 1, 2015 · 3 comments

Comments

@eminence
Copy link

eminence commented May 1, 2015

My scenario is a little unusual. At work, I don't have the ability to install packages system-wide, so I have a large collection of code installed into a homedirectory prefix. My environment has $CFLAGS and $LDFLAGS configured with -I and -L options that point to my custom prefix.

I have a version of libgit2 installed that is different from the version of libgit2 required by git2-rs. This seems to be causing git2-rs to fail to build because it seems to be finding libgit2 headers from my own install, not the packaged version.

Build failed, waiting for other jobs to finish...
failed to run custom build command for `libgit2-sys v0.2.12`
Process didn't exit successfully: `/rd/gen/lxd/do_not_delete/devel/cargo/target/debug/build/libgit2-sys-02c2db14240aac09/build-script-build` (exit code: 101)
--- stdout
running: "cmake" "/u/users/lxd/.cargo/registry/src/github.com-1ecc6299db9ec823/libgit2-sys-0.2.12/libgit2" "-DTHREADSAFE=ON" "-DBUILD_SHARED_LIBS=OFF" "-DBUILD_CLAR=OFF" "-DCMAKE_BUILD_TYPE=Debug" "-DCMAKE_INSTALL_PREFIX=/rd/gen/lxd/do_not_delete/devel/cargo/target/x86_64-unknown-linux-gnu/debug/build/libgit2-sys-02c2db14240aac09/out" "-DBUILD_EXAMPLES=OFF" "-DCMAKE_C_FLAGS=-I/rd/gen/lxd/do_not_delete/lnx86_64/include -I/u/users/lxd/qt48base/include -ffunction-sections -fdata-sections -m64 -fPIC"
-- Could NOT find HTTP_Parser (missing:  HTTP_PARSER_INCLUDE_DIR HTTP_PARSER_LIBRARY) 
-- http-parser was not found or is too old; using bundled 3rd-party sources.
-- Configuring done
-- Generating done
-- Build files have been written to: /rd/gen/lxd/do_not_delete/devel/cargo/target/x86_64-unknown-linux-gnu/debug/build/libgit2-sys-02c2db14240aac09/out/build
running: "cmake" "--build" "." "--target" "install"
gmake[1]: Entering directory `/rd/gen/lxd/do_not_delete/devel/cargo/target/x86_64-unknown-linux-gnu/debug/build/libgit2-sys-02c2db14240aac09/out/build'
gmake[2]: Entering directory `/rd/gen/lxd/do_not_delete/devel/cargo/target/x86_64-unknown-linux-gnu/debug/build/libgit2-sys-02c2db14240aac09/out/build'
gmake[3]: Entering directory `/rd/gen/lxd/do_not_delete/devel/cargo/target/x86_64-unknown-linux-gnu/debug/build/libgit2-sys-02c2db14240aac09/out/build'
gmake[3]: Leaving directory `/rd/gen/lxd/do_not_delete/devel/cargo/target/x86_64-unknown-linux-gnu/debug/build/libgit2-sys-02c2db14240aac09/out/build'
gmake[3]: Entering directory `/rd/gen/lxd/do_not_delete/devel/cargo/target/x86_64-unknown-linux-gnu/debug/build/libgit2-sys-02c2db14240aac09/out/build'
[  1%] Building C object CMakeFiles/git2.dir/src/diff_tform.c.o
/u/users/lxd/.cargo/registry/src/github.com-1ecc6299db9ec823/libgit2-sys-0.2.12/libgit2/src/diff_tform.c: In function 'normalize_find_opts':
/u/users/lxd/.cargo/registry/src/github.com-1ecc6299db9ec823/libgit2-sys-0.2.12/libgit2/src/diff_tform.c:355: error: 'GIT_HASHSIG_ALLOW_SMALL_FILES' undeclared (first use in this function)
/u/users/lxd/.cargo/registry/src/github.com-1ecc6299db9ec823/libgit2-sys-0.2.12/libgit2/src/diff_tform.c:355: error: (Each undeclared identifier is reported only once
/u/users/lxd/.cargo/registry/src/github.com-1ecc6299db9ec823/libgit2-sys-0.2.12/libgit2/src/diff_tform.c:355: error: for each function it appears in.)
At top level:
cc1: warning: unrecognized command line option "-Wno-unused-const-variable"
gmake[3]: *** [CMakeFiles/git2.dir/src/diff_tform.c.o] Error 1
gmake[3]: Leaving directory `/rd/gen/lxd/do_not_delete/devel/cargo/target/x86_64-unknown-linux-gnu/debug/build/libgit2-sys-02c2db14240aac09/out/build'
gmake[2]: *** [CMakeFiles/git2.dir/all] Error 2
gmake[2]: Leaving directory `/rd/gen/lxd/do_not_delete/devel/cargo/target/x86_64-unknown-linux-gnu/debug/build/libgit2-sys-02c2db14240aac09/out/build'
gmake[1]: *** [all] Error 2
gmake[1]: Leaving directory `/rd/gen/lxd/do_not_delete/devel/cargo/target/x86_64-unknown-linux-gnu/debug/build/libgit2-sys-02c2db14240aac09/out/build'

--- stderr
thread '<main>' panicked at '
command did not execute successfully, got: exit code: 2

build script failed, must exit now', /u/users/lxd/.cargo/registry/src/github.com-1ecc6299db9ec823/libgit2-sys-0.2.12/build.rs:109

Any thoughts about how to deal with this? The only workaround that I know of is to unset CFLAGS and LDFLAGS before building git2-rs

Thanks,
-Andrew

@alexcrichton
Copy link
Member

This is actually a great scenario where build script overrides come into play. You'll want to make a ~/.cargo/config file that looks like this:

[target.x86_64-unknown-linux-gnu.libgit2]
rustc-link-search = ["native=/path/to/libgit2/lib"]
rustc-link-lib = ["static=libgit2"]

That'll override libgit2-sys's build script so you'll be able to manually configure how it's linked to. Lemme know if you have any more trouble though!

@eminence
Copy link
Author

eminence commented May 1, 2015

From your example, it looks like the override instructs cargo where to find the libgit2 library. Am I reading this correctly? In my case, I want to use the version of libgit2 that is shipped with git2-rs, not the version already on my system. How would I do that?

@alexcrichton
Copy link
Member

Oh oops, sorry for misreading! I'm unfortunately not really sure how to fix something like this other than just recommending that you unset CFLAGS before the build :(

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

No branches or pull requests

2 participants