Skip to content
Snippets Groups Projects
Commit ca86742a authored by Donald Stufft's avatar Donald Stufft
Browse files

Merge pull request #41 from dstufft/support-system-lib

Enable using the system library and falling back to the bundled
parents bc3ad28c 3e1fea20
No related branches found
No related tags found
No related merge requests found
language: python
python: 2.7
env:
- TOXENV=py26
- TOXENV=py27
- TOXENV=py32
- TOXENV=py33
- TOXENV=pypy
- TOXENV=py26 SODIUM_INSTALL=bundled
- TOXENV=py27 SODIUM_INSTALL=bundled
- TOXENV=py32 SODIUM_INSTALL=bundled
- TOXENV=py33 SODIUM_INSTALL=bundled
- TOXENV=pypy SODIUM_INSTALL=bundled
- TOXENV=py26 SODIUM_INSTALL=system
- TOXENV=py27 SODIUM_INSTALL=system
- TOXENV=py32 SODIUM_INSTALL=system
- TOXENV=py33 SODIUM_INSTALL=system
- TOXENV=pypy SODIUM_INSTALL=system
install:
# Add the PyPy repository
......@@ -16,6 +21,18 @@ install:
# This is required because we need to get rid of the Travis installed PyPy
# or it'll take precedence over the PPA installed one.
- "if [[ $TOXENV == 'pypy' ]]; then sudo rm -rf /usr/local/pypy/bin; fi"
# Install Sodium if we need too
- "if [[ $SODIUM_INSTALL == 'system' ]]; then wget https://download.libsodium.org/libsodium/releases/LATEST.tar.gz; fi"
- "if [[ $SODIUM_INSTALL == 'system' ]]; then tar zxvf LATEST.tar.gz; fi"
- "if [[ $SODIUM_INSTALL == 'system' ]]; then cd libsodium-*; fi"
- "if [[ $SODIUM_INSTALL == 'system' ]]; then ./configure; fi"
- "if [[ $SODIUM_INSTALL == 'system' ]]; then make; fi"
- "if [[ $SODIUM_INSTALL == 'system' ]]; then make check; fi"
- "if [[ $SODIUM_INSTALL == 'system' ]]; then sudo make install; fi"
- "if [[ $SODIUM_INSTALL == 'system' ]]; then sudo ldconfig; fi"
# Install tox and coveralls so we can run our tests
- pip install tox coveralls
......
......@@ -25,6 +25,10 @@ from distutils.command.build_ext import build_ext as _build_ext
from setuptools import Distribution, setup
SODIUM_MAJOR = 4
SODIUM_MINOR = 3
def here(*paths):
return os.path.abspath(os.path.join(os.path.dirname(__file__), *paths))
......@@ -67,10 +71,45 @@ else:
ext_modules = [nacl.nacl.ffi.verifier.get_extension()]
def use_system():
install_type = os.environ.get("SODIUM_INSTALL")
if install_type == "system":
# If we are forcing system installs, don't compile the bundled one
return True
elif install_type == "bundled":
# If we are forcing bundled installs, compile it
return False
# Detect if we have libsodium available
import cffi
ffi = cffi.FFI()
ffi.cdef("""
int sodium_library_version_major();
int sodium_library_version_minor();
""")
try:
system = ffi.dlopen("libsodium")
except OSError:
# We couldn't locate libsodium so we'll use the bundled one
return False
if system.sodium_library_version_major() != SODIUM_MAJOR:
return False
if system.sodium_library_version_minor() < SODIUM_MINOR:
return False
# If we got this far then the system library should be good enough
return True
class Distribution(Distribution):
def has_c_libraries(self):
return True
return not use_system()
class build_clib(_build_clib):
......@@ -95,6 +134,9 @@ class build_clib(_build_clib):
return ["sodium"]
def run(self):
if use_system():
return
build_temp = os.path.abspath(self.build_temp)
# Ensure our temporary build directory exists
......@@ -129,11 +171,14 @@ class build_clib(_build_clib):
class build_ext(_build_ext):
def run(self):
build_clib = self.get_finalized_command("build_clib")
self.include_dirs.append(
os.path.join(build_clib.build_clib, "include")
)
self.library_dirs.append(os.path.join(build_clib.build_clib, "lib"))
if self.distribution.has_c_libraries():
build_clib = self.get_finalized_command("build_clib")
self.include_dirs.append(
os.path.join(build_clib.build_clib, "include"),
)
self.library_dirs.append(
os.path.join(build_clib.build_clib, "lib"),
)
return _build_ext.run(self)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment