Skip to content

Commit b0876cc

Browse files
committed
Install libgdpy.lib on Windows (needed for 3rd party Cyton module doing cimport godot)
1 parent 8b72803 commit b0876cc

File tree

3 files changed

+26
-93
lines changed

3 files changed

+26
-93
lines changed

src/meson.build

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,10 +217,34 @@ lib_gdpy = shared_library(
217217
dependencies: [dep_godot, dep_python],
218218
install_rpath: lib_gdpy_rpath, # To find libpython
219219
install: true,
220-
install_dir: 'addons/gdpy/' + host_platform,
220+
install_dir: join_paths('addons/gdpy/', host_platform),
221221
)
222222

223223

224+
# On Windows, manually install the import library (.lib) alongside the DLL
225+
# because Meson doesn't do this automatically with custom install_dir.
226+
# This .lib file is needed for linking 3rd party Cython module that do a `cimport godot`.
227+
if host_platform.startswith('windows')
228+
meson.add_install_script(
229+
python,
230+
[
231+
'-c',
232+
'''
233+
import os, sys, shutil, pathlib
234+
src = pathlib.Path(sys.argv[1])
235+
destdir = pathlib.Path(os.environ["MESON_INSTALL_DESTDIR_PREFIX"])
236+
host_platform = sys.argv[2]
237+
dst = destdir / f"addons/gdpy/{host_platform}/{src.name}"
238+
print(f"cp {src} {dst}")
239+
shutil.copyfile(src, dst)
240+
''',
241+
lib_gdpy.full_path().replace('.dll', '.lib'),
242+
host_platform,
243+
]
244+
)
245+
endif
246+
247+
224248
# This dependency is used by all Cython modules to retreive the `gdpy_gdapi`
225249
# global variable that is declared as extern in `godot.hazmat.gdapi`
226250
# Note we don't need to configure a rpath for Cython modules, this is because

tests/3-init-with-cython-hook/build.py

Lines changed: 0 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -11,97 +11,9 @@
1111
raise SystemExit(0)
1212

1313

