Skip to content

Commit ac6f1c7

Browse files
committed
recipes: add panda3d recipe
1 parent c8822ae commit ac6f1c7

File tree

3 files changed

+164
-5
lines changed

3 files changed

+164
-5
lines changed

pythonforandroid/recipe.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,8 +1204,8 @@ def get_wheel_platform_tag(self, arch):
12041204
"x86": "i686",
12051205
}[arch.arch]
12061206

1207-
def install_wheel(self, arch, built_wheels):
1208-
_wheel = built_wheels[0]
1207+
def install_wheel(self, arch, pattern):
1208+
_wheel = [realpath(whl) for whl in glob.glob(pattern)][0]
12091209
built_wheel_dir = dirname(_wheel)
12101210
# Fix wheel platform tag
12111211
wheel_tag = wheel_tags(
@@ -1247,13 +1247,11 @@ def build_arch(self, arch):
12471247
"builddir={}".format(sub_build_dir),
12481248
] + self.extra_build_args
12491249

1250-
built_wheels = []
12511250
with current_directory(build_dir):
12521251
shprint(
12531252
sh.Command(self.ctx.python_recipe.python_exe), *build_args, _env=env
12541253
)
1255-
built_wheels = [realpath(whl) for whl in glob.glob("dist/*.whl")]
1256-
self.install_wheel(arch, built_wheels)
1254+
self.install_wheel(arch, join(build_dir,"dist", "*.whl"))
12571255

12581256

