Skip to content

Commit 1747cf6

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 129b494 commit 1747cf6

File tree

4 files changed

+180
-182
lines changed

4 files changed

+180
-182
lines changed

.github/workflows/build.yml

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,19 @@ on:
1212

1313
jobs:
1414
build:
15-
runs-on: ${{ matrix.os }}
15+
runs-on: ${{ matrix.target.os }}
1616
strategy:
1717
fail-fast: false
1818
matrix:
19-
include:
20-
- platform: linux
21-
arch: x86_64
22-
os: ubuntu-latest
23-
- platform: windows
24-
arch: x86_64
25-
os: windows-latest
26-
- platform: macos
27-
arch: x86_64
28-
os: macos-latest
29-
- platform: macos
30-
arch: arm64
31-
os: macos-latest
19+
python_standalone_build: [20231002]
20+
python_version: [3.12.0]
21+
target:
22+
[
23+
{ platform: linux, arch: x86_64, os: ubuntu-latest },
24+
{ platform: windows, arch: x86_64, os: windows-latest },
25+
{ platform: macos, arch: x86_64, os: macos-latest },
26+
{ platform: macos, arch: arm64, os: macos-latest },
27+
]
3228

3329
steps:
3430
- name: Checkout repository
@@ -39,7 +35,8 @@ jobs:
3935
- name: Setup Python
4036
uses: actions/setup-python@v5
4137
with:
42-
python-version: '3.12'
38+
# Note that this is for scons, not for the python version we are building.
39+
python-version: 3.12
4340

4441
- name: Setup SCons
4542
shell: bash
@@ -49,56 +46,56 @@ jobs:
4946
scons --version
5047
5148
- name: Build extension (Linux)
52-
if: matrix.os == 'ubuntu-latest'
49+
if: matrix.target.os == 'ubuntu-latest'
5350
run: |
54-
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} single_source=true
51+
scons platform=${{ matrix.target.platform }} arch=${{ matrix.target.arch }} python_standalone_build=${{ matrix.python_standalone_build }} python_version=${{ matrix.python_version }} single_source=true
5552
5653
- name: Build extension (Windows)
57-
if: matrix.os == 'windows-latest'
54+
if: matrix.target.os == 'windows-latest'
5855
shell: pwsh
5956
run: |
60-
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} single_source=true
57+
scons platform=${{ matrix.target.platform }} arch=${{ matrix.target.arch }} python_standalone_build=${{ matrix.python_standalone_build }} python_version=${{ matrix.python_version }} single_source=true
6158
6259
- name: Build extension (macOS)
63-
if: matrix.os == 'macos-latest'
60+
if: matrix.target.os == 'macos-latest'
6461
run: |
65-
scons platform=${{ matrix.platform }} arch=${{ matrix.arch }} single_source=true
62+
scons platform=${{ matrix.target.platform }} arch=${{ matrix.target.arch }} python_standalone_build=${{ matrix.python_standalone_build }} python_version=${{ matrix.python_version }} single_source=true
6663
6764
- name: Upload artifacts (Linux)
68-
if: matrix.os == 'ubuntu-latest'
65+
if: matrix.target.os == 'ubuntu-latest'
6966
uses: actions/upload-artifact@v4
7067
with:
71-
name: godot-python-${{ matrix.platform }}-${{ matrix.arch }}
68+
name: godot-python-${{ matrix.target.platform }}-${{ matrix.target.arch }}-py${{ matrix.python_version }}-ig${{ matrix.python_standalone_build }}
7269
path: bin/**/*
7370
retention-days: 30
7471

7572
- name: Upload artifacts (Windows)
76-
if: matrix.os == 'windows-latest'
73+
if: matrix.target.os == 'windows-latest'
7774
uses: actions/upload-artifact@v4
7875
with:
79-
name: godot-python-${{ matrix.platform }}-${{ matrix.arch }}
76+
name: godot-python-${{ matrix.target.platform }}-${{ matrix.target.arch }}-py${{ matrix.python_version }}-ig${{ matrix.python_standalone_build }}
8077
path: |
8178
bin/**/*
8279
!bin/**/*.lib
8380
!bin/**/*.exp
8481
retention-days: 30
8582