14-
# # Here we run the build with the Python from the host development environment
15-
# # (i.e. not the embedded Python that will run the extension).
16-
# #
17-
# # The reason for this is the embedded Python has issues building native extensions
18-
# # since it has been compiled in a totally different environment that the one
19-
# # it runs on, leading to incorrect flags passed during extension compilation
20-
# # (see https://github.com/indygreg/python-build-standalone/issues/152).
21-
# #
22-
# # So instead we have to rely on the Python from the development environment, which
23-
# # of course means its version (and platform !) must be the same to preserve ABI
24-
# # compatibility.
25-
26-
# match platform.machine().lower():
27-
# case "x86" | "x86_64" as cpu:
28-
# pass
29-
# case "amd64" | "x64":
30-
# cpu = "x86_64"
31-
# case unknown:
32-
# raise SystemExit(f"Unknown CPU architecture {unknown}")
33-
34-
35-
# match platform.system():
36-
# case "Windows":
37-
# embedded_platform_path = PROJECT_DIR / f"addons/gdpy/windows-{cpu}"
38-
# embedded_libgdpy_path = embedded_platform_path / "libgdpy.dll"
39-
# embedded_python_path = embedded_platform_path / "python.exe"
40-
# lib_pattern = "my.*.pyd"
41-
42-
# case "Linux":
43-
# embedded_platform_path = PROJECT_DIR / f"addons/gdpy/linux-{cpu}"
44-
# embedded_libgdpy_path = embedded_platform_path / "libgdpy.so"
45-
# embedded_python_path = embedded_platform_path / "bin/python3"
46-
# lib_pattern = "my.*.so"
47-
48-
# case "iOS":
49-
# embedded_platform_path = PROJECT_DIR / f"addons/gdpy/macos-{cpu}"
50-
# embedded_libgdpy_path = embedded_platform_path / "libgdpy.dylib"
51-
# embedded_python_path = embedded_platform_path / "bin/python3"
52-
# lib_pattern = "my.*.dylib"
53-
54-
# case unknown:
55-
# raise SystemExit(f"Unknown platform `{unknown}`")
56-
57-
58-
# embedded_version = subprocess.check_output([str(embedded_python_path), "--version"]).decode().strip()
59-
# host_version = subprocess.check_output([sys.executable, "--version"]).decode().strip()
60-
# if embedded_version != host_version:
61-
# BOLD_RED = "\x1b[1;31m"
62-
# NO_COLOR = "\x1b[0;0m"
63-
# print(
64-
# f"{BOLD_RED}"
65-
# "WARNING: Python extension loading may fail: host and embedded versions differ"
66-
# f" (host: {host_version}, embedded: {embedded_version})"
67-
# f"{NO_COLOR}"
68-
# )
69-
70-
71-
# match platform.system():
72-
# case "Windows":
73-
# embedded_site_packages_path = embedded_platform_path / "Lib/site-packages/"
74-
# case "Linux" | "iOS":
75-
# # `"Python 3.12.1"` -> `3, 12`
76-
# embedded_version_major, embedded_version_minor = map(
77-
# int, embedded_version.removeprefix("Python ").split(".")[:2]
78-
# )
79-
# embedded_site_packages_path = (
80-
# embedded_platform_path
81-
# / f"lib/python{embedded_version_major}.{embedded_version_minor}/site-packages/"
82-
# )
83-
# case unknown:
84-
# raise SystemExit(f"Unknown platform `{unknown}`")
85-
86-
8714
cmd = [sys.executable, "setup.py", "build_ext", "--build-lib", str(PROJECT_DIR)]
8815
print(" ".join(cmd))
8916
subprocess.check_call(
9017
cmd,
9118
cwd=PROJECT_DIR,
92-
# env={
93-
# **os.environ,
94-
# "EMBEDDED_PLATFORM_PATH": str(embedded_platform_path),
95-
# "EMBEDDED_SITE_PACKAGES_PATH": str(embedded_site_packages_path),
96-
# },
9719
)
98-
99-
100-
# # Finally remove the platform info from the shared library, this is to avoid
101-
# # annoying update everytime we change CPython embedded version.
102-
# lib_candidates = list(PROJECT_DIR.glob(lib_pattern))
103-
# assert len(lib_candidates) == 1, lib_candidates
104-
# lib = lib_candidates[0]
105-
# lib_new_name = f"my{lib.suffix}"
106-
# print(f"renaming {lib.name} -> {lib_new_name}")
107-
# shutil.move(lib, lib.parent / lib_new_name)

tests/3-init-with-cython-hook/setup.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,24 +34,21 @@
3434
match platform.system():
3535
case "Windows":
3636
embedded_platform_path = PROJECT_DIR / f"addons/gdpy/windows-{cpu}"
37-
embedded_libgdpy_path = embedded_platform_path / "libgdpy.lib"
37+
embedded_libgdpy_path = embedded_platform_path / "gdpy.lib"
3838
embedded_python_path = embedded_platform_path / "python.exe"
3939
embedded_site_packages_path = embedded_platform_path / "Lib/site-packages/"
40-
# lib_pattern = "my.*.pyd"
4140

4241
case "Linux":
4342
embedded_platform_path = PROJECT_DIR / f"addons/gdpy/linux-{cpu}"
4443
embedded_libgdpy_path = embedded_platform_path / "libgdpy.so"
4544
embedded_python_path = embedded_platform_path / "bin/python3"
4645
embedded_site_packages_path = next(embedded_platform_path.glob("lib/python*/site-packages"))
47-
# lib_pattern = "my.*.so"
4846

4947
case "iOS":
5048
embedded_platform_path = PROJECT_DIR / f"addons/gdpy/macos-{cpu}"
5149
embedded_libgdpy_path = embedded_platform_path / "libgdpy.dylib"
5250
embedded_python_path = embedded_platform_path / "bin/python3"
5351
embedded_site_packages_path = next(embedded_platform_path.glob("lib/python*/site-packages"))
54-
# lib_pattern = "my.*.dylib"
5552

5653
case unknown:
5754
raise SystemExit(f"Unknown platform `{unknown}`")

0 commit comments

Comments
 (0)