Skip to content

Commit

Permalink
Add config options for indygreg standalone python build version, as w…
Browse files Browse the repository at this point in the history
…ell as python version. Move build files. Unlock windows and linux build configs for arm64.
  • Loading branch information
Ivorforce committed Oct 28, 2024
1 parent 093d987 commit 13e116a
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 160 deletions.
25 changes: 17 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,23 @@ jobs:
- platform: linux
arch: x86_64
os: ubuntu-latest
python_version: 3.12.0
python_standalone_build: 20231002
- platform: windows
arch: x86_64
os: windows-latest
python_version: 3.12.0
python_standalone_build: 20231002
- platform: macos
arch: x86_64
os: macos-latest
python_version: 3.12.0
python_standalone_build: 20231002
- platform: macos
arch: arm64
os: macos-latest
python_version: 3.12.0
python_standalone_build: 20231002

steps:
- name: Checkout repository
Expand All @@ -39,7 +47,8 @@ jobs:
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
# Note that this is for scons, not for the python version we are building.
python-version: 3.12

- name: Setup SCons
shell: bash
Expand All @@ -51,39 +60,39 @@ jobs:
- name: Build extension (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} single_source=true
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} python_standalone_build=${{ matrix.python_standalone_build }} python_version=${{ matrix.python_version }} single_source=true
- name: Build extension (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} single_source=true
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} python_standalone_build=${{ matrix.python_standalone_build }} python_version=${{ matrix.python_version }} single_source=true
- name: Build extension (macOS)
if: matrix.os == 'macos-latest'
run: |
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} single_source=true
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} python_standalone_build=${{ matrix.python_standalone_build }} python_version=${{ matrix.python_version }} single_source=true
- name: Create archive (Linux)
if: matrix.os == 'ubuntu-latest'
run: |
cd bin/
zip -q -r ../godot-python-${{ matrix.platform }}-${{ matrix.arch }}.zip *
zip -q -r ../godot-python-${{ matrix.platform }}.${{ matrix.arch }}.${{ matrix.python_standalone_build }}.${{ matrix.python_version }}.zip *
cd ../
- name: Upload artifacts (Linux)
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v3
with:
name: godot-python-${{ matrix.platform }}-${{ matrix.arch }}
name: godot-python-${{ matrix.platform }}.${{ matrix.arch }}.${{ matrix.python_standalone_build }}.${{ matrix.python_version }}
path: godot-python*.zip
retention-days: 30

- name: Upload artifacts (Windows)
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v3
with:
name: godot-python-${{ matrix.platform }}-${{ matrix.arch }}
name: godot-python-${{ matrix.platform }}.${{ matrix.arch }}.${{ matrix.python_standalone_build }}.${{ matrix.python_version }}
path: |
bin/**/*
!bin/**/*.lib
Expand All @@ -94,7 +103,7 @@ jobs:
if: matrix.os == 'macos-latest'
uses: actions/upload-artifact@v3
with:
name: godot-python-${{ matrix.platform }}-${{ matrix.arch }}
name: godot-python-${{ matrix.platform }}.${{ matrix.arch }}.${{ matrix.python_standalone_build }}.${{ matrix.python_version }}
path: bin/**/*
retention-days: 30

