From b4123c23265df4bd1a48b4c6b524e6336526aefd Mon Sep 17 00:00:00 2001 From: Lukas Tenbrink Date: Thu, 24 Oct 2024 20:00:25 +0200 Subject: [PATCH] Fix the builds on macOS (universal). Closes #11. --- src/util/system.cpp | 2 +- test/python.gdextension | 2 +- tools/build/prepare_python.py | 18 +++++++++++++++++- tools/build/python_config.py | 2 +- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/util/system.cpp b/src/util/system.cpp index e034429..0efbfe3 100644 --- a/src/util/system.cpp +++ b/src/util/system.cpp @@ -30,7 +30,7 @@ void system_quick_exit(int status) { #ifdef WINDOWS_ENABLED TerminateProcess(GetCurrentProcess(), status); #else - std::quick_exit(status); + std::_Exit(0); #endif } diff --git a/test/python.gdextension b/test/python.gdextension index 9389be2..3a38a18 100644 --- a/test/python.gdextension +++ b/test/python.gdextension @@ -5,7 +5,7 @@ entry_symbol = "python_extension_init" [libraries] -macos = "res://bin/macos/libgodot-python.macos.framework" +macos = "res://bin/macos/libgodot-python.macos.universal.dylib" windows.x86_32 = "res://bin/windows-x86_32/libgodot-python.windows.x86_32.dll" windows.x86_64 = "res://bin/windows-x86_64/libgodot-python.windows.x86_64.dll" diff --git a/tools/build/prepare_python.py b/tools/build/prepare_python.py index b277a18..8108249 100644 --- a/tools/build/prepare_python.py +++ b/tools/build/prepare_python.py @@ -59,6 +59,19 @@ def add_platform_config(*args, **kwargs): executable = 'python.exe', ) +add_platform_config( + platform = 'macos', + arch = 'universal', + source_url = 'https://github.com/indygreg/python-build-standalone/releases/download/' + '20231002/cpython-3.12.0+20231002-x86_64-apple-darwin-install_only.tar.gz', + so_suffixes = ['.os'], + ext_suffixes = ['.os'], + so_path = 'lib/libpython3.12.dylib', + python_lib_dir = 'lib/python3.12', + python_ext_dir = 'lib/python3.12/lib-dynload', + executable = 'bin/python3.12', +) + def fetch_python_for_platform(platform: str, arch: str, dest_dir: pathlib.Path): config = platform_configs[(platform, arch)] @@ -84,7 +97,10 @@ def prepare_for_platform(platform: str, arch: str, dest_dir.mkdir(parents=True, exist_ok=True) shutil.copy2(src / config.so_path, dest_dir) - subprocess.run(['strip', '-s', str(dest_dir / pathlib.Path(config.so_path).name)], check=True) + if platform == 'macos': + subprocess.run(['strip', '-x', str(dest_dir / pathlib.Path(config.so_path).name)], check=True) + else: + subprocess.run(['strip', '-s', str(dest_dir / pathlib.Path(config.so_path).name)], check=True) if (src / config.python_ext_dir).exists(): dest_ext_dir = dest_dir / 'python3.12' / 'lib-dynload' diff --git a/tools/build/python_config.py b/tools/build/python_config.py index 99e8a3a..35d6d89 100644 --- a/tools/build/python_config.py +++ b/tools/build/python_config.py @@ -111,7 +111,7 @@ def normpath(path: str) -> str: config_vars.link_libs = _stable_unique([ *itertools.chain(*( - (v.removeprefix('-l') for v in value.split()) + (v.removeprefix('-l') for v in value.split() if v.startswith('-l')) for name in ('LIBS', 'SYSLIBS') if (value := sysconfig_vars.get(name)) )),