Skip to content

Fix Android tests #23

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

Merged
merged 2 commits into from
Jun 12, 2025
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
1 change: 1 addition & 0 deletions tests/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions tests/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ 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"]
Comment on lines -36 to -37
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

android.test-groups = ["numpy"]

Unfortunately the Chaquopy NumPy wheel won't work with the CPython testbed, as it packages OpenBLAS in a Chaquopy-specific location.

android.xbuild-tools = ["cmake", "ninja"]

xbuild-tools is not implemented on Android: pypa/cibuildwheel#2349 (comment)

android.environment.PIP_EXTRA_INDEX_URL = "https://chaquo.com/pypi-13.1"
android.environment.ANDROID_API_LEVEL = "24" # Needed to include libc++ in the wheel.
2 changes: 1 addition & 1 deletion tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand what's going on here, but going by the linked issues and PRs, neither do the pybind11 maintainers, so I don't feel too bad.

raises=RuntimeError,
reason="See Issue #2847, PR #2999, PR #4324",
strict=not env.PYPY, # PR 5569
Expand Down
11 changes: 11 additions & 0 deletions tools/pybind11NewTools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,17 @@ if(TARGET ${_Python}::Python)
endif()

if(TARGET ${_Python}::Module)
# 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(
TARGET ${_Python}::Module
APPEND
PROPERTY INTERFACE_LINK_LIBRARIES "${${_Python}_LIBRARIES}")
endif()

set_property(
TARGET pybind11::module
APPEND
Expand Down
2 changes: 1 addition & 1 deletion tools/pybind11Tools.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ target_link_libraries(
pybind11::module
INTERFACE
pybind11::python_link_helper
"$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>>:pybind11::_ClassicPythonLibraries>")
"$<$<OR:$<PLATFORM_ID:Windows>,$<PLATFORM_ID:Cygwin>,$<PLATFORM_ID:Android>>:pybind11::_ClassicPythonLibraries>")

target_link_libraries(pybind11::embed INTERFACE pybind11::pybind11
pybind11::_ClassicPythonLibraries)
Expand Down
Loading