Skip to content

tuning x11-64 platform for aarch64 and pyhton3.9 #302

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ Godot Python, because you want Python on Godot !
The goal of this project is to provide Python language support as a scripting
module for the `Godot <http://godotengine.org>`_ game engine.

Notes
====

This version is a hack to build godot-python on aarch64 (tested on RaspberryPi 4 2GB, swap maxxed out to 11+GB, Raspberry Pi OS / Debian 10.5), replacing platform x11-64. Before launching the build with the usual instructions below, grab manually an aarch64 build from `python-build-standalone project <https://github.com/indygreg/python-build-standalone/>`_ under the CI menu ("actions") -- aarch64 linux is not part of official releases and only comes with python3.9 as of 2021-05-30. Prefer a version without debug and optimisations, e.g. "lto". Place the .tar.zst package in ``/tmp/cpython-3.9.5-aarch64-unknown-linux-gnu.tar.zst``. Compilation will likely take hours.

Quickstart
==========
Expand Down
22 changes: 12 additions & 10 deletions platforms/x11-64/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,27 @@ else:
env["godot_binary_download_platform"] = "x11.64"
env["cpython_build"] = cpython_build
env["cpython_build_dir"] = cpython_build
env["DIST_SITE_PACKAGES"] = Dir(f"{env['DIST_PLATFORM']}/lib/python3.8/site-packages")
env["DIST_SITE_PACKAGES"] = Dir(f"{env['DIST_PLATFORM']}/lib/python3.9/site-packages")


### Build config for pythonscript ###


env.AppendUnique(CFLAGS=["-m64"])
env.AppendUnique(LINKFLAGS=["-m64"])
#env.AppendUnique(CFLAGS=["-m64"])
#env.AppendUnique(LINKFLAGS=["-m64"])
# Cannot use CPPPATH&LIBPATH here given headers are within `cpython_build` target,
# so Scons consider the headers are a missing target
env.AppendUnique(CFLAGS=[f"-I{cpython_build.abspath}/include/python3.8/"])
env.AppendUnique(CFLAGS=[f"-I{cpython_build.abspath}/include/python3.9/"])
env.AppendUnique(LINKFLAGS=[f"-L{cpython_build.abspath}/lib"])
env.AppendUnique(CYTHON_COMPILE_DEPS=[cpython_build])


### Fetch Python prebuild ###


CPYTHON_PREBUILD_URL = "https://github.com/indygreg/python-build-standalone/releases/download/20200822/cpython-3.8.5-x86_64-unknown-linux-gnu-pgo-20200823T0036.tar.zst"
#CPYTHON_PREBUILD_URL = "https://github.com/indygreg/python-build-standalone/releases/download/20200822/cpython-3.8.5-x86_64-unknown-linux-gnu-pgo-20200823T0036.tar.zst"
# download manually a binary for aarch64-unknown-linux-gnu and place it in /tmp/ E.g. grab a release or CI artifacts from https://github.com/indygreg/python-build-standalone -- prefer a version with optimisations and no debug, i.e. "lto"
PYTHON_PREBUILD_URL = "file:///tmp/cpython-3.9.5-aarch64-unknown-linux-gnu.tar.zst"
cpython_prebuild_archive = env.Download(
target=File(CPYTHON_PREBUILD_URL.rsplit("/", 1)[1]), url=CPYTHON_PREBUILD_URL
)
Expand Down Expand Up @@ -71,9 +73,9 @@ def generate_cpython_build(target, source, env):
prebuild = Path(source[0].abspath) / "python"

conf = json.loads((prebuild / "PYTHON.json").read_text())
assert conf["version"] == "5"
assert conf["version"] == "7"
assert conf["libpython_link_mode"] == "shared"
assert conf["target_triple"] == "x86_64-unknown-linux-gnu"
assert conf["target_triple"] == "aarch64-unknown-linux-gnu"

shutil.copytree(str(prebuild / "install"), str(build), symlinks=True)
shutil.copytree(str(prebuild / "licenses"), str(build / "licenses"), symlinks=True)
Expand All @@ -87,7 +89,7 @@ def generate_cpython_build(target, source, env):
assert config.exists()
shutil.rmtree(str(config))

stdlib_path = build / "lib/python3.8"
stdlib_path = build / "lib/python3.9"

# Remove tests lib (pretty big and basically useless)
shutil.rmtree(str(stdlib_path / "test"))
Expand All @@ -101,12 +103,12 @@ def generate_cpython_build(target, source, env):

# Zip the stdlib to save plenty of space \o/
if env["compressed_stdlib"]:
tmp_stdlib_path = build / "lib/tmp_python3.8"
tmp_stdlib_path = build / "lib/tmp_python3.9"
shutil.move(str(stdlib_path), str(tmp_stdlib_path))
stdlib_path.mkdir()
shutil.move(str(tmp_stdlib_path / "lib-dynload"), str(stdlib_path / "lib-dynload"))
shutil.make_archive(
base_name=build / "lib/python38", format="zip", root_dir=str(tmp_stdlib_path)
base_name=build / "lib/python39", format="zip", root_dir=str(tmp_stdlib_path)
)
shutil.rmtree(str(tmp_stdlib_path))
# Oddly enough, os.py must be present (even if empty !) otherwise
Expand Down
2 changes: 1 addition & 1 deletion pythonscript/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ elif env["platform"].startswith("osx"):
c_env.AppendUnique(CFLAGS=["-Werror-implicit-function-declaration"])

else: # x11
c_env.AppendUnique(LIBS=["python3.8"])
c_env.AppendUnique(LIBS=["python3.9"])
c_env.AppendUnique(LINKFLAGS=["-Wl,-rpath,'$$ORIGIN/lib'"])
c_env.AppendUnique(CFLAGS=["-Werror-implicit-function-declaration"])
c_env.Depends("pythonscript.c", env["cpython_build"])
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ appdirs==1.4.4 \
--hash=sha256:a841dacd6b99318a741b166adb07e19ee71a274450e68237b4650ca1055ab128
# via black
autopxd2==1.1.0 \
--hash=sha256:faa4b7eeb6b1d7217c46d3660640d4a72fb5c86d4559017c1f58a55d34332b2a
--hash=sha256:687d77b167020354c0e7d0d47b906494fb9004a74ca3c80a479c83d8cbe6eee1
# via -r requirements.in
black==20.8b1 \
--hash=sha256:1c02557aa099101b9d21496f8a914e9ed2222ef70336404eeeac8edba836fbea
Expand Down
2 changes: 1 addition & 1 deletion site_scons/site_tools/cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def CythonCompile(env, target, source):
SHLIBSUFFIX=".so",
CFLAGS=cflags,
LINKFLAGS=[*linkflags, *env["LINKFLAGS"]],
LIBS=["python3.8", "pythonscript"],
LIBS=["python3.9", "pythonscript"],
# LIBS=[*env["CYTHON_LIBS"], *env["LIBS"]],
# LIBPATH=[*env['CYTHON_LIBPATH'], *env['LIBPATH']]
)
Expand Down