From a1b2edb831fa5fdc02741b649c1a74c7178e9d32 Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Wed, 11 Jun 2025 23:16:04 +0100 Subject: [PATCH 1/2] Android tests working --- tests/env.py | 1 + tests/pyproject.toml | 3 +-- tests/test_exceptions.py | 2 +- tools/pybind11NewTools.cmake | 10 ++++++++++ tools/pybind11Tools.cmake | 2 +- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/env.py b/tests/env.py index d234c425d4..95cc1ac611 100644 --- a/tests/env.py +++ b/tests/env.py @@ -6,6 +6,7 @@ import pytest +ANDROID = sys.platform.startswith("android") LINUX = sys.platform.startswith("linux") MACOS = sys.platform.startswith("darwin") WIN = sys.platform.startswith("win32") or sys.platform.startswith("cygwin") diff --git a/tests/pyproject.toml b/tests/pyproject.toml index dbb693d753..013a7e49b9 100644 --- a/tests/pyproject.toml +++ b/tests/pyproject.toml @@ -33,6 +33,5 @@ pyodide.test-groups = ["numpy", "scipy"] ios.test-groups = ["numpy"] ios.xbuild-tools = ["cmake", "ninja"] ios.environment.PIP_EXTRA_INDEX_URL = "https://pypi.anaconda.org/beeware/simple" -android.test-groups = ["numpy"] -android.xbuild-tools = ["cmake", "ninja"] +android.environment.ANDROID_API_LEVEL = "24" # Needed to include libc++ in the wheel. android.environment.PIP_EXTRA_INDEX_URL = "https://chaquo.com/pypi-13.1" diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 921540194a..79b3879034 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -76,7 +76,7 @@ def test_cross_module_exceptions(msg): # TODO: FIXME @pytest.mark.xfail( - "env.MACOS and env.PYPY", + "(env.MACOS and env.PYPY) or env.ANDROID", raises=RuntimeError, reason="See Issue #2847, PR #2999, PR #4324", strict=not env.PYPY, # PR 5569 diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index 087784c22c..66f2b4dda8 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -243,6 +243,16 @@ if(TARGET ${_Python}::Python) endif() if(TARGET ${_Python}::Module) + # Older versions of CMake don't know that Android requires modules to link to + # libpython, so they generate Python::Module as an INTERFACE library. + get_target_property(module_target_type ${_Python}::Module TYPE) + if(ANDROID AND module_target_type STREQUAL INTERFACE_LIBRARY) + set_property( + TARGET ${_Python}::Module + APPEND + PROPERTY INTERFACE_LINK_LIBRARIES "${${_Python}_LIBRARIES}") + endif() + set_property( TARGET pybind11::module APPEND diff --git a/tools/pybind11Tools.cmake b/tools/pybind11Tools.cmake index 8ef2dbb842..ac24e315d8 100644 --- a/tools/pybind11Tools.cmake +++ b/tools/pybind11Tools.cmake @@ -119,7 +119,7 @@ target_link_libraries( pybind11::module INTERFACE pybind11::python_link_helper - "$<$,$>:pybind11::_ClassicPythonLibraries>") + "$<$,$,$>:pybind11::_ClassicPythonLibraries>") target_link_libraries(pybind11::embed INTERFACE pybind11::pybind11 pybind11::_ClassicPythonLibraries) From 899cf0bd1bf0f75a6dc420694e0147f56dffd2ab Mon Sep 17 00:00:00 2001 From: Malcolm Smith Date: Wed, 11 Jun 2025 23:41:36 +0100 Subject: [PATCH 2/2] Clarifications --- tests/pyproject.toml | 1 - tools/pybind11NewTools.cmake | 5 +++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/pyproject.toml b/tests/pyproject.toml index 013a7e49b9..c91388ca0d 100644 --- a/tests/pyproject.toml +++ b/tests/pyproject.toml @@ -34,4 +34,3 @@ ios.test-groups = ["numpy"] ios.xbuild-tools = ["cmake", "ninja"] ios.environment.PIP_EXTRA_INDEX_URL = "https://pypi.anaconda.org/beeware/simple" android.environment.ANDROID_API_LEVEL = "24" # Needed to include libc++ in the wheel. -android.environment.PIP_EXTRA_INDEX_URL = "https://chaquo.com/pypi-13.1" diff --git a/tools/pybind11NewTools.cmake b/tools/pybind11NewTools.cmake index 66f2b4dda8..e881ca7ca2 100644 --- a/tools/pybind11NewTools.cmake +++ b/tools/pybind11NewTools.cmake @@ -243,8 +243,9 @@ if(TARGET ${_Python}::Python) endif() if(TARGET ${_Python}::Module) - # Older versions of CMake don't know that Android requires modules to link to - # libpython, so they generate Python::Module as an INTERFACE library. + # On Android, older versions of CMake don't know that modules need to link against + # libpython, so Python::Module will be an INTERFACE target with no associated library + # files. get_target_property(module_target_type ${_Python}::Module TYPE) if(ANDROID AND module_target_type STREQUAL INTERFACE_LIBRARY) set_property(