11from __future__ import annotations
22
33from pathlib import Path
4- from platform import machine
5- from sys import platform
64
75from packaging .tags import platform_tags
86from setuptools import setup
@@ -15,16 +13,26 @@ def _get_platform_tag() -> str:
1513 See https://packaging.python.org/en/latest/specifications/platform-compatibility-tags/.
1614 """
1715
18- if platform == "darwin" :
16+ # generally return the first, meaning the most-specific, platform tag:
17+ tag = next (platform_tags ())
18+
19+ if tag .startswith ("macos_" ):
1920 # pip seems finicky about platform tags with larger macos versions, so just
2021 # tell arm64 is 11.0 and everything is is 10.9:
21- if machine () == "arm64" :
22+ if tag . endswith ( "_arm64" ) :
2223 return "macosx_11_0_arm64"
2324
2425 return "macosx_10_9_x86_64"
2526
26- # return the first, meaning the most-specific, platform tag:
27- return next (platform_tags ())
27+ if tag .startswith ("manylinux_" ):
28+ # The v8 build process bundles its own Linux sysroots which work on Linuxes at
29+ # least this old (regardless of the platform we build on):
30+ if tag .endswith ("_aarch64" ):
31+ return "manylinux_2_27_aarch64"
32+
33+ return "manylinux_2_27_x86_64"
34+
35+ return tag
2836
2937
3038# From https://stackoverflow.com/questions/76450587/python-wheel-that-includes-shared-library-is-built-as-pure-python-platform-indep:
@@ -36,6 +44,31 @@ def finalize_options(self) -> None:
3644 def get_tag (self ) -> tuple [str , str , str ]:
3745 return "py3" , "none" , _get_platform_tag ()
3846
47+ def run (self ) -> None :
48+ mini_racer_src_dir = Path (__file__ ).parent / "src" / "py_mini_racer"
49+ if (
50+ not (mini_racer_src_dir / "mini_racer.dll" ).exists ()
51+ and not (mini_racer_src_dir / "libmini_racer.so" ).exists ()
52+ and not (mini_racer_src_dir / "libmini_racer.dylib" ).exists ()
53+ ):
54+ # PyMiniRacer does not support a traditional from-source pip build, because
55+ # the v8 build is generally very slow, fragile, has many external
56+ # dependencies (exactly *which* depends on your system), and furthermore for
57+ # many systems the only viable build option is to cross-compile from
58+ # *another* system.
59+ # The intent of PyMiniRacer project is to build for all major platforms from
60+ # the GitHub home, and publish binary wheels to pip, so that you do not need
61+ # to build the wheel from source yourself.
62+ # If you want to build PyMiniRacer, you should use PyMiniRacer's build
63+ # system, starting with `just build-dll`, on a supported platform.
64+ # If you have an architecture that PyMiniRacer does not yet provide a wheel
65+ # for, consider contributing a pull request to add it at:
66+ # https://github.com/bpcreech/PyMiniRacer.
67+ msg = "Run `just build-dll` before building a PyMiniRacer wheel."
68+ raise RuntimeError (msg )
69+
70+ super ().run ()
71+
3972
4073def _generate_readme () -> str :
4174 return "\n " .join (
0 commit comments