Skip to content
Merged
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
2 changes: 1 addition & 1 deletion pythonforandroid/archs.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def get_env(self, with_flags_in_cc=True):
env['CPPFLAGS'] = ' '.join(self.common_cppflags).format(
ctx=self.ctx,
command_prefix=self.command_prefix,
python_includes=join(self.ctx.python_recipe.get_build_dir(self.arch), 'Include')
python_includes=join(Recipe.get_recipe("python3", self.ctx).include_root(self.arch))
)

# LDFLAGS: Link the extra global link paths first before anything else
Expand Down
94 changes: 15 additions & 79 deletions pythonforandroid/recipes/matplotlib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,93 +1,29 @@
from pythonforandroid.recipe import PyProjectRecipe
from pythonforandroid.util import ensure_dir
from pythonforandroid.recipe import MesonRecipe
from pythonforandroid.logger import shprint

from os.path import join
import shutil
import sh


class MatplotlibRecipe(PyProjectRecipe):
version = '3.8.4'
class MatplotlibRecipe(MesonRecipe):
version = '3.10.7'
url = 'https://github.com/matplotlib/matplotlib/archive/v{version}.zip'
patches = ["skip_macos.patch"]
depends = ['kiwisolver', 'numpy', 'pillow', 'setuptools', 'freetype']
depends = ['kiwisolver', 'numpy', 'pillow']
python_depends = ['cycler', 'fonttools', 'packaging', 'pyparsing', 'python-dateutil']
hostpython_prerequisites = ["setuptools_scm>=7"]
patches = ["meson.patch"]
need_stl_shared = True

def generate_libraries_pc_files(self, arch):
"""
Create *.pc files for libraries that `matplotib` depends on.

Because, for unix platforms, the mpl install script uses `pkg-config`
to detect libraries installed in non standard locations (our case...
well...we don't even install the libraries...so we must trick a little
the mlp install).
"""
pkg_config_path = self.get_recipe_env(arch)['PKG_CONFIG_PATH']
ensure_dir(pkg_config_path)

lib_to_pc_file = {
# `pkg-config` search for version freetype2.pc, our current
# version for freetype, but we have our recipe named without
# the version...so we add it in here for our pc file
'freetype': 'freetype2.pc',
}

for lib_name in {'freetype'}:
pc_template_file = join(
self.get_recipe_dir(),
f'lib{lib_name}.pc.template'
)
# read template file into buffer
with open(pc_template_file) as template_file:
text_buffer = template_file.read()
# set the library absolute path and library version
lib_recipe = self.get_recipe(lib_name, self.ctx)
text_buffer = text_buffer.replace(
'path_to_built', lib_recipe.get_build_dir(arch.arch),
)
text_buffer = text_buffer.replace(
'library_version', lib_recipe.version,
)

# write the library pc file into our defined dir `PKG_CONFIG_PATH`
pc_dest_file = join(pkg_config_path, lib_to_pc_file[lib_name])
with open(pc_dest_file, 'w') as pc_file:
pc_file.write(text_buffer)

def prebuild_arch(self, arch):
shutil.copyfile(
join(self.get_recipe_dir(), "setup.cfg.template"),
join(self.get_build_dir(arch), "mplsetup.cfg"),
)
self.generate_libraries_pc_files(arch)

def get_recipe_env(self, arch, **kwargs):
env = super().get_recipe_env(arch, **kwargs)

# we make use of the same directory than `XDG_CACHE_HOME`, for our
# custom library pc files, so we have all the install files that we
# generate at the same place
env['XDG_CACHE_HOME'] = join(self.get_build_dir(arch), 'p4a_files')
env['PKG_CONFIG_PATH'] = env['XDG_CACHE_HOME']

# creating proper *.pc files for our libraries does not seem enough to
# success with our build (without depending on system development
# libraries), but if we tell the compiler where to find our libraries
# and includes, then the install success :)
freetype = self.get_recipe('freetype', self.ctx)
free_lib_dir = join(freetype.get_build_dir(arch.arch), 'objs', '.libs')
free_inc_dir = join(freetype.get_build_dir(arch.arch), 'include')
env['CFLAGS'] += f' -I{free_inc_dir}'
env['LDFLAGS'] += f' -L{free_lib_dir}'

# `freetype` could be built with `harfbuzz` support,
# so we also include the necessary flags...just to be sure
if 'harfbuzz' in self.ctx.recipe_build_order:
harfbuzz = self.get_recipe('harfbuzz', self.ctx)
harf_build = harfbuzz.get_build_dir(arch.arch)
env['CFLAGS'] += f' -I{harf_build} -I{join(harf_build, "src")}'
env['LDFLAGS'] += f' -L{join(harf_build, "src", ".libs")}'
env['CXXFLAGS'] += ' -Wno-c++11-narrowing'
return env

def build_arch(self, arch):
python_path = join(self.ctx.python_recipe.get_build_dir(arch), "android-build", "python3")
self.extra_build_args += [f'-Csetup-args=-Dpython3_program={python_path}']
shprint(sh.cp, self.real_hostpython_location, python_path)
super().build_arch(arch)


recipe = MatplotlibRecipe()
10 changes: 0 additions & 10 deletions pythonforandroid/recipes/matplotlib/libfreetype.pc.template

This file was deleted.

21 changes: 21 additions & 0 deletions pythonforandroid/recipes/matplotlib/meson.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
diff '--color=auto' -uNr matplotlib-3.10.7/meson.build matplotlib-3.10.7.mod/meson.build
--- matplotlib-3.10.7/meson.build 2025-10-09 04:16:31.000000000 +0530
+++ matplotlib-3.10.7.mod/meson.build 2025-10-12 10:19:29.664280049 +0530
@@ -36,7 +36,7 @@

# https://mesonbuild.com/Python-module.html
py_mod = import('python')
-py3 = py_mod.find_installation(pure: false)
+py3 = py_mod.find_installation(get_option('python3_program'), pure: false)
py3_dep = py3.dependency()

pybind11_dep = dependency('pybind11', version: '>=2.13.2')
diff '--color=auto' -uNr matplotlib-3.10.7/meson.options matplotlib-3.10.7.mod/meson.options
--- matplotlib-3.10.7/meson.options 2025-10-09 04:16:31.000000000 +0530
+++ matplotlib-3.10.7.mod/meson.options 2025-10-12 10:19:23.762042521 +0530
@@ -28,3 +28,5 @@
# default is determined by fallback.
option('rcParams-backend', type: 'string', value: 'auto',
description: 'Set default backend at runtime')
+
+option('python3_program', type : 'string', value : '', description : 'Path to Python 3 executable')
38 changes: 0 additions & 38 deletions pythonforandroid/recipes/matplotlib/setup.cfg.template

This file was deleted.

12 changes: 0 additions & 12 deletions pythonforandroid/recipes/matplotlib/skip_macos.patch

This file was deleted.

Loading