Use C++ compiler on win32.

This commit is contained in:
INADA Naoki 2012-08-19 02:53:16 +09:00
parent 7c03f322fa
commit 670bb3ca15

View file

@ -4,23 +4,62 @@ version = (0, 2, 1, 'dev1')
import os import os
import sys import sys
import shutil
from glob import glob from glob import glob
from distutils.command.sdist import sdist from distutils.command.sdist import sdist
from setuptools import setup, Extension from setuptools import setup, Extension
from distutils.command.build_ext import build_ext
try: try:
from Cython.Distutils import build_ext
import Cython.Compiler.Main as cython_compiler import Cython.Compiler.Main as cython_compiler
have_cython = True have_cython = True
except ImportError: except ImportError:
from distutils.command.build_ext import build_ext
have_cython = False 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 # make msgpack/__verison__.py
f = open('msgpack/__version__.py', 'w') f = open('msgpack/__version__.py', 'w')
f.write("version = %r\n" % (version,)) try:
f.close() f.write("version = %r\n" % (version,))
del f finally:
f.close()
del f
version_str = '.'.join(str(x) for x in version[:3]) version_str = '.'.join(str(x) for x in version[:3])
if len(version) > 3 and version[3] != 'final': 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. # take care of extension modules.
if have_cython: if have_cython:
sources = ['msgpack/_msgpack.pyx']
class Sdist(sdist): class Sdist(sdist):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
cy_opt = cython_compiler.default_options.copy()
#cy_opt['cplus'] = True
for src in glob('msgpack/*.pyx'): for src in glob('msgpack/*.pyx'):
cython_compiler.compile(glob('msgpack/*.pyx'), cy_opt) cythonize(src)
sdist.__init__(self, *args, **kwargs) sdist.__init__(self, *args, **kwargs)
else: 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 Sdist = sdist
sources = ['msgpack/_msgpack.c']
libraries = [] libraries = []
language = 'c'
if sys.platform == 'win32': if sys.platform == 'win32':
libraries.append('ws2_32') libraries.append('ws2_32')
language = 'c++'
if sys.byteorder == 'big': if sys.byteorder == 'big':
macros = [('__BIG_ENDIAN__', '1')] macros = [('__BIG_ENDIAN__', '1')]
@ -61,10 +89,9 @@ msgpack_mod = Extension('msgpack._msgpack',
sources=sources, sources=sources,
libraries=libraries, libraries=libraries,
include_dirs=['.'], include_dirs=['.'],
language=language,
define_macros=macros, define_macros=macros,
) )
del sources, libraries, language, macros del sources, libraries, macros
desc = 'MessagePack (de)serializer.' desc = 'MessagePack (de)serializer.'
@ -77,7 +104,7 @@ setup(name='msgpack-python',
author='INADA Naoki', author='INADA Naoki',
author_email='songofacandy@gmail.com', author_email='songofacandy@gmail.com',
version=version_str, version=version_str,
cmdclass={'build_ext': build_ext, 'sdist': Sdist}, cmdclass={'build_ext': BuildExt, 'sdist': Sdist},
ext_modules=[msgpack_mod], ext_modules=[msgpack_mod],
packages=['msgpack'], packages=['msgpack'],
description=desc, description=desc,