I managed to get this setup up, in order to do it I had to read up on OSX's implementation of @rpath
:
- https://blogs.oracle.com/dipol/entry/dynamic_libraries_rpath_and_mac
- http://www.mikeash.com/pyblog/friday-qa-2009-11-06-linking-and-install-names.html
- http://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man1/install_name_tool.1.html
After reading these I proceeded with a clean install, like so :
libgit2
emil ~/Sites/env/testenv > export LIBGIT2=`pwd`
emil ~/Sites/env/testenv > git clone git://github.com/libgit2/libgit2.git -b v0.18.0
NOTE: Make sure you checkout the tag compatible with the current pygit2
version, at the moment you can use -b v0.18.0
.
(testenv)emil ~/sites/env/testenv/libgit2 > mkdir build && cd build
(testenv)emil ~/sites/env/testenv/libgit2/build > cmake .. -DCMAKE_INSTALL_PREFIX=$LIBGIT2
(testenv)emil ~/sites/env/testenv/libgit2/build > cmake --build . --target install
NOTE: If you don't have cmake
install it with Homebrew, with brew install cmake
Now we need to set the install name on the libgit2
library so that it can be found in a rpath
.
(testenv)emil ~/sites/env/testenv/lib > otool -D libgit2.0.18.0.dylib
libgit2.0.18.0.dylib:
libgit2.0.dylib
(testenv)emil ~/sites/env/testenv/lib > install_name_tool -id "@rpath/libgit2.0.18.0.dylib" libgit2.0.18.0.dylib
(testenv)emil ~/sites/env/testenv/lib > otool -D libgit2.0.18.0.dylib
libgit2.0.18.0.dylib:
@rpath/libgit2.0.18.0.dylib
pygit2
(testenv)emil ~/sites/env/testenv > git clone git://github.com/libgit2/pygit2.git
(testenv)emil ~/sites/env/testenv > cd pygit2/
(testenv)emil ~/sites/env/testenv/pygit2 > python setup.py build
NOTE: The OSX linker doesn't have some of the LDFLAGS recommended in the pygit2 tutorial so skip using them for now, you will set the rpath
later.
(testenv)emil ~/sites/env/testenv/pygit2 > python setup.py install
Ok, now you will get an error like this because the rpath
is not set up properly on the pygit2 library :
(testenv)emil ~/sites/env/testenv/pygit2 > python -c 'import pygit2'
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "pygit2/__init__.py", line 32, in <module>
import _pygit2
ImportError: dlopen(/Users/emil/sites/env/testenv/lib/python2.7/site-packages/_pygit2.so, 2): Library not loaded: @rpath/libgit2.0.18.0.dylib
Referenced from: /Users/emil/sites/env/testenv/lib/python2.7/site-packages/_pygit2.so
Reason: image not found
So let's set it :
(testenv)emil ~/sites/env/testenv/pygit2 > cd /Users/emil/sites/env/testenv/lib/python2.7/site-packages/
(testenv)emil ~/sites/env/testenv/lib/python2.7/site-packages > install_name_tool -add_rpath "@loader_path/../../" _pygit2.so
Now test it, if there is no output everything went fine :
(testenv)emil ~/sites/env/testenv/lib/python2.7/site-packages > python -c 'import pygit2'
:)