Skip to content

Commit 2358169

Browse files
committed
recipes: add new polars recipe
1 parent 87a32be commit 2358169

File tree

2 files changed

+185
-0
lines changed

2 files changed

+185
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import sh
2+
from os.path import join, basename
3+
from glob import glob
4+
from multiprocessing import cpu_count
5+
from pythonforandroid.recipe import PyProjectRecipe
6+
from pythonforandroid.util import current_directory, ensure_dir
7+
from pythonforandroid.logger import shprint
8+
9+
10+
class Panda3dRecipe(PyProjectRecipe):
11+
version = "1.10.14"
12+
url = "https://github.com/panda3d/panda3d/archive/refs/tags/v{version}.tar.gz"
13+
patches = ["makepanda.patch"]
14+
15+
def get_recipe_env(self, arch):
16+
env = super().get_recipe_env(arch)
17+
env["ANDROID_NDK_ROOT"] = self.ctx.ndk_dir
18+
env["ANDROID_SDK_ROOT"] = self.ctx.sdk_dir
19+
env["ANDROID_TARGET_API"] = str(self.ctx.android_api)
20+
21+
env["CXXFLAGS"] += " -stdlib=libstdc++ -Wno-unsupported-floating-point-opt"
22+
env["CFLAGS"] += " -Wno-unsupported-floating-point-opt"
23+
24+
# Python includes
25+
python_includes = self.ctx.python_recipe.include_root(arch.arch)
26+
env["CXXFLAGS"] += " -I{}".format(python_includes)
27+
env["CFLAGS"] += " -I{}".format(python_includes)
28+
29+
return env
30+
31+
def build_arch(self, arch):
32+
self.install_hostpython_prerequisites()
33+
build_dir = self.get_build_dir(arch)
34+
env = self.get_recipe_env(arch)
35+
outputdir = join(build_dir, "dist")
36+
ensure_dir(outputdir)
37+
# Used by makepanda
38+
_arch = {
39+
"armeabi-v7a": "armv7a",
40+
"arm64-v8a": "aarch64",
41+
"x86": "x86",
42+
"x86_64": "x86_64",
43+
}[arch.arch]
44+
45+
# Setup python lib folder
46+
panda3d_lib_dir = join(build_dir, "thirdparty/android-libs-{}".format(_arch), "python", "lib")
47+
ensure_dir(panda3d_lib_dir)
48+
for lib in glob(join(self.ctx.python_recipe.link_root(arch.arch), "*.so")):
49+
shprint(
50+
sh.ln, "-sf", lib, join(panda3d_lib_dir, basename(lib))
51+
)
52+
53+
with current_directory(build_dir):
54+
shprint(
55+
sh.Command(self.hostpython_location),
56+
"makepanda/makepanda.py",
57+
"--everything",
58+
"--outputdir",
59+
outputdir,
60+
"--arch",
61+
_arch,
62+
"--target",
63+
"android-{}".format(self.ctx.ndk_api),
64+
"--threads",
65+
str(cpu_count()),
66+
"--wheel",
67+
_env=env
68+
)
69+
self.install_wheel(arch, join(build_dir, "dist", "*.whl"))
70+
71+
72+
recipe = Panda3dRecipe()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
diff '--color=auto' -uNr panda3d/makepanda/makepandacore.py panda3d.mod/makepanda/makepandacore.py
2+
--- panda3d/makepanda/makepandacore.py 2024-05-17 15:33:46.876526187 +0530
3+
+++ panda3d.mod/makepanda/makepandacore.py 2024-05-17 17:06:05.318793873 +0530
4+
@@ -2681,15 +2681,17 @@
5+
arch_dir = 'arch-arm64'
6+
else:
7+
arch_dir = 'arch-' + arch
8+
- SDK["SYSROOT"] = os.path.join(ndk_root, 'platforms', 'android-%s' % (api), arch_dir).replace('\\', '/')
9+
- #IncDirectory("ALWAYS", os.path.join(SDK["SYSROOT"], 'usr', 'include'))
10+
+ SDK["SYSROOT"] = os.path.join(ndk_root, "toolchains", "llvm", "prebuilt", "linux-x86_64", "sysroot", "usr")
11+
+ IncDirectory("ALWAYS", os.path.join(SDK["SYSROOT"], 'usr', 'include'))
12+
13+
# Starting with NDK r16, libc++ is the recommended STL to use.
14+
stdlibc = os.path.join(ndk_root, 'sources', 'cxx-stl', 'llvm-libc++')
15+
IncDirectory("ALWAYS", os.path.join(stdlibc, 'include').replace('\\', '/'))
16+
- LibDirectory("ALWAYS", os.path.join(stdlibc, 'libs', abi).replace('\\', '/'))
17+
+ LibDirectory("ALWAYS", os.path.join(ndk_root, "toolchains", "llvm", "prebuilt",
18+
+ "linux-x86_64", "sysroot", "usr", "lib",
19+
+ ANDROID_TRIPLE, str(ANDROID_API)) .replace('\\', '", "'))
20+
21+
- stl_lib = os.path.join(stdlibc, 'libs', abi, 'libc++_shared.so')
22+
+ stl_lib = os.path.join(ndk_root, SDK["SYSROOT"], "lib", ANDROID_TRIPLE, "libc++_shared.so")
23+
LibName("ALWAYS", stl_lib.replace('\\', '/'))
24+
CopyFile(os.path.join(GetOutputDir(), 'lib', 'libc++_shared.so'), stl_lib)
25+
26+
@@ -2699,11 +2701,12 @@
27+
IncDirectory("ALWAYS", support.replace('\\', '/'))
28+
if api < 21:
29+
LibName("ALWAYS", "-landroid_support")
30+
-
31+
+
32+
+ target_api = os.environ["ANDROID_TARGET_API"]
33+
# Determine the location of android.jar.
34+
- SDK["ANDROID_JAR"] = os.path.join(sdk_root, 'platforms', 'android-%s' % (api), 'android.jar')
35+
+ SDK["ANDROID_JAR"] = os.path.join(sdk_root, 'platforms', 'android-%s' % (target_api), 'android.jar')
36+
if not os.path.isfile(SDK["ANDROID_JAR"]):
37+
- 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))
38+
+ 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))
39+
40+
# Which build tools versions do we have? Pick the latest.
41+
versions = []
42+
diff '--color=auto' -uNr panda3d/makepanda/makepanda.py panda3d.mod/makepanda/makepanda.py
43+
--- panda3d/makepanda/makepanda.py 2024-05-17 15:33:46.856521623 +0530
44+
+++ panda3d.mod/makepanda/makepanda.py 2024-05-17 16:53:32.974433320 +0530
45+
@@ -1197,7 +1197,7 @@
46+
# CgGL is covered by the Cg framework, and we don't need X11 components on OSX
47+
if not PkgSkip("NVIDIACG") and not RUNTIME:
48+
SmartPkgEnable("CGGL", "", ("CgGL"), "Cg/cgGL.h", thirdparty_dir = "nvidiacg")
49+
- if not RUNTIME and GetTarget() != "android":
50+
+ if not RUNTIME and False: # GetTarget() != "android":
51+
SmartPkgEnable("X11", "x11", "X11", ("X11", "X11/Xlib.h", "X11/XKBlib.h"))
52+
53+
if GetHost() != "darwin":
54+
@@ -1580,23 +1580,12 @@
55+
if 'NOARCH:' + arch.upper() not in opts:
56+
cmd += " -arch %s" % arch
57+
58+
- if "SYSROOT" in SDK:
59+
- if GetTarget() != "android":
60+
- cmd += ' --sysroot=%s' % (SDK["SYSROOT"])
61+
- else:
62+
- ndk_dir = SDK["ANDROID_NDK"].replace('\\', '/')
63+
- cmd += ' -isystem %s/sysroot/usr/include' % (ndk_dir)
64+
- cmd += ' -isystem %s/sysroot/usr/include/%s' % (ndk_dir, SDK["ANDROID_TRIPLE"])
65+
- cmd += ' -no-canonical-prefixes'
66+
-
67+
# Android-specific flags.
68+
arch = GetTargetArch()
69+
70+
if GetTarget() == "android":
71+
# Most of the specific optimization flags here were
72+
# just copied from the default Android Makefiles.
73+
- if "ANDROID_API" in SDK:
74+
- cmd += ' -D__ANDROID_API__=' + str(SDK["ANDROID_API"])
75+
if "ANDROID_GCC_TOOLCHAIN" in SDK:
76+
cmd += ' -gcc-toolchain ' + SDK["ANDROID_GCC_TOOLCHAIN"].replace('\\', '/')
77+
cmd += ' -ffunction-sections -funwind-tables'
78+
@@ -2117,33 +2106,17 @@
79+
for arch in OSX_ARCHS:
80+
if 'NOARCH:' + arch.upper() not in opts:
81+
cmd += " -arch %s" % arch
82+
-
83+
+
84+
elif GetTarget() == 'android':
85+
arch = GetTargetArch()
86+
if "ANDROID_GCC_TOOLCHAIN" in SDK:
87+
cmd += ' -gcc-toolchain ' + SDK["ANDROID_GCC_TOOLCHAIN"].replace('\\', '/')
88+
cmd += " -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now"
89+
- if arch == 'armv7a':
90+
- cmd += ' -target armv7-none-linux-androideabi'
91+
- cmd += " -march=armv7-a -Wl,--fix-cortex-a8"
92+
- elif arch == 'arm':
93+
- cmd += ' -target armv5te-none-linux-androideabi'
94+
- elif arch == 'aarch64':
95+
- cmd += ' -target aarch64-none-linux-android'
96+
- elif arch == 'mips':
97+
- cmd += ' -target mipsel-none-linux-android'
98+
- cmd += ' -mips32'
99+
- elif arch == 'mips64':
100+
- cmd += ' -target mips64el-none-linux-android'
101+
- elif arch == 'x86':
102+
- cmd += ' -target i686-none-linux-android'
103+
- elif arch == 'x86_64':
104+
- cmd += ' -target x86_64-none-linux-android'
105+
cmd += ' -lc -lm'
106+
else:
107+
cmd += " -pthread"
108+
109+
- if "SYSROOT" in SDK:
110+
+ if "SYSROOT" in SDK and GetTarget() != 'android':
111+
cmd += " --sysroot=%s -no-canonical-prefixes" % (SDK["SYSROOT"])
112+
113+
if LDFLAGS != "":

0 commit comments

Comments
 (0)