Skip to content

Commit

Permalink
recipes: add new polars recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
T-Dynamos committed May 22, 2024
1 parent 87a32be commit 2358169
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 0 deletions.
72 changes: 72 additions & 0 deletions pythonforandroid/recipes/panda3d/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import sh
from os.path import join, basename
from glob import glob
from multiprocessing import cpu_count
from pythonforandroid.recipe import PyProjectRecipe
from pythonforandroid.util import current_directory, ensure_dir
from pythonforandroid.logger import shprint


class Panda3dRecipe(PyProjectRecipe):
version = "1.10.14"
url = "https://github.com/panda3d/panda3d/archive/refs/tags/v{version}.tar.gz"
patches = ["makepanda.patch"]

def get_recipe_env(self, arch):
env = super().get_recipe_env(arch)
env["ANDROID_NDK_ROOT"] = self.ctx.ndk_dir
env["ANDROID_SDK_ROOT"] = self.ctx.sdk_dir
env["ANDROID_TARGET_API"] = str(self.ctx.android_api)

env["CXXFLAGS"] += " -stdlib=libstdc++ -Wno-unsupported-floating-point-opt"
env["CFLAGS"] += " -Wno-unsupported-floating-point-opt"

# Python includes
python_includes = self.ctx.python_recipe.include_root(arch.arch)
env["CXXFLAGS"] += " -I{}".format(python_includes)
env["CFLAGS"] += " -I{}".format(python_includes)

return env

def build_arch(self, arch):
self.install_hostpython_prerequisites()
build_dir = self.get_build_dir(arch)
env = self.get_recipe_env(arch)
outputdir = join(build_dir, "dist")
ensure_dir(outputdir)
# Used by makepanda
_arch = {
"armeabi-v7a": "armv7a",
"arm64-v8a": "aarch64",
"x86": "x86",
"x86_64": "x86_64",
}[arch.arch]

# Setup python lib folder
panda3d_lib_dir = join(build_dir, "thirdparty/android-libs-{}".format(_arch), "python", "lib")
ensure_dir(panda3d_lib_dir)
for lib in glob(join(self.ctx.python_recipe.link_root(arch.arch), "*.so")):
shprint(
sh.ln, "-sf", lib, join(panda3d_lib_dir, basename(lib))
)

with current_directory(build_dir):
shprint(
sh.Command(self.hostpython_location),
"makepanda/makepanda.py",
"--everything",
"--outputdir",
outputdir,
"--arch",
_arch,
"--target",
"android-{}".format(self.ctx.ndk_api),
"--threads",
str(cpu_count()),
"--wheel",
_env=env
)
self.install_wheel(arch, join(build_dir, "dist", "*.whl"))


recipe = Panda3dRecipe()
113 changes: 113 additions & 0 deletions pythonforandroid/recipes/panda3d/makepanda.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
diff '--color=auto' -uNr panda3d/makepanda/makepandacore.py panda3d.mod/makepanda/makepandacore.py
--- panda3d/makepanda/makepandacore.py 2024-05-17 15:33:46.876526187 +0530
+++ panda3d.mod/makepanda/makepandacore.py 2024-05-17 17:06:05.318793873 +0530
@@ -2681,15 +2681,17 @@
arch_dir = 'arch-arm64'
else:
arch_dir = 'arch-' + arch
- SDK["SYSROOT"] = os.path.join(ndk_root, 'platforms', 'android-%s' % (api), arch_dir).replace('\\', '/')
- #IncDirectory("ALWAYS", os.path.join(SDK["SYSROOT"], 'usr', 'include'))
+ SDK["SYSROOT"] = os.path.join(ndk_root, "toolchains", "llvm", "prebuilt", "linux-x86_64", "sysroot", "usr")
+ IncDirectory("ALWAYS", os.path.join(SDK["SYSROOT"], 'usr', 'include'))

# Starting with NDK r16, libc++ is the recommended STL to use.
stdlibc = os.path.join(ndk_root, 'sources', 'cxx-stl', 'llvm-libc++')
IncDirectory("ALWAYS", os.path.join(stdlibc, 'include').replace('\\', '/'))
- LibDirectory("ALWAYS", os.path.join(stdlibc, 'libs', abi).replace('\\', '/'))
+ LibDirectory("ALWAYS", os.path.join(ndk_root, "toolchains", "llvm", "prebuilt",
+ "linux-x86_64", "sysroot", "usr", "lib",
+ ANDROID_TRIPLE, str(ANDROID_API)) .replace('\\', '", "'))

- stl_lib = os.path.join(stdlibc, 'libs', abi, 'libc++_shared.so')
+ stl_lib = os.path.join(ndk_root, SDK["SYSROOT"], "lib", ANDROID_TRIPLE, "libc++_shared.so")
LibName("ALWAYS", stl_lib.replace('\\', '/'))
CopyFile(os.path.join(GetOutputDir(), 'lib', 'libc++_shared.so'), stl_lib)

