Skip to content

Commit 691959c

Browse files
authored
matplotlib: fix build (#3230)
Thanks a lot!
1 parent bd7fe6f commit 691959c

File tree

6 files changed

+37
-140
lines changed

6 files changed

+37
-140
lines changed

pythonforandroid/archs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def get_env(self, with_flags_in_cc=True):
132132
env['CPPFLAGS'] = ' '.join(self.common_cppflags).format(
133133
ctx=self.ctx,
134134
command_prefix=self.command_prefix,
135-
python_includes=join(self.ctx.python_recipe.get_build_dir(self.arch), 'Include')
135+
python_includes=join(Recipe.get_recipe("python3", self.ctx).include_root(self.arch))
136136
)
137137

138138
# LDFLAGS: Link the extra global link paths first before anything else
Lines changed: 15 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,29 @@
1-
from pythonforandroid.recipe import PyProjectRecipe
2-
from pythonforandroid.util import ensure_dir
1+
from pythonforandroid.recipe import MesonRecipe
2+
from pythonforandroid.logger import shprint
33

44
from os.path import join
5-
import shutil
5+
import sh
66

77

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

16-
def generate_libraries_pc_files(self, arch):
17-
"""
18-
Create *.pc files for libraries that `matplotib` depends on.
19-
20-
Because, for unix platforms, the mpl install script uses `pkg-config`
21-
to detect libraries installed in non standard locations (our case...
22-
well...we don't even install the libraries...so we must trick a little
23-
the mlp install).
24-
"""
25-
pkg_config_path = self.get_recipe_env(arch)['PKG_CONFIG_PATH']
26-
ensure_dir(pkg_config_path)
27-
28-
lib_to_pc_file = {
29-
# `pkg-config` search for version freetype2.pc, our current
30-
# version for freetype, but we have our recipe named without
31-
# the version...so we add it in here for our pc file
32-
'freetype': 'freetype2.pc',
33-
}
34-
35-
for lib_name in {'freetype'}:
36-
pc_template_file = join(
37-
self.get_recipe_dir(),
38-
f'lib{lib_name}.pc.template'
39-
)
40-
# read template file into buffer
41-
with open(pc_template_file) as template_file:
42-
text_buffer = template_file.read()
43-
# set the library absolute path and library version
44-
lib_recipe = self.get_recipe(lib_name, self.ctx)
45-
text_buffer = text_buffer.replace(
46-
'path_to_built', lib_recipe.get_build_dir(arch.arch),
47-
)
48-
text_buffer = text_buffer.replace(
49-
'library_version', lib_recipe.version,
50-
)
51-
52-
# write the library pc file into our defined dir `PKG_CONFIG_PATH`
53-
pc_dest_file = join(pkg_config_path, lib_to_pc_file[lib_name])
54-
with open(pc_dest_file, 'w') as pc_file:
55-
pc_file.write(text_buffer)
56-
57-
def prebuild_arch(self, arch):
58-
shutil.copyfile(
59-
join(self.get_recipe_dir(), "setup.cfg.template"),
60-
join(self.get_build_dir(arch), "mplsetup.cfg"),
61-
)
62-
self.generate_libraries_pc_files(arch)
63-
6417
def get_recipe_env(self, arch, **kwargs):
6518
env = super().get_recipe_env(arch, **kwargs)
66-
67-
# we make use of the same directory than `XDG_CACHE_HOME`, for our
68-
# custom library pc files, so we have all the install files that we
69-
# generate at the same place
70-
env['XDG_CACHE_HOME'] = join(self.get_build_dir(arch), 'p4a_files')
71-
env['PKG_CONFIG_PATH'] = env['XDG_CACHE_HOME']
72-
73-
# creating proper *.pc files for our libraries does not seem enough to
74-
# success with our build (without depending on system development
75-
# libraries), but if we tell the compiler where to find our libraries
76-
# and includes, then the install success :)
77-
freetype = self.get_recipe('freetype', self.ctx)
78-
free_lib_dir = join(freetype.get_build_dir(arch.arch), 'objs', '.libs')
79-
free_inc_dir = join(freetype.get_build_dir(arch.arch), 'include')
80-
env['CFLAGS'] += f' -I{free_inc_dir}'
81-
env['LDFLAGS'] += f' -L{free_lib_dir}'
82-
83-
# `freetype` could be built with `harfbuzz` support,
84-
# so we also include the necessary flags...just to be sure
85-
if 'harfbuzz' in self.ctx.recipe_build_order:
86-
harfbuzz = self.get_recipe('harfbuzz', self.ctx)
87-
harf_build = harfbuzz.get_build_dir(arch.arch)
88-
env['CFLAGS'] += f' -I{harf_build} -I{join(harf_build, "src")}'
89-
env['LDFLAGS'] += f' -L{join(harf_build, "src", ".libs")}'
19+
env['CXXFLAGS'] += ' -Wno-c++11-narrowing'
9020
return env
9121

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

9329
recipe = MatplotlibRecipe()

pythonforandroid/recipes/matplotlib/libfreetype.pc.template

Lines changed: 0 additions & 10 deletions
This file was deleted.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
diff '--color=auto' -uNr matplotlib-3.10.7/meson.build matplotlib-3.10.7.mod/meson.build
2+
--- matplotlib-3.10.7/meson.build 2025-10-09 04:16:31.000000000 +0530
3+
+++ matplotlib-3.10.7.mod/meson.build 2025-10-12 10:19:29.664280049 +0530
4+
@@ -36,7 +36,7 @@
5+
6+
# https://mesonbuild.com/Python-module.html
7+
py_mod = import('python')
8+
-py3 = py_mod.find_installation(pure: false)
9+
+py3 = py_mod.find_installation(get_option('python3_program'), pure: false)
10+
py3_dep = py3.dependency()
11+
12+
pybind11_dep = dependency('pybind11', version: '>=2.13.2')
13+
diff '--color=auto' -uNr matplotlib-3.10.7/meson.options matplotlib-3.10.7.mod/meson.options
14+
--- matplotlib-3.10.7/meson.options 2025-10-09 04:16:31.000000000 +0530
15+
+++ matplotlib-3.10.7.mod/meson.options 2025-10-12 10:19:23.762042521 +0530
16+
@@ -28,3 +28,5 @@
17+
# default is determined by fallback.
18+
option('rcParams-backend', type: 'string', value: 'auto',
19+
description: 'Set default backend at runtime')
20+
+
21+
+option('python3_program', type : 'string', value : '', description : 'Path to Python 3 executable')

pythonforandroid/recipes/matplotlib/setup.cfg.template

Lines changed: 0 additions & 38 deletions
This file was deleted.

pythonforandroid/recipes/matplotlib/skip_macos.patch

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)