Skip to content

Commit

Permalink
Add a setup.py and a LICENSE, and move the shared library file into l…
Browse files Browse the repository at this point in the history
…lvmlite.binding package
  • Loading branch information
pitrou committed Oct 23, 2014
1 parent 803d8d8 commit 57e49da
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 13 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*.so
*.dylib
*.dll
build/
dist/
*.egg-info
ffi/build/
htmlcov/
.coverage
Expand Down
24 changes: 24 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Copyright (c) 2014-, Continuum Analytics, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
10 changes: 6 additions & 4 deletions ffi/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

here_dir = os.path.abspath(os.path.dirname(__file__))
build_dir = os.path.join(here_dir, 'build')
target_dir = os.path.join(os.path.dirname(here_dir), 'llvmlite', 'binding')


def main_win32():
Expand All @@ -22,22 +23,23 @@ def main_win32():
os.chdir(build_dir)
subprocess.check_call(['cmake', here_dir])
subprocess.check_call(['cmake', '--build', '.', '--config', config])
shutil.copy(os.path.join(build_dir, config, 'llvmlite.dll'), here_dir)
shutil.copy(os.path.join(build_dir, config, 'llvmlite.dll'), target_dir)


def main_posix(kind):
def main_posix(kind, library_ext):
os.chdir(here_dir)
makefile = "Makefile.%s" % (kind,)
subprocess.check_call(['make', '-f', makefile])
shutil.copy('libllvmlite' + library_ext, target_dir)


def main():
if sys.platform == 'win32':
main_win32()
elif sys.platform.startswith('linux'):
main_posix('linux')
main_posix('linux', '.so')
elif sys.platform == 'darwin':
main_posix('osx')
main_posix('osx', '.dylib')
else:
raise RuntimeError("unsupported platform: %r" % (sys.platform,))

Expand Down
23 changes: 14 additions & 9 deletions llvmlite/binding/ffi.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@ def _make_opaque_ref(name):
LLVMTargetMachineRef = _make_opaque_ref("LLVMTargetMachine")
LLVMMemoryBufferRef = _make_opaque_ref("LLVMMemoryBuffer")

ffi_dir = os.path.join(
os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'ffi')

if os.name == 'posix':
if sys.platform == 'darwin':
lib = ctypes.CDLL(os.path.join(ffi_dir, 'libllvmlite.dylib'))
def get_library_name():
"""
Return the name of the llvmlite shared library file.
"""
if os.name == 'posix':
if sys.platform == 'darwin':
return 'libllvmlite.dylib'
else:
return 'libllvmlite.so'
else:
lib = ctypes.CDLL(os.path.join(ffi_dir, 'libllvmlite.so'))
else:
assert os.name == 'nt'
lib = ctypes.CDLL(os.path.join(ffi_dir, 'llvmlite.dll'))
assert os.name == 'nt'
return 'llvmlite.dll'


lib = ctypes.CDLL(os.path.join(os.path.dirname(__file__), get_library_name()))


class _DeadPointer(object):
Expand Down
39 changes: 39 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
try:
from setuptools import setup, Extension
except ImportError:
from distutils.core import setup, Extension

from llvmlite.binding import ffi


packages = ['llvmlite',
'llvmlite.binding',
'llvmlite.llvmpy',
'llvmlite.tests',
]

setup(name='llvmlite',
description="lightweight wrapper around basic LLVM functionality",

classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 2.6",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3.3",
"Programming Language :: Python :: 3.4",
"Topic :: Software Development :: Code Generators",
"Topic :: Software Development :: Compilers",
],
# Include the separately-compiled shared library
package_data={
"llvmlite.binding": [ffi.get_library_name()],
},
author="Continuum Analytics, Inc.",
author_email="[email protected]",
url="https://github.com/numba/llvmlite",
packages=packages,
license="BSD",
)

0 comments on commit 57e49da

Please sign in to comment.