mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
GH-114809: Add support for macOS multi-arch builds with the JIT enabled (#131751)
Co-authored-by: Ronald Oussoren <ronaldoussoren@mac.com> Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
This commit is contained in:
parent
2b67db7ce3
commit
26c0248b54
7 changed files with 152 additions and 102 deletions
|
@ -25,6 +25,7 @@ TOOLS = TOOLS_JIT.parent
|
|||
CPYTHON = TOOLS.parent
|
||||
PYTHON_EXECUTOR_CASES_C_H = CPYTHON / "Python" / "executor_cases.c.h"
|
||||
TOOLS_JIT_TEMPLATE_C = TOOLS_JIT / "template.c"
|
||||
ASYNCIO_RUNNER = asyncio.Runner()
|
||||
|
||||
_S = typing.TypeVar("_S", _schema.COFFSection, _schema.ELFSection, _schema.MachOSection)
|
||||
_R = typing.TypeVar(
|
||||
|
@ -35,6 +36,7 @@ _R = typing.TypeVar(
|
|||
@dataclasses.dataclass
|
||||
class _Target(typing.Generic[_S, _R]):
|
||||
triple: str
|
||||
condition: str
|
||||
_: dataclasses.KW_ONLY
|
||||
alignment: int = 1
|
||||
args: typing.Sequence[str] = ()
|
||||
|
@ -188,7 +190,12 @@ class _Target(typing.Generic[_S, _R]):
|
|||
return stencil_groups
|
||||
|
||||
def build(
|
||||
self, out: pathlib.Path, *, comment: str = "", force: bool = False
|
||||
self,
|
||||
out: pathlib.Path,
|
||||
*,
|
||||
comment: str = "",
|
||||
force: bool = False,
|
||||
stencils_h: str = "jit_stencils.h",
|
||||
) -> None:
|
||||
"""Build jit_stencils.h in the given directory."""
|
||||
if not self.stable:
|
||||
|
@ -197,14 +204,14 @@ class _Target(typing.Generic[_S, _R]):
|
|||
outline = "=" * len(warning)
|
||||
print("\n".join(["", outline, warning, request, outline, ""]))
|
||||
digest = f"// {self._compute_digest(out)}\n"
|
||||
jit_stencils = out / "jit_stencils.h"
|
||||
jit_stencils = out / stencils_h
|
||||
if (
|
||||
not force
|
||||
and jit_stencils.exists()
|
||||
and jit_stencils.read_text().startswith(digest)
|
||||
):
|
||||
return
|
||||
stencil_groups = asyncio.run(self._build_stencils())
|
||||
stencil_groups = ASYNCIO_RUNNER.run(self._build_stencils())
|
||||
jit_stencils_new = out / "jit_stencils.h.new"
|
||||
try:
|
||||
with jit_stencils_new.open("w") as file:
|
||||
|
@ -512,10 +519,12 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
|
|||
"""Build a _Target for the given host "triple" and options."""
|
||||
target: _COFF | _ELF | _MachO
|
||||
if re.fullmatch(r"aarch64-apple-darwin.*", host):
|
||||
target = _MachO(host, alignment=8, prefix="_")
|
||||
condition = "defined(__aarch64__) && defined(__APPLE__)"
|
||||
target = _MachO(host, condition, alignment=8, prefix="_")
|
||||
elif re.fullmatch(r"aarch64-pc-windows-msvc", host):
|
||||
args = ["-fms-runtime-lib=dll", "-fplt"]
|
||||
target = _COFF(host, alignment=8, args=args)
|
||||
condition = "defined(_M_ARM64)"
|
||||
target = _COFF(host, condition, alignment=8, args=args)
|
||||
elif re.fullmatch(r"aarch64-.*-linux-gnu", host):
|
||||
args = [
|
||||
"-fpic",
|
||||
|
@ -523,22 +532,27 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
|
|||
# was required to disable them.
|
||||
"-mno-outline-atomics",
|
||||
]
|
||||
target = _ELF(host, alignment=8, args=args)
|
||||
condition = "defined(__aarch64__) && defined(__linux__)"
|
||||
target = _ELF(host, condition, alignment=8, args=args)
|
||||
elif re.fullmatch(r"i686-pc-windows-msvc", host):
|
||||
args = [
|
||||
"-DPy_NO_ENABLE_SHARED",
|
||||
# __attribute__((preserve_none)) is not supported
|
||||
"-Wno-ignored-attributes",
|
||||
]
|
||||
target = _COFF(host, args=args, prefix="_")
|
||||
condition = "defined(_M_IX86)"
|
||||
target = _COFF(host, condition, args=args, prefix="_")
|
||||
elif re.fullmatch(r"x86_64-apple-darwin.*", host):
|
||||
target = _MachO(host, prefix="_")
|
||||
condition = "defined(__x86_64__) && defined(__APPLE__)"
|
||||
target = _MachO(host, condition, prefix="_")
|
||||
elif re.fullmatch(r"x86_64-pc-windows-msvc", host):
|
||||
args = ["-fms-runtime-lib=dll"]
|
||||
target = _COFF(host, args=args)
|
||||
condition = "defined(_M_X64)"
|
||||
target = _COFF(host, condition, args=args)
|
||||
elif re.fullmatch(r"x86_64-.*-linux-gnu", host):
|
||||
args = ["-fno-pic", "-mcmodel=medium", "-mlarge-data-threshold=0"]
|
||||
target = _ELF(host, args=args)
|
||||
condition = "defined(__x86_64__) && defined(__linux__)"
|
||||
target = _ELF(host, condition, args=args)
|
||||
else:
|
||||
raise ValueError(host)
|
||||
return target
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue