diff --git a/pythonforandroid/archs.py b/pythonforandroid/archs.py index c2c1f91fc7..d09cee0ba9 100644 --- a/pythonforandroid/archs.py +++ b/pythonforandroid/archs.py @@ -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 diff --git a/pythonforandroid/recipes/matplotlib/__init__.py b/pythonforandroid/recipes/matplotlib/__init__.py index 6fffd45596..f3ac80bddc 100644 --- a/pythonforandroid/recipes/matplotlib/__init__.py +++ b/pythonforandroid/recipes/matplotlib/__init__.py @@ -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() diff --git a/pythonforandroid/recipes/matplotlib/libfreetype.pc.template b/pythonforandroid/recipes/matplotlib/libfreetype.pc.template deleted file mode 100644 index df5ef288dc..0000000000 --- a/pythonforandroid/recipes/matplotlib/libfreetype.pc.template +++ /dev/null @@ -1,10 +0,0 @@ -prefix=path_to_built -exec_prefix=${prefix} -includedir=${prefix}/include -libdir=${exec_prefix}/objs/.libs - -Name: freetype2 -Description: The freetype2 library -Version: library_version -Cflags: -I${includedir} -Libs: -L${libdir} -lfreetype diff --git a/pythonforandroid/recipes/matplotlib/meson.patch b/pythonforandroid/recipes/matplotlib/meson.patch new file mode 100644 index 0000000000..babab09002 --- /dev/null +++ b/pythonforandroid/recipes/matplotlib/meson.patch @@ -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') diff --git a/pythonforandroid/recipes/matplotlib/setup.cfg.template b/pythonforandroid/recipes/matplotlib/setup.cfg.template deleted file mode 100644 index 96ef80d4d2..0000000000 --- a/pythonforandroid/recipes/matplotlib/setup.cfg.template +++ /dev/null @@ -1,38 +0,0 @@ -# Rename this file to mplsetup.cfg to modify Matplotlib's build options. - -[libs] -# By default, Matplotlib builds with LTO, which may be slow if you re-compile -# often, and don't need the space saving/speedup. -enable_lto = False -# By default, Matplotlib downloads and builds its own copies of FreeType and of -# Qhull. You may set the following to True to instead link against a system -# FreeType/Qhull. As an exception, Matplotlib defaults to the system version -# of FreeType on AIX. -system_freetype = True -#system_qhull = False - -[packages] -# There are a number of data subpackages from Matplotlib that are -# considered optional. All except 'tests' data (meaning the baseline -# image files) are installed by default, but that can be changed here. -#tests = False - -[gui_support] -# Matplotlib supports multiple GUI toolkits, known as backends. -# The MacOSX backend requires the Cocoa headers included with XCode. -# You can select whether to build it by uncommenting the following line. -# It is never built on Linux or Windows, regardless of the config value. -# -macosx = False - -[rc_options] -# User-configurable options -# -# Default backend, one of: Agg, Cairo, GTK3Agg, GTK3Cairo, GTK4Agg, GTK4Cairo, -# MacOSX, Pdf, Ps, QtAgg, QtCairo, SVG, TkAgg, WX, WXAgg. -# -# The Agg, Ps, Pdf and SVG backends do not require external dependencies. Do -# not choose MacOSX if you have disabled the relevant extension modules. The -# default is determined by fallback. -# -#backend = Agg \ No newline at end of file diff --git a/pythonforandroid/recipes/matplotlib/skip_macos.patch b/pythonforandroid/recipes/matplotlib/skip_macos.patch deleted file mode 100644 index 7652750769..0000000000 --- a/pythonforandroid/recipes/matplotlib/skip_macos.patch +++ /dev/null @@ -1,12 +0,0 @@ -diff '--color=auto' -uNr matplotlib-3.8.4/setupext.py matplotlib-3.8.4.mod/setupext.py ---- matplotlib-3.8.4/setupext.py 2024-04-04 04:06:51.000000000 +0530 -+++ matplotlib-3.8.4.mod/setupext.py 2024-04-30 19:31:39.608063438 +0530 -@@ -782,7 +782,7 @@ - name = 'macosx' - - def check(self): -- if sys.platform != 'darwin': -+ if True: #sys.platform != 'darwin': - raise Skipped("Mac OS-X only") - return super().check() -