Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add correct CFLAGS to hostpython3 and -fPIC flag to avoid relocation error for few recipes #2136

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pythonforandroid/recipes/Pillow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ def get_recipe_env(self, arch=None, with_flags_in_cc=True):
cflags += ' -I{}'.format(free_inc_dir)
cflags += ' -I{}'.format(jpeg_inc_dir)
cflags += ' -I{}'.format(ndk_include_dir)
cflags += ' -fPIC'
rdbisme marked this conversation as resolved.
Show resolved Hide resolved

env['LIBS'] = ' -lpng -lfreetype -lharfbuzz -ljpeg -lturbojpeg'

Expand Down
6 changes: 6 additions & 0 deletions pythonforandroid/recipes/android/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class AndroidRecipe(IncludedFilesBehaviour, CythonRecipe):
def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
env.update(self.config_env)

cflags = " -fPIC"

if cflags not in env["CFLAGS"]:
env["CFLAGS"] += cflags

return env

def prebuild_arch(self, arch):
Expand Down
13 changes: 12 additions & 1 deletion pythonforandroid/recipes/hostpython3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import sh

from multiprocessing import cpu_count
Expand Down Expand Up @@ -81,6 +82,15 @@ def build_arch(self, arch):
build_dir = join(recipe_build_dir, self.build_subdir)
ensure_dir(build_dir)

# ... And add that dir into the include flags
env = os.environ
cppflags = f" -I{build_dir}"

try:
env["CPPFLAGS"] += cppflags
except KeyError:
env["CPPFLAGS"] = cppflags

with current_directory(recipe_build_dir):
# Configure the build
with current_directory(build_dir):
Expand All @@ -101,7 +111,8 @@ def build_arch(self, arch):
raise BuildInterruptingException(
"Could not find Setup.dist or Setup in Python build")

shprint(sh.make, '-j', str(cpu_count()), '-C', build_dir)
shprint(sh.make, '-j', str(cpu_count()), '-C', build_dir,
_env=env)

# make a copy of the python executable giving it the name we want,
# because we got different python's executable names depending on
Expand Down
5 changes: 5 additions & 0 deletions pythonforandroid/recipes/kivy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def get_recipe_env(self, arch):
join(self.ctx.bootstrap.build_dir, 'jni', 'SDL2_ttf'),
])

cflags = " -fPIC"

if cflags not in env["CFLAGS"]:
env["CFLAGS"] += cflags

return env


Expand Down
10 changes: 10 additions & 0 deletions pythonforandroid/recipes/pyjnius/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ class PyjniusRecipe(CythonRecipe):
patches = [('sdl2_jnienv_getter.patch', will_build('sdl2')),
('genericndkbuild_jnienv_getter.patch', will_build('genericndkbuild'))]

def get_recipe_env(self, arch=None, with_flags_in_cc=True):
env = super().get_recipe_env(arch, with_flags_in_cc)

cflags = " -fPIC"

if cflags not in env["CFLAGS"]:
env["CFLAGS"] += cflags

return env

def postbuild_arch(self, arch):
super().postbuild_arch(arch)
info('Copying pyjnius java class to classes build dir')
Expand Down