support building python bindings for python 3 and 64 bit

This commit is contained in:
Steven Siloti 2018-03-25 13:31:26 -07:00 committed by Arvid Norberg
parent 1c867a5026
commit e7e5805c56
3 changed files with 61 additions and 7 deletions

View File

@ -8,6 +8,8 @@ import modules ;
use-project /torrent : ../.. ;
BOOST_ROOT = [ modules.peek : BOOST_ROOT ] ;
# this is used to make bjam use the same version of python which is executing setup.py
LIBTORRENT_PYTHON_INTERPRETER = [ modules.peek : LIBTORRENT_PYTHON_INTERPRETER ] ;
feature visibility : default hidden : composite ;
feature.compose <visibility>hidden : <cflags>-fvisibility=hidden <cxxflags>-fvisibility-inlines-hidden ;
@ -16,10 +18,20 @@ feature libtorrent-link : shared static : composite propagated ;
feature libtorrent-python-pic : off on : composite propagated link-incompatible ;
feature.compose <libtorrent-python-pic>on : <cflags>-fPIC ;
# this is just to force boost build to pick the desired python target when using LIBTORRENT_PYTHON_INTERPRETER
feature libtorrent-python : on ;
if $(LIBTORRENT_PYTHON_INTERPRETER)
{
echo "using python interpreter at: " $(LIBTORRENT_PYTHON_INTERPRETER) ;
using python : : "$(LIBTORRENT_PYTHON_INTERPRETER)" : : : <libtorrent-python>on ;
}
if $(BOOST_ROOT)
{
use-project /boost : $(BOOST_ROOT) ;
alias boost_python : /boost/python//boost_python : : : <include>$(BOOST_ROOT) ;
alias boost_python3 : /boost/python//boost_python3 : : : <include>$(BOOST_ROOT) ;
}
else
{
@ -40,9 +52,13 @@ else
# the names are decorated in MacPorts
lib boost_python : : <target-os>darwin <name>boost_python-mt
: : $(boost-include-path) ;
lib boost_python3 : : <target-os>darwin <name>boost_python3-mt
: : $(boost-include-path) ;
lib boost_python : : <name>boost_python
: : $(boost-include-path) ;
lib boost_python3 : : <name>boost_python3
: : $(boost-include-path) ;
}
@ -79,16 +95,33 @@ rule libtorrent_linking ( properties * )
ECHO "WARNING: you cannot link statically against boost-python on linux, because it links against pthread statically in that case, which is not allowed" ;
}
local boost_python_lib ;
for local prop in $(properties)
{
switch $(prop)
{
case <python>2.* : boost_python_lib = boost_python ;
case <python>3.* : boost_python_lib = boost_python3 ;
}
}
if ! $(boost_python_lib)
{
ECHO "WARNING: unknown python version" ;
boost_python_lib = boost_python ;
}
# linux must link dynamically against boost python because it pulls
# in libpthread, which must be linked dynamically since we're building a .so
# (the static build of libpthread is not position independent)
if <boost-link>shared in $(properties) || <target-os>linux in $(properties)
{
result += <library>boost_python/<link>shared ;
result += <library>$(boost_python_lib)/<link>shared ;
}
else
{
result += <library>boost_python/<link>static ;
result += <library>$(boost_python_lib)/<link>static ;
}
if <libtorrent-link>shared in $(properties)

View File

@ -74,15 +74,36 @@ if '--bjam' in sys.argv:
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'
# See https://wiki.python.org/moin/WindowsCompilers for a table of msvc versions
# used for each python version
# Specify the full version number for 9.0 and 10.0 because apparently
# older versions of boost don't support only specifying the major number and
# there was only one version of msvc with those majors.
# Only specify the major for msvc-14 so that 14.1, 14.11, etc can be used.
# Hopefully people building with msvc-14 are using a new enough version of boost
# for this to work.
if sys.version_info[0:2] in ((2, 6), (2, 7), (3, 0), (3, 1), (3, 2)):
toolset = ' toolset=msvc-9.0'
elif sys.version_info[0:2] in ((3, 3), (3, 4)):
toolset = ' toolset=msvc-10.0'
elif sys.version_info[0:2] in ((3, 5), (3, 6)):
toolset = ' toolset=msvc-14'
else:
# unknown python version, lets hope the user has the right version of msvc configured
toolset = ' toolset=msvc'
parallel_builds = ' -j%d' % multiprocessing.cpu_count()
if sys.maxsize > 2**32:
address_model = ' address-model=64'
else:
address_model = ' address-model=32'
# add extra quoting around the path to prevent bjam from parsing it as a list
# if the path has spaces
os.environ['LIBTORRENT_PYTHON_INTERPRETER'] = '"' + sys.executable + '"'
# build libtorrent using bjam and build the installer with distutils
cmdline = 'b2 libtorrent-link=static boost-link=static release optimization=space stage_module --abbreviate-paths' + toolset + parallel_builds
cmdline = 'b2 libtorrent-link=static boost-link=static release optimization=space stage_module --abbreviate-paths' + address_model + toolset + parallel_builds
print(cmdline)
if os.system(cmdline) != 0:
print('build failed')

2
setup.py Executable file → Normal file
View File

@ -2,4 +2,4 @@
import os
os.chdir('bindings/python')
execfile('setup.py')
exec(open('setup.py').read())