Skip to content

Commit 5f1183a

Browse files
committed
Add config options for indygreg standalone python build version, as well as python version. Move build files. Unlock windows and linux build configs for arm64.
1 parent 093d987 commit 5f1183a

File tree

4 files changed

+174
-159
lines changed

4 files changed

+174
-159
lines changed

.github/workflows/build.yml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,33 @@ jobs:
2020
- platform: linux
2121
arch: x86_64
2222
os: ubuntu-latest
23+
python_version: 3.12.0
24+
python_standalone_build: 20231002
25+
- platform: linux
26+
arch: arm64
27+
os: ubuntu-latest
28+
python_version: 3.12.0
29+
python_standalone_build: 20231002
2330
- platform: windows
2431
arch: x86_64
2532
os: windows-latest
33+
python_version: 3.12.0
34+
python_standalone_build: 20231002
35+
- platform: windows
36+
arch: arm64
37+
os: windows-latest
38+
python_version: 3.12.0
39+
python_standalone_build: 20231002
2640
- platform: macos
2741
arch: x86_64
2842
os: macos-latest
43+
python_version: 3.12.0
44+
python_standalone_build: 20231002
2945
- platform: macos
3046
arch: arm64
3147
os: macos-latest
48+
python_version: 3.12.0
49+
python_standalone_build: 20231002
3250

3351
steps:
3452
- name: Checkout repository
@@ -39,7 +57,7 @@ jobs:
3957
- name: Setup Python
4058
uses: actions/setup-python@v4
4159
with:
42-
python-version: '3.12'
60+
python_version: ${{ matrix.python_version }}
4361

4462
- name: Setup SCons
4563
shell: bash
@@ -51,39 +69,39 @@ jobs:
5169
- name: Build extension (Linux)
5270
if: matrix.os == 'ubuntu-latest'
5371
run: |
54-
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} single_source=true
72+
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} python_standalone_build=${{ matrix.python_standalone_build }} python_version=${{ matrix.python_version }} single_source=true
5573
5674
- name: Build extension (Windows)
5775
if: matrix.os == 'windows-latest'
5876
shell: pwsh
5977
run: |
60-
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} single_source=true
78+
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} python_standalone_build=${{ matrix.python_standalone_build }} python_version=${{ matrix.python_version }} single_source=true
6179
6280
- name: Build extension (macOS)
6381
if: matrix.os == 'macos-latest'
6482
run: |
65-
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} single_source=true
83+
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} python_standalone_build=${{ matrix.python_standalone_build }} python_version=${{ matrix.python_version }} single_source=true
6684
6785
- name: Create archive (Linux)
6886
if: matrix.os == 'ubuntu-latest'
6987
run: |
7088
cd bin/
71-
zip -q -r ../godot-python-${{ matrix.platform }}-${{ matrix.arch }}.zip *
89+
zip -q -r ../godot-python-${{ matrix.platform }}.${{ matrix.arch }}.${{ matrix.python_standalone_build }}.${{ matrix.python_version }}.zip *
7290
cd ../
7391
7492
- name: Upload artifacts (Linux)
7593
if: matrix.os == 'ubuntu-latest'
7694
uses: actions/upload-artifact@v3
7795
with:
78-
name: godot-python-${{ matrix.platform }}-${{ matrix.arch }}
96+
name: godot-python-${{ matrix.platform }}.${{ matrix.arch }}.${{ matrix.python_standalone_build }}.${{ matrix.python_version }}
7997
path: godot-python*.zip
8098
retention-days: 30
8199

