mirror of
https://github.com/msgpack/msgpack-python.git
synced 2025-10-19 20:03:16 +00:00
Use C++ compiler on win32.
This commit is contained in:
parent
7c03f322fa
commit
670bb3ca15
1 changed files with 48 additions and 21 deletions
69
setup.py
69
setup.py
|
@ -4,23 +4,62 @@ version = (0, 2, 1, 'dev1')
|
|||
|
||||
import os
|
||||
import sys
|
||||
import shutil
|
||||
from glob import glob
|
||||
from distutils.command.sdist import sdist
|
||||
from setuptools import setup, Extension
|
||||
|
||||
from distutils.command.build_ext import build_ext
|
||||
|
||||
try:
|
||||
from Cython.Distutils import build_ext
|
||||
import Cython.Compiler.Main as cython_compiler
|
||||
have_cython = True
|
||||
except ImportError:
|
||||
from distutils.command.build_ext import build_ext
|
||||
have_cython = False
|
||||
|
||||
|
||||
def cythonize(src):
|
||||
sys.stderr.write("cythonize: %r\n" % (src,))
|
||||
cython_compiler.compile([src])
|
||||
|
||||
def ensure_source(src):
|
||||
pyx = os.path.splitext(src)[0] + '.pyx'
|
||||
|
||||
if not os.path.exists(src):
|
||||
if not have_cython:
|
||||
raise Exception("""\
|
||||
Cython is required for building extension from checkout.
|
||||
Install Cython >= 0.16 or install msgpack from PyPI.
|
||||
""")
|
||||
cythonize(src)
|
||||
elif (os.path.exists(pyx) and
|
||||
os.stat(src).st_mtime < os.stat(pyx).st_mtime and
|
||||
have_cython):
|
||||
cythonize(src)
|
||||
|
||||
# Use C++ compiler on win32.
|
||||
# MSVC9 doesn't provide stdint.h when using C Compiler.
|
||||
if sys.platform == 'win32':
|
||||
cpp = src + 'pp'
|
||||
shutil.copy(src, cpp)
|
||||
return cpp
|
||||
else:
|
||||
return src
|
||||
|
||||
|
||||
class BuildExt(build_ext):
|
||||
def build_extension(self, ext):
|
||||
ext.sources = map(ensure_source, ext.sources)
|
||||
return build_ext.build_extension(self, ext)
|
||||
|
||||
|
||||
# make msgpack/__verison__.py
|
||||
f = open('msgpack/__version__.py', 'w')
|
||||
f.write("version = %r\n" % (version,))
|
||||
f.close()
|
||||
del f
|
||||
try:
|
||||
f.write("version = %r\n" % (version,))
|
||||
finally:
|
||||
f.close()
|
||||
del f
|
||||
|
||||
version_str = '.'.join(str(x) for x in version[:3])
|
||||
if len(version) > 3 and version[3] != 'final':
|
||||
|
@ -28,29 +67,18 @@ if len(version) > 3 and version[3] != 'final':
|
|||
|
||||
# take care of extension modules.
|
||||
if have_cython:
|
||||
sources = ['msgpack/_msgpack.pyx']
|
||||
|
||||
class Sdist(sdist):
|
||||
def __init__(self, *args, **kwargs):
|
||||
cy_opt = cython_compiler.default_options.copy()
|
||||
#cy_opt['cplus'] = True
|
||||
for src in glob('msgpack/*.pyx'):
|
||||
cython_compiler.compile(glob('msgpack/*.pyx'), cy_opt)
|
||||
cythonize(src)
|
||||
sdist.__init__(self, *args, **kwargs)
|
||||
else:
|
||||
sources = ['msgpack/_msgpack.c']
|
||||
|
||||
for f in sources:
|
||||
if not os.path.exists(f):
|
||||
raise ImportError("Building msgpack from VCS needs Cython. Install Cython or use sdist package.")
|
||||
|
||||
Sdist = sdist
|
||||
|
||||
sources = ['msgpack/_msgpack.c']
|
||||
libraries = []
|
||||
language = 'c'
|
||||
if sys.platform == 'win32':
|
||||
libraries.append('ws2_32')
|
||||
language = 'c++'
|
||||
|
||||
if sys.byteorder == 'big':
|
||||
macros = [('__BIG_ENDIAN__', '1')]
|
||||
|
@ -61,10 +89,9 @@ msgpack_mod = Extension('msgpack._msgpack',
|
|||
sources=sources,
|
||||
libraries=libraries,
|
||||
include_dirs=['.'],
|
||||
language=language,
|
||||
define_macros=macros,
|
||||
)
|
||||
del sources, libraries, language, macros
|
||||
del sources, libraries, macros
|
||||
|
||||
|
||||
desc = 'MessagePack (de)serializer.'
|
||||
|
@ -77,7 +104,7 @@ setup(name='msgpack-python',
|
|||
author='INADA Naoki',
|
||||
author_email='songofacandy@gmail.com',
|
||||
version=version_str,
|
||||
cmdclass={'build_ext': build_ext, 'sdist': Sdist},
|
||||
cmdclass={'build_ext': BuildExt, 'sdist': Sdist},
|
||||
ext_modules=[msgpack_mod],
|
||||
packages=['msgpack'],
|
||||
description=desc,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue