Skip to content

Commit 40f0090

Browse files
committed
Merge pull request kivy#510 from kivy/arch_support
Arch support
2 parents 38db03e + aad5b49 commit 40f0090

File tree

32 files changed

+321
-378
lines changed

32 files changed

+321
-378
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Broad goals of the revamp project include:
2727
- (WIP) Support python3 (recipe exists but crashes on android)
2828
- (WIP) Support some kind of binary distribution, including on windows (semi-implemented, just needs finishing)
2929
- ✓ Be a standalone Pypi module (not on pypi yet but setup.py works)
30-
- Support multiple architectures
30+
- Support multiple architectures (full multiarch builds not complete, but arm and x86 with different config both work now)
3131

3232
We are currently working to stabilise all parts of the toolchain and
3333
add more features. Support for pygame-based APKs is almost feature

doc/source/commands.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ supply those that you need.
7070
``--force_build BOOL``
7171
Whether the distribution must be compiled from scratch.
7272

73+
``--arch``
74+
The architecture to build for. Currently only one architecture can be
75+
targeted at a time, and a given distribution can only include one architecture.
76+
77+
7378
.. note:: These options are preliminary. Others will include toggles
7479
for allowing downloads, and setting additional directories
7580
from which to load user dists.

doc/source/quickstart.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,10 @@ correct and try to continue the build.
254254
Configuration file
255255
~~~~~~~~~~~~~~~~~~
256256

257-
python-for-android look on the current directory if there is a `.p4a`
258-
configuration file. If it found it, it adds all the lines as options
259-
to the command line. For example, you can put the options you would
260-
always write such as:
257+
python-for-android checks in the current directory for a configuration
258+
file named ``.p4a``. If found, it adds all the lines as options to the
259+
command line. For example, you can add the options you would always
260+
include such as:
261261

262262
--dist_name my_example
263263
--android_api 19

pythonforandroid/bootstraps/empty/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, logger, info_main, which
1+
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchARM, logger, info_main, which
22
from os.path import join, exists
33
from os import walk
44
import glob

pythonforandroid/bootstraps/pygame/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, info_main
1+
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchARM, info_main
22
from os.path import join, exists
33
from os import walk
44
import glob
@@ -19,8 +19,10 @@ def run_distribute(self):
1919
# self.name)
2020
src_path = join(self.bootstrap_dir, 'build')
2121

22-
# AND: Hardcoding armeabi - naughty!
23-
arch = ArchAndroid(self.ctx)
22+
arch = self.ctx.archs[0]
23+
if len(self.ctx.archs) > 1:
24+
raise ValueError('built for more than one arch, but bootstrap cannot handle that yet')
25+
info('Bootstrap running with arch {}'.format(arch))
2426

2527
with current_directory(self.dist_dir):
2628

@@ -58,7 +60,7 @@ def run_distribute(self):
5860
shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7'))
5961

6062
# AND: Copylibs stuff should go here
61-
shprint(sh.mv, join('libs', 'armeabi', 'libpymodules.so'), 'private/')
63+
shprint(sh.mv, join('libs', arch.arch, 'libpymodules.so'), 'private/')
6264
shprint(sh.cp, join('python-install', 'include' , 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/'))
6365

6466
info('Removing some unwanted files')

pythonforandroid/bootstraps/pygame/build/jni/application/Android.mk

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LOCAL_CFLAGS := $(foreach D, $(APP_SUBDIRS), -I$(LOCAL_PATH)/$(D)) \
1818
-I$(LOCAL_PATH)/../jpeg \
1919
-I$(LOCAL_PATH)/../intl \
2020
-I$(LOCAL_PATH)/.. \
21-
-I$(LOCAL_PATH)/../../../../other_builds/python2/armeabi/python2/python-install/include/python2.7
21+
-I$(LOCAL_PATH)/../../../../other_builds/python2/$(ARCH)/python2/python-install/include/python2.7
2222
# -I$(LOCAL_PATH)/../../../../python-install/include/python2.7
2323
# -I$(LOCAL_PATH)/../../../build/python-install/include/python2.7
2424

@@ -39,7 +39,8 @@ LOCAL_STATIC_LIBRARIES := jpeg png
3939
LOCAL_LDLIBS := -lpython2.7 -lGLESv1_CM -ldl -llog -lz
4040

4141
# AND: Another hardcoded path that should be templated
42-
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/python2/armeabi/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
42+
# AND: NOT TEMPALTED! We can use $ARCH
43+
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/python2/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
4344

4445
LIBS_WITH_LONG_SYMBOLS := $(strip $(shell \
4546
for f in $(LOCAL_PATH)/../../libs/$ARCH/*.so ; do \

pythonforandroid/bootstraps/sdl2/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, info_main
1+
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchARM, info_main
22
from os.path import join, exists
33
from os import walk
44
import glob
@@ -20,8 +20,10 @@ def run_distribute(self):
2020
with open('local.properties', 'w') as fileh:
2121
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
2222

23-
# AND: Hardcoding armeabi - naughty!
24-
arch = ArchAndroid(self.ctx)
23+
arch = self.ctx.archs[0]
24+
if len(self.ctx.archs) > 1:
25+
raise ValueError('built for more than one arch, but bootstrap cannot handle that yet')
26+
info('Bootstrap running with arch {}'.format(arch))
2527

2628
with current_directory(self.dist_dir):
2729
info('Copying python distribution')
@@ -32,7 +34,6 @@ def run_distribute(self):
3234
shprint(sh.mkdir, 'assets')
3335

3436
hostpython = sh.Command(self.ctx.hostpython)
35-
# AND: This *doesn't* need to be in arm env?
3637
shprint(hostpython, '-OO', '-m', 'compileall',
3738
self.ctx.get_python_install_dir(),
3839
_tail=10, _filterout="^Listing", _critical=True)
@@ -50,8 +51,8 @@ def run_distribute(self):
5051
shprint(sh.mkdir, '-p', join('private', 'include', 'python2.7'))
5152

5253
# AND: Copylibs stuff should go here
53-
if exists(join('libs', 'armeabi', 'libpymodules.so')):
54-
shprint(sh.mv, join('libs', 'armeabi', 'libpymodules.so'), 'private/')
54+
if exists(join('libs', arch.arch, 'libpymodules.so')):
55+
shprint(sh.mv, join('libs', arch.arch, 'libpymodules.so'), 'private/')
5556
shprint(sh.cp, join('python-install', 'include' , 'python2.7', 'pyconfig.h'), join('private', 'include', 'python2.7/'))
5657

5758
info('Removing some unwanted files')

pythonforandroid/bootstraps/sdl2/build/jni/Application.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# APP_STL := stlport_static
55

66
# APP_ABI := armeabi armeabi-v7a x86
7-
APP_ABI := armeabi
7+
APP_ABI := $(ARCH)

pythonforandroid/bootstraps/sdl2/build/jni/src/Android.mk

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/$(SDL_PATH)/include
1212
LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.c \
1313
start.c
1414

15-
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/python2/armeabi/python2/python-install/include/python2.7
15+
LOCAL_CFLAGS += -I$(LOCAL_PATH)/../../../../other_builds/python2/$(ARCH)/python2/python-install/include/python2.7
1616

1717
LOCAL_SHARED_LIBRARIES := SDL2
1818

1919
LOCAL_LDLIBS := -lGLESv1_CM -lGLESv2 -llog -lpython2.7
2020

21-
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/python2/armeabi/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
21+
LOCAL_LDFLAGS += -L$(LOCAL_PATH)/../../../../other_builds/python2/$(ARCH)/python2/python-install/lib $(APPLICATION_ADDITIONAL_LDFLAGS)
2222

2323
include $(BUILD_SHARED_LIBRARY)

pythonforandroid/bootstraps/sdl2python3/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchAndroid, info_main
1+
from pythonforandroid.toolchain import Bootstrap, shprint, current_directory, info, warning, ArchARM, info_main
22
from os.path import join, exists
33
from os import walk
44
import glob
@@ -23,7 +23,7 @@ def run_distribute(self):
2323
fileh.write('sdk.dir={}'.format(self.ctx.sdk_dir))
2424

2525
# AND: Hardcoding armeabi - naughty!
26-
arch = ArchAndroid(self.ctx)
26+
arch = ArchARM(self.ctx)
2727

2828
with current_directory(self.dist_dir):
2929
info('Copying python distribution')

pythonforandroid/recipes/android/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import CythonRecipe, shprint, ensure_dir, current_directory, ArchAndroid, IncludedFilesBehaviour
2+
from pythonforandroid.toolchain import CythonRecipe, shprint, ensure_dir, current_directory, ArchARM, IncludedFilesBehaviour
33
import sh
44
from os.path import exists, join
55

pythonforandroid/recipes/freetype/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchAndroid
2+
from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchARM
33
from os.path import exists, join, realpath
44
from os import uname
55
import glob
@@ -12,8 +12,8 @@ class FreetypeRecipe(Recipe):
1212

1313
depends = ['harfbuzz']
1414

15-
def should_build(self):
16-
if exists(join(self.get_build_dir('armeabi'), 'objs', '.libs', 'libfreetype.so')):
15+
def should_build(self, arch):
16+
if exists(join(self.get_build_dir(arch.arch), 'objs', '.libs', 'libfreetype.so')):
1717
return False
1818
return True
1919

pythonforandroid/recipes/harfbuzz/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchAndroid
2+
from pythonforandroid.toolchain import Recipe, shprint, get_directory, current_directory, ArchARM
33
from os.path import exists, join, realpath
44
from os import uname
55
import glob
@@ -10,8 +10,8 @@ class HarfbuzzRecipe(Recipe):
1010
version = '0.9.40'
1111
url = 'http://www.freedesktop.org/software/harfbuzz/release/harfbuzz-{version}.tar.bz2'
1212

13-
def should_build(self):
14-
if exists(join(self.get_build_dir('armeabi'), 'src', '.libs', 'libharfbuzz.so')):
13+
def should_build(self, arch):
14+
if exists(join(self.get_build_dir(arch.arch), 'src', '.libs', 'libharfbuzz.so')):
1515
return False
1616
return True
1717

pythonforandroid/recipes/hostpython2/__init__.py

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,27 @@ class Hostpython2Recipe(Recipe):
1212

1313
conflicts = ['hostpython3']
1414

15-
def prebuild_armeabi(self):
15+
def get_build_container_dir(self, arch=None):
16+
choices = self.check_recipe_choices()
17+
dir_name = '-'.join([self.name] + choices)
18+
return join(self.ctx.build_dir, 'other_builds', dir_name, 'desktop')
19+
20+
def get_build_dir(self, arch=None):
21+
return join(self.get_build_container_dir(), self.name)
22+
23+
def prebuild_arch(self, arch):
1624
# Override hostpython Setup?
1725
shprint(sh.cp, join(self.get_recipe_dir(), 'Setup'),
18-
join(self.get_build_dir('armeabi'), 'Modules', 'Setup'))
19-
20-
def build_armeabi(self):
21-
# AND: Should use an i386 recipe system
22-
warning('Running hostpython build. Arch is armeabi! '
23-
'This is naughty, need to fix the Arch system!')
26+
join(self.get_build_dir(), 'Modules', 'Setup'))
2427

25-
# AND: Fix armeabi again
26-
with current_directory(self.get_build_dir('armeabi')):
28+
def build_arch(self, arch):
29+
with current_directory(self.get_build_dir()):
2730

2831
if exists('hostpython'):
2932
info('hostpython already exists, skipping build')
30-
self.ctx.hostpython = join(self.get_build_dir('armeabi'),
33+
self.ctx.hostpython = join(self.get_build_dir(),
3134
'hostpython')
32-
self.ctx.hostpgen = join(self.get_build_dir('armeabi'),
35+
self.ctx.hostpgen = join(self.get_build_dir(),
3336
'hostpgen')
3437
return
3538

@@ -49,8 +52,8 @@ def build_armeabi(self):
4952
'hostpython build! Exiting.')
5053
exit(1)
5154

52-
self.ctx.hostpython = join(self.get_build_dir('armeabi'), 'hostpython')
53-
self.ctx.hostpgen = join(self.get_build_dir('armeabi'), 'hostpgen')
55+
self.ctx.hostpython = join(self.get_build_dir(), 'hostpython')
56+
self.ctx.hostpgen = join(self.get_build_dir(), 'hostpgen')
5457

5558

5659
recipe = Hostpython2Recipe()

pythonforandroid/recipes/kivy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, ArchAndroid
2+
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, ArchARM
33
from os.path import exists, join
44
import sh
55
import glob

pythonforandroid/recipes/kivysdl2python3/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, ArchAndroid
2+
from pythonforandroid.toolchain import CythonRecipe, shprint, current_directory, ArchARM
33
from os.path import exists, join
44
import sh
55
import glob
@@ -35,7 +35,7 @@ def get_recipe_env(self, arch):
3535
return env
3636

3737
# def build_armeabi(self):
38-
# env = ArchAndroid(self.ctx).get_env()
38+
# env = ArchARM(self.ctx).get_env()
3939

4040
# env['LDFLAGS'] = env['LDFLAGS'] + ' -L{}'.format(self.ctx.libs_dir)
4141
# env['LDSHARED'] = env['LIBLINK']

pythonforandroid/recipes/numpy/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ def prebuild_arch(self, arch):
2020
print('numpy already patched, skipping')
2121
return
2222

23-
self.apply_patch('patches/fix-numpy.patch')
24-
self.apply_patch('patches/prevent_libs_check.patch')
25-
self.apply_patch('patches/ar.patch')
26-
self.apply_patch('patches/lib.patch')
23+
self.apply_patch('patches/fix-numpy.patch', arch.arch)
24+
self.apply_patch('patches/prevent_libs_check.patch', arch.arch)
25+
self.apply_patch('patches/ar.patch', arch.arch)
26+
self.apply_patch('patches/lib.patch', arch.arch)
2727

2828
# AND: Fix this warning!
2929
warning('Numpy is built assuming the archiver name is '

pythonforandroid/recipes/openssl/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class OpenSSLRecipe(Recipe):
88
version = '1.0.2e'
99
url = 'https://www.openssl.org/source/openssl-{version}.tar.gz'
1010

11-
def should_build(self):
12-
return not exists(join(self.get_build_dir('armeabi'), 'libssl.a'))
11+
def should_build(self, arch):
12+
return not exists(join(self.get_build_dir(arch.arch), 'libssl.a'))
1313

1414
def build_arch(self, arch):
1515
env = self.get_recipe_env(arch)

pythonforandroid/recipes/pygame/__init__.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import Recipe, shprint, ArchAndroid, current_directory, debug, info, ensure_dir
2+
from pythonforandroid.toolchain import Recipe, shprint, ArchARM, current_directory, debug, info, ensure_dir
33
from os.path import exists, join
44
import sh
55
import glob
@@ -26,21 +26,20 @@ def get_recipe_env(self, arch):
2626
ensure_dir(liblink_path)
2727
return env
2828

29-
def prebuild_armeabi(self):
30-
if exists(join(self.get_build_container_dir('armeabi'), '.patched')):
29+
def prebuild_arch(self, arch):
30+
if exists(join(self.get_build_container_dir(arch.arch), '.patched')):
3131
info('Pygame already patched, skipping.')
3232
return
3333
shprint(sh.cp, join(self.get_recipe_dir(), 'Setup'),
34-
join(self.get_build_dir('armeabi'), 'Setup'))
35-
self.apply_patch(join('patches', 'fix-surface-access.patch'))
36-
self.apply_patch(join('patches', 'fix-array-surface.patch'))
37-
self.apply_patch(join('patches', 'fix-sdl-spam-log.patch'))
38-
shprint(sh.touch, join(self.get_build_container_dir('armeabi'), '.patched'))
34+
join(self.get_build_dir(arch.arch), 'Setup'))
35+
self.apply_patch(join('patches', 'fix-surface-access.patch'), arch.arch)
36+
self.apply_patch(join('patches', 'fix-array-surface.patch'), arch.arch)
37+
self.apply_patch(join('patches', 'fix-sdl-spam-log.patch'), arch.arch)
38+
shprint(sh.touch, join(self.get_build_container_dir(arch.arch), '.patched'))
3939

40-
def build_armeabi(self):
40+
def build_arch(self, arch):
4141
# AND: I'm going to ignore any extra pythonrecipe or cythonrecipe behaviour for now
4242

43-
arch = ArchAndroid(self.ctx)
4443
env = self.get_recipe_env(arch)
4544

4645
env['CFLAGS'] = env['CFLAGS'] + ' -I{jni_path}/png -I{jni_path}/jpeg'.format(
@@ -57,7 +56,7 @@ def build_armeabi(self):
5756

5857
env['LDSHARED'] = join(self.ctx.root_dir, 'tools', 'liblink')
5958

60-
with current_directory(self.get_build_dir('armeabi')):
59+
with current_directory(self.get_build_dir(arch.arch)):
6160
info('hostpython is ' + self.ctx.hostpython)
6261
hostpython = sh.Command(self.ctx.hostpython)
6362
shprint(hostpython, 'setup.py', 'install', '-O2', _env=env,

pythonforandroid/recipes/pyjnius/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import CythonRecipe, shprint, ArchAndroid, current_directory, info
2+
from pythonforandroid.toolchain import CythonRecipe, shprint, ArchARM, current_directory, info
33
import sh
44
import glob
55
from os.path import join, exists
@@ -18,7 +18,7 @@ def prebuild_arch(self, arch):
1818
if exists(join(build_dir, '.patched')):
1919
print('pyjniussdl2 already pathed, skipping')
2020
return
21-
self.apply_patch('sdl2_jnienv_getter.patch')
21+
self.apply_patch('sdl2_jnienv_getter.patch', arch.arch)
2222
shprint(sh.touch, join(build_dir, '.patched'))
2323

2424
def postbuild_arch(self, arch):

pythonforandroid/recipes/pyopenssl/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def prebuild_arch(self, arch):
2222
if exists(join(build_dir, '.patched')):
2323
print('pyOpenSSL already patched, skipping')
2424
return
25-
self.apply_patch('fix-dlfcn.patch')
25+
self.apply_patch('fix-dlfcn.patch', arch.arch)
2626
shprint(sh.touch, join(build_dir, '.patched'))
2727

2828
def get_recipe_env(self, arch):

pythonforandroid/recipes/pysdl2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
from pythonforandroid.toolchain import PythonRecipe, shprint, current_directory, ArchAndroid
2+
from pythonforandroid.toolchain import PythonRecipe, shprint, current_directory, ArchARM
33
from os.path import exists, join
44
import sh
55
import glob

0 commit comments

Comments
 (0)