diff --git a/imgui_bundle_cmake/internal/add_imgui_bundle_bindings.cmake b/imgui_bundle_cmake/internal/add_imgui_bundle_bindings.cmake index cd44560d..c538d742 100644 --- a/imgui_bundle_cmake/internal/add_imgui_bundle_bindings.cmake +++ b/imgui_bundle_cmake/internal/add_imgui_bundle_bindings.cmake @@ -137,6 +137,20 @@ function(add_imgui_bundle_bindings) target_link_libraries(${python_native_module_name} PUBLIC ${bound_library}) + # On Android, explicitly link against the Python library + if(ANDROID) + if(DEFINED ENV{ANDROID_PYTHON_LIBRARY}) + message(STATUS "Android: Linking ${python_native_module_name} against Python library: $ENV{ANDROID_PYTHON_LIBRARY}") + target_link_libraries(${python_native_module_name} PRIVATE "$ENV{ANDROID_PYTHON_LIBRARY}") + else() + message(WARNING "Android: ANDROID_PYTHON_LIBRARY environment variable not set!") + endif() + endif() + + # Link with OpenGL (necessary for nanobind on desktop platforms) + if (NOT EMSCRIPTEN AND NOT ANDROID) + find_package(OpenGL REQUIRED) + target_link_libraries(${python_native_module_name} PUBLIC OpenGL::GL) # Link with OpenGL (necessary for nanobind) if (NOT EMSCRIPTEN) if (APPLE) diff --git a/pyproject.toml b/pyproject.toml index 36d2d9de..4644cfde 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -121,6 +121,15 @@ cmake.version = ">=3.26.1" build.verbose = true logging.level = "INFO" +[[tool.scikit-build.overrides]] +if.platform-system = "android" +cmake.args = [ + "-DPython_FIND_STRATEGY=LOCATION", + "-DIMGUI_BUNDLE_WITH_HELLO_IMGUI=OFF", + "-DIMGUI_BUNDLE_PYTHON_DISABLE_OPENGL2=ON", + "-DIMGUI_BUNDLE_PYTHON_DISABLE_OPENGL3=ON", +] + [tool.isort] profile = "black" @@ -199,11 +208,25 @@ before-all = "apk add xorg-server-dev libxcursor-dev libxi-dev libxinerama-dev l skip = ["*win32"] #------------------------------------ -# android wheels +# android wheels options #------------------------------------ -# Android wheel support is experimental, and available in a separate branch (not officially supported at the moment) -# See: https://github.com/pthom/imgui_bundle/tree/android-wheel -# Related PR: https://github.com/pthom/imgui_bundle/pull/438 +[tool.cibuildwheel.android] +build = "cp313-*" +archs = ["arm64_v8a"] + +[tool.cibuildwheel.android.environment] +ANDROID_API_LEVEL = "31" +ANDROID_ABI = "arm64-v8a" +IMGUI_BUNDLE_WITH_HELLO_IMGUI = "OFF" +IMGUI_BUNDLE_WITH_IMMAPP = "OFF" +IMGUI_BUNDLE_WITH_IMMVISION = "OFF" +IMGUI_BUNDLE_WITH_IMFILEDIALOG = "OFF" +IMGUI_BUNDLE_WITH_IMGUI_TEX_INSPECT = "OFF" +IMGUI_BUNDLE_WITH_IMGUI_TEST_ENGINE = "OFF" +IMGUI_BUNDLE_PYTHON_DISABLE_OPENGL2 = "ON" +IMGUI_BUNDLE_PYTHON_DISABLE_OPENGL3 = "ON" +ANDROID_PYTHON_LIBRARY = "$(python -c 'from pathlib import Path; import os; tf = Path(os.environ[\"CMAKE_TOOLCHAIN_FILE\"]); print(next((tf.parent / \"python\" / \"prefix\" / \"lib\").glob(\"libpython3.*.so\")))')" + # ═══════════════════════════════════════════════════════════════════════════ # Custom Build Configurations