|
11 | 11 | raise SystemExit(0) |
12 | 12 |
|
13 | 13 |
|
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 | | - |
87 | 14 | cmd = [sys.executable, "setup.py", "build_ext", "--build-lib", str(PROJECT_DIR)] |
88 | 15 | print(" ".join(cmd)) |
89 | 16 | subprocess.check_call( |
90 | 17 | cmd, |
91 | 18 | 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 | | - # }, |
97 | 19 | ) |
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) |
0 commit comments