Expand Down
131 changes: 73 additions & 58 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,15 @@ opts.Add(
# godot python options

opts.Add(
PathVariable(
key="python",
help="Path to the `python` to build against.",
default='python3',
validator=(lambda key, val, env: build_utils.validate_executable(key, val, env)
if not env.get('python_lib_dir') else None),
)
key="python_version",
help="Version of python to use. Must be available in the python_standalone_build.",
default='3.12.0',
)

opts.Add(
key="python_standalone_build",
help="Build ID to use for the python version. You can find the list of builds at https://github.com/indygreg/python-build-standalone/releases.",
default="20231002",
)

opts.Add(
Expand Down Expand Up @@ -291,44 +293,52 @@ env.Alias("godot_module_archive", [

from tools.build import prepare_python

prepared_python_config = prepare_python.platform_configs[(env['platform'], env['arch'])]
prepared_python_config = prepare_python.configure(
platform=env['platform'],
arch=env['arch'],
python_version=env['python_version'],
build=env['python_standalone_build'],
)


def _fetch_python(target, source, env):
dest = pathlib.Path(target[0].path).parent
dest.mkdir(parents=True, exist_ok=True)
prepare_python.fetch_python_for_platform(env['platform'], env['arch'], dest)

fetch_python_alias = env.Alias("fetch_python", [
Builder(action = env.Action(_fetch_python, "Fetching Python"))(
env,
target = os.fspath(generated_path / 'python'
/ prepared_python_config.name / pathlib.Path(prepared_python_config.source_url).name),
source = [
],
)
])
try:
prepare_python.fetch_python_for_config(prepared_python_config, target[0])
except Exception as e:
print(f"Error while fetching python: {e}")
return 1

fetched_python_files = env.Command(
target = os.fspath(
generated_path / 'python' / prepared_python_config.name / pathlib.Path(prepared_python_config.source_url).name
),
source = [
],
action=_fetch_python
)


def _prepare_python(target, source, env):
dest = pathlib.Path(target[0].path).parent.resolve()
dest.mkdir(parents=True, exist_ok=True)

src = pathlib.Path(source[0].path).parent.resolve()

env['python'] = prepare_python.prepare_for_platform(env['platform'], env['arch'],
src_dir = src, dest_dir = dest)

prepare_python_alias = env.Alias("prepare_python", [
Builder(action = Action(_prepare_python, "Preparing Python"))(
env,
target = f'bin/{prepared_python_config.name}/python312.zip', # XXX: version
source = [
fetch_python_alias[0].children(),
prepare_python.__file__,
],
)
])
try:
dest = pathlib.Path(target[0].path).parent.resolve()
dest.mkdir(parents=True, exist_ok=True)

src = pathlib.Path(source[0].path).parent.resolve()

env['python'] = prepare_python.prepare_for_platform(prepared_python_config,
src_dir = src, dest_dir = dest)
except Exception as e:
print(f"Error while preparing python: {e}")
return 1

prepared_python_files = env.Command(
target = f'bin/{prepared_python_config.name}/python{prepared_python_config.python_version_minor}-lib.zip',
source = [
*fetched_python_files,
prepare_python.__file__,
],
action=_prepare_python
)



Expand Down Expand Up @@ -366,31 +376,36 @@ env.Append(CPPDEFINES = [f'PYGODOT_ARCH=\\"{env["arch"]}\\"'])


def _append_python_config(env, target, **kwargs):
src_dir = generated_path / 'python' / prepared_python_config.name
env['python'] = os.fspath(prepare_python.get_python_for_platform(env['platform'], env['arch'], src_dir))
try:
src_dir = generated_path / 'python' / prepared_python_config.name
env['python'] = os.fspath(prepare_python.get_python_for_platform(prepared_python_config, src_dir))

from tools.build import python_config
_config_vars = python_config.get_python_config_vars(env)
from tools.build import python_config
_config_vars = python_config.get_python_config_vars(env)

env.Append(LIBPATH = _config_vars.lib_paths)
env.Append(LINKFLAGS = _config_vars.link_flags)
env.Append(LIBS = _config_vars.link_libs)
env.Append(CPPPATH = _config_vars.include_flags)
env.Append(LIBPATH = _config_vars.lib_paths)
env.Append(LINKFLAGS = _config_vars.link_flags)
env.Append(LIBS = _config_vars.link_libs)
env.Append(CPPPATH = _config_vars.include_flags)

if env['platform'] != 'windows':
env.Append(CPPDEFINES = [f'PYTHON_LIBRARY_PATH=\\"{_config_vars.ldlibrary or ""}\\"'])
if env['platform'] != 'windows':
env.Append(CPPDEFINES = [f'PYTHON_LIBRARY_PATH=\\"{_config_vars.ldlibrary or ""}\\"'])

dest = pathlib.Path(target[0].path)
dest.write_text(repr(_config_vars))
dest = pathlib.Path(target[0].path)
dest.write_text(repr(_config_vars))
except Exception as e:
print(f"Error while appending python config: {e}")
return 1


append_python_config = Builder(action = Action(_append_python_config, None))(
env, target='src/.generated/.append_python_config', source=None)

env.Depends(append_python_config, prepare_python_alias)
env.AlwaysBuild(append_python_config)
append_python_config_files = env.Command(
source=prepared_python_files,
target='src/.generated/.append_python_config',
action=_append_python_config
)

env.Depends(sources, append_python_config)
env.AlwaysBuild(append_python_config_files)
env.Depends(sources, append_python_config_files)


# library name
Expand All @@ -410,7 +425,7 @@ env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"]
library_name = "libgodot-python{}{}".format(env["suffix"], env["SHLIBSUFFIX"])

library = env.SharedLibrary(
target = f"bin/{env['platform']}-{env['arch']}/{library_name}",
target = f"bin/{prepared_python_config.name}/{library_name}",
source = sources,
)

Expand Down
3 changes: 1 addition & 2 deletions src/extension/extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ static bool init_python_isolated() {
auto py_major = std::to_string(PY_MAJOR_VERSION);
auto py_minor = std::to_string(PY_MINOR_VERSION);
auto py_version = py_major + "." + py_minor;
auto py_version_no_dot = py_major + py_minor;
auto python_zip_name = "python" + py_version_no_dot + ".zip";
auto python_zip_name = "python" + py_version + "-lib.zip";
auto python_lib_name = "python" + py_version;

add_module_search_path((runtime_config.python_home_path / python_zip_name).string());
Expand Down
Loading

0 comments on commit 13e116a

Please sign in to comment.