8000 GH-114809: Add support for macOS multi-arch builds with the JIT enabled by savannahostrowski · Pull Request #131751 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content
8000

GH-114809: Add support for macOS multi-arch builds with the JIT enabled #131751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
efd5863
First draft of supporting fat builds on macOS with the experimental JIT
ronaldoussoren Feb 20, 2024
4f493cd
merge conflict
savannahostrowski Sep 25, 2024
a55268e
fix up merge
savannahostrowski Sep 25, 2024
bce7980
add fix for CI?;
savannahostrowski Sep 25, 2024
b606b48
Fix up to make generic
savannahostrowski Sep 25, 2024
a382a44
Fix up conditions
savannahostrowski Sep 27, 2024
ff3d363
Save state before merge
savannahostrowski Mar 26, 2025
3bc2820
Merge main and fix conflicts
savannahostrowski Mar 26, 2025
348f2b6
Fix event loop binding error for _CORES in FAT builds
savannahostrowski Mar 26, 2025
4b31a30
📜🤖 Added by blurb_it.
blurb-it[bot] Mar 26, 2025
4564bc4
Try using weakref?
savannahostrowski Mar 26, 2025
2d381ca
Merge branch 'og_fat_build' of https://github.com/savannahostrowski/c…
savannahostrowski Mar 26, 2025
49f86a1
Remove weakref and lazily instantiate cores
savannahostrowski Mar 27, 2025
467ffe1
use Runner
savannahostrowski Apr 3, 2025
fd858bc
Merge branch 'main' into og_fat_build
savannahostrowski Apr 3, 2025
58649ff
Remove conditional and fix indentation in stencils
savannahostrowski Apr 11, 2025
182612c
Merge branch 'og_fat_build' of https://github.com/savannahostrowski/c…
savannahostrowski Apr 11, 2025
30a4d99
Merge branch 'main' into og_fat_build
savannahostrowski Apr 11, 2025
b172a41
CI updates
savannahostrowski Apr 11, 2025
18e77f2
Merge branch 'og_fat_build' of https://github.com/savannahostrowski/c…
savannahostrowski Apr 11, 2025
de3f896
Remove extra space
savannahostrowski Apr 11, 2025
7c22761
Fix condition typo
savannahostrowski Apr 11, 2025
c54250b
undo
savannahostrowski Apr 11, 2025
c21573f
Update jit.yml
savannahostrowski Apr 11, 2025
4332f10
Merge branch 'main' into og_fat_build
savannahostrowski Apr 16, 2025
dd5f196
Merge branch 'main' into og_fat_build
brandtbucher Apr 28, 2025
cdc4bfb
Merge branch 'main' into og_fat_build
savannahostrowski Apr 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix event loop binding error for _CORES in FAT builds
  • Loading branch information
savannahostrowski committed Mar 26, 2025
commit 348f2b6d24186acb28aa8ab7bdc5098feac93a1e
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Tools/unicode/data/
# hendrikmuhs/ccache-action@v1
/.ccache
/cross-build/
/jit_stencils.h
/jit_stencils*.h
/platform
/profile-clean-stamp
/profile-run-stamp
Expand Down
11 changes: 9 additions & 2 deletions Tools/jit/_llvm.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,19 @@ async def wrapper(
return wrapper


_CORES = asyncio.BoundedSemaphore(os.cpu_count() or 1)
_CORES: asyncio.BoundedSemaphore | None = None


def _get_cores() -> asyncio.BoundedSemaphore:
global _CORES
if _CORES is None:
_CORES = asyncio.BoundedSemaphore(os.cpu_count() or 1)
return _CORES


async def _run(tool: str, args: typing.Iterable[str], echo: bool = False) -> str | None:
command = [tool, *args]
async with _CORES:
async with _get_cores():
if echo:
print(shlex.join(command))
try:
Expand Down
10 changes: 3 additions & 7 deletions Tools/jit/_targets.py
8000
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
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(
Expand All @@ -45,7 +44,6 @@ class _Target(typing.Generic[_S, _R]):
debug: bool = False
verbose: bool = False
known_symbols: dict[str, int] = dataclasses.field(default_factory=dict)
basename: str = ""

def _compute_digest(self, out: pathlib.Path) -> str:
hasher = hashlib.sha256()
Expand Down Expand Up @@ -201,7 +199,7 @@ def build(
and jit_stencils.read_text().startswith(digest)
):
return
stencil_groups = ASYNCIO_RUNNER.run(self._build_stencils())
stencil_groups = asyncio.run(self._build_stencils())
jit_stencils_new = out / "jit_stencils.h.new"
try:
with jit_stencils_new.open("w") as file:
Expand Down Expand Up @@ -506,9 +504,7 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
target: _COFF | _ELF | _MachO
if re.fullmatch(r"aarch64-apple-darwin.*", host):
condition = "defined(__aarch64__) && defined(__APPLE__)"
target = _MachO(
host, condition, alignment=8, prefix="_", basename="aarch64-apple-darwin"
)
target = _MachO(host, condition, alignment=8, prefix="_")
elif re.fullmatch(r"aarch64-pc-windows-msvc", host):
args = ["-fms-runtime-lib=dll", "-fplt"]
condition = "defined(_M_ARM64)"
Expand All @@ -532,7 +528,7 @@ def get_target(host: str) -> _COFF | _ELF | _MachO:
target = _COFF(host, condition, args=args, prefix="_")
elif re.fullmatch(r"x86_64-apple-darwin.*", host):
condition = "defined(__x86_64__) && defined(__APPLE__)"
target = _MachO(host, condition, prefix="_", basename="x86_64-apple-darwin")
target = _MachO(host, condition, prefix="_")
elif re.fullmatch(r"x86_64-pc-windows-msvc", host):
args = ["-fms-runtime-lib=dll"]
condition = "defined(_M_X64)"
Expand Down
18 changes: 6 additions & 12 deletions Tools/jit/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,14 @@
"-v", "--verbose", action="store_true", help="echo commands as they are run"
)
args = parser.parse_args()
print(args.target)

if len(args.target) == 1:
# Single triple specified, assume this is a normal build
target = args.target[0]
target.debug = args.debug
target.force = args.force
target.verbose = args.verbose
target.build(pathlib.Path.cwd(), comment=comment)
args.target.debug = args.debug
args.target.verbose = args.verbose
args.target.build(pathlib.Path.cwd(), comment=comment, force=args.force)

else:
# Multiple triples specified, assume this is a macOS multi-architecture build
# - Generate multiple stencil headers
# - Generate a helper header that includes the stencils for the current
# architecture.
# Build for multiple targets (e.g. universal2)
for target in args.target:
target.debug = args.debug
target.force = args.force
Expand All @@ -49,6 +42,7 @@
pathlib.Path.cwd(),
comment=comment,
stencils_h=f"jit_stencils-{target.triple}.h",
force=args.force,
)

with open("jit_stencils.h", "w") as fp:
Expand All @@ -57,5 +51,5 @@
fp.write(f'# include "jit_stencils-{target.triple}.h"\n')

fp.write("#else\n")
fp.write('# error "unexpected cpu type"\n')
fp.write('# error "unexpected target"\n')
fp.write("#endif\n")
Loading
0