Skip to content

Commit 605766b

Browse files
committed
Merge pull request kivy#637 from brussee/libtorrent-recipe
add libtorrent recipe
2 parents cd6b78d + 84709a6 commit 605766b

File tree

7 files changed

+197
-0
lines changed

7 files changed

+197
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory
2+
from os.path import join, exists
3+
import sh
4+
5+
# This recipe creates a custom toolchain and bootstraps Boost from source to build Boost.Build
6+
# including python bindings
7+
class BoostRecipe(Recipe):
8+
version = '1.60.0'
9+
# Don't forget to change the URL when changing the version
10+
url = 'http://downloads.sourceforge.net/project/boost/boost/{version}/boost_1_60_0.tar.bz2'
11+
depends = ['python2']
12+
patches = ['disable-so-version.patch', 'use-android-libs.patch']
13+
14+
def should_build(self, arch):
15+
return not exists(join(self.get_build_dir(arch.arch), 'b2'))
16+
17+
def prebuild_arch(self, arch):
18+
super(BoostRecipe, self).prebuild_arch(arch)
19+
env = self.get_recipe_env(arch)
20+
with current_directory(self.get_build_dir(arch.arch)):
21+
# Make custom toolchain
22+
bash = sh.Command('bash')
23+
shprint(bash, join(self.ctx.ndk_dir, 'build/tools/make-standalone-toolchain.sh'),
24+
'--ndk-dir=' + self.ctx.ndk_dir,
25+
'--arch=' + env['ARCH'],
26+
'--platform=android-' + str(self.ctx.android_api),
27+
'--toolchain=' + env['CROSSHOST'] + '-' + env['TOOLCHAIN_VERSION'],
28+
'--install-dir=' + env['CROSSHOME'],
29+
'--system=' + 'linux-x86_64'
30+
)
31+
# Install app stl
32+
shutil.copyfile(join(env['CROSSHOME'], env['CROSSHOST'], 'lib/libgnustl_shared.so'),
33+
join(self.ctx.get_libs_dir(arch.arch), 'libgnustl_shared.so'))
34+
35+
def build_arch(self, arch):
36+
super(BoostRecipe, self).build_arch(arch)
37+
env = self.get_recipe_env(arch)
38+
with current_directory(self.get_build_dir(arch.arch)):
39+
# Compile Boost.Build engine with this custom toolchain
40+
bash = sh.Command('bash')
41+
shprint(bash, 'bootstrap.sh',
42+
'--with-python=' + join(env['PYTHON_ROOT'], 'bin/python.host'),
43+
'--with-python-version=2.7',
44+
'--with-python-root=' + env['PYTHON_ROOT']
45+
) # Do not pass env
46+
shutil.copyfile(join(self.get_recipe_dir(), 'user-config.jam'),
47+
join(env['BOOST_BUILD_PATH'], 'user-config.jam'))
48+
49+
def select_build_arch(self, arch):
50+
return arch.arch.replace('eabi', '')
51+
52+
def get_recipe_env(self, arch):
53+
env = super(BoostRecipe, self).get_recipe_env(arch)
54+
#env['OPENSSL_BUILD_PATH'] = self.get_recipe('openssl', self.ctx).get_build_dir(arch.arch)
55+
env['BOOST_BUILD_PATH'] = self.get_build_dir(arch.arch) # find user-config.jam
56+
env['BOOST_ROOT'] = env['BOOST_BUILD_PATH'] # find boost source
57+
env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
58+
env['ARCH'] = self.select_build_arch(arch)
59+
env['ANDROIDAPI'] = str(self.ctx.android_api)
60+
env['CROSSHOST'] = env['ARCH'] + '-linux-androideabi'
61+
env['CROSSHOME'] = join(env['BOOST_ROOT'], 'standalone-' + env['ARCH'] + '-toolchain')
62+
env['TOOLCHAIN_PREFIX'] = join(env['CROSSHOME'], 'bin', env['CROSSHOST'])
63+
return env
64+
65+
recipe = BoostRecipe()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--- boost/boostcpp.jam 2015-12-14 03:30:09.000000000 +0100
2+
+++ boost-patch/boostcpp.jam 2016-02-08 16:38:40.510859612 +0100
3+
@@ -155,8 +155,9 @@
4+
if $(type) = SHARED_LIB &&
5+
! [ $(property-set).get <target-os> ] in windows cygwin darwin aix &&
6+
! [ $(property-set).get <toolset> ] in pgi
7+
{
8+
+ return $(result) ; # disable version suffix for android
9+
result = $(result).$(BOOST_VERSION) ;
10+
}
11+
12+
return $(result) ;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- boost/tools/build/src/tools/python.jam 2015-10-16 20:55:36.000000000 +0200
2+
+++ boost-patch/tools/build/src/tools/python.jam 2016-02-09 13:16:09.519261546 +0100
3+
@@ -646,6 +646,7 @@
4+
5+
case aix : return <library>pthread <library>dl ;
6+
7+
+ case * : return ; # use Android builtin libs
8+
case * : return <library>pthread <library>dl
9+
<toolset>gcc:<library>util <toolset-intel:platform>linux:<library>util ;
10+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import os ;
2+
3+
local ANDROIDNDK = [ os.environ ANDROIDNDK ] ;
4+
local ANDROIDAPI = [ os.environ ANDROIDAPI ] ;
5+
local TOOLCHAIN_VERSION = [ os.environ TOOLCHAIN_VERSION ] ;
6+
local TOOLCHAIN_PREFIX = [ os.environ TOOLCHAIN_PREFIX ] ;
7+
local ARCH = [ os.environ ARCH ] ;
8+
local PYTHON_ROOT = [ os.environ PYTHON_ROOT ] ;
9+
#local OPENSSL_BUILD_PATH = [ os.environ OPENSSL_BUILD_PATH ] ;
10+
11+
using gcc : $(ARCH) : $(TOOLCHAIN_PREFIX)-g++ :
12+
<architecture>$(ARCH)
13+
<archiver>$(TOOLCHAIN_PREFIX)-ar
14+
<compileflags>-DBOOST_SP_USE_PTHREADS
15+
<compileflags>-DBOOST_AC_USE_PTHREADS
16+
<cxxflags>-DBOOST_SP_USE_PTHREADS
17+
<cxxflags>-DBOOST_AC_USE_PTHREADS
18+
<cxxflags>-frtti
19+
<cxxflags>-fexceptions
20+
<compileflags>-I$(ANDROIDNDK)/platforms/android-$(ANDROIDAPI)/arch-$(ARCH)/usr/include
21+
<compileflags>-I$(ANDROIDNDK)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/include
22+
<compileflags>-I$(ANDROIDNDK)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/$(ARCH)/include
23+
<compileflags>-I$(PYTHON_ROOT)/include/python2.7
24+
#<compileflags>-I$(OPENSSL_BUILD_PATH)/include
25+
#<compileflags>-I$(OPENSSL_BUILD_PATH)/include/openssl
26+
<linkflags>--sysroot=$(ANDROIDNDK)/platforms/android-$(ANDROIDAPI)/arch-$(ARCH)
27+
<linkflags>-L$(ANDROIDNDK)/sources/cxx-stl/gnu-libstdc++/$(TOOLCHAIN_VERSION)/libs/$(ARCH)
28+
<linkflags>-L$(PYTHON_ROOT)/lib
29+
#<linkflags>-L$(OPENSSL_BUILD_PATH)
30+
<linkflags>-lgnustl_shared
31+
<linkflags>-lpython2.7
32+
#<linkflags>-lcrypto
33+
#<linkflags>-lssl
34+
;
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from pythonforandroid.toolchain import Recipe, shprint, shutil, current_directory
2+
from os.path import join, exists
3+
import sh
4+
5+
# This recipe builds libtorrent with Python bindings
6+
# It depends on Boost.Build and the source of several Boost libraries present in BOOST_ROOT,
7+
# which is all provided by the boost recipe
8+
class LibtorrentRecipe(Recipe):
9+
version = '1.0.8'
10+
# Don't forget to change the URL when changing the version
11+
url = 'http://github.com/arvidn/libtorrent/archive/libtorrent-1_0_8.tar.gz'
12+
depends = ['boost', 'python2'] #'openssl'
13+
patches = ['disable-so-version.patch', 'use-soname-python.patch']
14+
15+
def should_build(self, arch):
16+
return not ( self.has_libs(arch, 'libboost_python.so', 'libboost_system.so', 'libtorrent.so')
17+
and self.ctx.has_package('libtorrent.so', arch.arch) )
18+
19+
def build_arch(self, arch):
20+
super(LibtorrentRecipe, self).build_arch(arch)
21+
env = self.get_recipe_env(arch)
22+
with current_directory(join(self.get_build_dir(arch.arch), 'bindings/python')):
23+
# Compile libtorrent with boost libraries and python bindings
24+
b2 = sh.Command(join(env['BOOST_ROOT'], 'b2'))
25+
shprint(b2,
26+
'-q',
27+
'-j5',
28+
'toolset=gcc-' + env['ARCH'],
29+
'target-os=android',
30+
'threading=multi',
31+
'link=shared',
32+
'boost-link=shared',
33+
'boost=source',
34+
# 'encryption=openssl',
35+
'--prefix=' + env['CROSSHOME'],
36+
'release'
37+
, _env=env)
38+
# Copy the shared libraries into the libs folder
39+
build_subdirs = 'gcc-arm/release/boost-link-shared/boost-source/libtorrent-python-pic-on/target-os-android/threading-multi/visibility-hidden' #encryption-openssl
40+
shutil.copyfile(join(env['BOOST_BUILD_PATH'], 'bin.v2/libs/python/build', build_subdirs, 'libboost_python.so'),
41+
join(self.ctx.get_libs_dir(arch.arch), 'libboost_python.so'))
42+
shutil.copyfile(join(env['BOOST_BUILD_PATH'], 'bin.v2/libs/system/build', build_subdirs, 'libboost_system.so'),
43+
join(self.ctx.get_libs_dir(arch.arch), 'libboost_system.so'))
44+
shutil.copyfile(join(self.get_build_dir(arch.arch), 'bin', build_subdirs, 'libtorrent.so'),
45+
join(self.ctx.get_libs_dir(arch.arch), 'libtorrent.so'))
46+
shutil.copyfile(join(self.get_build_dir(arch.arch), 'bindings/python/bin', build_subdirs, 'libtorrent.so'),
47+
join(self.ctx.get_site_packages_dir(arch.arch), 'libtorrent.so'))
48+
49+
def get_recipe_env(self, arch):
50+
env = super(LibtorrentRecipe, self).get_recipe_env(arch)
51+
# Copy environment from boost recipe
52+
env.update(self.get_recipe('boost', self.ctx).get_recipe_env(arch))
53+
return env
54+
55+
recipe = LibtorrentRecipe()
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--- libtorrent/Jamfile 2016-01-17 23:52:45.000000000 +0100
2+
+++ libtorrent-patch/Jamfile 2016-02-09 13:37:57.499561750 +0100
3+
@@ -325,6 +325,7 @@
4+
if $(type) = SHARED_LIB &&
5+
( ! ( [ $(property-set).get <target-os> ] in windows cygwin ) )
6+
{
7+
+ return $(name) ; # disable version suffix for android
8+
name = $(name).$(VERSION) ;
9+
}
10+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--- libtorrent/bindings/python/Jamfile 2016-01-17 23:52:45.000000000 +0100
2+
+++ libtorrent-patch/bindings/python/Jamfile 2016-02-09 17:11:44.261578000 +0100
3+
@@ -35,7 +35,7 @@
4+
5+
if ( <toolset>gcc in $(properties) )
6+
{
7+
- result += <linkflags>-Wl,-Bsymbolic ;
8+
+ result += <linkflags>-Wl,-soname=libtorrentpython.so,-Bsymbolic ;
9+
}
10+
}
11+

0 commit comments

Comments
 (0)