simplified setup.py to always build the bindings using bjam

This commit is contained in:
Arvid Norberg 2014-03-23 07:34:18 +00:00
parent e2e4044b9b
commit 45f3fa4696
7 changed files with 84 additions and 95 deletions

View File

@ -1,3 +1,4 @@
* simplified building python bindings
* make ignore_non_routers more forgiving in the case there are no UPnP * make ignore_non_routers more forgiving in the case there are no UPnP
devices at a known router. Should improve UPnP compatibility. devices at a known router. Should improve UPnP compatibility.
* include reason in peer_blocked_alert * include reason in peer_blocked_alert

View File

@ -1,4 +1,4 @@
Copyright (c) 2003-2010, Arvid Norberg Copyright (c) 2003-2014, Arvid Norberg
All rights reserved. All rights reserved.
Redistribution and use in source and binary forms, with or without Redistribution and use in source and binary forms, with or without

View File

@ -1,10 +1,14 @@
import python ; import python ;
import feature : feature ;
use-project /torrent : ../.. ; use-project /torrent : ../.. ;
lib boost_python : : <target-os>darwin <name>boost_python-mt $(boost-library-search-path) ; lib boost_python : : <target-os>darwin <name>boost_python-mt $(boost-library-search-path) ;
lib boost_python : : <name>boost_python ; lib boost_python : : <name>boost_python ;
feature visibility : default hidden : composite propagated link-incompatible ;
feature.compose <visibility>hidden : <cflags>-fvisibility=hidden <cxxflags>-fvisibility-inlines-hidden ;
rule libtorrent_linking ( properties * ) rule libtorrent_linking ( properties * )
{ {
local result ; local result ;
@ -19,7 +23,12 @@ rule libtorrent_linking ( properties * )
|| <toolset>clang in $(properties) || <toolset>clang in $(properties)
|| <toolset>clang-darwin in $(properties) || <toolset>clang-darwin in $(properties)
{ {
result += <cxxflags>-fvisibility=hidden ; result += <visibility>hidden ;
if ( <toolset>gcc in $(properties) )
{
result += <linkflags>-Wl,-Bsymbolic ;
}
} }
if <boost>source in $(properties) if <boost>source in $(properties)
@ -35,7 +44,7 @@ rule libtorrent_linking ( properties * )
if <link>static in $(properties) if <link>static in $(properties)
{ {
result += <library>/torrent//torrent/<link>static ; result += <library>/torrent//torrent/<link>static/<boost-link>static ;
} }
else else
{ {
@ -45,14 +54,23 @@ rule libtorrent_linking ( properties * )
else else
{ {
result += <library>boost_python ; result += <library>boost_python ;
if <link>static in $(properties)
{
result += <library>/torrent//torrent/<link>static/<boost-link>static ;
}
else
{
result += <library>/torrent//torrent/<link>shared/<boost-link>shared ; result += <library>/torrent//torrent/<link>shared/<boost-link>shared ;
} }
}
return $(result) ; return $(result) ;
} }
python-extension libtorrent python-extension libtorrent
: src/module.cpp : # sources
src/module.cpp
src/big_number.cpp src/big_number.cpp
src/converters.cpp src/converters.cpp
src/create_torrent.cpp src/create_torrent.cpp
@ -73,9 +91,10 @@ python-extension libtorrent
src/ip_filter.cpp src/ip_filter.cpp
src/magnet_uri.cpp src/magnet_uri.cpp
src/error_code.cpp src/error_code.cpp
: <include>src : # requirements
<include>src
<conditional>@libtorrent_linking <conditional>@libtorrent_linking
: : # default build
<boost-link>static <boost-link>static
; ;

54
bindings/python/setup.py Normal file
View File

@ -0,0 +1,54 @@
#!/usr/bin/env python
from distutils import sysconfig
from distutils.core import setup, Extension
import os
import platform
import sys
import shutil
import multiprocessing
if not '--help' in sys.argv \
and not '--help-commands' in sys.argv:
toolset = ''
file_ext = '.so'
if platform.system() == 'Windows':
# msvc 9.0 (2008) is the official windows compiler for python 2.6
# http://docs.python.org/whatsnew/2.6.html#build-and-c-api-changes
toolset = ' msvc-9.0'
file_ext = '.pyd'
parallell_builds = ' -j%d' % multiprocessing.cpu_count()
# build libtorrent using bjam and build the installer with distutils
cmdline = 'bjam boost=source link=static geoip=static boost-link=static release optimization=space stage_module --abbreviate-paths' + toolset + parallell_builds
print cmdline
if os.system(cmdline) != 0:
print('build failed')
sys.exit(1)
try: os.mkdir('build')
except: pass
try: shutil.rmtree('build/lib')
except: pass
try: os.mkdir('build/lib')
except: pass
try: os.mkdir('libtorrent')
except: pass
shutil.copyfile('libtorrent' + file_ext, 'build/lib/libtorrent' + file_ext)
setup( name='python-libtorrent',
version='1.0.0',
author = 'Arvid Norberg',
author_email='arvid@rasterbar.com',
description = 'Python bindings for libtorrent-rasterbar',
long_description = 'Python bindings for libtorrent-rasterbar',
url = 'http://libtorrent.org',
platforms = [platform.system() + '-' + platform.machine()],
license = 'BSD',
packages = ['libtorrent'],
)

View File

@ -1,86 +0,0 @@
#!/usr/bin/env python
from distutils import sysconfig
from distutils.core import setup, Extension
import os
import platform
import sys
if '@BOOST_PYTHON_LIB@' == '':
print('You need to pass --enable-python-binding to configure in order '),
print('to properly use this setup. There is no boost.python library configured now')
sys.exit(1)
def parse_cmd(cmdline, prefix, keep_prefix = False):
ret = []
for token in cmdline.split():
if token[:len(prefix)] == prefix:
if keep_prefix:
ret.append(token)
else:
ret.append(token[len(prefix):])
return ret
def arch():
if platform.system() != 'Darwin': return []
a = os.uname()[4]
if a == 'Power Macintosh': a = 'ppc'
return ['-arch', a]
if platform.system() == 'Windows':
# on windows, build using bjam and build an installer
import shutil
# msvc 9.0 (2008) is the official windows compiler for python 2.6
# http://docs.python.org/whatsnew/2.6.html#build-and-c-api-changes
if os.system('bjam boost=source link=static geoip=static boost-link=static release msvc-9.0 optimization=space') != 0:
print('build failed')
sys.exit(1)
try: os.mkdir(r'build')
except: pass
try: os.mkdir(r'build\lib')
except: pass
try: os.mkdir(r'libtorrent')
except: pass
shutil.copyfile(r'bin\msvc-9.0\release\boost-source\geoip-static\link-static\optimization-space\threading-multi\libtorrent.pyd', r'.\build\lib\libtorrent.pyd')
setup( name='python-libtorrent',
version='@PACKAGE_VERSION@',
author = 'Arvid Norberg',
author_email='@PACKAGE_BUGREPORT@',
description = 'Python bindings for libtorrent-rasterbar',
long_description = 'Python bindings for libtorrent-rasterbar',
url = 'http://www.rasterbar.com/products/libtorrent/index.html',
platforms = 'Windows',
license = 'Boost Software License - Version 1.0 - August 17th, 2003',
packages = ['libtorrent'],
)
sys.exit(0)
config_vars = sysconfig.get_config_vars()
if "CFLAGS" in config_vars and "-Wstrict-prototypes" in config_vars["CFLAGS"]:
config_vars["CFLAGS"] = config_vars["CFLAGS"].replace("-Wstrict-prototypes", " ")
if "OPT" in config_vars and "-Wstrict-prototypes" in config_vars["OPT"]:
config_vars["OPT"] = config_vars["OPT"].replace("-Wstrict-prototypes", " ")
source_list = os.listdir(os.path.join(os.path.dirname(__file__), "src"))
source_list = [os.path.join("src", s) for s in source_list if s.endswith(".cpp")]
extra_cmd = '@COMPILETIME_OPTIONS@ @CPPFLAGS@ @LIBS@ @BOOST_SYSTEM_LIB@ @BOOST_PYTHON_LIB@ @PTHREAD_LIBS@ @OPENSSL_LIBS@ @OPENSSL_LDFLAGS@ @OPENSSL_INCLUDES@'
setup( name='python-libtorrent',
version='@PACKAGE_VERSION@',
author = 'Arvid Norberg',
author_email='@PACKAGE_BUGREPORT@',
description = 'Python bindings for libtorrent-rasterbar',
long_description = 'Python bindings for libtorrent-rasterbar',
url = 'http://www.rasterbar.com/products/libtorrent/index.html',
platforms = 'any',
license = 'Boost Software License - Version 1.0 - August 17th, 2003',
ext_modules = [Extension('libtorrent',
sources = source_list,
language='c++',
include_dirs = ['@top_srcdir@/include'] + parse_cmd(extra_cmd, '-I'),
library_dirs = ['@top_builddir@/src/.libs'] + parse_cmd(extra_cmd, '-L'),
extra_link_args = '@LDFLAGS@'.split() + arch(),
extra_compile_args = parse_cmd(extra_cmd, '-D', True) + arch(),
libraries = ['torrent-rasterbar'] + parse_cmd(extra_cmd, '-l'))],
)

View File

@ -173,7 +173,7 @@ AC_CHECK_FUNCS([clock_gettime], [],
) )
dnl Pass some build options to setup.py and .pc file dnl Pass some build options to .pc file
COMPILETIME_OPTIONS="" COMPILETIME_OPTIONS=""
@ -687,7 +687,6 @@ AC_CONFIG_FILES(
[tools/Makefile] [tools/Makefile]
[bindings/Makefile] [bindings/Makefile]
[bindings/python/Makefile] [bindings/python/Makefile]
[bindings/python/setup.py]
[libtorrent-rasterbar.pc] [libtorrent-rasterbar.pc]
[libtorrent-rasterbar-cmake.pc] [libtorrent-rasterbar-cmake.pc]
) )

View File

@ -25,6 +25,8 @@ def substitute_file(name):
l = ':Version: %d.%d.%d\n' % (version[0], version[1], version[2]) l = ':Version: %d.%d.%d\n' % (version[0], version[1], version[2])
elif 'VERSION = ' in l and name.endswith('Jamfile'): elif 'VERSION = ' in l and name.endswith('Jamfile'):
l = 'VERSION = %d.%d.%d ;\n' % (version[0], version[1], version[2]) l = 'VERSION = %d.%d.%d ;\n' % (version[0], version[1], version[2])
elif 'version=' in l and name.endswith('setup.py'):
l = "\tversion='%d.%d.%d'\n" % (version[0], version[1], version[2])
subst += l subst += l