82100
- name: Upload artifacts (Windows)
83101
if: matrix.os == 'windows-latest'
84102
uses: actions/upload-artifact@v3
85103
with:
86-
name: godot-python-${{ matrix.platform }}-${{ matrix.arch }}
104+
name: godot-python-${{ matrix.platform }}.${{ matrix.arch }}.${{ matrix.python_standalone_build }}.${{ matrix.python_version }}
87105
path: |
88106
bin/**/*
89107
!bin/**/*.lib
@@ -94,7 +112,7 @@ jobs:
94112
if: matrix.os == 'macos-latest'
95113
uses: actions/upload-artifact@v3
96114
with:
97-
name: godot-python-${{ matrix.platform }}-${{ matrix.arch }}
115+
name: godot-python-${{ matrix.platform }}.${{ matrix.arch }}.${{ matrix.python_standalone_build }}.${{ matrix.python_version }}
98116
path: bin/**/*
99117
retention-days: 30
100118

SConstruct

Lines changed: 73 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,15 @@ opts.Add(
8686
# godot python options
8787

8888
opts.Add(
89-
PathVariable(
90-
key="python",
91-
help="Path to the `python` to build against.",
92-
default='python3',
93-
validator=(lambda key, val, env: build_utils.validate_executable(key, val, env)
94-
if not env.get('python_lib_dir') else None),
95-
)
89+
key="python_version",
90+
help="Version of python to use. Must be available in the python_standalone_build.",
91+
default='3.12.0',
92+
)
93+
94+
opts.Add(
95+
key="python_standalone_build",
96+
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.",
97+
default="20231002",
9698
)
9799

98100
opts.Add(
@@ -291,44 +293,52 @@ env.Alias("godot_module_archive", [
291293

292294
from tools.build import prepare_python
293295

294-
prepared_python_config = prepare_python.platform_configs[(env['platform'], env['arch'])]
296+
prepared_python_config = prepare_python.configure(
297+
platform=env['platform'],
298+
arch=env['arch'],
299+
python_version=env['python_version'],
300+
build=env['python_standalone_build'],
301+
)
295302

296303

297304
def _fetch_python(target, source, env):
298-
dest = pathlib.Path(target[0].path).parent
299-
dest.mkdir(parents=True, exist_ok=True)
300-
prepare_python.fetch_python_for_platform(env['platform'], env['arch'], dest)
301-
302-
fetch_python_alias = env.Alias("fetch_python", [
303-
Builder(action = env.Action(_fetch_python, "Fetching Python"))(
304-
env,
305-
target = os.fspath(generated_path / 'python'
306-
/ prepared_python_config.name / pathlib.Path(prepared_python_config.source_url).name),
307-
source = [
308-
],
309-
)
310-
])
305+
try:
306+
prepare_python.fetch_python_for_config(prepared_python_config, target[0])
307+
except Exception as e:
308+
print(f"Error while fetching python: {e}")
309+
return 1
310+
311+
fetched_python_files = env.Command(
312+
target = os.fspath(
313+
generated_path / 'python' / prepared_python_config.name / pathlib.Path(prepared_python_config.source_url).name
314+
),
315+
source = [
316+
],
317+
action=_fetch_python
318+
)
311319

312320

313321
def _prepare_python(target, source, env):
314-
dest = pathlib.Path(target[0].path).parent.resolve()
315-
dest.mkdir(parents=True, exist_ok=True)
316-
317-
src = pathlib.Path(source[0].path).parent.resolve()
318-
319-
env['python'] = prepare_python.prepare_for_platform(env['platform'], env['arch'],
320-
src_dir = src, dest_dir = dest)
321-
322-
prepare_python_alias = env.Alias("prepare_python", [
323-
Builder(action = Action(_prepare_python, "Preparing Python"))(
324-
env,
325-
target = f'bin/{prepared_python_config.name}/python312.zip', # XXX: version
326-
source = [
327-
fetch_python_alias[0].children(),
328-
prepare_python.__file__,
329-
],
330-
)
331-
])
322+
try:
323+
dest = pathlib.Path(target[0].path).parent.resolve()
324+
dest.mkdir(parents=True, exist_ok=True)
325+
326+
src = pathlib.Path(source[0].path).parent.resolve()
327+
328+
env['python'] = prepare_python.prepare_for_platform(prepared_python_config,
329+
src_dir = src, dest_dir = dest)
330+
except Exception as e:
331+
print(f"Error while preparing python: {e}")
332+
return 1
333+
334+
prepared_python_files = env.Command(
335+
target = f'bin/{prepared_python_config.name}/python{prepared_python_config.python_version_minor}-lib.zip',
336+
source = [
337+
*fetched_python_files,
338+
prepare_python.__file__,
339+
],
340+
action=_prepare_python
341+
)
332342

333343

334344

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

367377

368378
def _append_python_config(env, target, **kwargs):
369-
src_dir = generated_path / 'python' / prepared_python_config.name
370-
env['python'] = os.fspath(prepare_python.get_python_for_platform(env['platform'], env['arch'], src_dir))
379+
try:
380+
src_dir = generated_path / 'python' / prepared_python_config.name
381+
env['python'] = os.fspath(prepare_python.get_python_for_platform(prepared_python_config, src_dir))
371382

372-
from tools.build import python_config
373-
_config_vars = python_config.get_python_config_vars(env)
383+
from tools.build import python_config
384+
_config_vars = python_config.get_python_config_vars(env)
374385

375-
env.Append(LIBPATH = _config_vars.lib_paths)
376-
env.Append(LINKFLAGS = _config_vars.link_flags)
377-
env.Append(LIBS = _config_vars.link_libs)
378-
env.Append(CPPPATH = _config_vars.include_flags)
386+
env.Append(LIBPATH = _config_vars.lib_paths)
387+
env.Append(LINKFLAGS = _config_vars.link_flags)
388+
env.Append(LIBS = _config_vars.link_libs)
389+
env.Append(CPPPATH = _config_vars.include_flags)
379390

380-
if env['platform'] != 'windows':
381-
env.Append(CPPDEFINES = [f'PYTHON_LIBRARY_PATH=\\"{_config_vars.ldlibrary or ""}\\"'])
391+
if env['platform'] != 'windows':
392+
env.Append(CPPDEFINES = [f'PYTHON_LIBRARY_PATH=\\"{_config_vars.ldlibrary or ""}\\"'])
382393

383-
dest = pathlib.Path(target[0].path)
384-
dest.write_text(repr(_config_vars))
394+
dest = pathlib.Path(target[0].path)
395+
dest.write_text(repr(_config_vars))
396+
except Exception as e:
397+
print(f"Error while appending python config: {e}")
398+
return 1
385399

386400

387-
append_python_config = Builder(action = Action(_append_python_config, None))(
388-
env, target='src/.generated/.append_python_config', source=None)
389-
390-
env.Depends(append_python_config, prepare_python_alias)
391-
env.AlwaysBuild(append_python_config)
401+
append_python_config_files = env.Command(
402+
source=prepared_python_files,
403+
target='src/.generated/.append_python_config',
404+
action=_append_python_config
405+
)
392406

393-
env.Depends(sources, append_python_config)
407+
env.AlwaysBuild(append_python_config_files)
408+
env.Depends(sources, append_python_config_files)
394409

395410

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

412427
library = env.SharedLibrary(
413-
target = f"bin/{env['platform']}-{env['arch']}/{library_name}",
428+
target = f"bin/{prepared_python_config.name}/{library_name}",
414429
source = sources,
415430
)
416431

src/extension/extension.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,7 @@ static bool init_python_isolated() {
169169
auto py_major = std::to_string(PY_MAJOR_VERSION);
170170
auto py_minor = std::to_string(PY_MINOR_VERSION);
171171
auto py_version = py_major + "." + py_minor;
172-
auto py_version_no_dot = py_major + py_minor;
173-
auto python_zip_name = "python" + py_version_no_dot + ".zip";
172+
auto python_zip_name = "python" + py_version + "-lib.zip";
174173
auto python_lib_name = "python" + py_version;
175174

176175
add_module_search_path((runtime_config.python_home_path / python_zip_name).string());

0 commit comments

Comments
 (0)