12591257
class MesonRecipe(PyProjectRecipe):
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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["CXXFLAGS"] += " -stdlib=libstdc++ -Wno-unsupported-floating-point-opt"
20+
# Python includes
21+
env["CXXFLAGS"] += " -I{}".format(self.ctx.python_recipe.include_root(arch.arch))
22+
return env
23+
24+
def build_arch(self, arch):
25+
self.install_hostpython_prerequisites()
26+
build_dir = self.get_build_dir(arch)
27+
env = self.get_recipe_env(arch)
28+
outputdir = join(build_dir, "dist")
29+
ensure_dir(outputdir)
30+
# Used by makepanda
31+
_arch = {
32+
"armeabi-v7a":"armv7a",
33+
"arm64-v8a":"aarch64",
34+
"x86":"x86",
35+
"x86_64":"x86_64",
36+
}[arch.arch]
37+
38+
panda3d_lib_dir = join(build_dir, "thirdparty/android-libs-{}".format(_arch) , "python", "lib")
39+
ensure_dir(panda3d_lib_dir)
40+
[shprint(
41+
sh.ln, "-sf", lib, join(panda3d_lib_dir, basename(lib))
42+
) for lib in glob(join(self.ctx.python_recipe.link_root(arch.arch), "*.so"))]
43+
44+
with current_directory(build_dir):
45+
shprint(
46+
sh.Command(self.hostpython_location),
47+
"makepanda/makepanda.py",
48+
"--everything",
49+
"--outputdir",
50+
outputdir,
51+
"--arch",
52+
_arch,
53+
"--target",
54+
"android-{}".format(self.ctx.ndk_api),
55+
"--threads",
56+
str(cpu_count()),
57+
"--wheel",
58+
_env=env
59+
)
60+
self.install_wheel(arch, join(build_dir,"dist", "*.whl"))
61+
62+
63+
recipe = Panda3dRecipe()
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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 16:01:09.802187617 +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+
+ # # Starting with NDK r16, libc++ is the recommended STL to use.
15+
stdlibc = os.path.join(ndk_root, 'sources', 'cxx-stl', 'llvm-libc++')
16+
IncDirectory("ALWAYS", os.path.join(stdlibc, 'include').replace('\\', '/'))
17+
- LibDirectory("ALWAYS", os.path.join(stdlibc, 'libs', abi).replace('\\', '/'))
18+
+ LibDirectory("ALWAYS", os.path.join(ndk_root, "toolchains", "llvm", "prebuilt",
19+
+ "linux-x86_64", "sysroot", "usr", "lib",
20+
+ ANDROID_TRIPLE, str(ANDROID_API)) .replace('\\', '", "'))
21+
22+
- stl_lib = os.path.join(stdlibc, 'libs', abi, 'libc++_shared.so')
23+
+ stl_lib = os.path.join(ndk_root, SDK["SYSROOT"], "lib", ANDROID_TRIPLE, "libc++_shared.so")
24+
LibName("ALWAYS", stl_lib.replace('\\', '/'))
25+
CopyFile(os.path.join(GetOutputDir(), 'lib', 'libc++_shared.so'), stl_lib)
26+
27+
diff '--color=auto' -uNr panda3d/makepanda/makepanda.py panda3d.mod/makepanda/makepanda.py
28+
--- panda3d/makepanda/makepanda.py 2024-05-17 15:33:46.856521623 +0530
29+
+++ panda3d.mod/makepanda/makepanda.py 2024-05-17 16:07:56.873041831 +0530
30+
@@ -1580,14 +1580,15 @@
31+
if 'NOARCH:' + arch.upper() not in opts:
32+
cmd += " -arch %s" % arch
33+
34+
- if "SYSROOT" in SDK:
35+
- if GetTarget() != "android":
36+
- cmd += ' --sysroot=%s' % (SDK["SYSROOT"])
37+
- else:
38+
- ndk_dir = SDK["ANDROID_NDK"].replace('\\', '/')
39+
- cmd += ' -isystem %s/sysroot/usr/include' % (ndk_dir)
40+
- cmd += ' -isystem %s/sysroot/usr/include/%s' % (ndk_dir, SDK["ANDROID_TRIPLE"])
41+
- cmd += ' -no-canonical-prefixes'
42+
+ # if "SYSROOT" in SDK:
43+
+ # if GetTarget() != "android":
44+
+ # cmd += ' --sysroot=%s' % (SDK["SYSROOT"])
45+
+ # else:
46+
+ # ndk_dir = SDK["ANDROID_NDK"].replace('\\', '/')
47+
+ #
48+
+ # cmd += ' -isystem %s/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/include ' % (ndk_dir)
49+
+ #
50+
+ # cmd += ' -no-canonical-prefixes'
51+
52+
# Android-specific flags.
53+
arch = GetTargetArch()
54+
@@ -1595,8 +1596,6 @@
55+
if GetTarget() == "android":
56+
# Most of the specific optimization flags here were
57+
# just copied from the default Android Makefiles.
58+
- if "ANDROID_API" in SDK:
59+
- cmd += ' -D__ANDROID_API__=' + str(SDK["ANDROID_API"])
60+
if "ANDROID_GCC_TOOLCHAIN" in SDK:
61+
cmd += ' -gcc-toolchain ' + SDK["ANDROID_GCC_TOOLCHAIN"].replace('\\', '/')
62+
cmd += ' -ffunction-sections -funwind-tables'
63+
@@ -2117,33 +2116,17 @@
64+
for arch in OSX_ARCHS:
65+
if 'NOARCH:' + arch.upper() not in opts:
66+
cmd += " -arch %s" % arch
67+
-
68+
+
69+
elif GetTarget() == 'android':
70+
arch = GetTargetArch()
71+
if "ANDROID_GCC_TOOLCHAIN" in SDK:
72+
cmd += ' -gcc-toolchain ' + SDK["ANDROID_GCC_TOOLCHAIN"].replace('\\', '/')
73+
cmd += " -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now"
74+
- if arch == 'armv7a':
75+
- cmd += ' -target armv7-none-linux-androideabi'
76+
- cmd += " -march=armv7-a -Wl,--fix-cortex-a8"
77+
- elif arch == 'arm':
78+
- cmd += ' -target armv5te-none-linux-androideabi'
79+
- elif arch == 'aarch64':
80+
- cmd += ' -target aarch64-none-linux-android'
81+
- elif arch == 'mips':
82+
- cmd += ' -target mipsel-none-linux-android'
83+
- cmd += ' -mips32'
84+
- elif arch == 'mips64':
85+
- cmd += ' -target mips64el-none-linux-android'
86+
- elif arch == 'x86':
87+
- cmd += ' -target i686-none-linux-android'
88+
- elif arch == 'x86_64':
89+
- cmd += ' -target x86_64-none-linux-android'
90+
cmd += ' -lc -lm'
91+
else:
92+
cmd += " -pthread"
93+
94+
- if "SYSROOT" in SDK:
95+
+ if "SYSROOT" in SDK and GetTarget() != 'android':
96+
cmd += " --sysroot=%s -no-canonical-prefixes" % (SDK["SYSROOT"])
97+
98+
if LDFLAGS != "":

0 commit comments

Comments
 (0)