pynacl

Python wrapper for http://nacl.cace-project.eu/
git clone https://code.literati.org/pynacl.git
Log | Files | Refs | README

setup.py (2808B)


      1 #!/usr/bin/env python
      2 """
      3 Build and install the NaCl wrapper.
      4 """
      5 
      6 import sys, os, platform, re
      7 from distutils.core import setup, Extension
      8 
      9 hostname = platform.node()
     10 shost = re.sub(r'[^a-zA-Z0-9]+', '', hostname.split(".")[0])
     11 
     12 # http://docs.python.org/library/platform.html#platform.architecture
     13 # recommends this to test the 64-bitness of the current interpreter:
     14 is_64bits = sys.maxsize > 2**32
     15 # My OS-X 10.6 laptop reports platform.uname()[4]=='i386', but
     16 # is_64bits==True, and gcc appears to use -m64 by default. The symptoms of
     17 # getting it wrong are errors during any compilation that tries to use
     18 # libnacl.a:
     19 #  ld: warning: in .../libnacl.a, file is not of required architecture
     20 #  Undefined symbols:
     21 #    "_crypto_hash_sha512_ref", referenced from:
     22 #        _main in ....o
     23 #  ld: symbol(s) not found
     24 
     25 # note that system Python will try to compile everything for multiple arches
     26 # at once ("universal binaries"), with "-arch i386 -arch ppc -arch x86_64",
     27 # but each libnacl.a is for just a single arch (there are two copies, in
     28 # lib/x86/ and lib/amd64). So you can expect some harmless "not of required
     29 # architecture" warnings when running setup.py build, probably four:
     30 # (libnacl.a,randombytes.o) * (ppc, i386).
     31 
     32 if is_64bits:
     33     arch='amd64'
     34 else:
     35     arch='x86'
     36 
     37 EMBEDDED_NACL = "nacl-20110221"
     38 BUILD_DIR = os.path.join(EMBEDDED_NACL, "build")
     39 if not os.path.isdir(BUILD_DIR):
     40     print("""\
     41 It looks like you haven't built NaCl yet. Please do:
     42 
     43  cd %s
     44  ./do
     45 
     46 That will compile in furious silence for a long time (25 minutes on
     47 my 2010 laptop). If you want to watch for progress, look in
     48 %s/*/log .
     49 
     50 Then re-run this setup.py command.""") % (EMBEDDED_NACL, BUILD_DIR)
     51     sys.exit(1)
     52 
     53 dirs = os.listdir(BUILD_DIR)
     54 if len(dirs) == 1:
     55     NACL_DIR = os.path.join(BUILD_DIR, dirs[0])
     56 elif shost in dirs:
     57     NACL_DIR = os.path.join(BUILD_DIR, shost)
     58 else:
     59     print("""\
     60 This NaCl directory appears to have been compiled for multiple machines. I
     61 was expecting to use '%s', but found [%s] in:
     62 
     63  %s
     64 """) % (shost, ", ".join(dirs), BUILD_DIR)
     65     sys.exit(1)
     66 
     67 include_dirs = [os.path.join(NACL_DIR, "include", arch)]
     68 library_dirs = [os.path.join(NACL_DIR, "lib", arch)]
     69 extra_objects = [os.path.join(NACL_DIR, "lib", arch, "randombytes.o")]
     70 
     71 nacl_module = Extension('_nacl', ['nacl.i'],
     72                         include_dirs=include_dirs,
     73                         library_dirs=library_dirs,
     74                         extra_compiler_args=['-fPIC'],
     75                         extra_link_args=['-fPIC'],
     76                         libraries=['nacl'],
     77                         extra_objects=extra_objects)
     78 
     79 setup (name = 'nacl',
     80        version = '0.1',
     81        author      = "Sean Lynch",
     82        description = """Python wrapper for NaCl""",
     83        ext_modules = [nacl_module],
     84        py_modules  = ["nacl"])