@@ -2699,11 +2701,12 @@
IncDirectory("ALWAYS", support.replace('\\', '/'))
if api < 21:
LibName("ALWAYS", "-landroid_support")
-
+
+ target_api = os.environ["ANDROID_TARGET_API"]
# Determine the location of android.jar.
- SDK["ANDROID_JAR"] = os.path.join(sdk_root, 'platforms', 'android-%s' % (api), 'android.jar')
+ SDK["ANDROID_JAR"] = os.path.join(sdk_root, 'platforms', 'android-%s' % (target_api), 'android.jar')
if not os.path.isfile(SDK["ANDROID_JAR"]):
- exit("Cannot find %s. Install platform API level %s via the SDK manager or change the targeted API level with --target=android-#" % (SDK["ANDROID_JAR"], api))
+ exit("Cannot find %s. Install platform API level %s via the SDK manager or change the targeted API level with --target=android-#" % (SDK["ANDROID_JAR"], target_api))

# Which build tools versions do we have? Pick the latest.
versions = []
diff '--color=auto' -uNr panda3d/makepanda/makepanda.py panda3d.mod/makepanda/makepanda.py
--- panda3d/makepanda/makepanda.py 2024-05-17 15:33:46.856521623 +0530
+++ panda3d.mod/makepanda/makepanda.py 2024-05-17 16:53:32.974433320 +0530
@@ -1197,7 +1197,7 @@
# CgGL is covered by the Cg framework, and we don't need X11 components on OSX
if not PkgSkip("NVIDIACG") and not RUNTIME:
SmartPkgEnable("CGGL", "", ("CgGL"), "Cg/cgGL.h", thirdparty_dir = "nvidiacg")
- if not RUNTIME and GetTarget() != "android":
+ if not RUNTIME and False: # GetTarget() != "android":
SmartPkgEnable("X11", "x11", "X11", ("X11", "X11/Xlib.h", "X11/XKBlib.h"))

if GetHost() != "darwin":
@@ -1580,23 +1580,12 @@
if 'NOARCH:' + arch.upper() not in opts:
cmd += " -arch %s" % arch

- if "SYSROOT" in SDK:
- if GetTarget() != "android":
- cmd += ' --sysroot=%s' % (SDK["SYSROOT"])
- else:
- ndk_dir = SDK["ANDROID_NDK"].replace('\\', '/')
- cmd += ' -isystem %s/sysroot/usr/include' % (ndk_dir)
- cmd += ' -isystem %s/sysroot/usr/include/%s' % (ndk_dir, SDK["ANDROID_TRIPLE"])
- cmd += ' -no-canonical-prefixes'
-
# Android-specific flags.
arch = GetTargetArch()

if GetTarget() == "android":
# Most of the specific optimization flags here were
# just copied from the default Android Makefiles.
- if "ANDROID_API" in SDK:
- cmd += ' -D__ANDROID_API__=' + str(SDK["ANDROID_API"])
if "ANDROID_GCC_TOOLCHAIN" in SDK:
cmd += ' -gcc-toolchain ' + SDK["ANDROID_GCC_TOOLCHAIN"].replace('\\', '/')
cmd += ' -ffunction-sections -funwind-tables'
@@ -2117,33 +2106,17 @@
for arch in OSX_ARCHS:
if 'NOARCH:' + arch.upper() not in opts:
cmd += " -arch %s" % arch
-
+
elif GetTarget() == 'android':
arch = GetTargetArch()
if "ANDROID_GCC_TOOLCHAIN" in SDK:
cmd += ' -gcc-toolchain ' + SDK["ANDROID_GCC_TOOLCHAIN"].replace('\\', '/')
cmd += " -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now"
- if arch == 'armv7a':
- cmd += ' -target armv7-none-linux-androideabi'
- cmd += " -march=armv7-a -Wl,--fix-cortex-a8"
- elif arch == 'arm':
- cmd += ' -target armv5te-none-linux-androideabi'
- elif arch == 'aarch64':
- cmd += ' -target aarch64-none-linux-android'
- elif arch == 'mips':
- cmd += ' -target mipsel-none-linux-android'
- cmd += ' -mips32'
- elif arch == 'mips64':
- cmd += ' -target mips64el-none-linux-android'
- elif arch == 'x86':
- cmd += ' -target i686-none-linux-android'
- elif arch == 'x86_64':
- cmd += ' -target x86_64-none-linux-android'
cmd += ' -lc -lm'
else:
cmd += " -pthread"

- if "SYSROOT" in SDK:
+ if "SYSROOT" in SDK and GetTarget() != 'android':
cmd += " --sysroot=%s -no-canonical-prefixes" % (SDK["SYSROOT"])

if LDFLAGS != "":

0 comments on commit 2358169

Please sign in to comment.