8683
- name: Upload artifacts (macOS)
87-
if: matrix.os == 'macos-latest'
84+
if: matrix.target.os == 'macos-latest'
8885
uses: actions/upload-artifact@v4
8986
with:
90-
name: godot-python-${{ matrix.platform }}-${{ matrix.arch }}
87+
name: godot-python-${{ matrix.target.platform }}-${{ matrix.target.arch }}-py${{ matrix.python_version }}-ig${{ matrix.python_standalone_build }}
9188
path: bin/**/*
9289
retention-days: 30
9390

9491
- name: Release artifact
9592
if: ${{ inputs.release }}
9693
run: |
97-
if [[ "${{ matrix.os }}" == "ubuntu-latest" ]]; then
94+
if [[ "${{ matrix.target.os }}" == "ubuntu-latest" ]]; then
9895
echo "Releasing artifact for linux"
99-
elif [[ "${{ matrix.os }}" == "windows-latest" ]]; then
96+
elif [[ "${{ matrix.target.os }}" == "windows-latest" ]]; then
10097
echo "Releasing artifact for windows"
101-
elif [[ "${{ matrix.os }}" == "macos-latest" ]]; then
98+
elif [[ "${{ matrix.target.os }}" == "macos-latest" ]]; then
10299
echo "Releasing artifact for macOS"
103100
merge:
104101
runs-on: ubuntu-latest

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(
@@ -311,44 +313,52 @@ env.Alias("godot_module_archive", [
311313

312314
from tools.build import prepare_python
313315

314-
prepared_python_config = prepare_python.platform_configs[(env['platform'], env['arch'])]
316+
prepared_python_config = prepare_python.configure(
317+
platform=env['platform'],
318+
arch=env['arch'],
319+
python_version=env['python_version'],
320+
build=env['python_standalone_build'],
321+
)
315322

316323

317324
def _fetch_python(target, source, env):
318-
dest = pathlib.Path(target[0].path).parent
319-
dest.mkdir(parents=True, exist_ok=True)
320-
prepare_python.fetch_python_for_platform(env['platform'], env['arch'], dest)
321-
322-
fetch_python_alias = env.Alias("fetch_python", [
323-
Builder(action = env.Action(_fetch_python, "Fetching Python"))(
324-
env,
325-
target = os.fspath(generated_path / 'python'
326-
/ prepared_python_config.name / pathlib.Path(prepared_python_config.source_url).name),
327-
source = [
328-
],
329-
)
330-
])
325+
try:
326+
prepare_python.fetch_python_for_config(prepared_python_config, target[0])
327+
except Exception as exc:
328+
print(f"Error while fetching python: {exc}")
329+
return 1
330+
331+
fetched_python_files = env.Command(
332+
target = os.fspath(
333+
generated_path / 'python' / prepared_python_config.name / pathlib.Path(prepared_python_config.source_url).name
334+
),
335+
source = [
336+
],
337+
action=_fetch_python
338+
)
331339

332340

333341
def _prepare_python(target, source, env):
334-
dest = pathlib.Path(target[0].path).parent.resolve()
335-
dest.mkdir(parents=True, exist_ok=True)
336-
337-
src = pathlib.Path(source[0].path).parent.resolve()
338-
339-
env['python'] = prepare_python.prepare_for_platform(env['platform'], env['arch'],
340-
src_dir = src, dest_dir = dest)
341-
342-
prepare_python_alias = env.Alias("prepare_python", [
343-
Builder(action = Action(_prepare_python, "Preparing Python"))(
344-
env,
345-
target = f'bin/{prepared_python_config.name}/python312.zip', # XXX: version
346-
source = [
347-
fetch_python_alias[0].children(),
348-
prepare_python.__file__,
349-
],
350-
)
351-
])
342+
try:
343+
dest = pathlib.Path(target[0].path).parent.resolve()
344+
dest.mkdir(parents=True, exist_ok=True)
345+
346+
src = pathlib.Path(source[0].path).parent.resolve()
347+
348+
env['python'] = prepare_python.prepare_for_platform(prepared_python_config,
349+
src_dir = src, dest_dir = dest)
350+
except Exception as exc:
351+
print(f"Error while preparing python: {exc}")
352+
return 1
353+
354+
prepared_python_files = env.Command(
355+
target = f'bin/{prepared_python_config.name}/python{prepared_python_config.python_version_minor}-lib.zip',
356+
source = [
357+
*fetched_python_files,
358+
prepare_python.__file__,
359+
],
360+
action=_prepare_python
361+
)
352362

353363

354364

@@ -386,31 +396,36 @@ env.Append(CPPDEFINES = [f'PYGODOT_ARCH=\\"{env["arch"]}\\"'])
386396

387397

388398
def _append_python_config(env, target, **kwargs):
389-
src_dir = generated_path / 'python' / prepared_python_config.name
390-
env['python'] = os.fspath(prepare_python.get_python_for_platform(env['platform'], env['arch'], src_dir))
399+
try:
400+
src_dir = generated_path / 'python' / prepared_python_config.name
401+
env['python'] = os.fspath(prepare_python.get_python_for_platform(prepared_python_config, src_dir))
391402

392-
from tools.build import python_config
393-
_config_vars = python_config.get_python_config_vars(env)
403+
from tools.build import python_config
404+
_config_vars = python_config.get_python_config_vars(env)
394405

395-
env.Append(LIBPATH = _config_vars.lib_paths)
396-
env.Append(LINKFLAGS = _config_vars.link_flags)
397-
env.Append(LIBS = _config_vars.link_libs)
398-
env.Append(CPPPATH = _config_vars.include_flags)
406+
env.Append(LIBPATH = _config_vars.lib_paths)
407+
env.Append(LINKFLAGS = _config_vars.link_flags)
408+
env.Append(LIBS = _config_vars.link_libs)
409+
env.Append(CPPPATH = _config_vars.include_flags)
399410

400-
if env['platform'] != 'windows':
401-
env.Append(CPPDEFINES = [f'PYTHON_LIBRARY_PATH=\\"{_config_vars.ldlibrary or ""}\\"'])
411+
if env['platform'] != 'windows':
412+
env.Append(CPPDEFINES = [f'PYTHON_LIBRARY_PATH=\\"{_config_vars.ldlibrary or ""}\\"'])
402413

403-
dest = pathlib.Path(target[0].path)
404-
dest.write_text(repr(_config_vars))
414+
dest = pathlib.Path(target[0].path)
415+
dest.write_text(repr(_config_vars))
416+
except Exception as exc:
417+
print(f"Error while appending python config: {exc}")
418+
return 1
405419

406420

407-
append_python_config = Builder(action = Action(_append_python_config, None))(
408-
env, target='src/.generated/.append_python_config', source=None)
409-
410-
env.Depends(append_python_config, prepare_python_alias)
411-
env.AlwaysBuild(append_python_config)
421+
append_python_config_files = env.Command(
422+
source=prepared_python_files,
423+
target='src/.generated/.append_python_config',
424+
action=_append_python_config
425+
)
412426

413-
env.Depends(sources, append_python_config)
427+
env.AlwaysBuild(append_python_config_files)
428+
env.Depends(sources, append_python_config_files)
414429

415430

416431
# library name
@@ -430,7 +445,7 @@ env["OBJSUFFIX"] = suffix + env["OBJSUFFIX"]
430445
library_name = "libgodot-python{}{}".format(env["suffix"], env["SHLIBSUFFIX"])
431446

432447
library = env.SharedLibrary(
433-
target = f"bin/{env['platform']}-{env['arch']}/{library_name}",
448+
target = f"bin/{prepared_python_config.name}/{library_name}",
434449
source = sources,
435450
)
436451

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)